Housekeeping and removal of none additions
Clean up debugging statements from fund_accounts. Removed the addition of the nonce increment for contracts deploy as this was only affecting mneumonic-generated accounts which is not meant for dev environment.
This commit is contained in:
parent
5e3740f088
commit
9382f98933
|
@ -184,11 +184,8 @@ Blockchain.prototype.run = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.createFundAndUnlockAccounts = function(cb) {
|
Blockchain.prototype.createFundAndUnlockAccounts = function(cb) {
|
||||||
console.dir('createFundAndUnlockAccounts');
|
|
||||||
let devFunds = new DevFunds(this.config);
|
let devFunds = new DevFunds(this.config);
|
||||||
devFunds.createFundAndUnlockAccounts((err) => {
|
devFunds.createFundAndUnlockAccounts((err) => {
|
||||||
console.dir("=====> done!");
|
|
||||||
console.dir(arguments);
|
|
||||||
cb(err);
|
cb(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,9 +14,7 @@ class DevFunds {
|
||||||
this.networkId = null;
|
this.networkId = null;
|
||||||
this.balance = Web3.utils.toWei("1", "ether");
|
this.balance = Web3.utils.toWei("1", "ether");
|
||||||
if (this.blockchainConfig.account.balance) {
|
if (this.blockchainConfig.account.balance) {
|
||||||
console.dir('[blockchain/dev_funds]: converting balance from ' + this.blockchainConfig.account.balance);
|
|
||||||
this.balance = getWeiBalanceFromString(this.blockchainConfig.account.balance, this.web3);
|
this.balance = getWeiBalanceFromString(this.blockchainConfig.account.balance, this.web3);
|
||||||
console.dir('[blockchain/dev_funds]: converted balance to ' + this.balance);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +34,7 @@ class DevFunds {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(function() { self._sendTx() }, 3000);
|
setInterval(function() { self._sendTx(); }, 1500);
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
|
@ -57,7 +55,6 @@ class DevFunds {
|
||||||
if (accounts.length > 1) {
|
if (accounts.length > 1) {
|
||||||
this.accounts = accounts.slice(1);
|
this.accounts = accounts.slice(1);
|
||||||
}
|
}
|
||||||
console.dir('----- CURRENT ACCOUNTS ' + this.accounts);
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -66,89 +63,54 @@ class DevFunds {
|
||||||
const numAccountsToCreate = numAccounts - (this.accounts.length + 1);
|
const numAccountsToCreate = numAccounts - (this.accounts.length + 1);
|
||||||
if (numAccountsToCreate === 0) return cb();
|
if (numAccountsToCreate === 0) return cb();
|
||||||
|
|
||||||
console.dir("creating " + numAccountsToCreate + " new accounts with password " + password);
|
|
||||||
async.timesLimit(numAccountsToCreate, 1, (_, next) => {
|
async.timesLimit(numAccountsToCreate, 1, (_, next) => {
|
||||||
console.dir("--- creating new account");
|
|
||||||
this.web3.eth.personal.newAccount(password, next);
|
this.web3.eth.personal.newAccount(password, next);
|
||||||
}, (err, accounts) => {
|
}, (err, accounts) => {
|
||||||
if (err) console.error(err);
|
if (err) return cb(err);
|
||||||
console.dir("-- accounts created are ");
|
|
||||||
console.dir(accounts);
|
|
||||||
this.accounts = accounts;
|
this.accounts = accounts;
|
||||||
cb(err);
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unlockAccounts(password, cb) {
|
unlockAccounts(password, cb) {
|
||||||
console.dir('--- CURRENT ACCOUNTS ' + this.accounts);
|
|
||||||
async.each(this.accounts, (account, next) => {
|
async.each(this.accounts, (account, next) => {
|
||||||
console.dir('-- unlocking account ' + account + ' with password ' + password);
|
|
||||||
this.web3.eth.personal.unlockAccount(account, password).then((result) => {
|
this.web3.eth.personal.unlockAccount(account, password).then((result) => {
|
||||||
console.dir('-- unlocked account ' + account + ' with password ' + password + ' and result ' + result);
|
|
||||||
next();
|
next();
|
||||||
}).catch(next);
|
}).catch(next);
|
||||||
}, (err) => {
|
}, cb);
|
||||||
console.dir('-- FINISHED UNLOCKING ACCOUNTS, err= ' + err);
|
|
||||||
cb(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fundAccounts(balance, cb) {
|
fundAccounts(balance, cb) {
|
||||||
console.dir('-- funding accounts...');
|
|
||||||
|
|
||||||
async.each(this.accounts, (account, next) => {
|
async.each(this.accounts, (account, next) => {
|
||||||
this.web3.eth.getBalance(account).then(currBalance => {
|
this.web3.eth.getBalance(account).then(currBalance => {
|
||||||
const remainingBalance = balance - currBalance;
|
const remainingBalance = balance - currBalance;
|
||||||
console.dir("---- account " + account + " balance needed = " + remainingBalance);
|
|
||||||
if (remainingBalance <= 0) return next();
|
if (remainingBalance <= 0) return next();
|
||||||
|
|
||||||
console.dir("-- funding account " + account + " with balance " + remainingBalance);
|
|
||||||
this.web3.eth.sendTransaction({to: account, value: remainingBalance}).then((result) => {
|
this.web3.eth.sendTransaction({to: account, value: remainingBalance}).then((result) => {
|
||||||
console.dir('FUNDING ACCT result: ' + JSON.stringify(result));
|
|
||||||
next();
|
next();
|
||||||
}).catch(next);
|
}).catch(next);
|
||||||
}, (err) => {
|
}, cb);
|
||||||
console.dir('-- FINISHED FUNDING ACCOUNTS, err= ' + err);
|
|
||||||
cb(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createFundAndUnlockAccounts(cb) {
|
createFundAndUnlockAccounts(cb) {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
(next) => {
|
(next) => {
|
||||||
console.dir('--- CONNECTING TO NODE');
|
|
||||||
this.connectToNode(next);
|
this.connectToNode(next);
|
||||||
},
|
},
|
||||||
(next) => {
|
(next) => {
|
||||||
console.dir('--- CREATING THE ACCOUNTS');
|
|
||||||
this.createAccounts(this.numAccounts, this.password, next);
|
this.createAccounts(this.numAccounts, this.password, next);
|
||||||
},
|
},
|
||||||
(next) => {
|
(next) => {
|
||||||
console.dir('--- UNLOCKING THE ACCOUNTS');
|
|
||||||
this.unlockAccounts(this.password, next);
|
this.unlockAccounts(this.password, next);
|
||||||
},
|
},
|
||||||
(next) => {
|
(next) => {
|
||||||
console.dir('--- FUNDING THE ACCOUNTS');
|
|
||||||
this.regularTxs();
|
this.regularTxs();
|
||||||
this.regularUnlocks();
|
this.regularUnlocks();
|
||||||
this.fundAccounts(this.balance, next);
|
this.fundAccounts(this.balance, next);
|
||||||
}
|
}
|
||||||
], (err) => {
|
], cb);
|
||||||
console.dir(`--- COMPLETED THE ACCOUNTS (${this.accounts.join(', ')} and funded with ${this.balance} wei)`);
|
|
||||||
if (err) console.error('Error creating, unlocking, and funding accounts', JSON.stringify(err));
|
|
||||||
|
|
||||||
// this.web3.eth.getAccounts().then((accounts) => {
|
|
||||||
// let numAccts = accounts.length;
|
|
||||||
// accounts.forEach((account) => {
|
|
||||||
// this.web3.eth.getBalance(account).then((balance) => {
|
|
||||||
// console.dir('[contracts/dev_funds]: account ' + account + ' has balance of ' + balance);
|
|
||||||
// if(--numAccts === 0) cb(err);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
cb(err);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,6 @@ class AccountParser {
|
||||||
if (accountConfig.balance) {
|
if (accountConfig.balance) {
|
||||||
hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
|
hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
|
||||||
//hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
|
//hexBalance = getHexBalanceFromString(accountConfig.balance, web3);
|
||||||
console.dir('[contracts/accountParser]: balance ' + accountConfig.balance + ' converted to hex ' + hexBalance);
|
|
||||||
}
|
}
|
||||||
if (accountConfig.privateKey) {
|
if (accountConfig.privateKey) {
|
||||||
if (!accountConfig.privateKey.startsWith('0x')) {
|
if (!accountConfig.privateKey.startsWith('0x')) {
|
||||||
|
|
|
@ -51,7 +51,6 @@ class Blockchain {
|
||||||
const protocol = (this.contractsConfig.deployment.type === "rpc") ? this.contractsConfig.deployment.protocol : 'ws';
|
const protocol = (this.contractsConfig.deployment.type === "rpc") ? this.contractsConfig.deployment.protocol : 'ws';
|
||||||
let provider;
|
let provider;
|
||||||
this.web3Endpoint = utils.buildUrl(protocol, this.contractsConfig.deployment.host, this.contractsConfig.deployment.port);//`${protocol}://${this.contractsConfig.deployment.host}:${this.contractsConfig.deployment.port}`;
|
this.web3Endpoint = utils.buildUrl(protocol, this.contractsConfig.deployment.host, this.contractsConfig.deployment.port);//`${protocol}://${this.contractsConfig.deployment.host}:${this.contractsConfig.deployment.port}`;
|
||||||
console.dir('[blockchain/contracts]: web3 endpoint: ' + this.web3Endpoint);
|
|
||||||
const providerOptions = {
|
const providerOptions = {
|
||||||
web3: this.web3,
|
web3: this.web3,
|
||||||
accountsConfig: this.contractsConfig.deployment.accounts,
|
accountsConfig: this.contractsConfig.deployment.accounts,
|
||||||
|
@ -65,7 +64,6 @@ class Blockchain {
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function checkNode(next) {
|
function checkNode(next) {
|
||||||
console.dir('[blockchain/contracts]: check node');
|
|
||||||
self.assertNodeConnection(true, (err) => {
|
self.assertNodeConnection(true, (err) => {
|
||||||
if (err && self.web3StartedInProcess) {
|
if (err && self.web3StartedInProcess) {
|
||||||
// Already started blockchain in another node, we really have a node problem
|
// Already started blockchain in another node, we really have a node problem
|
||||||
|
@ -79,7 +77,6 @@ class Blockchain {
|
||||||
}
|
}
|
||||||
self.web3StartedInProcess = true;
|
self.web3StartedInProcess = true;
|
||||||
self.startBlockchainNode(() => {
|
self.startBlockchainNode(() => {
|
||||||
console.dir('[blockchain/contracts]: starting blockchain node');
|
|
||||||
// Need to re-initialize web3 to connect to the new blockchain node
|
// Need to re-initialize web3 to connect to the new blockchain node
|
||||||
provider.stop();
|
provider.stop();
|
||||||
self.initWeb3(cb);
|
self.initWeb3(cb);
|
||||||
|
@ -87,11 +84,9 @@ class Blockchain {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function startProvider(next) {
|
function startProvider(next) {
|
||||||
console.dir('[blockchain/contracts]: starting web3 provider');
|
|
||||||
provider.startWeb3Provider(next);
|
provider.startWeb3Provider(next);
|
||||||
},
|
},
|
||||||
function fundAccountsIfNeeded(next) {
|
function fundAccountsIfNeeded(next) {
|
||||||
console.dir('[blockchain/contracts]: funding accounts');
|
|
||||||
self.isWeb3Ready = true;
|
self.isWeb3Ready = true;
|
||||||
provider.fundAccounts(next);
|
provider.fundAccounts(next);
|
||||||
}
|
}
|
||||||
|
@ -184,11 +179,7 @@ class Blockchain {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.events.setCommandHandler("blockchain:gasPrice", function(cb) {
|
this.events.setCommandHandler("blockchain:gasPrice", function(cb) {
|
||||||
console.dir('[blockchain/contracts]: getting gas price...');
|
self.getGasPrice(cb);
|
||||||
self.getGasPrice((gp) => {
|
|
||||||
console.dir('[blockchain/contracts]: got gasPrice of ' + gp);
|
|
||||||
cb(gp);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -287,16 +278,7 @@ class Blockchain {
|
||||||
}
|
}
|
||||||
let accountConfig = self.blockchainConfig.account;
|
let accountConfig = self.blockchainConfig.account;
|
||||||
let selectedAccount = accountConfig && accountConfig.address;
|
let selectedAccount = accountConfig && accountConfig.address;
|
||||||
console.dir('[contracts/blockchain]: setting default account of ' + (selectedAccount || accounts[0]));
|
|
||||||
self.setDefaultAccount(selectedAccount || accounts[0]);
|
self.setDefaultAccount(selectedAccount || accounts[0]);
|
||||||
console.dir('[contracts/blockchain]: accounts on node = ');
|
|
||||||
//let numAccts = accounts.length;
|
|
||||||
self.web3.eth.getAccounts().then((accounts) => {
|
|
||||||
accounts.forEach((account) => {
|
|
||||||
self.web3.eth.getBalance(account).then((balance) => console.dir('[contracts/blockchain]: account ' + account + ' has balance of ' + balance));
|
|
||||||
//if(--numAccts === 0) cb();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,6 @@ class ContractDeployer {
|
||||||
},
|
},
|
||||||
function getGasPriceForNetwork(next) {
|
function getGasPriceForNetwork(next) {
|
||||||
self.events.request("blockchain:gasPrice", (gasPrice) => {
|
self.events.request("blockchain:gasPrice", (gasPrice) => {
|
||||||
console.dir('[contracts/contracts]: got gasPrice of ' + gasPrice);
|
|
||||||
contract.gasPrice = contract.gasPrice || gasPrice;
|
contract.gasPrice = contract.gasPrice || gasPrice;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
|
@ -54,21 +54,18 @@ class ContractsManager {
|
||||||
self.contracts = {};
|
self.contracts = {};
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function loadContractFiles(callback) {
|
function loadContractFiles(callback) {
|
||||||
console.dir('[contracts/contracts]: load contract files');
|
|
||||||
self.events.request("config:contractsFiles", (contractsFiles) => {
|
self.events.request("config:contractsFiles", (contractsFiles) => {
|
||||||
self.contractsFiles = contractsFiles;
|
self.contractsFiles = contractsFiles;
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function loadContractConfigs(callback) {
|
function loadContractConfigs(callback) {
|
||||||
console.dir('[contracts/contracts]: load contract configs');
|
|
||||||
self.events.request("config:contractsConfig", (contractsConfig) => {
|
self.events.request("config:contractsConfig", (contractsConfig) => {
|
||||||
self.contractsConfig = cloneDeep(contractsConfig);
|
self.contractsConfig = cloneDeep(contractsConfig);
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function compileContracts(callback) {
|
function compileContracts(callback) {
|
||||||
console.dir('[contracts/contracts]: compile contracts');
|
|
||||||
self.events.emit("status", __("Compiling..."));
|
self.events.emit("status", __("Compiling..."));
|
||||||
if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) {
|
if (process.env.isTest && self.compiledContracts && Object.keys(self.compiledContracts).length) {
|
||||||
// Only compile once for tests
|
// Only compile once for tests
|
||||||
|
@ -80,7 +77,6 @@ class ContractsManager {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function prepareContractsFromConfig(callback) {
|
function prepareContractsFromConfig(callback) {
|
||||||
console.dir('[contracts/contracts]: prepare contracts from config');
|
|
||||||
self.events.emit("status", __("Building..."));
|
self.events.emit("status", __("Building..."));
|
||||||
let className, contract;
|
let className, contract;
|
||||||
for (className in self.contractsConfig.contracts) {
|
for (className in self.contractsConfig.contracts) {
|
||||||
|
@ -94,11 +90,9 @@ class ContractsManager {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function getGasPriceForNetwork(callback) {
|
function getGasPriceForNetwork(callback) {
|
||||||
console.dir('[contracts/contracts]: gas price for network, passed in gasPrice from config: ' + self.contractsConfig.gasPrice);
|
|
||||||
return callback(null, self.contractsConfig.gasPrice);
|
return callback(null, self.contractsConfig.gasPrice);
|
||||||
},
|
},
|
||||||
function prepareContractsFromCompilation(gasPrice, callback) {
|
function prepareContractsFromCompilation(gasPrice, callback) {
|
||||||
console.dir('[contracts/contracts]: using gasprice ' + gasPrice + ', prepare contracts from compilation');
|
|
||||||
let className, compiledContract, contractConfig, contract;
|
let className, compiledContract, contractConfig, contract;
|
||||||
for (className in self.compiledContracts) {
|
for (className in self.compiledContracts) {
|
||||||
compiledContract = self.compiledContracts[className];
|
compiledContract = self.compiledContracts[className];
|
||||||
|
@ -126,7 +120,6 @@ class ContractsManager {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function setDeployIntention(callback) {
|
function setDeployIntention(callback) {
|
||||||
console.dir('[contracts/contracts]: set deploy intention');
|
|
||||||
let className, contract;
|
let className, contract;
|
||||||
for (className in self.contracts) {
|
for (className in self.contracts) {
|
||||||
contract = self.contracts[className];
|
contract = self.contracts[className];
|
||||||
|
@ -144,7 +137,6 @@ class ContractsManager {
|
||||||
},
|
},
|
||||||
/*eslint complexity: ["error", 11]*/
|
/*eslint complexity: ["error", 11]*/
|
||||||
function dealWithSpecialConfigs(callback) {
|
function dealWithSpecialConfigs(callback) {
|
||||||
console.dir('[contracts/contracts]: deal with special configs');
|
|
||||||
let className, contract, parentContractName, parentContract;
|
let className, contract, parentContractName, parentContract;
|
||||||
let dictionary = Object.keys(self.contracts);
|
let dictionary = Object.keys(self.contracts);
|
||||||
|
|
||||||
|
@ -194,7 +186,6 @@ class ContractsManager {
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
function removeContractsWithNoCode(callback) {
|
function removeContractsWithNoCode(callback) {
|
||||||
console.dir('[contracts/contracts]: remove Contracts with no code');
|
|
||||||
let className, contract;
|
let className, contract;
|
||||||
let dictionary = Object.keys(self.contracts);
|
let dictionary = Object.keys(self.contracts);
|
||||||
for (className in self.contracts) {
|
for (className in self.contracts) {
|
||||||
|
@ -216,7 +207,6 @@ class ContractsManager {
|
||||||
/*eslint complexity: ["error", 16]*/
|
/*eslint complexity: ["error", 16]*/
|
||||||
/*eslint max-depth: ["error", 16]*/
|
/*eslint max-depth: ["error", 16]*/
|
||||||
function determineDependencies(callback) {
|
function determineDependencies(callback) {
|
||||||
console.dir('[contracts/contracts]: determining dependencies');
|
|
||||||
let className, contract;
|
let className, contract;
|
||||||
for (className in self.contracts) {
|
for (className in self.contracts) {
|
||||||
contract = self.contracts[className];
|
contract = self.contracts[className];
|
||||||
|
|
|
@ -67,7 +67,6 @@ class DeployManager {
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function buildContracts(callback) {
|
function buildContracts(callback) {
|
||||||
self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => {
|
self.events.request("contracts:build", self.deployOnlyOnConfig, (err) => {
|
||||||
console.dir('[contracts/deploy_manager]: done building contracts');
|
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -83,28 +82,20 @@ class DeployManager {
|
||||||
|
|
||||||
// TODO: could be implemented as an event (beforeDeployAll)
|
// TODO: could be implemented as an event (beforeDeployAll)
|
||||||
function checkIsConnectedToBlockchain(callback) {
|
function checkIsConnectedToBlockchain(callback) {
|
||||||
console.dir('[contracts/deploy_manager]: checking connection to blockchain');
|
|
||||||
self.blockchain.onReady(() => {
|
self.blockchain.onReady(() => {
|
||||||
console.dir('[contracts/deploy_manager]: onReady called, asserting node connection');
|
self.blockchain.assertNodeConnection(callback);
|
||||||
self.blockchain.assertNodeConnection((err) => {
|
|
||||||
console.dir('[contracts/deploy_manager]: node connection asserted, err: ' + JSON.stringify(err));
|
|
||||||
callback(err);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO: this can be done on the fly or as part of the initialization
|
// TODO: this can be done on the fly or as part of the initialization
|
||||||
function determineDefaultAccount(callback) {
|
function determineDefaultAccount(callback) {
|
||||||
console.dir('[contracts/deploy_manager]: determining default acct');
|
|
||||||
self.blockchain.determineDefaultAccount((err) => {
|
self.blockchain.determineDefaultAccount((err) => {
|
||||||
callback(err);
|
callback(err);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
function deployAllContracts(callback) {
|
function deployAllContracts(callback) {
|
||||||
console.dir('[contracts/deploy_manager]: deploying all contracts');
|
|
||||||
self.deployAll(function (err) {
|
self.deployAll(function (err) {
|
||||||
console.dir('[contracts/deploy_manager]: done deploying all contracts, err: ' + JSON.stringify(err));
|
|
||||||
if (!err) {
|
if (!err) {
|
||||||
self.events.emit('contractsDeployed');
|
self.events.emit('contractsDeployed');
|
||||||
}
|
}
|
||||||
|
@ -115,7 +106,6 @@ class DeployManager {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function runAfterDeploy(callback) {
|
function runAfterDeploy(callback) {
|
||||||
console.dir('[contracts/deploy_manager]: emitting and running actions for event "contracts:deploy:afterAll"');
|
|
||||||
self.plugins.emitAndRunActionsForEvent('contracts:deploy:afterAll', callback);
|
self.plugins.emitAndRunActionsForEvent('contracts:deploy:afterAll', callback);
|
||||||
}
|
}
|
||||||
], function (err, _result) {
|
], function (err, _result) {
|
||||||
|
|
|
@ -2,13 +2,14 @@ const async = require('async');
|
||||||
const TARGET = 0x7FFFFFFFFFFFFFFF;
|
const TARGET = 0x7FFFFFFFFFFFFFFF;
|
||||||
const ALREADY_FUNDED = 'alreadyFunded';
|
const ALREADY_FUNDED = 'alreadyFunded';
|
||||||
|
|
||||||
function fundAccount(web3, accountAddress, hexBalance, nonce, callback) {
|
function fundAccount(web3, accountAddress, hexBalance, callback) {
|
||||||
if (!hexBalance) {
|
if (!hexBalance) {
|
||||||
hexBalance = TARGET;
|
hexBalance = TARGET;
|
||||||
}
|
}
|
||||||
const targetBalance = (typeof hexBalance === 'string') ? parseInt(hexBalance, 16) : hexBalance;
|
const targetBalance = (typeof hexBalance === 'string') ? parseInt(hexBalance, 16) : hexBalance;
|
||||||
let accountBalance;
|
let accountBalance;
|
||||||
let coinbaseAddress;
|
let coinbaseAddress;
|
||||||
|
let lastNonce;
|
||||||
let gasPrice;
|
let gasPrice;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
|
@ -51,23 +52,17 @@ function fundAccount(web3, accountAddress, hexBalance, nonce, callback) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return next(err);
|
return next(err);
|
||||||
}
|
}
|
||||||
|
lastNonce = nonce;
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function sendTransaction(next) {
|
function sendTransaction(next) {
|
||||||
console.dir('[contracts/fundAccount]: sending tx ' + JSON.stringify({
|
|
||||||
from: coinbaseAddress,
|
|
||||||
to: accountAddress,
|
|
||||||
value: targetBalance - accountBalance,
|
|
||||||
gasPrice: gasPrice,
|
|
||||||
nonce: nonce
|
|
||||||
}));
|
|
||||||
web3.eth.sendTransaction({
|
web3.eth.sendTransaction({
|
||||||
from: coinbaseAddress,
|
from: coinbaseAddress,
|
||||||
to: accountAddress,
|
to: accountAddress,
|
||||||
value: targetBalance - accountBalance,
|
value: targetBalance - accountBalance,
|
||||||
gasPrice: gasPrice,
|
gasPrice: gasPrice,
|
||||||
nonce: nonce
|
nonce: lastNonce
|
||||||
}, next);
|
}, next);
|
||||||
}
|
}
|
||||||
], (err) => {
|
], (err) => {
|
||||||
|
|
|
@ -78,12 +78,8 @@ class Provider {
|
||||||
if (!self.isDev) {
|
if (!self.isDev) {
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
let nonce = 0;
|
|
||||||
async.each(self.accounts, (account, eachCb) => {
|
async.each(self.accounts, (account, eachCb) => {
|
||||||
console.dir('[contracts/provider]: nonce is ' + nonce);
|
fundAccount(self.web3, account.address, account.hexBalance, eachCb);
|
||||||
fundAccount(self.web3, account.address, account.hexBalance, nonce++, (err) => {
|
|
||||||
eachCb(err);
|
|
||||||
});
|
|
||||||
}, callback);
|
}, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue