-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(evm-api): implement
eth_getBlockByHash
(#783)
* Add blockId storage * Store block id * Implement getCommitById * Add cache * Add eth_getBlockByHash * Remove store
- Loading branch information
1 parent
8304bda
commit 1e710e2
Showing
7 changed files
with
83 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { BlockResource } from "../resources/index.js"; | ||
|
||
@injectable() | ||
export class EthGetBlockByHashAction implements Contracts.Api.RPC.Action { | ||
public readonly name: string = "eth_getBlockByHash"; | ||
|
||
@inject(Identifiers.Application.Instance) | ||
private readonly app!: Contracts.Kernel.Application; | ||
|
||
@inject(Identifiers.Database.Service) | ||
private readonly databaseService!: Contracts.Database.DatabaseService; | ||
|
||
public readonly schema = { | ||
$id: `jsonRpc_${this.name}`, | ||
|
||
maxItems: 2, | ||
minItems: 2, | ||
|
||
prefixItems: [{ $ref: "prefixedHex" }, { type: "boolean" }], // TODO: Replace prefixedHex with prefixedBlockId | ||
type: "array", | ||
}; | ||
|
||
public async handle(parameters: [string, boolean]): Promise<object | null> { | ||
const transactionObject = parameters[1]; | ||
|
||
const commit = await this.databaseService.getCommitById(parameters[0].slice(2)); | ||
|
||
if (!commit) { | ||
// eslint-disable-next-line unicorn/no-null | ||
return null; | ||
} | ||
|
||
return this.app.resolve(BlockResource).transform(commit.block, transactionObject); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters