forked from atticlab/wormhole
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ethereum: mine ganache blocks in the background
Fixes wormhole-foundation#75.
- Loading branch information
Leo
committed
Nov 18, 2020
1 parent
22368de
commit da768a0
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
This script advances Ganache network state. It runs as a sidecar pod alongside the devnet and | ||
ensures that manual token transfers triggered through the web UI will be able to be confirmed. | ||
*/ | ||
|
||
advanceBlock = () => { | ||
return new Promise((resolve, reject) => { | ||
web3.currentProvider.send({ | ||
jsonrpc: "2.0", | ||
method: "evm_mine", | ||
id: new Date().getTime() | ||
}, (err, result) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
const newBlockHash = web3.eth.getBlock('latest').hash; | ||
|
||
return resolve(newBlockHash) | ||
}); | ||
}); | ||
} | ||
|
||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
module.exports = function(callback) { | ||
const fn = async () => { | ||
while (true) { | ||
console.log(await advanceBlock()); | ||
await sleep(1000); | ||
} | ||
} | ||
|
||
fn().catch(reason => console.error(reason)) | ||
} |