This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds blockchain query functions and logger
- Loading branch information
1 parent
04106af
commit 801b5de
Showing
8 changed files
with
136 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:46:41.257Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:46:41.264Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:47:41.137Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:47:41.143Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:17.417Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:17.423Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:28.448Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:28.454Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:31.997Z"} | ||
{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{"0x880248D134a1481b051AfB4B765758F9b9152991":{}},"0x880248D134a1481b051AfB4B765758F9b9152991":{"0x263d4d7fffc17149ae3c436e4bd6aa4cb20303e9":{}},"level":"info","message":"","timestamp":"2018-02-06T22:49:32.002Z"} |
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,27 @@ | ||
// Formatted calls to the bridge contracts | ||
const leftPad = require('left-pad'); | ||
|
||
// Get the block corresponding to the last block header Merkle root committed | ||
// to the chain. queryAddr is the address of the bridge contract on the chain | ||
// being queried and bridgedAddr is the address of the bridge on the other chain. | ||
exports.getLastBlock = function(queryAddr, bridgedAddr, client, cb) { | ||
const data = `${LAST_BLOCK_ABI}${leftPad(bridgedAddr.slice(2), 64, '0')}`; | ||
client.eth.call({ to: queryAddr, data: data }, (err, ret) => { | ||
if (err) { cb(err); } | ||
else { cb(null, parseInt(ret, 16)); } | ||
}) | ||
} | ||
|
||
// Get the current proposer for the chain being queried | ||
exports.getProposer = function(queryAddr, client, cb) { | ||
const data = GET_PROPOSER_ABI; | ||
client.eth.call({ to: queryAddr, data: data }, (err, ret) => { | ||
if (err) { cb(err); } | ||
else { cb(null, ret); } | ||
}) | ||
} | ||
|
||
// getLastBlock(address) | ||
const LAST_BLOCK_ABI = '0x4929dfa1'; | ||
// getProposer() | ||
const GET_PROPOSER_ABI = '0xe9790d02'; |
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,19 @@ | ||
// Logging | ||
const winston = require('winston'); | ||
|
||
// This will be overwritten when we know where the log file should be; | ||
let logger = null; | ||
exports.logger = logger; | ||
|
||
// Setup the winston logger | ||
exports.setLogger = function(fPath) { | ||
logger = new (winston.Logger)({ | ||
transports: [ | ||
new (winston.transports.File)({ filename: `${fPath}/log`, json: false, timestamp: true }) | ||
] | ||
}) | ||
} | ||
|
||
exports.getLogger = function() { | ||
return logger; | ||
} |
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