Skip to content

Commit

Permalink
mine script
Browse files Browse the repository at this point in the history
  • Loading branch information
derpy-duck committed Oct 10, 2023
1 parent 4e5f51d commit b97bc70
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 167 deletions.
7 changes: 6 additions & 1 deletion devnet/eth-devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ spec:
- --chain-id=1
- --silent
- --mnemonic=myth like bonus scare over problem client lizard pioneer submit female collect
- --block-time=1
ports:
- containerPort: 8545
name: rpc
Expand All @@ -61,5 +60,11 @@ spec:
initialDelaySeconds: 90
tcpSocket:
port: 2000
- name: mine
image: eth-node
command:
- /bin/sh
- -c
- "npm run mine"
---

8 changes: 6 additions & 2 deletions devnet/eth-devnet2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ spec:
- --chain-id=1397
- --silent
- --mnemonic=myth like bonus scare over problem client lizard pioneer submit female collect
- --block-time=1

ports:
- containerPort: 8545
name: rpc
Expand All @@ -63,3 +61,9 @@ spec:
initialDelaySeconds: 90
tcpSocket:
port: 2000
- name: mine
image: eth-node
command:
- /bin/sh
- -c
- "npm run mine"
36 changes: 0 additions & 36 deletions ethereum/mine.js

This file was deleted.

37 changes: 37 additions & 0 deletions ethereum/mine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This script advances Anvil 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.
*/

import fetch from "node-fetch"

const RPC_URL = 'http://localhost:8545'

const advanceBlock = () => {
return new Promise((resolve, reject) => {
fetch(RPC_URL, {
method: 'POST',
headers: {'content-type': 'application/json'},
body: JSON.stringify({
jsonrpc: '2.0',
id: new Date().getTime(),
method: "evm_mine",
})
}).then(() => {
resolve(0);
})
});
}

function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}

const fn = async () => {
while (true) {
await advanceBlock();
await sleep(1000);
}
}

fn().catch(reason => console.error(reason))
Loading

0 comments on commit b97bc70

Please sign in to comment.