add interval to send txs to deal with geth --dev bug

This commit is contained in:
Iuri Matias 2018-07-18 13:29:02 +03:00
parent 3d1db2b21e
commit 28dd6dba60

View File

@ -11,6 +11,7 @@ class DevFunds {
this.numAccounts = this.blockchainConfig.account.numAccounts || 0;
this.password = readFileSync(dappPath('config/development/password'), 'utf8').replace('\n', '');
this.web3 = new Web3();
this.networkId = null;
this.balance = Web3.utils.toWei("1", "ether");
if (this.blockchainConfig.account.balance) {
console.dir('[blockchain/dev_funds]: converting balance from ' + this.blockchainConfig.account.balance);
@ -19,6 +20,29 @@ class DevFunds {
}
}
_sendTx() {
if (this.networkId !== 1337) {
return;
}
this.web3.eth.sendTransaction({value: "1000000000000000", to: "0xA2817254cb8E7b6269D1689c3E0eBadbB78889d1", from: this.web3.eth.defaultAccount});
}
// trigger regular txs due to a bug in geth and stuck transactions in --dev mode
regularTxs(cb) {
const self = this;
self.web3.eth.net.getId().then((networkId) => {
self.networkId = networkId;
if (self.networkId !== 1337) {
return;
}
setInterval(function() { self._sendTx() }, 3000);
if (cb) {
cb();
}
});
}
connectToNode(cb) {
this.web3.setProvider(new Web3.providers.WebsocketProvider(buildUrl('ws', this.blockchainConfig.wsHost, this.blockchainConfig.wsPort), { headers: { Origin: "http://localhost:8000" } }));
@ -67,8 +91,6 @@ class DevFunds {
fundAccounts(balance, cb) {
console.dir('-- funding accounts...');
async.each(this.accounts, (account, next) => {
this.web3.eth.getBalance(account).then(currBalance => {
const remainingBalance = balance - currBalance;
@ -85,8 +107,6 @@ class DevFunds {
cb(err);
});
});
}
createFundAndUnlockAccounts(cb) {
@ -105,6 +125,7 @@ class DevFunds {
},
(next) => {
console.dir('--- FUNDING THE ACCOUNTS');
this.regularTxs();
this.fundAccounts(this.balance, next);
}
], (err) => {