Skip to content

Commit

Permalink
Merge pull request #2 from acebusters/chore/parity-support
Browse files Browse the repository at this point in the history
Query local block number using JSON RPC..
  • Loading branch information
troggy authored Dec 4, 2017
2 parents 68b548f + 1ab406a commit e4183f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# geth-healthcheck

Little http node.js server to run along the geth node. Returns **503 Service Unavailable** if the last block number on the local node is off by 4 or more blocks from the last block nubmer from Etherscan. Otherwise returns **200 OK**
Little http node.js server to run along the ethereum node. Node needs to have JSONRPC enabled. Returns **503 Service Unavailable** if the last block number on the local node is off by 4 or more blocks from the last block nubmer from Etherscan. Otherwise returns **200 OK**

## Installation
1. Install node.js if needed:
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const MAX_BLOCK_DIFFERENCE = 3;

const getLocalBlockNum = () => {
return new Promise((resolve, reject) => {
exec('geth --exec eth.blockNumber attach', (error, stdout, stderr) => {
exec('curl --data \'{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}\' -H "Content-Type: application/json" -X POST localhost:8545', (error, stdout, stderr) => {
if (error) {
return reject(`${error}`);
}
resolve(parseInt(stdout.trim()));
resolve(parseInt(JSON.parse(stdout.trim()).result));
});
});
};
Expand Down

0 comments on commit e4183f3

Please sign in to comment.