Merge pull request #25 from 67P/update-kredits-contracts
Update kredits contracts
This commit is contained in:
commit
8cfbc222fc
35
index.js
35
index.js
@ -6,7 +6,7 @@ const Kredits = require('kredits-contracts');
|
||||
|
||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||
const walletJson = fs.readFileSync(walletPath);
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL || 'http://localhost:7545';
|
||||
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||
const networkId = parseInt(process.env.KREDITS_NETWORK_ID || 100);
|
||||
|
||||
const ipfsConfig = {
|
||||
@ -27,9 +27,9 @@ module.exports = async function(robot) {
|
||||
|
||||
let wallet;
|
||||
try {
|
||||
wallet = await ethers.Wallet.fromEncryptedWallet(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
||||
wallet = await ethers.Wallet.fromEncryptedJson(walletJson, process.env.KREDITS_WALLET_PASSWORD);
|
||||
} catch(error) {
|
||||
robot.logger.warn('[hubot-kredits] Could not load wallet:', error);
|
||||
robot.logger.warning('[hubot-kredits] Could not load wallet:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
@ -37,9 +37,13 @@ module.exports = async function(robot) {
|
||||
// Ethereum provider/node setup
|
||||
//
|
||||
|
||||
const ethProvider = new ethers.providers.JsonRpcProvider(providerUrl, {chainId: networkId});
|
||||
ethProvider.signer = wallet;
|
||||
wallet.provider = ethProvider;
|
||||
let ethProvider;
|
||||
if (providerUrl) {
|
||||
ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
||||
} else {
|
||||
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||
}
|
||||
const signer = wallet.connect(ethProvider);
|
||||
|
||||
//
|
||||
// Kredits contracts setup
|
||||
@ -47,13 +51,18 @@ module.exports = async function(robot) {
|
||||
|
||||
let kredits;
|
||||
try {
|
||||
kredits = await Kredits.setup(ethProvider, wallet, ipfsConfig);
|
||||
kredits = await new Kredits(signer.provider, signer, {
|
||||
// TODO support local devchain custom address
|
||||
apm: 'open.aragonpm.eth',
|
||||
ipfsConfig
|
||||
}).init();
|
||||
} catch(error) {
|
||||
robot.logger.warn('[hubot-kredits] Could not set up kredits:', error);
|
||||
robot.logger.warning('[hubot-kredits] Could not set up kredits:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
const Contributor = kredits.Contributor;
|
||||
const Operator = kredits.Operator;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
robot.logger.info('[hubot-kredits] Wallet address: ' + wallet.address);
|
||||
|
||||
@ -74,7 +83,7 @@ module.exports = async function(robot) {
|
||||
|
||||
robot.respond(/got ETH\??/i, res => {
|
||||
ethProvider.getBalance(wallet.address).then((balance) => {
|
||||
res.send(`my wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
||||
res.send(`My wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
||||
});
|
||||
});
|
||||
|
||||
@ -87,7 +96,7 @@ module.exports = async function(robot) {
|
||||
});
|
||||
|
||||
robot.respond(/list open proposals/i, res => {
|
||||
Operator.all().then((proposals) => {
|
||||
Proposal.all().then((proposals) => {
|
||||
proposals.forEach((proposal) => {
|
||||
if (!proposal.executed) {
|
||||
Contributor.getById(proposal.contributorId).then((contributor) => {
|
||||
@ -111,13 +120,13 @@ module.exports = async function(robot) {
|
||||
robot.logger.debug(`[hubot-kredits] Watching events from block ${nextBlock} onward`);
|
||||
ethProvider.resetEventsBlock(nextBlock);
|
||||
|
||||
Operator.on('ProposalCreated', handleProposalCreated);
|
||||
Proposal.on('ProposalCreated', handleProposalCreated);
|
||||
});
|
||||
}
|
||||
|
||||
function handleProposalCreated(proposalId, creatorAccount, contributorId, amount) {
|
||||
Contributor.getById(contributorId).then((contributor) => {
|
||||
Operator.getById(proposalId).then((proposal) => {
|
||||
Proposal.getById(proposalId).then((proposal) => {
|
||||
robot.logger.debug(`[hubot-kredits] Proposal created (${proposal.description})`);
|
||||
// messageRoom(`Let's give ${contributor.name} some kredits for ${proposal.url} (${proposal.description}): https://kredits.kosmos.org`);
|
||||
});
|
||||
|
@ -16,7 +16,8 @@ module.exports = async function(robot, kredits) {
|
||||
}
|
||||
|
||||
const Contributor = kredits.Contributor;
|
||||
const Operator = kredits.Operator;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
function getContributorByGithubUser(username) {
|
||||
return Contributor.all().then(contributors => {
|
||||
@ -45,7 +46,7 @@ module.exports = async function(robot, kredits) {
|
||||
kind: 'dev'
|
||||
};
|
||||
|
||||
return Operator.addProposal(contributionAttr).catch(error => {
|
||||
return Proposal.addProposal(contributionAttr).catch(error => {
|
||||
robot.logger.error(`[hubot-kredits] Error:`, error);
|
||||
messageRoom(`I wanted to propose giving kredits to GitHub user ${githubUser} for ${url}, but I cannot find their info. Please add them as a contributor: https://kredits.kosmos.org`);
|
||||
});
|
||||
|
@ -13,7 +13,8 @@ module.exports = async function(robot, kredits) {
|
||||
robot.logger.debug('[hubot-kredits] Loading MediaWiki integration...')
|
||||
|
||||
const Contributor = kredits.Contributor;
|
||||
const Operator = kredits.Operator;
|
||||
const Proposal = kredits.Proposal;
|
||||
const Contribution = kredits.Contribution;
|
||||
|
||||
const wikiURL = process.env.KREDITS_MEDIAWIKI_URL;
|
||||
const apiURL = wikiURL + 'api.php';
|
||||
@ -43,7 +44,7 @@ module.exports = async function(robot, kredits) {
|
||||
kind: 'docs'
|
||||
};
|
||||
|
||||
return Operator.addProposal(contribution).catch(error => {
|
||||
return Proposal.addProposal(contribution).catch(error => {
|
||||
robot.logger.error(`[hubot-kredits] Adding proposal failed:`, error);
|
||||
});
|
||||
}).catch(() => {
|
||||
|
1585
package-lock.json
generated
1585
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@ -10,13 +10,14 @@
|
||||
"create-wallet": "scripts/create-wallet.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"ethers": "^3.0.15",
|
||||
"eth-provider": "^0.2.2",
|
||||
"ethers": "^4.0.27",
|
||||
"group-array": "^0.3.3",
|
||||
"kosmos-schemas": "^1.1.2",
|
||||
"node-cron": "^1.2.1",
|
||||
"node-fetch": "^1.6.3",
|
||||
"prompt": "^1.0.0",
|
||||
"kredits-contracts": "3.x"
|
||||
"kredits-contracts": "4.x",
|
||||
"node-cron": "^2.0.3",
|
||||
"node-fetch": "^2.3.0",
|
||||
"prompt": "^1.0.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
Loading…
x
Reference in New Issue
Block a user