From 73552a6994557dd55d9388fdc83cfa4bcad81659 Mon Sep 17 00:00:00 2001 From: "Sebastijan K." <58827427+sebastijankuzner@users.noreply.github.com> Date: Mon, 2 Dec 2024 10:52:33 +0100 Subject: [PATCH] feat(evm-api): implement `eth_getUncleByBlockNumberAndIndex` (#790) * Add eth_getUncleByBlockNumberAndIndex * Import --- ...eth-get-uncle-by-block-number-and-index.ts | 28 +++++++++++++++++++ packages/api-evm/source/actions/index.ts | 1 + packages/api-evm/source/service-provider.ts | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts diff --git a/packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts b/packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts new file mode 100644 index 000000000..aeba9d78f --- /dev/null +++ b/packages/api-evm/source/actions/eth-get-uncle-by-block-number-and-index.ts @@ -0,0 +1,28 @@ +import { inject, injectable } from "@mainsail/container"; +import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts"; + +@injectable() +export class EthGetUncleByBlockNumberAndIndex implements Contracts.Api.RPC.Action { + @inject(Identifiers.State.Store) + private readonly stateStore!: Contracts.State.Store; + + public readonly name: string = "eth_getUncleByBlockNumberAndIndex"; + + public readonly schema = { + $id: `jsonRpc_${this.name}`, + maxItems: 2, + minItems: 2, + + prefixItems: [{ $ref: "prefixedHex" }, { $ref: "prefixedHex" }], + type: "array", + }; + + public async handle(parameters: [string]): Promise { + if (this.stateStore.getHeight() < Number(parameters[0])) { + throw new Exceptions.RpcError("Block not found"); + } + + // eslint-disable-next-line unicorn/no-null + return null; + } +} diff --git a/packages/api-evm/source/actions/index.ts b/packages/api-evm/source/actions/index.ts index b96fd1d10..de43571b0 100644 --- a/packages/api-evm/source/actions/index.ts +++ b/packages/api-evm/source/actions/index.ts @@ -7,6 +7,7 @@ export * from "./eth-get-code.js"; export * from "./eth-get-storage-at.js"; export * from "./eth-get-transaction-count.js"; export * from "./eth-get-uncle-by-block-hash-and-index.js"; +export * from "./eth-get-uncle-by-block-number-and-index.js"; export * from "./eth-get-uncle-count-by-block-hash.js"; export * from "./eth-get-uncle-count-by-block-number.js"; export * from "./net-listening.js"; diff --git a/packages/api-evm/source/service-provider.ts b/packages/api-evm/source/service-provider.ts index 40b0b871c..c05d3ea8d 100644 --- a/packages/api-evm/source/service-provider.ts +++ b/packages/api-evm/source/service-provider.ts @@ -12,6 +12,7 @@ import { EthGetStorageAtAction, EthGetTransactionCount, EthGetUncleByBlockHashAndIndex, + EthGetUncleByBlockNumberAndIndex, EthGetUncleCountByBlockHash, EthGetUncleCountByBlockNumber, NetListeningAction, @@ -76,6 +77,7 @@ export class ServiceProvider extends AbstractServiceProvider { this.app.resolve(EthGetStorageAtAction), this.app.resolve(EthGetTransactionCount), this.app.resolve(EthGetUncleByBlockHashAndIndex), + this.app.resolve(EthGetUncleByBlockNumberAndIndex), this.app.resolve(EthGetUncleCountByBlockHash), this.app.resolve(EthGetUncleCountByBlockNumber), this.app.resolve(NetListeningAction),