Skip to content

Commit

Permalink
RPC: fix hex conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Sep 19, 2024
1 parent 3192019 commit 725294c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
8 changes: 3 additions & 5 deletions packages/cli/src/rpc/modules/beacon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ export class beacon {
}
const lookup = new ContentLookup(
this._beacon,
fromHexString(
getBeaconContentKey(
BeaconLightClientNetworkContentType.LightClientUpdatesByRange,
LightClientUpdatesByRangeKey.serialize({ startPeriod: BigInt(params[0]), count: 1n }),
),
getBeaconContentKey(
BeaconLightClientNetworkContentType.LightClientUpdatesByRange,
LightClientUpdatesByRangeKey.serialize({ startPeriod: BigInt(params[0]), count: 1n }),
),
)
const res = await lookup.startLookup()
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { bigIntToHex, intToHex, toBytes } from '@ethereumjs/util'
import { bigIntToHex, hexToBytes, intToHex, toBytes } from '@ethereumjs/util'
import { GET_LOGS_BLOCK_RANGE_LIMIT, NetworkId, getLogs } from 'portalnetwork'

import { INTERNAL_ERROR, INVALID_PARAMS } from '../error-code.js'
Expand Down Expand Up @@ -137,7 +137,7 @@ export class eth {
this._client.logger(
`eth_getBlockByHash request received. blockHash: ${blockHash} includeTransactions: ${includeTransactions}`,
)
const block = await this._client.ETH.getBlockByHash(blockHash, includeTransactions)
const block = await this._client.ETH.getBlockByHash(hexToBytes(blockHash), includeTransactions)
//@ts-ignore @ethereumjs/block has some weird typing discrepancy
if (block !== undefined) return block
throw new Error('Block not found')
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/rpc/modules/portal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ export class portal {
async historyStore(params: [string, string]) {
const [contentKey, content] = params.map((param) => fromHexString(param))
try {
await this._history.store(toHexString(contentKey), content)
await this._history.store(contentKey, content)
return true
} catch {
return false
Expand All @@ -902,7 +902,7 @@ export class portal {
const [contentKey, content] = params
try {
const contentKeyBytes = fromHexString(contentKey)
await this._state.store(toHexString(contentKeyBytes), fromHexString(content))
await this._state.store(contentKeyBytes, fromHexString(content))
this.logger(`stored ${contentKey} in state network db`)
return true
} catch {
Expand All @@ -922,7 +922,7 @@ export class portal {
async beaconStore(params: [string, string]) {
const [contentKey, content] = params.map((param) => fromHexString(param))
try {
await this._beacon.store(toHexString(contentKey), content)
await this._beacon.store(contentKey, content)
return true
} catch (e) {
console.log(e)
Expand Down
10 changes: 3 additions & 7 deletions packages/cli/src/rpc/modules/ultralight.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
HistoryNetworkContentType,
NetworkId,
addRLPSerializedBlock,
fromHexString,
} from 'portalnetwork'
import { hexToBytes } from '@ethereumjs/util'
import { HistoryNetworkContentType, NetworkId, addRLPSerializedBlock } from 'portalnetwork'

import { INTERNAL_ERROR } from '../error-code.js'
import { middleware, validators } from '../validators.js'
Expand Down Expand Up @@ -98,7 +94,7 @@ export class ultralight {
`ultralight_addContentToDB request received for ${HistoryNetworkContentType[type]} ${contentKey}`,
)
try {
await this._history!.store(contentKey, fromHexString(value))
await this._history!.store(hexToBytes(contentKey), hexToBytes(value))
this.logger(`${type} value for ${contentKey} added to content DB`)
return `${type} value for ${contentKey} added to content DB`
} catch (err: any) {
Expand Down

0 comments on commit 725294c

Please sign in to comment.