Skip to content

Commit

Permalink
fix: resolves #33
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Dec 1, 2024
1 parent 2e1217e commit 2e0d4af
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-waves-stare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ox": patch
---

Added support for block identifiers.
17 changes: 16 additions & 1 deletion src/core/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type * as Errors from './Errors.js'
import * as Hex from './Hex.js'
import * as Transaction from './Transaction.js'
import * as Withdrawal from './Withdrawal.js'
import type { Compute } from './internal/types.js'
import type { Compute, OneOf } from './internal/types.js'

/** A Block as defined in the [Execution API specification](https://github.com/ethereum/execution-apis/blob/main/src/schemas/block.yaml). */
export type Block<
Expand Down Expand Up @@ -78,6 +78,21 @@ export type Block<
/** A Block hash. */
export type Hash = Hex.Hex

/** A Block identifier. */
export type Identifier<bigintType = bigint> = {
/** Whether or not to throw an error if the block is not in the canonical chain as described below. Only allowed in conjunction with the blockHash tag. Defaults to false. */
requireCanonical?: boolean | undefined
} & OneOf<
| {
/** The block in the canonical chain with this number */
blockNumber: Number<bigintType>
}
| {
/** The block uniquely identified by this hash. The `blockNumber` and `blockHash` properties are mutually exclusive; exactly one of them must be set. */
blockHash: Hash
}
>

/** A Block number. */
export type Number<bigintType = bigint> = bigintType

Expand Down
54 changes: 45 additions & 9 deletions src/core/internal/rpcSchemas/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,19 @@ export type Eth = RpcSchema.From<
| [transaction: TransactionRequest.Rpc]
| [
transaction: TransactionRequest.Rpc,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
| [
transaction: TransactionRequest.Rpc,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
// TODO: add type
stateOverride: unknown,
]
Expand Down Expand Up @@ -160,11 +168,19 @@ export type Eth = RpcSchema.From<
| [transaction: TransactionRequest.Rpc]
| [
transaction: TransactionRequest.Rpc,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
| [
transaction: TransactionRequest.Rpc,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
// TODO: add type
stateOverride: unknown,
]
Expand Down Expand Up @@ -230,7 +246,11 @@ export type Eth = RpcSchema.From<
method: 'eth_getBalance'
params: [
address: Address.Address,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
}
ReturnType: Hex.Hex
Expand Down Expand Up @@ -330,7 +350,11 @@ export type Eth = RpcSchema.From<
method: 'eth_getCode'
params: [
address: Address.Address,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
}
ReturnType: Hex.Hex
Expand Down Expand Up @@ -403,7 +427,11 @@ export type Eth = RpcSchema.From<
/** An array of storage-keys that should be proofed and included. */
storageKeys: Hex.Hex[],
/** Block identifier to pull the proof from. */
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
}
ReturnType: AccountProof.Rpc
Expand All @@ -423,7 +451,11 @@ export type Eth = RpcSchema.From<
params: [
address: Address.Address,
index: Hex.Hex,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
}
ReturnType: Hex.Hex
Expand Down Expand Up @@ -490,7 +522,11 @@ export type Eth = RpcSchema.From<
method: 'eth_getTransactionCount'
params: [
address: Address.Address,
block: Block.Number<Hex.Hex> | Block.Tag | Block.Hash,
block:
| Block.Number<Hex.Hex>
| Block.Tag
| Block.Hash
| Block.Identifier,
]
}
ReturnType: Hex.Hex
Expand Down

0 comments on commit 2e0d4af

Please sign in to comment.