From ae913e41409ab9cebb573791da8aa1813e253f63 Mon Sep 17 00:00:00 2001 From: Eduardo Pereira Date: Thu, 21 Mar 2019 16:52:55 -0300 Subject: [PATCH] Adaptations to be compatible with block explorers --- src/loom-provider.ts | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/loom-provider.ts b/src/loom-provider.ts index a76b5ed2..b1b2526c 100644 --- a/src/loom-provider.ts +++ b/src/loom-provider.ts @@ -176,11 +176,35 @@ const numberToHexLC = (num: number): string => { return numberToHex(num).toLowerCase() } +const ZEROED_HEX_256 = + '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' const ZEROED_HEX_32 = '0x0000000000000000000000000000000000000000000000000000000000000000' const ZEROED_HEX_20 = '0x0000000000000000000000000000000000000000' const ZEROED_HEX_8 = '0x0000000000000000' const ZEROED_HEX = '0x0' +const BLOCK_ZERO: IEthBlock = { + number: ZEROED_HEX, + hash: '0x0000000000000000000000000000000000000000000000000000000000000001', + parentHash: ZEROED_HEX_32, + nonce: ZEROED_HEX_8, + sha3Uncles: ZEROED_HEX_32, + logsBloom: ZEROED_HEX_256, + transactionsRoot: ZEROED_HEX_32, + stateRoot: ZEROED_HEX_32, + receiptsRoot: ZEROED_HEX_32, + miner: ZEROED_HEX_20, + difficulty: ZEROED_HEX, + totalDifficulty: ZEROED_HEX, + extraData: ZEROED_HEX, + size: ZEROED_HEX, + gasLimit: ZEROED_HEX, + gasUsed: ZEROED_HEX, + timestamp: '0x5af97a40', + transactions: [], + uncles: [] +} + /** * Web3 provider that interacts with EVM contracts deployed on Loom DAppChains. */ @@ -502,6 +526,10 @@ export class LoomProvider { const blockHash = payload.params[0] const isFull = payload.params[1] || true + if (blockHash === ZEROED_HEX_32) { + return Promise.resolve(BLOCK_ZERO) + } + const result = await this._client.getEvmBlockByHashAsync(blockHash, isFull) if (!result) { @@ -515,6 +543,11 @@ export class LoomProvider { const blockNumberToSearch = payload.params[0] === 'latest' ? payload.params[0] : hexToNumber(payload.params[0]) const isFull = payload.params[1] || true + + if (blockNumberToSearch === 0) { + return Promise.resolve(BLOCK_ZERO) + } + const result = await this._client.getEvmBlockByNumberAsync(`${blockNumberToSearch}`, isFull) if (!result) { @@ -770,10 +803,9 @@ export class LoomProvider { } }) - // TODO: Should be on backed - // Ugly fix, since block 0x1 has a parent hash block ZEROED_HEX_32 + // Parent hash is empty for the block 0x1 so this fix it if (parentHash === '0x' && number === '0x1') { - parentHash = ZEROED_HEX_32 + parentHash = '0x0000000000000000000000000000000000000000000000000000000000000001' } // Some ZEROED values aren't at the moment