winston added as our logger by default
This commit is contained in:
parent
0a2eb7972d
commit
f2bb705960
15
bot/index.js
15
bot/index.js
|
@ -1,16 +1,25 @@
|
||||||
|
const winston = require('winston');
|
||||||
const SignerProvider = require('ethjs-provider-signer');
|
const SignerProvider = require('ethjs-provider-signer');
|
||||||
const sign = require('ethjs-signer').sign;
|
const sign = require('ethjs-signer').sign;
|
||||||
const Eth = require('ethjs-query');
|
const Eth = require('ethjs-query');
|
||||||
const prices = require('./prices');
|
const prices = require('./prices');
|
||||||
const config = require('../config');
|
const config = require('../config');
|
||||||
|
|
||||||
|
|
||||||
const provider = new SignerProvider(config.signerPath, {
|
const provider = new SignerProvider(config.signerPath, {
|
||||||
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, process.env.KEY)),
|
signTransaction: (rawTx, cb) => cb(null, sign(rawTx, process.env.KEY)),
|
||||||
accounts: (cb) => cb(null, [address]),
|
accounts: (cb) => cb(null, [address]),
|
||||||
});
|
});
|
||||||
const eth = new Eth(provider);
|
const eth = new Eth(provider);
|
||||||
|
|
||||||
|
const logger = winston.createLogger({
|
||||||
|
level: 'info',
|
||||||
|
format: winston.format.json(),
|
||||||
|
transports: [
|
||||||
|
new winston.transports.File({ filename: 'error.log', level: 'error' }),
|
||||||
|
new winston.transports.File({ filename: 'info.log', level: 'info'}),
|
||||||
|
new winston.transports.File({ filename: 'combined.log' })
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
const bountyLabels = {
|
const bountyLabels = {
|
||||||
'bounty-xs': 1,
|
'bounty-xs': 1,
|
||||||
|
@ -69,8 +78,8 @@ const getGasPrice = function(req) {
|
||||||
// Check how to handle errors when promises does not arrive
|
// Check how to handle errors when promises does not arrive
|
||||||
}
|
}
|
||||||
|
|
||||||
const log = function() {
|
const log = function(msg) {
|
||||||
console.log(arguments);
|
logger.info(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
96
index.js
96
index.js
|
@ -1,67 +1,67 @@
|
||||||
/*
|
/*
|
||||||
* Bot that receives a POST request (from a GitHub issue comment webhook)
|
* Bot that receives a POST request (from a GitHub issue comment webhook)
|
||||||
* and in case it's a comment that has "@autobounty <decimal> <currency>"
|
* 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
|
* awards that bounty to the address posted earlier in the thread (by the
|
||||||
* commiteth bot).
|
* commiteth bot).
|
||||||
* TODO tests
|
* TODO tests
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
const bot = require('./bot');
|
const bot = require('./bot');
|
||||||
|
|
||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
cors = require('cors'),
|
cors = require('cors'),
|
||||||
helmet = require('helmet'),
|
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());
|
app.use(helmet());
|
||||||
|
|
||||||
// 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.urlEndpoint}`, jsonParser, function(req, res, next) {
|
app.post(`${config.urlEndpoint}`, jsonParser, function(req, res, next) {
|
||||||
// TODO decide how long the delay to start everything should be
|
// TODO decide how long the delay to start everything should be
|
||||||
if (!req.body || !req.body.action)
|
if (!req.body || !req.body.action)
|
||||||
return res.sendStatus(400);
|
return res.sendStatus(400);
|
||||||
|
|
||||||
if (!bot.needsFunding(req))
|
if (!bot.needsFunding(req))
|
||||||
return res.sendStatus(204);
|
return res.sendStatus(204);
|
||||||
|
|
||||||
//const eth = bot.eth;
|
//const eth = bot.eth;
|
||||||
//const from = config.sourceAddress;
|
//const from = config.sourceAddress;
|
||||||
//const to = bot.getAddress(req);
|
//const to = bot.getAddress(req);
|
||||||
const amount = bot.getAmount(req);
|
const amount = bot.getAmount(req);
|
||||||
const gasPrice = bot.getGasPrice();
|
const gasPrice = bot.getGasPrice();
|
||||||
console.log('amount: ', amount);
|
bot.log('amount: ' + amount);
|
||||||
console.log('gasPrice: ', gasPrice);
|
bot.log('gasPrice: ' + gasPrice);
|
||||||
/*
|
/*
|
||||||
eth.getTransactionCount(address, (err, nonce) => {
|
eth.getTransactionCount(address, (err, nonce) => {
|
||||||
eth.sendTransaction({
|
eth.sendTransaction({
|
||||||
from: from,
|
from: from,
|
||||||
to: to,
|
to: to,
|
||||||
gas: gas,
|
gas: gas,
|
||||||
gasPrice: gasPrice,
|
gasPrice: gasPrice,
|
||||||
value: amount,
|
value: amount,
|
||||||
nonce,
|
nonce,
|
||||||
}, (err, txID) => {
|
}, (err, txID) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
config.log('Request failed', err)
|
config.log('Request failed', err)
|
||||||
return res.status(500).json(err)
|
return res.status(500).json(err)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
config.log('Successful request:', txID)
|
config.log('Successful request:', txID)
|
||||||
res.json({ txID })
|
res.json({ txID })
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
*/
|
*/
|
||||||
return res.sendStatus(200);
|
return res.sendStatus(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
const port = process.env.PORT || 8181
|
const port = process.env.PORT || 8181
|
||||||
app.listen(port, function(){
|
app.listen(port, function(){
|
||||||
console.log('Autobounty listening on port', port);
|
console.log('Autobounty listening on port', port);
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
"express": "^4.15.2",
|
"express": "^4.15.2",
|
||||||
"helmet": "^3.9.0",
|
"helmet": "^3.9.0",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"web3": "^0.18.2"
|
"web3": "^0.18.2",
|
||||||
|
"winston": "^2.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue