Skip to content

Commit

Permalink
feat(evm-api): implement eth_getUncleByBlockHashAndIndex (#789)
Browse files Browse the repository at this point in the history
* Add eth_getUncleByBlockHashAndIndex

* Register handler

* Fix schema
  • Loading branch information
sebastijankuzner authored Dec 2, 2024
1 parent 954ccf3 commit 47ab48b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { inject, injectable } from "@mainsail/container";
import { Contracts, Exceptions, Identifiers } from "@mainsail/contracts";

@injectable()
export class EthGetUncleByBlockHashAndIndex implements Contracts.Api.RPC.Action {
@inject(Identifiers.Database.Service)
private readonly databaseService!: Contracts.Database.DatabaseService;

public readonly name: string = "eth_getUncleByBlockHashAndIndex";

public readonly schema = {
$id: `jsonRpc_${this.name}`,
maxItems: 2,
minItems: 2,

prefixItems: [{ $ref: "prefixedHex" }, { $ref: "prefixedHex" }], // TODO: Replace prefixedHex with prefixedBlockId
type: "array",
};

public async handle(parameters: [string]): Promise<null> {
if (!this.databaseService.hasCommitById(parameters[0].slice(2))) {
throw new Exceptions.RpcError("Block not found");
}

// eslint-disable-next-line unicorn/no-null
return null;
}
}
1 change: 1 addition & 0 deletions packages/api-evm/source/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from "./eth-get-block-by-number.js";
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-count-by-block-hash.js";
export * from "./eth-get-uncle-count-by-block-number.js";
export * from "./net-listening.js";
Expand Down
2 changes: 2 additions & 0 deletions packages/api-evm/source/service-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
EthGetCodeAction,
EthGetStorageAtAction,
EthGetTransactionCount,
EthGetUncleByBlockHashAndIndex,
EthGetUncleCountByBlockHash,
EthGetUncleCountByBlockNumber,
NetListeningAction,
Expand Down Expand Up @@ -74,6 +75,7 @@ export class ServiceProvider extends AbstractServiceProvider<Server> {
this.app.resolve(EthGetCodeAction),
this.app.resolve(EthGetStorageAtAction),
this.app.resolve(EthGetTransactionCount),
this.app.resolve(EthGetUncleByBlockHashAndIndex),
this.app.resolve(EthGetUncleCountByBlockHash),
this.app.resolve(EthGetUncleCountByBlockNumber),
this.app.resolve(NetListeningAction),
Expand Down

0 comments on commit 47ab48b

Please sign in to comment.