WIP: autobounty

This commit is contained in:
Jordi Montes 2018-01-19 11:42:58 +01:00
parent 96ebc1d70f
commit 19e3df1938
2 changed files with 68 additions and 66 deletions

View File

@ -1,4 +1,41 @@
module.exports={ const SignerProvider = require('ethjs-provider-signer');
webhook: {URLEndpoint: "/autobounty/fund"}, const sign = require('ethjs-signer').sign;
bounty: {} const Eth = require('ethjs-query');
const provider = new SignerProvider(process.env.NODE, {
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, process.env.KEY)),
accounts: (cb) => cb(null, [address]),
});
const eth = new Eth(provider);
const needsFunding = function(req) {
if (req.action !== 'created' || !req.hasOwnProperty('comment'))
return false
else if (req.comment.user.login !== 'status-open-bounty')
return false
return true
}
const getAddress = function(req) {
commentBody = req.body.comment.body;
return commentBody.substring(commentBody.search("Contract address:") + 18, commentBody.search("Contract address:") + 60)
}
const getAmount = function(req) {
return 0;
}
const log = function() {
console.log(arguments);
}
module.exports = {
webhook: {URLEndpoint: "/autobounty/fund"},
eth: new Eth(provider),
needsFunding: needsFunding,
getAddress: getAddress,
getAmount: getAmount,
log: log
} }

View File

@ -7,84 +7,49 @@
* REVIEW parsing, non-persisting storage of addresses, hardcoded string length. * REVIEW parsing, non-persisting storage of addresses, hardcoded string length.
* Depends on commiteth version as of 2017-06-10. * Depends on commiteth version as of 2017-06-10.
*/ */
https://duckduckgo.com/
const config = require('./config'); const config = require('./config');
const SignerProvider = require('ethjs-provider-signer');
const sign = require('ethjs-signer').sign;
const Eth = require('ethjs-query');
const address = process.env.ADDRESS;
const name = process.env.NAME;
const provider = new SignerProvider(process.env.NODE, {
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, process.env.KEY)),
accounts: (cb) => cb(null, [address]),
});
const eth = new Eth(provider);
var express = require('express'), var express = require('express'),
cors = require('cors'), cors = require('cors'),
helmet = require('helmet'),
app = express(), app = express(),
bodyParser = require('body-parser'), bodyParser = require('body-parser'),
jsonParser = bodyParser.json(); jsonParser = bodyParser.json();
app.use(cors()); app.use(cors());
app.use(helmet());
// Store issue ids and their bounty addresses
var issueData = {};
// Receive a POST request at the address specified by an env. var. // Receive a POST request at the address specified by an env. var.
app.post(`${config.webhook.URLEndpoint}`, jsonParser, function(req, res, next){ app.post(`${config.webhook.URLEndpoint}`, jsonParser, function(req, res, next) {
if (!req.body) if (!req.body || !req.body.action)
return res.sendStatus(400); return res.sendStatus(400);
return res.sendStatus(200)
/*var commentBody = req.body.comment.body; if (!config.needsFunding(req))
var issueId = req.body.issue.id; return res.sendStatus(204);
var namePosition = commentBody.search("@" + name);
// Store toAddress from commiteth const eth = config.eth;
if (namePosition == -1 ) { const address = config.address;
if (req.body.comment.user.login == 'commiteth') { // TODO no existence check const toAddress = config.getAddress(req);
issueData[issueId] = {"toAddress": commentBody.substring(commentBody.search("Contract address:") + 18, commentBody.search("Contract address:") + 60)} const amount = config.getAmount(req);
console.log(issueData);
return res.status(204); eth.getTransactionCount(address, (err, nonce) => {
} eth.sendTransaction({
} from: address,
else { to: toAddress, // Address from earlier in the thread
var postNameWords = commentBody.substring(namePosition + 1 + name.length + 1).trim().split(' '); gas: 100000,
var amount = 0; value: amount,
if (postNameWords.length > 0) { nonce,
if(postNameWords[0] == "standard") { }, (err, txID) => {
amount = process.env.STANDARD_BOUNTY; if (err) {
config.log('Request failed', err)
return res.status(500).json(err)
} }
else { else {
amount = parseFloat(postNameWords[0]); config.log('Successful request:', txID)
res.json({ txID })
} }
} });
console.log("Trying to give " + amount + " ETH to " + issueData[issueId].toAddress + " for issue " + issueId);
issueData[issueId].amount = amount;
// Conduct the transaction
eth.getTransactionCount(address, (err, nonce) => {
eth.sendTransaction({
from: address, // Specified in webhook, secret
to: issueData[issueId].toAddress, // Address from earlier in the thread
gas: 100000,
value: issueData[issueId].amount,
nonce,
}, (err, txID) => {
if (err) {
console.log('Request failed', err)
return res.status(500).json(err)
}
else {
console.log('Successful request:', txID)
res.json({ txID })
}
});
});
}*/
}); });
const port = process.env.PORT || 8181 const port = process.env.PORT || 8181