-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathmassPayment.js
68 lines (61 loc) · 2.36 KB
/
massPayment.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var fs = require('fs');
var request = require('request');
/**
* Put your settings here:
* - filename: file to which the payments for the mass payment tool are written
* - node: address of your node in the form http://<ip>:<port>
* - apiKey: the API key of the node that is used for distribution
* - feeAssetId: id of the asset used to pay the fee, null for Waves
* - fee: amount of fee to spend for the tx
*/
var config = {
filename: '<your payments file>',
node: 'http://<ip>:<port>',
apiKey: 'put the apiKey for the node here',
feeAssetId: null,
fee: 10000
};
/**
* The method that starts the payment process.
*/
var start = function() {
var paymentsString = fs.readFileSync(config.filename).toString();
var payments = JSON.parse(paymentsString);
// start with the first payment, in case there is an error in the process,
// it could just be restarted by changing the 0 to the the last successful
// transmission increased by 1.
doPayment(payments, 0);
};
/**
* This method executes the actual payment transactions. One per second, so that the network
* is not flooded. This could potentially be modified once the transaction limit of 100 tx
* per block is raised.
*
* @param payments the array of payments (necessary to start this method recursively)
* @param counter the current payment that should be done
*/
var doPayment = function(payments, counter) {
var payment = payments[counter];
if (config.feeAssetId !== null) {
payment.feeAssetId = config.feeAssetId;
payment.fee = config.fee;
}
setTimeout(function() {
request.post({ url: config.node + '/assets/transfer', json: payment, headers: { "Accept": "application/json", "Content-Type": "application/json", "api_key": config.apiKey } }, function(err, response, body) {
if (err) {
console.log(err);
} else {
if (body.error) {
console.log('error during transfer: ' + body.message);
} else {
console.log(counter + ' send ' + payment.amount + ' of ' + payment.assetId + ' to ' + payment.recipient + '!');
}
counter++;
if (counter < payments.length) {
doPayment(payments, counter);
}
}
});
}, 1000);
};
start();