Skip to content

Commit

Permalink
Add action
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastijankuzner committed Jan 10, 2025
1 parent cdb4d80 commit f19ea60
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { inject, injectable } from "@mainsail/container";
import { Contracts, Identifiers } from "@mainsail/contracts";

import { TransactionResource } from "../resources/index.js";

@injectable()
export class EthGetTransactionByBlockNumberAndIndex implements Contracts.Api.RPC.Action {
@inject(Identifiers.Application.Instance)
private readonly app!: Contracts.Kernel.Application;

@inject(Identifiers.Database.Service)
private readonly databaseService!: Contracts.Database.DatabaseService;

public readonly name: string = "eth_getTransactionByBlockNumberAndIndex";

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

maxItems: 2,
minItems: 2,

prefixItems: [{ $ref: "prefixedHex" }, { $ref: "prefixedHex" }], // TODO: Use block id & limit sequence
type: "array",
};

public async handle(parameters: [string, string]): Promise<any> {
const transaction = await this.databaseService.getTransactionByBlockIdAndIndex(
parameters[0].slice(2),
Number.parseInt(parameters[1]),
);

if (!transaction) {
return null;
}

return this.app.resolve(TransactionResource).transform(transaction.data);
}
}
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 @@ -8,6 +8,7 @@ export * from "./eth-get-block-transaction-count-by-number.js";
export * from "./eth-get-code.js";
export * from "./eth-get-storage-at.js";
export * from "./eth-get-transaction-by-block-hash-and-index.js";
export * from "./eth-get-transaction-by-block-number-and-index.js";
export * from "./eth-get-transaction-by-hash.js";
export * from "./eth-get-transaction-count.js";
export * from "./eth-get-uncle-by-block-hash-and-index.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 @@ -13,6 +13,7 @@ import {
EthGetCodeAction,
EthGetStorageAtAction,
EthGetTransactionByBlockHashAndIndex,
EthGetTransactionByBlockNumberAndIndex,
EthGetTransactionByHash,
EthGetTransactionCount,
EthGetUncleByBlockHashAndIndex,
Expand Down Expand Up @@ -84,6 +85,7 @@ export class ServiceProvider extends AbstractServiceProvider<Server> {
this.app.resolve(EthGetCodeAction),
this.app.resolve(EthGetStorageAtAction),
this.app.resolve(EthGetTransactionByBlockHashAndIndex),
this.app.resolve(EthGetTransactionByBlockNumberAndIndex),
this.app.resolve(EthGetTransactionByHash),
this.app.resolve(EthGetTransactionCount),
this.app.resolve(EthGetUncleByBlockHashAndIndex),
Expand Down

0 comments on commit f19ea60

Please sign in to comment.