ethereum: mine ganache blocks in the background

Fixes #75.
This commit is contained in:
Leo 2020-11-18 13:56:56 +01:00
parent 22368def3e
commit da768a09c4
3 changed files with 43 additions and 2 deletions

View File

@ -95,8 +95,7 @@ Next, send some of them back to Ethereum:
<img src="https://user-images.githubusercontent.com/859697/98734694-a1228400-23a2-11eb-8f39-13000631c839.png" width="66%" />
MetaMask will ask you to confirm the transaction. You have to run send-eth-lockups.sh script in the background to
force Ganache to mint new blocks such that the bridge can reach its confirmation threshold (https://github.com/certusone/wormhole/issues/75).
MetaMask will ask you to confirm the transaction.
After a few seconds, the SPL token balance shown below will increase as the VAA gets accepted on Solana.

View File

@ -49,3 +49,9 @@ spec:
- /bin/sh
- -c
- "npm run migrate && sleep infinity"
- name: mine
image: eth-node
command:
- /bin/sh
- -c
- "npx truffle exec mine.js"

36
ethereum/mine.js Normal file
View File

@ -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))
}