It works!
This commit is contained in:
parent
44a2b49e2b
commit
217219fc68
92
index.js
92
index.js
@ -35,22 +35,87 @@ engine.addProvider(new Web3Subprovider(new Web3.providers.HttpProvider(providerU
|
|||||||
engine.start();
|
engine.start();
|
||||||
|
|
||||||
let web3 = new Web3(engine);
|
let web3 = new Web3(engine);
|
||||||
|
web3.eth.defaultAccount = hubotWalletAddress;
|
||||||
|
|
||||||
let contracts = kreditsContracts(web3, config);
|
let contracts = kreditsContracts(web3, config);
|
||||||
let Kredits = contracts['Kredits'];
|
let kredits = contracts['Kredits'];
|
||||||
|
|
||||||
console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
console.log('[HUBOT-KREDITS] Wallet address: ' + hubotWalletAddress);
|
||||||
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
|
||||||
if (err) { console.log('[HUBOT-KREDITS] Error checking balance'); return; }
|
|
||||||
if (balance <= 0) {
|
|
||||||
console.log('[HUBOT-KREDITS] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
||||||
|
if (err) { console.log('[HUBOT-KREDITS] Error checking balance'); return; }
|
||||||
|
if (balance <= 0) {
|
||||||
|
console.log('[HUBOT-KREDITS] Hubot is broke. Please send some ETH to ' + hubotWalletAddress);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let getValueFromContract = function(contractMethod, ...args) {
|
||||||
|
console.log('[kredits] read from contract', contractMethod, ...args);
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
kredits[contractMethod](...args, (err, data) => {
|
||||||
|
if (err) { reject(err); }
|
||||||
|
resolve(data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let getContributorData = function(i) {
|
||||||
|
let promise = new Promise((resolve, reject) => {
|
||||||
|
getValueFromContract('contributorAddresses', i).then(address => {
|
||||||
|
console.log('address', address);
|
||||||
|
getValueFromContract('contributors', address).then(person => {
|
||||||
|
console.log('person', person);
|
||||||
|
let contributor = {
|
||||||
|
address: address,
|
||||||
|
github_username: person[1],
|
||||||
|
github_uid: person[0],
|
||||||
|
ipfsHash: person[2]
|
||||||
|
};
|
||||||
|
console.log('[kredits] contributor', contributor);
|
||||||
|
resolve(contributor);
|
||||||
|
});
|
||||||
|
}).catch(err => reject(err));
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
let getContributors = function() {
|
||||||
|
return getValueFromContract('contributorsCount').then(contributorsCount => {
|
||||||
|
let contributors = [];
|
||||||
|
|
||||||
|
for(var i = 0; i < contributorsCount.toNumber(); i++) {
|
||||||
|
contributors.push(getContributorData(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.all(contributors);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
let getContributorByGithubUser = function(username) {
|
||||||
|
let promise = new Promise((resolve, reject) => {
|
||||||
|
getContributors().then(contributors => {
|
||||||
|
let contrib = contributors.find(c => {
|
||||||
|
return c.github_username === username;
|
||||||
|
});
|
||||||
|
if (contrib) {
|
||||||
|
resolve(contrib);
|
||||||
|
} else {
|
||||||
|
reject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return promise;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = function(robot) {
|
module.exports = function(robot) {
|
||||||
|
|
||||||
|
function messageRoom(message) {
|
||||||
|
robot.messageRoom(process.env.KREDITS_ROOM, message);
|
||||||
|
}
|
||||||
|
|
||||||
function amountFromIssueLabels(issue) {
|
function amountFromIssueLabels(issue) {
|
||||||
let kreditsLabel = issue.labels.map(l => l.name)
|
let kreditsLabel = issue.labels.map(l => l.name)
|
||||||
.filter(n => n.match(/^kredits/))[0];
|
.filter(n => n.match(/^kredits/))[0];
|
||||||
@ -75,12 +140,19 @@ web3.eth.getBalance(hubotWalletAddress, function (err, balance) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function createProposal(recipient, amount, url/*, metaData*/) {
|
function createProposal(recipient, amount, url/*, metaData*/) {
|
||||||
return new Promise((resolve/*, reject*/) => {
|
return new Promise((resolve, reject) => {
|
||||||
// TODO write metaData to IPFS
|
// TODO write metaData to IPFS
|
||||||
console.log(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
|
console.log(`Creating proposal to issue ${amount}₭S to ${recipient} for ${url}...`);
|
||||||
|
|
||||||
Kredits.addProposal(recipient, amount, url, '');
|
getContributorByGithubUser(recipient).then(c => {
|
||||||
robot.messageRoom(process.env.KREDITS_ROOM, `new proposal: ${amount} for ${recipient}`);
|
kredits.addProposal(c.address, amount, url, '', (e/* , d */) => {
|
||||||
|
if (e) { reject(); return; }
|
||||||
|
messageRoom(`New proposal created: ${amount} for ${recipient}`);
|
||||||
|
});
|
||||||
|
}, () => {
|
||||||
|
messageRoom(`Couldn\'t find contributor data for ${recipient}. Please add them first!`);
|
||||||
|
});
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ethereumjs-wallet": "mvayngrib/ethereumjs-wallet",
|
"ethereumjs-wallet": "mvayngrib/ethereumjs-wallet",
|
||||||
"kredits-contracts": "67p/kredits-contracts",
|
"kredits-contracts": "2.0.0",
|
||||||
"node-fetch": "^1.6.3",
|
"node-fetch": "^1.6.3",
|
||||||
"prompt": "^1.0.0",
|
"prompt": "^1.0.0",
|
||||||
"web3": "^0.18.4",
|
"web3": "^0.18.4",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user