add Prague engine API support types (#140)
This commit is contained in:
parent
4d80530dd5
commit
85e34e8ab2
|
@ -26,15 +26,15 @@ jobs:
|
|||
include:
|
||||
- target:
|
||||
os: linux
|
||||
builder: ubuntu-20.04
|
||||
builder: ubuntu-latest
|
||||
shell: bash
|
||||
- target:
|
||||
os: macos
|
||||
builder: macos-12
|
||||
builder: macos-latest
|
||||
shell: bash
|
||||
- target:
|
||||
os: windows
|
||||
builder: windows-2019
|
||||
builder: windows-latest
|
||||
shell: msys2 {0}
|
||||
|
||||
defaults:
|
||||
|
|
20
web3.nim
20
web3.nim
|
@ -73,7 +73,7 @@ type
|
|||
data*: seq[byte]
|
||||
sender*: TSender
|
||||
|
||||
proc getValue(params: RequestParamsRx, field: string, FieldType: type):
|
||||
func getValue(params: RequestParamsRx, field: string, FieldType: type):
|
||||
Result[FieldType, string] {.gcsafe, raises: [].} =
|
||||
try:
|
||||
for param in params.named:
|
||||
|
@ -86,7 +86,7 @@ proc getValue(params: RequestParamsRx, field: string, FieldType: type):
|
|||
except CatchableError as exc:
|
||||
return err(exc.msg)
|
||||
|
||||
proc toJsonString(params: RequestParamsRx):
|
||||
func toJsonString(params: RequestParamsRx):
|
||||
Result[JsonString, string] {.gcsafe, raises: [].} =
|
||||
try:
|
||||
let res = JrpcSys.encode(params.toTx)
|
||||
|
@ -111,7 +111,7 @@ proc handleSubscriptionNotification(w: Web3, params: RequestParamsRx):
|
|||
|
||||
ok()
|
||||
|
||||
proc newWeb3*(provider: RpcClient): Web3 =
|
||||
func newWeb3*(provider: RpcClient): Web3 =
|
||||
result = Web3(provider: provider)
|
||||
result.subscriptions = initTable[string, Subscription]()
|
||||
let w3 = result
|
||||
|
@ -221,7 +221,7 @@ proc subscribeForLogs*(w: Web3, options: FilterOptions,
|
|||
else:
|
||||
result.historicalEventsProcessed = true
|
||||
|
||||
proc addAddressAndSignatureToOptions(options: FilterOptions, address: Address, topic: Topic): FilterOptions =
|
||||
func addAddressAndSignatureToOptions(options: FilterOptions, address: Address, topic: Topic): FilterOptions =
|
||||
result = options
|
||||
if result.address.kind == slkNull:
|
||||
result.address = AddressOrList(kind: slkSingle, single: address)
|
||||
|
@ -429,16 +429,16 @@ proc exec*[T](c: ContractInvocation[T, Web3SenderImpl], value = 0.u256, gas = 30
|
|||
#let response = waitFor w3.eth.eth_sendTransaction(cc)
|
||||
#echo response
|
||||
|
||||
proc contractSender*(web3: Web3, T: typedesc, toAddress: Address): Sender[T] =
|
||||
func contractSender*(web3: Web3, T: typedesc, toAddress: Address): Sender[T] =
|
||||
Sender[T](sender: Web3SenderImpl(web3: web3, contractAddress: toAddress))
|
||||
|
||||
proc createMutableContractInvocation*(sender: Web3SenderImpl, ReturnType: typedesc, data: sink seq[byte]): ContractInvocation[ReturnType, Web3SenderImpl] {.inline.} =
|
||||
func createMutableContractInvocation*(sender: Web3SenderImpl, ReturnType: typedesc, data: sink seq[byte]): ContractInvocation[ReturnType, Web3SenderImpl] {.inline.} =
|
||||
ContractInvocation[ReturnType, Web3SenderImpl](sender: sender, data: data)
|
||||
|
||||
proc createImmutableContractInvocation*(sender: Web3SenderImpl, ReturnType: typedesc, data: sink seq[byte]): ContractInvocation[ReturnType, Web3SenderImpl] {.inline.} =
|
||||
func createImmutableContractInvocation*(sender: Web3SenderImpl, ReturnType: typedesc, data: sink seq[byte]): ContractInvocation[ReturnType, Web3SenderImpl] {.inline.} =
|
||||
ContractInvocation[ReturnType, Web3SenderImpl](sender: sender, data: data)
|
||||
|
||||
proc contractInstance*(
|
||||
func contractInstance*(
|
||||
web3: Web3, T: typedesc, toAddress: Address): AsyncSender[T] =
|
||||
AsyncSender[T](
|
||||
sender: Web3AsyncSenderImpl(
|
||||
|
@ -499,7 +499,7 @@ proc isDeployed*(s: Sender, atBlock: RtBlockIdentifier): Future[bool] {.async.}
|
|||
proc subscribe*[TContract](s: Sender[TContract], t: typedesc, cb: proc): Future[Subscription] {.inline.} =
|
||||
subscribe(s, t, FilterOptions(), cb, SubscriptionErrorHandler nil)
|
||||
|
||||
proc copy[T](s: AsyncSender[T]): AsyncSender[T] =
|
||||
func copy[T](s: AsyncSender[T]): AsyncSender[T] =
|
||||
result = s
|
||||
result.sender.new()
|
||||
result.sender[] = s.sender[]
|
||||
|
@ -518,4 +518,4 @@ macro adjust*(s: AsyncSender, modifications: varargs[untyped]): untyped =
|
|||
let fieldVal = s[1]
|
||||
result[1].add quote do:
|
||||
`cp`.sender.`fieldName` = `fieldVal`
|
||||
result[1].add(cp)
|
||||
result[1].add(cp)
|
|
@ -54,10 +54,13 @@ derefType(ReceiptObject).useDefaultSerializationIn JrpcConv
|
|||
#------------------------------------------------------------------------------
|
||||
|
||||
WithdrawalV1.useDefaultSerializationIn JrpcConv
|
||||
DepositReceiptV1.useDefaultSerializationIn JrpcConv
|
||||
ExitV1.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadV1.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadV2.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadV1OrV2.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadV3.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadV4.useDefaultSerializationIn JrpcConv
|
||||
BlobsBundleV1.useDefaultSerializationIn JrpcConv
|
||||
ExecutionPayloadBodyV1.useDefaultSerializationIn JrpcConv
|
||||
PayloadAttributesV1.useDefaultSerializationIn JrpcConv
|
||||
|
@ -71,6 +74,7 @@ TransitionConfigurationV1.useDefaultSerializationIn JrpcConv
|
|||
GetPayloadV2Response.useDefaultSerializationIn JrpcConv
|
||||
GetPayloadV2ResponseExact.useDefaultSerializationIn JrpcConv
|
||||
GetPayloadV3Response.useDefaultSerializationIn JrpcConv
|
||||
GetPayloadV4Response.useDefaultSerializationIn JrpcConv
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# execution_types
|
||||
|
@ -400,4 +404,4 @@ func `$`*(v: TypedTransaction): string {.inline.} =
|
|||
func `$`*(v: RlpEncodedBytes): string {.inline.} =
|
||||
"0x" & distinctBase(v).toHex
|
||||
|
||||
{.pop.}
|
||||
{.pop.}
|
|
@ -1,5 +1,5 @@
|
|||
# nim-web3
|
||||
# Copyright (c) 2022-2023 Status Research & Development GmbH
|
||||
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
|
@ -28,6 +28,7 @@ createRpcSigsFromNim(RpcClient):
|
|||
proc engine_newPayloadV1(payload: ExecutionPayloadV1): PayloadStatusV1
|
||||
proc engine_newPayloadV2(payload: ExecutionPayloadV2): PayloadStatusV1
|
||||
proc engine_newPayloadV3(payload: ExecutionPayloadV3, expectedBlobVersionedHashes: seq[VersionedHash], parentBeaconBlockRoot: FixedBytes[32]): PayloadStatusV1
|
||||
proc engine_newPayloadV4(payload: ExecutionPayloadV4, expectedBlobVersionedHashes: seq[VersionedHash], parentBeaconBlockRoot: FixedBytes[32]): PayloadStatusV1
|
||||
proc engine_forkchoiceUpdatedV1(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Option[PayloadAttributesV1]): ForkchoiceUpdatedResponse
|
||||
proc engine_forkchoiceUpdatedV2(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Option[PayloadAttributesV2]): ForkchoiceUpdatedResponse
|
||||
proc engine_forkchoiceUpdatedV3(forkchoiceState: ForkchoiceStateV1, payloadAttributes: Option[PayloadAttributesV3]): ForkchoiceUpdatedResponse
|
||||
|
@ -35,6 +36,7 @@ createRpcSigsFromNim(RpcClient):
|
|||
proc engine_getPayloadV2(payloadId: PayloadID): GetPayloadV2Response
|
||||
proc engine_getPayloadV2_exact(payloadId: PayloadID): GetPayloadV2ResponseExact
|
||||
proc engine_getPayloadV3(payloadId: PayloadID): GetPayloadV3Response
|
||||
proc engine_getPayloadV4(payloadId: PayloadID): GetPayloadV4Response
|
||||
proc engine_exchangeTransitionConfigurationV1(transitionConfiguration: TransitionConfigurationV1): TransitionConfigurationV1
|
||||
proc engine_getPayloadBodiesByHashV1(hashes: seq[BlockHash]): seq[Option[ExecutionPayloadBodyV1]]
|
||||
proc engine_getPayloadBodiesByRangeV1(start: Quantity, count: Quantity): seq[Option[ExecutionPayloadBodyV1]]
|
||||
|
@ -115,4 +117,4 @@ template newPayload*(
|
|||
template exchangeCapabilities*(
|
||||
rpcClient: RpcClient,
|
||||
methods: seq[string]): Future[seq[string]] =
|
||||
engine_exchangeCapabilities(rpcClient, methods)
|
||||
engine_exchangeCapabilities(rpcClient, methods)
|
|
@ -25,6 +25,19 @@ type
|
|||
address*: Address
|
||||
amount*: Quantity
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md#depositreceiptv1
|
||||
DepositReceiptV1* = object
|
||||
pubkey*: FixedBytes[48]
|
||||
withdrawalCredentials*: FixedBytes[32]
|
||||
amount*: Quantity
|
||||
signature*: FixedBytes[96]
|
||||
index*: Quantity
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md#exitv1
|
||||
ExitV1* = object
|
||||
sourceAddress*: Address
|
||||
validatorPublicKey*: FixedBytes[48]
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/paris.md#executionpayloadv1
|
||||
ExecutionPayloadV1* = object
|
||||
parentHash*: Hash256
|
||||
|
@ -110,10 +123,33 @@ type
|
|||
blobGasUsed*: Quantity
|
||||
excessBlobGas*: Quantity
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md#executionpayloadv4
|
||||
ExecutionPayloadV4* = object
|
||||
parentHash*: Hash256
|
||||
feeRecipient*: Address
|
||||
stateRoot*: Hash256
|
||||
receiptsRoot*: Hash256
|
||||
logsBloom*: FixedBytes[256]
|
||||
prevRandao*: FixedBytes[32]
|
||||
blockNumber*: Quantity
|
||||
gasLimit*: Quantity
|
||||
gasUsed*: Quantity
|
||||
timestamp*: Quantity
|
||||
extraData*: DynamicBytes[0, 32]
|
||||
baseFeePerGas*: UInt256
|
||||
blockHash*: Hash256
|
||||
transactions*: seq[TypedTransaction]
|
||||
withdrawals*: seq[WithdrawalV1]
|
||||
blobGasUsed*: Quantity
|
||||
excessBlobGas*: Quantity
|
||||
depositReceipts*: seq[DepositReceiptV1]
|
||||
exits*: seq[ExitV1]
|
||||
|
||||
SomeExecutionPayload* =
|
||||
ExecutionPayloadV1 |
|
||||
ExecutionPayloadV2 |
|
||||
ExecutionPayloadV3
|
||||
ExecutionPayloadV3 |
|
||||
ExecutionPayloadV4
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/ee3df5bc38f28ef35385cefc9d9ca18d5e502778/src/engine/cancun.md#blobsbundlev1
|
||||
BlobsBundleV1* = object
|
||||
|
@ -210,10 +246,18 @@ type
|
|||
blobsBundle*: BlobsBundleV1
|
||||
shouldOverrideBuilder*: bool
|
||||
|
||||
# https://github.com/ethereum/execution-apis/blob/90a46e9137c89d58e818e62fa33a0347bba50085/src/engine/prague.md#response-1
|
||||
GetPayloadV4Response* = object
|
||||
executionPayload*: ExecutionPayloadV3
|
||||
blockValue*: UInt256
|
||||
blobsBundle*: BlobsBundleV1
|
||||
shouldOverrideBuilder*: bool
|
||||
|
||||
SomeGetPayloadResponse* =
|
||||
ExecutionPayloadV1 |
|
||||
GetPayloadV2Response |
|
||||
GetPayloadV3Response
|
||||
GetPayloadV3Response |
|
||||
GetPayloadV4Response
|
||||
|
||||
const
|
||||
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/common.md#errors
|
||||
|
@ -232,4 +276,4 @@ const
|
|||
{.push raises: [].}
|
||||
|
||||
template `==`*(a, b: TypedTransaction): bool =
|
||||
distinctBase(a) == distinctBase(b)
|
||||
distinctBase(a) == distinctBase(b)
|
Loading…
Reference in New Issue