Skip to content

Commit ae913e4

Browse files
committed
Adaptations to be compatible with block explorers
1 parent f9b04d0 commit ae913e4

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/loom-provider.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,35 @@ const numberToHexLC = (num: number): string => {
176176
return numberToHex(num).toLowerCase()
177177
}
178178

179+
const ZEROED_HEX_256 =
180+
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
179181
const ZEROED_HEX_32 = '0x0000000000000000000000000000000000000000000000000000000000000000'
180182
const ZEROED_HEX_20 = '0x0000000000000000000000000000000000000000'
181183
const ZEROED_HEX_8 = '0x0000000000000000'
182184
const ZEROED_HEX = '0x0'
183185

186+
const BLOCK_ZERO: IEthBlock = {
187+
number: ZEROED_HEX,
188+
hash: '0x0000000000000000000000000000000000000000000000000000000000000001',
189+
parentHash: ZEROED_HEX_32,
190+
nonce: ZEROED_HEX_8,
191+
sha3Uncles: ZEROED_HEX_32,
192+
logsBloom: ZEROED_HEX_256,
193+
transactionsRoot: ZEROED_HEX_32,
194+
stateRoot: ZEROED_HEX_32,
195+
receiptsRoot: ZEROED_HEX_32,
196+
miner: ZEROED_HEX_20,
197+
difficulty: ZEROED_HEX,
198+
totalDifficulty: ZEROED_HEX,
199+
extraData: ZEROED_HEX,
200+
size: ZEROED_HEX,
201+
gasLimit: ZEROED_HEX,
202+
gasUsed: ZEROED_HEX,
203+
timestamp: '0x5af97a40',
204+
transactions: [],
205+
uncles: []
206+
}
207+
184208
/**
185209
* Web3 provider that interacts with EVM contracts deployed on Loom DAppChains.
186210
*/
@@ -502,6 +526,10 @@ export class LoomProvider {
502526
const blockHash = payload.params[0]
503527
const isFull = payload.params[1] || true
504528

529+
if (blockHash === ZEROED_HEX_32) {
530+
return Promise.resolve(BLOCK_ZERO)
531+
}
532+
505533
const result = await this._client.getEvmBlockByHashAsync(blockHash, isFull)
506534

507535
if (!result) {
@@ -515,6 +543,11 @@ export class LoomProvider {
515543
const blockNumberToSearch =
516544
payload.params[0] === 'latest' ? payload.params[0] : hexToNumber(payload.params[0])
517545
const isFull = payload.params[1] || true
546+
547+
if (blockNumberToSearch === 0) {
548+
return Promise.resolve(BLOCK_ZERO)
549+
}
550+
518551
const result = await this._client.getEvmBlockByNumberAsync(`${blockNumberToSearch}`, isFull)
519552

520553
if (!result) {
@@ -770,10 +803,9 @@ export class LoomProvider {
770803
}
771804
})
772805

773-
// TODO: Should be on backed
774-
// Ugly fix, since block 0x1 has a parent hash block ZEROED_HEX_32
806+
// Parent hash is empty for the block 0x1 so this fix it
775807
if (parentHash === '0x' && number === '0x1') {
776-
parentHash = ZEROED_HEX_32
808+
parentHash = '0x0000000000000000000000000000000000000000000000000000000000000001'
777809
}
778810

779811
// Some ZEROED values aren't at the moment

0 commit comments

Comments
 (0)