Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make intToHex produce valid Quantity #71

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions getBlocksForRange.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { intToHex, hexToInt } = require('./hexUtils')

module.exports = getBlocksForRange

async function getBlocksForRange({ provider, fromBlock, toBlock }) {
Expand All @@ -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) => {
Expand Down
5 changes: 1 addition & 4 deletions hexUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion log-filter.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down