autobounty/index.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-06-10 15:07:15 +00:00
/*
* Bot that receives a POST request (from a GitHub issue comment webhook)
* and in case it's a comment that has "@autobounty <decimal> <currency>"
* awards that bounty to the address posted earlier in the thread (by the
* commiteth bot).
2017-06-10 18:24:34 +00:00
* TODO tests
2017-06-14 12:34:26 +00:00
* REVIEW parsing, non-persisting storage of addresses, hardcoded string length.
* Depends on commiteth version as of 2017-06-10.
2017-06-10 15:07:15 +00:00
*/
2018-01-17 16:48:56 +00:00
const config = require('./config');
const bot = require('./bot');
2018-01-17 16:48:56 +00:00
2017-06-09 10:15:53 +00:00
var express = require('express'),
cors = require('cors'),
2018-01-19 10:42:58 +00:00
helmet = require('helmet'),
2017-06-11 06:23:57 +00:00
app = express(),
bodyParser = require('body-parser'),
jsonParser = bodyParser.json();
2017-03-07 11:24:01 +00:00
app.use(cors());
2018-01-19 10:42:58 +00:00
app.use(helmet());
2018-01-17 16:48:56 +00:00
2017-06-10 15:07:15 +00:00
// Receive a POST request at the address specified by an env. var.
app.post(`${config.urlEndpoint}`, jsonParser, function(req, res, next) {
// TODO decide how long the delay to start everything should be
2018-01-19 10:42:58 +00:00
if (!req.body || !req.body.action)
return res.sendStatus(400);
2018-01-19 10:42:58 +00:00
2018-01-20 13:15:49 +00:00
if (!bot.needsFunding(req))
2018-01-19 10:42:58 +00:00
return res.sendStatus(204);
2018-01-20 13:15:49 +00:00
//const eth = bot.eth;
//const from = config.sourceAddress;
//const to = bot.getAddress(req);
const amount = bot.getAmount(req);
const gasPrice = bot.getGasPrice();
2018-01-20 13:15:49 +00:00
console.log('amount: ', amount);
console.log('gasPrice: ', gasPrice);
/*
2018-01-19 10:42:58 +00:00
eth.getTransactionCount(address, (err, nonce) => {
eth.sendTransaction({
from: from,
to: to,
gas: gas,
gasPrice: gasPrice,
2018-01-19 10:42:58 +00:00
value: amount,
nonce,
}, (err, txID) => {
if (err) {
config.log('Request failed', err)
return res.status(500).json(err)
2017-03-10 09:01:43 +00:00
}
else {
2018-01-19 10:42:58 +00:00
config.log('Successful request:', txID)
res.json({ txID })
2017-03-10 09:01:43 +00:00
}
2018-01-20 12:36:58 +00:00
});
});
2018-01-20 13:15:49 +00:00
*/
return res.sendStatus(200);
2017-03-07 11:24:01 +00:00
});
const port = process.env.PORT || 8181
app.listen(port, function(){
console.log('Autobounty listening on port', port);
2017-06-10 18:24:34 +00:00
});