fund accounts in wallet using contracts config

This commit is contained in:
Jonathan Rainville 2018-06-07 13:06:09 -04:00
parent 9c9bb761a4
commit 1b89199f50
2 changed files with 9 additions and 5 deletions

View File

@ -1,8 +1,12 @@
const async = require('async');
const TARGET = 15000000000000000000;
const TARGET = 0x7FFFFFFFFFFFFFFF;
const ALREADY_FUNDED = 'alreadyFunded';
function fundAccount(web3, accountAddress, callback) {
function fundAccount(web3, accountAddress, hexBalance, callback) {
if (!hexBalance) {
hexBalance = TARGET;
}
const targetBalance = (typeof hexBalance === 'string') ? parseInt(hexBalance, 16) : hexBalance;
let accountBalance;
let coinbaseAddress;
let lastNonce;
@ -14,7 +18,7 @@ function fundAccount(web3, accountAddress, callback) {
if (err) {
return next(err);
}
if (balance >= TARGET) {
if (balance >= targetBalance) {
return next(ALREADY_FUNDED);
}
accountBalance = balance;
@ -56,7 +60,7 @@ function fundAccount(web3, accountAddress, callback) {
web3.eth.sendTransaction({
from: coinbaseAddress,
to: accountAddress,
value: TARGET - accountBalance,
value: targetBalance - accountBalance,
gasPrice: gasPrice,
nonce: lastNonce
}, next);

View File

@ -65,7 +65,7 @@ class Provider {
return callback();
}
async.each(self.accounts, (account, eachCb) => {
fundAccount(self.web3, account.address, eachCb);
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
}, callback);
}