Allow 0x as a numeric value for 0 in Provider formatter (#1104).

This commit is contained in:
Richard Moore 2020-10-22 21:03:51 -04:00
parent d8cdd0e94c
commit fe17a29581
No known key found for this signature in database
GPG Key ID: 665176BE8E9DC651
2 changed files with 7 additions and 6 deletions

View File

@ -349,19 +349,19 @@ export class EtherscanProvider extends BaseProvider{
const logs: Array<any> = await get(url, null, getResult); const logs: Array<any> = await get(url, null, getResult);
// Cache txHash => blockHash // Cache txHash => blockHash
let txs: { [hash: string]: string } = {}; let blocks: { [tag: string]: string } = {};
// Add any missing blockHash to the logs // Add any missing blockHash to the logs
for (let i = 0; i < logs.length; i++) { for (let i = 0; i < logs.length; i++) {
const log = logs[i]; const log = logs[i];
if (log.blockHash != null) { continue; } if (log.blockHash != null) { continue; }
if (txs[log.transactionHash] == null) { if (blocks[log.blockNumber] == null) {
const tx = await this.getTransaction(log.transactionHash); const block = await this.getBlock(log.blockNumber);
if (tx) { if (block) {
txs[log.transactionHash] = tx.blockHash blocks[log.blockNumber] = block.hash;
} }
} }
log.blockHash = txs[log.transactionHash]; log.blockHash = blocks[log.blockNumber];
} }
return logs; return logs;

View File

@ -164,6 +164,7 @@ export class Formatter {
// Requires a BigNumberish that is within the IEEE754 safe integer range; returns a number // Requires a BigNumberish that is within the IEEE754 safe integer range; returns a number
// Strict! Used on input. // Strict! Used on input.
number(number: any): number { number(number: any): number {
if (number === "0x") { return 0; }
return BigNumber.from(number).toNumber(); return BigNumber.from(number).toNumber();
} }