Skip to content

Commit

Permalink
Client: fix more hive RPC-Compat tests (#3503)
Browse files Browse the repository at this point in the history
* client: pass block to eth_call for block inspection data (base fee / blockhash)

* client: ensure "input" param is handled on RPC correctly

* client: add getTransactionByBlockNumberAndIndex
  • Loading branch information
jochem-brouwer authored Jul 15, 2024
1 parent c4bb979 commit 303b045
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
36 changes: 35 additions & 1 deletion packages/client/src/rpc/modules/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ export class Eth {
[[validators.hex, validators.blockHash], [validators.hex]]
)

this.getTransactionByBlockNumberAndIndex = middleware(
callWithStackTrace(this.getTransactionByBlockNumberAndIndex.bind(this), this._rpcDebug),
2,
[[validators.hex, validators.blockOption], [validators.hex]]
)

this.getTransactionByHash = middleware(
callWithStackTrace(this.getTransactionByHash.bind(this), this._rpcDebug),
1,
Expand Down Expand Up @@ -498,7 +504,9 @@ export class Eth {
const vm = await this._vm.shallowCopy()
await vm.stateManager.setStateRoot(block.header.stateRoot)

const { from, to, gas: gasLimit, gasPrice, value, data } = transaction
const { from, to, gas: gasLimit, gasPrice, value } = transaction

const data = transaction.data ?? transaction.input

const runCallOpts = {
caller: from !== undefined ? Address.fromString(from) : undefined,
Expand All @@ -507,6 +515,7 @@ export class Eth {
gasPrice: toType(gasPrice, TypeOutput.BigInt),
value: toType(value, TypeOutput.BigInt),
data: data !== undefined ? hexToBytes(data) : undefined,
block,
}
const { execResult } = await vm.evm.runCall(runCallOpts)
return bytesToHex(execResult.returnValue)
Expand Down Expand Up @@ -798,6 +807,31 @@ export class Eth {
}
}

/**
* Returns information about a transaction given a block hash and a transaction's index position.
* @param params An array of two parameter:
* 1. a block number
* 2. an integer of the transaction index position encoded as a hexadecimal.
*/
async getTransactionByBlockNumberAndIndex(params: [PrefixedHexString, string]) {
try {
const [blockNumber, txIndexHex] = params
const txIndex = parseInt(txIndexHex, 16)
const block = await getBlockByOption(blockNumber, this._chain)
if (block.transactions.length <= txIndex) {
return null
}

const tx = block.transactions[txIndex]
return jsonRpcTx(tx, block, txIndex)
} catch (error: any) {
throw {
code: INVALID_PARAMS,
message: error.message.toString(),
}
}
}

/**
* Returns the transaction by hash when available within `--txLookupLimit`
* @param params An array of one parameter:
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/rpc/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface RpcTx {
gasPrice?: PrefixedHexString
value?: PrefixedHexString
data?: PrefixedHexString
input?: PrefixedHexString // This is the "official" name of the property the client uses for "data" in the RPC spec
maxPriorityFeePerGas?: PrefixedHexString
maxFeePerGas?: PrefixedHexString
type?: PrefixedHexString
Expand Down

0 comments on commit 303b045

Please sign in to comment.