Skip to content

Commit

Permalink
Adaptations to be compatible with block explorers
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardonunesp committed Mar 21, 2019
1 parent f9b04d0 commit ae913e4
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions src/loom-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae913e4

Please sign in to comment.