Merge branch 'config' of https://github.com/jomsdev/autobounty into config

This commit is contained in:
Pol.Alvarez@BSC 2018-01-25 14:05:48 +01:00
commit 27830b5d0b
2 changed files with 41 additions and 18 deletions

View File

@ -28,12 +28,11 @@ app.post(`${config.urlEndpoint}`, jsonParser, function (req, res, next) {
} else if (!bot.needsFunding(req)) {
return res.sendStatus(204);
}
console.log('new req to process:' + req.body);
setTimeout(() => {
processRequest(req)
.then(() => {
console.log('Well funded');
})
bot.info('issue well funded: ' + res.body.issue.url);
})
.catch((err) => {
bot.error('Error funding issue: ' + req.body.issue.url);
bot.error('error: ' + err);
@ -52,9 +51,8 @@ const processRequest = function (req) {
// Asynchronous requests for Gas Price and Amount
const amountPromise = bot.getAmount(req);
const gasPricePromise = bot.getGasPrice();
console.log('processingRequest...');
return new Promise((resolve, reject) => {
Promise.all([amountPromise, gasPricePromise])
Promise.all([amountPromise, gasPricePromise])
.then(function (results) {
let amount = results[0];
let gasPrice = results[1];
@ -72,11 +70,10 @@ const processRequest = function (req) {
.catch(function (err) {
reject(err);
});
});
});
}
const sendTransaction = function (eth, from, to, amount, gasPrice) {
console.log('sending transaction...');
return new Promise((resolve, reject) => {
if (!config.realTransaction) {
let txID = -1;

View File

@ -13,19 +13,26 @@ All issues tagged with **[bounty](https://github.com/status-im/status-react/issu
#### The process
- An **[issue](https://github.com/status-im/status-react/issues)** is created at the repo
- Issue is labeled with **[bounty](https://github.com/status-im/status-react/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Abounty)** and **bounty-{xs,s,m,l,xl}**
- [Status OpenBounty](https://openbounty.status.im/) bot adds a bounty to the issue and it is displayed in the issue's comments
- This autobounty bot automatically funds that issue with a set amount of tokens based on another label decribing the size of the bounty based roughly on how many hours the team feels it will take to complete * the rate per hour they are willing to pay. When a successful Pull Request is merged, the contributor is paid that amount for their work autonomously, transparently and programmatically by the smart contract itself - no middle men involved at all.
1. An **[issue](https://github.com/status-im/status-react/issues)** is created at the repo
2. Issue is labeled with **[bounty](https://github.com/status-im/status-react/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Abounty)** and **bounty-{xs,s,m,l,xl}**
3. [Status OpenBounty](https://openbounty.status.im/) bot adds a bounty to the issue and it is displayed in the issue's comments
4. Webhook is triggered for issue comments.
5. Autobounty checks if the request needs funding (by default: if the user status-open-bounty posts a new comment). If it needs funding proceed to 6 otherwise do nothing.
6. Bot waits for X minutes (configurable parameter) to allow label corrections before proceeding.
7. Address to fund is obtained from status-open-bounty comment.
8. Amount to fund is computed as the hours of work corresponding to the given label times the configured price per hour divided by the token price obtained from etherscan.io (amount_of_work * price_per_hour / token_price).
9. The gas price for the transaction is retrieved from ethgasstation and the maximum gas used is a config param.
10. With all the information the bot funds the bounty from config param *sourceAddress*.
#### Configuration
This bot can be build using docker.
##### Bot config
* Remember to create the folder for the logPath before running the build.
Autobounty is build using docker. Before building the image, you need to set up a configuration as follows:
The [config]() folder contains the files for configuring the bot. The description for the variables can be found in *default.js*. Create a production config file (e.g. *production.js*) uing the {default,development}.js as template to override the default ones. **Remeber** to set the environment variable *NODE_ENV* in the dockerfile (e.g. `ENV NODE_ENV production`).
The [config]() folder contains the files for configuring the bot. The description for the variables can be found in *default.js*:
```javascript
// Debug mode for testing the bot
@ -34,7 +41,9 @@ The [config]() folder contains the files for configuring the bot. The descriptio
// URL where the bot is listening (e.g. '/funding')
urlEndpoint: '',
// Path for the log files (e.g. './log/')
// Path for the log files inside the docker image (e.g. './log/'),
remember to create the folder inside the docker workspace if you change it
(the folde will be copied to the docker image during the build)
logPath: '',
// URL for the signer (e.g. 'https://ropsten.infura.io')
@ -65,12 +74,29 @@ The [config]() folder contains the files for configuring the bot. The descriptio
realTransaction: false
```
The idea is to deploy the bot running
##### Github Webhook
Create a github webhook with the following information:
* Payoload URL: IP_HOST/URL_ENDPOINT
* Content Type: application/json
* Secret: blank
* Configure the webhook to be triggered by comments in issues selecting the Issue Comment box in 'Let me select individual events'
Where *IP_HOST* is the ip of the machine running the docker image and *URL_ENDPOINT* is the configuration variable with the same name in your custom config file.
#### Build
To build and run the docker image issue the following commands:
```bash
docker build -t autobounty .
docker run -p 8080:8080 autobounty
```
- Configure the PORT and NODE_ENV variables in the Dockerfile
- Create a production.js file using the {default,development}.js as example
#### Important Notes
* Bot always **aborts on error** and logs the cause of the error on the file *${LOG_PATH}/error.log*. The aborted transaction must then be manually funded.
* **Only one token** can be specified on the configuration file variable *token*.
* Autobounty bot assumes that the status-open-bounty will only post a single message. In case two messages are posted the issue would be **funded two times**.
The ongoing requests are not recorded in any persistent data storage. If the machine crashes during a request processing the request will be lost.