From 5be6972b94824d7c55e51116e90421913a8236fe Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Thu, 1 Sep 2022 12:53:01 +0200 Subject: [PATCH] fix: make `intToHex` produce valid `Quantity` --- getBlocksForRange.js | 19 ++----------------- hexUtils.js | 5 +---- log-filter.js | 2 +- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/getBlocksForRange.js b/getBlocksForRange.js index c3ab861..aa67604 100644 --- a/getBlocksForRange.js +++ b/getBlocksForRange.js @@ -1,3 +1,5 @@ +const { intToHex, hexToInt } = require('./hexUtils') + module.exports = getBlocksForRange async function getBlocksForRange({ provider, fromBlock, toBlock }) { @@ -16,23 +18,6 @@ async function getBlocksForRange({ provider, fromBlock, toBlock }) { return blockBodies } -function hexToInt(hexString) { - if (hexString === undefined || hexString === null) return hexString - return Number.parseInt(hexString, 16) -} - -function incrementHexInt(hexString){ - if (hexString === undefined || hexString === null) return hexString - const value = hexToInt(hexString) - return intToHex(value + 1) -} - -function intToHex(int) { - if (int === undefined || int === null) return int - const hexString = int.toString(16) - return '0x' + hexString -} - function sendAsync(provider, request) { return new Promise((resolve, reject) => { provider.sendAsync(request, (error, response) => { diff --git a/hexUtils.js b/hexUtils.js index 83dc9e3..417515c 100644 --- a/hexUtils.js +++ b/hexUtils.js @@ -50,10 +50,7 @@ function incrementHexInt(hexString){ function intToHex(int) { if (int === undefined || int === null) return int - let hexString = int.toString(16) - const needsLeftPad = hexString.length % 2 - if (needsLeftPad) hexString = '0' + hexString - return '0x' + hexString + return '0x' + int.toString(16) } function unsafeRandomBytes(byteCount) { diff --git a/log-filter.js b/log-filter.js index ef55746..8566a58 100644 --- a/log-filter.js +++ b/log-filter.js @@ -1,7 +1,7 @@ const EthQuery = require('eth-query') const pify = require('pify') const BaseFilterWithHistory = require('./base-filter-history') -const { bnToHex, hexToInt, incrementHexInt, minBlockRef, blockRefIsNumber } = require('./hexUtils') +const { hexToInt, incrementHexInt, minBlockRef, blockRefIsNumber } = require('./hexUtils') class LogFilter extends BaseFilterWithHistory {