diff --git a/web3/engine_api.nim b/web3/engine_api.nim index 6434083..87b83c9 100644 --- a/web3/engine_api.nim +++ b/web3/engine_api.nim @@ -58,6 +58,7 @@ createRpcSigsFromNim(RpcClient): executionRequests: Opt[array[3, seq[byte]]]): PayloadStatusV1 proc engine_forkchoiceUpdatedV2(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Opt[PayloadAttributes]): ForkchoiceUpdatedResponse proc engine_forkchoiceUpdatedV3(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Opt[PayloadAttributes]): ForkchoiceUpdatedResponse + proc engine_forkchoiceUpdatedV4(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Opt[PayloadAttributes]): ForkchoiceUpdatedResponse template forkchoiceUpdated*( rpcClient: RpcClient, @@ -77,6 +78,12 @@ template forkchoiceUpdated*( payloadAttributes: Opt[PayloadAttributesV3]): Future[ForkchoiceUpdatedResponse] = engine_forkchoiceUpdatedV3(rpcClient, forkchoiceState, payloadAttributes) +template forkchoiceUpdated*( + rpcClient: RpcClient, + forkchoiceState: ForkchoiceStateV1, + payloadAttributes: Opt[PayloadAttributesV4]): Future[ForkchoiceUpdatedResponse] = + engine_forkchoiceUpdatedV4(rpcClient, forkchoiceState, payloadAttributes) + template getPayload*( rpcClient: RpcClient, T: type ExecutionPayloadV1, diff --git a/web3/engine_api_types.nim b/web3/engine_api_types.nim index 5dff6b9..b8d3277 100644 --- a/web3/engine_api_types.nim +++ b/web3/engine_api_types.nim @@ -157,6 +157,15 @@ type withdrawals*: seq[WithdrawalV1] parentBeaconBlockRoot*: Hash32 + PayloadAttributesV4* = object + timestamp*: Quantity + prevRandao*: Bytes32 + suggestedFeeRecipient*: Address + withdrawals*: seq[WithdrawalV1] + parentBeaconBlockRoot*: Hash32 + targetBlobCount*: Quantity + maximumBlobCount*: Quantity + # This is ugly, but see the comment on ExecutionPayloadV1OrV2. PayloadAttributesV1OrV2* = object timestamp*: Quantity @@ -167,7 +176,8 @@ type SomePayloadAttributes* = PayloadAttributesV1 | PayloadAttributesV2 | - PayloadAttributesV3 + PayloadAttributesV3 | + PayloadAttributesV4 # https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.4/src/engine/paris.md#payloadstatusv1 PayloadExecutionStatus* {.pure.} = enum diff --git a/web3/eth_api_types.nim b/web3/eth_api_types.nim index c3d5c9a..bf95c37 100644 --- a/web3/eth_api_types.nim +++ b/web3/eth_api_types.nim @@ -92,6 +92,7 @@ type excessBlobGas*: Opt[Quantity] # EIP-4844 parentBeaconBlockRoot*: Opt[Hash32] # EIP-4788 requestsRoot*: Opt[Hash32] # EIP-7685 + targetBlobCount*: Opt[Quantity] # EIP-7742 WithdrawalObject* = object index*: Quantity diff --git a/web3/execution_types.nim b/web3/execution_types.nim index 3607d01..b6e0dc2 100644 --- a/web3/execution_types.nim +++ b/web3/execution_types.nim @@ -43,6 +43,8 @@ type suggestedFeeRecipient*: Address withdrawals*: Opt[seq[WithdrawalV1]] parentBeaconBlockRoot*: Opt[Hash32] + targetBlobCount*: Opt[Quantity] + maximumBlobCount*: Opt[Quantity] SomeOptionalPayloadAttributes* = Opt[PayloadAttributesV1] | @@ -71,7 +73,9 @@ func version*(payload: ExecutionPayload): Version = Version.V1 func version*(attr: PayloadAttributes): Version = - if attr.parentBeaconBlockRoot.isSome: + if attr.targetBlobCount.isSome or attr.maximumBlobCount.isSome: + Version.V4 + elif attr.parentBeaconBlockRoot.isSome: Version.V3 elif attr.withdrawals.isSome: Version.V2 @@ -120,6 +124,17 @@ func V3*(attr: PayloadAttributes): PayloadAttributesV3 = parentBeaconBlockRoot: attr.parentBeaconBlockRoot.get ) +func V4*(attr: PayloadAttributes): PayloadAttributesV4 = + PayloadAttributesV4( + timestamp: attr.timestamp, + prevRandao: attr.prevRandao, + suggestedFeeRecipient: attr.suggestedFeeRecipient, + withdrawals: attr.withdrawals.get(newSeq[WithdrawalV1]()), + parentBeaconBlockRoot: attr.parentBeaconBlockRoot.get, + targetBlobCount: attr.targetBlobCount.get, + maximumBlobCount: attr.maximumBlobCount.get, + ) + func V1*(attr: Opt[PayloadAttributes]): Opt[PayloadAttributesV1] = if attr.isNone: return Opt.none(PayloadAttributesV1) @@ -135,6 +150,11 @@ func V3*(attr: Opt[PayloadAttributes]): Opt[PayloadAttributesV3] = return Opt.none(PayloadAttributesV3) Opt.some(attr.get.V3) +func V4*(attr: Opt[PayloadAttributes]): Opt[PayloadAttributesV4] = + if attr.isNone: + return Opt.none(PayloadAttributesV4) + Opt.some(attr.get.V4) + func payloadAttributes*(attr: PayloadAttributesV1): PayloadAttributes = PayloadAttributes( timestamp: attr.timestamp, @@ -159,6 +179,17 @@ func payloadAttributes*(attr: PayloadAttributesV3): PayloadAttributes = parentBeaconBlockRoot: Opt.some(attr.parentBeaconBlockRoot) ) +func payloadAttributes*(attr: PayloadAttributesV4): PayloadAttributes = + PayloadAttributes( + timestamp: attr.timestamp, + prevRandao: attr.prevRandao, + suggestedFeeRecipient: attr.suggestedFeeRecipient, + withdrawals: Opt.some(attr.withdrawals), + parentBeaconBlockRoot: Opt.some(attr.parentBeaconBlockRoot), + targetBlobCount: Opt.some(attr.targetBlobCount), + maximumBlobCount: Opt.some(attr.maximumBlobCount), + ) + func payloadAttributes*(x: Opt[PayloadAttributesV1]): Opt[PayloadAttributes] = if x.isNone: Opt.none(PayloadAttributes) else: Opt.some(payloadAttributes x.get) @@ -171,6 +202,10 @@ func payloadAttributes*(x: Opt[PayloadAttributesV3]): Opt[PayloadAttributes] = if x.isNone: Opt.none(PayloadAttributes) else: Opt.some(payloadAttributes x.get) +func payloadAttributes*(x: Opt[PayloadAttributesV4]): Opt[PayloadAttributes] = + if x.isNone: Opt.none(PayloadAttributes) + else: Opt.some(payloadAttributes x.get) + func V1V2*(p: ExecutionPayload): ExecutionPayloadV1OrV2 = ExecutionPayloadV1OrV2( parentHash: p.parentHash,