Skip to content

Commit 28dd6db

Browse files
committed
add interval to send txs to deal with geth --dev bug
1 parent 3d1db2b commit 28dd6db

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

lib/cmds/blockchain/dev_funds.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class DevFunds {
1111
this.numAccounts = this.blockchainConfig.account.numAccounts || 0;
1212
this.password = readFileSync(dappPath('config/development/password'), 'utf8').replace('\n', '');
1313
this.web3 = new Web3();
14+
this.networkId = null;
1415
this.balance = Web3.utils.toWei("1", "ether");
1516
if (this.blockchainConfig.account.balance) {
1617
console.dir('[blockchain/dev_funds]: converting balance from ' + this.blockchainConfig.account.balance);
@@ -19,6 +20,29 @@ class DevFunds {
1920
}
2021
}
2122

23+
_sendTx() {
24+
if (this.networkId !== 1337) {
25+
return;
26+
}
27+
this.web3.eth.sendTransaction({value: "1000000000000000", to: "0xA2817254cb8E7b6269D1689c3E0eBadbB78889d1", from: this.web3.eth.defaultAccount});
28+
}
29+
30+
// trigger regular txs due to a bug in geth and stuck transactions in --dev mode
31+
regularTxs(cb) {
32+
const self = this;
33+
self.web3.eth.net.getId().then((networkId) => {
34+
self.networkId = networkId;
35+
if (self.networkId !== 1337) {
36+
return;
37+
}
38+
39+
setInterval(function() { self._sendTx() }, 3000);
40+
if (cb) {
41+
cb();
42+
}
43+
});
44+
}
45+
2246
connectToNode(cb) {
2347

2448
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 {
6791
fundAccounts(balance, cb) {
6892
console.dir('-- funding accounts...');
6993

70-
71-
7294
async.each(this.accounts, (account, next) => {
7395
this.web3.eth.getBalance(account).then(currBalance => {
7496
const remainingBalance = balance - currBalance;
@@ -85,8 +107,6 @@ class DevFunds {
85107
cb(err);
86108
});
87109
});
88-
89-
90110
}
91111

92112
createFundAndUnlockAccounts(cb) {
@@ -105,6 +125,7 @@ class DevFunds {
105125
},
106126
(next) => {
107127
console.dir('--- FUNDING THE ACCOUNTS');
128+
this.regularTxs();
108129
this.fundAccounts(this.balance, next);
109130
}
110131
], (err) => {

0 commit comments

Comments
 (0)