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

Client: fix more hive RPC-Compat tests #3503

Merged
merged 3 commits into from
Jul 15, 2024
Merged
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
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
Loading