Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Prague (EIP-7685, 6110, 7002, 7251, and 7702) fields #160

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/test_json_marshalling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ suite "JSON-RPC Quantity":
checkRandomObject(ProofResponse)
checkRandomObject(FilterOptions)
checkRandomObject(TransactionArgs)
checkRandomObject(AuthorizationObject)

checkRandomObject(BlockHeader)
checkRandomObject(BlockObject)
Expand Down
4 changes: 4 additions & 0 deletions web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ProofResponse.useDefaultSerializationIn JrpcConv
FilterOptions.useDefaultSerializationIn JrpcConv
TransactionArgs.useDefaultSerializationIn JrpcConv
FeeHistoryResult.useDefaultSerializationIn JrpcConv
AuthorizationObject.useDefaultSerializationIn JrpcConv
DepositRequestObject.useDefaultSerializationIn JrpcConv
WithdrawalRequestObject.useDefaultSerializationIn JrpcConv
ConsolidationRequestObject.useDefaultSerializationIn JrpcConv

derefType(BlockHeader).useDefaultSerializationIn JrpcConv
derefType(BlockObject).useDefaultSerializationIn JrpcConv
Expand Down
139 changes: 86 additions & 53 deletions web3/eth_api_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type
commitments*: Opt[seq[KZGCommitment]]
proofs*: Opt[seq[KZGProof]]

# EIP-7702
authorizationList*: Opt[seq[AuthorizationObject]]

## A block header object
BlockHeader* = ref object
number*: Quantity
Expand All @@ -83,41 +86,63 @@ type
blobGasUsed*: Opt[Quantity] # EIP-4844
excessBlobGas*: Opt[Quantity] # EIP-4844
parentBeaconBlockRoot*: Opt[Hash256] # EIP-4788
requestsRoot*: Opt[Hash256] # EIP-7685

WithdrawalObject* = object
index*: Quantity
validatorIndex*: Quantity
address*: Address
amount*: Quantity

DepositRequestObject* = object # EIP-6110
pubkey* : FixedBytes[48]
withdrawalCredentials*: FixedBytes[32]
amount* : Quantity
signature* : FixedBytes[96]
index* : Quantity

WithdrawalRequestObject* = object # EIP-7002
sourceAddress* : FixedBytes[20]
validatorPubkey*: FixedBytes[48]
amount* : Quantity

ConsolidationRequestObject* = object # EIP-7251
sourceAddress*: FixedBytes[20]
sourcePubkey* : FixedBytes[48]
targetPubkey* : FixedBytes[48]

## A block object, or null when no block was found
BlockObject* = ref object
number*: BlockNumber # the block number. null when its pending block.
hash*: Hash256 # hash of the block. null when its pending block.
parentHash*: Hash256 # hash of the parent block.
sha3Uncles*: Hash256 # SHA3 of the uncles data in the block.
logsBloom*: FixedBytes[256] # the bloom filter for the logs of the block. null when its pending block.
transactionsRoot*: Hash256 # the root of the transaction trie of the block.
stateRoot*: Hash256 # the root of the final state trie of the block.
receiptsRoot*: Hash256 # the root of the receipts trie of the block.
miner*: Address # the address of the beneficiary to whom the mining rewards were given.
difficulty*: UInt256 # integer of the difficulty for this block.
extraData*: HistoricExtraData # the "extra data" field of this block.
gasLimit*: Quantity # the maximum gas allowed in this block.
gasUsed*: Quantity # the total used gas by all transactions in this block.
timestamp*: Quantity # the unix timestamp for when the block was collated.
nonce*: Opt[FixedBytes[8]] # hash of the generated proof-of-work. null when its pending block.
mixHash*: Hash256
size*: Quantity # integer the size of this block in bytes.
totalDifficulty*: UInt256 # integer of the total difficulty of the chain until this block.
transactions*: seq[TxOrHash] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles*: seq[Hash256] # list of uncle hashes.
number*: BlockNumber # the block number. null when its pending block.
hash*: Hash256 # hash of the block. null when its pending block.
parentHash*: Hash256 # hash of the parent block.
sha3Uncles*: Hash256 # SHA3 of the uncles data in the block.
logsBloom*: FixedBytes[256] # the bloom filter for the logs of the block. null when its pending block.
transactionsRoot*: Hash256 # the root of the transaction trie of the block.
stateRoot*: Hash256 # the root of the final state trie of the block.
receiptsRoot*: Hash256 # the root of the receipts trie of the block.
miner*: Address # the address of the beneficiary to whom the mining rewards were given.
difficulty*: UInt256 # integer of the difficulty for this block.
extraData*: HistoricExtraData # the "extra data" field of this block.
gasLimit*: Quantity # the maximum gas allowed in this block.
gasUsed*: Quantity # the total used gas by all transactions in this block.
timestamp*: Quantity # the unix timestamp for when the block was collated.
nonce*: Opt[FixedBytes[8]]
mixHash*: Hash256 # hash of the generated proof-of-work. null when its pending block.
size*: Quantity # integer the size of this block in bytes.
totalDifficulty*: UInt256 # integer of the total difficulty of the chain until this block.
transactions*: seq[TxOrHash] # list of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.
uncles*: seq[Hash256] # list of uncle hashes.
baseFeePerGas*: Opt[UInt256] # EIP-1559
withdrawals*: Opt[seq[WithdrawalObject]] # EIP-4895
withdrawalsRoot*: Opt[Hash256] # EIP-4895
blobGasUsed*: Opt[Quantity] # EIP-4844
excessBlobGas*: Opt[Quantity] # EIP-4844
parentBeaconBlockRoot*: Opt[Hash256] # EIP-4788
depositRequests*: Opt[seq[DepositRequestObject]] # EIP-6110
withdrawalRequests*: Opt[seq[WithdrawalRequestObject]] # EIP-7002
consolidationRequests*: Opt[seq[ConsolidationRequestObject]] # EIP-7251
requestsRoot*: Opt[Hash256] # EIP-7685

TxOrHashKind* = enum
tohHash
Expand All @@ -139,21 +164,29 @@ type
error*: Opt[string]
gasUsed*: Quantity

TransactionObject* = ref object # A transaction object, or null when no transaction was found:
hash*: TxHash # hash of the transaction.
nonce*: Quantity # TODO: Is int? the number of transactions made by the sender prior to this one.
AuthorizationObject* = object
chainId*: Quantity
address*: Address
nonce*: Quantity
yParity*: Quantity
R*: UInt256
S*: UInt256

TransactionObject* = ref object # A transaction object, or null when no transaction was found:
hash*: TxHash # hash of the transaction.
nonce*: Quantity # TODO: Is int? the number of transactions made by the sender prior to this one.
blockHash*: Opt[BlockHash] # hash of the block where this transaction was in. null when its pending.
blockNumber*: Opt[BlockNumber] # block number where this transaction was in. null when its pending.
transactionIndex*: Opt[Quantity] # integer of the transactions index position in the block. null when its pending.
`from`*: Address # address of the sender.
`from`*: Address # address of the sender.
to*: Opt[Address] # address of the receiver. null when its a contract creation transaction.
value*: UInt256 # value transferred in Wei.
gasPrice*: Quantity # gas price provided by the sender in Wei.
gas*: Quantity # gas provided by the sender.
input*: seq[byte] # the data send along with the transaction.
v*: Quantity # ECDSA recovery id
r*: UInt256 # ECDSA signature r
s*: UInt256 # ECDSA signature s
value*: UInt256 # value transferred in Wei.
gasPrice*: Quantity # gas price provided by the sender in Wei.
gas*: Quantity # gas provided by the sender.
input*: seq[byte] # the data send along with the transaction.
v*: Quantity # ECDSA recovery id
r*: UInt256 # ECDSA signature r
s*: UInt256 # ECDSA signature s
yParity*: Opt[Quantity] # ECDSA y parity, none for Legacy, same as v for >= Tx2930
`type`*: Opt[Quantity] # EIP-2718, with 0x0 for Legacy
chainId*: Opt[Quantity] # EIP-159
Expand All @@ -162,20 +195,21 @@ type
maxPriorityFeePerGas*: Opt[Quantity] # EIP-1559
maxFeePerBlobGas*: Opt[UInt256] # EIP-4844
blobVersionedHashes*: Opt[seq[VersionedHash]] # EIP-4844

ReceiptObject* = ref object # A transaction receipt object, or null when no receipt was found:
transactionHash*: TxHash # hash of the transaction.
transactionIndex*: Quantity # integer of the transactions index position in the block.
blockHash*: BlockHash # hash of the block where this transaction was in.
blockNumber*: BlockNumber # block number where this transaction was in.
`from`*: Address # address of the sender.
authorizationList*: Opt[seq[AuthorizationObject]] # EIP-7702

ReceiptObject* = ref object # A transaction receipt object, or null when no receipt was found:
transactionHash*: TxHash # hash of the transaction.
transactionIndex*: Quantity # integer of the transactions index position in the block.
blockHash*: BlockHash # hash of the block where this transaction was in.
blockNumber*: BlockNumber # block number where this transaction was in.
`from`*: Address # address of the sender.
to*: Opt[Address] # address of the receiver. null when its a contract creation transaction.
cumulativeGasUsed*: Quantity # the total amount of gas used when this transaction was executed in the block.
effectiveGasPrice*: Quantity # The sum of the base fee and tip paid per unit of gas.
gasUsed*: Quantity # the amount of gas used by this specific transaction alone.
cumulativeGasUsed*: Quantity # the total amount of gas used when this transaction was executed in the block.
effectiveGasPrice*: Quantity # The sum of the base fee and tip paid per unit of gas.
gasUsed*: Quantity # the amount of gas used by this specific transaction alone.
contractAddress*: Opt[Address] # the contract address created, if the transaction was a contract creation, otherwise null.
logs*: seq[LogObject] # TODO: See Wiki for details. list of log objects, which this transaction generated.
logsBloom*: FixedBytes[256] # bloom filter for light clients to quickly retrieve related logs.
logs*: seq[LogObject] # TODO: See Wiki for details. list of log objects, which this transaction generated.
logsBloom*: FixedBytes[256] # bloom filter for light clients to quickly retrieve related logs.
`type`*: Opt[Quantity] # integer of the transaction type, 0x0 for legacy transactions, 0x1 for access list types, 0x2 for dynamic fees.
root*: Opt[Hash256] # 32 bytes of post-transaction stateroot (pre Byzantium)
status*: Opt[Quantity] # either 1 (success) or 0 (failure)
Expand All @@ -201,23 +235,22 @@ type
FilterOptions* = object
fromBlock*: Opt[RtBlockIdentifier] # (optional, default: "latest") integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.
toBlock*: Opt[RtBlockIdentifier] # (optional, default: "latest") integer block number, or "latest" for the last mined block or "pending", "earliest" for not yet mined transactions.
# TODO: address as optional list of address or optional address
address*: AddressOrList # (optional) contract address or a list of addresses from which logs should originate.
topics*: seq[TopicOrList] # (optional) list of DATA topics. Topics are order-dependent. Each topic can also be a list of DATA with "or" options.
blockHash*: Opt[BlockHash] # (optional) hash of the block. If its present, fromBlock and toBlock, should be none. Introduced in EIP234
address*: AddressOrList # (optional) contract address or a list of addresses from which logs should originate.
topics*: seq[TopicOrList] # (optional) list of DATA topics. Topics are order-dependent. Each topic can also be a list of DATA with "or" options.
blockHash*: Opt[BlockHash] # (optional) hash of the block. If its present, fromBlock and toBlock, should be none. Introduced in EIP234

LogObject* = object
removed*: bool # true when the log was removed, due to a chain reorganization. false if its a valid log.
removed*: bool # true when the log was removed, due to a chain reorganization. false if its a valid log.
logIndex*: Opt[Quantity] # integer of the log index position in the block. null when its pending log.
transactionIndex*: Opt[Quantity] # integer of the transactions index position log was created from. null when its pending log.
transactionHash*: Opt[TxHash] # hash of the transactions this log was created from. null when its pending log.
blockHash*: Opt[BlockHash] # hash of the block where this log was in. null when its pending. null when its pending log.
blockNumber*: Opt[BlockNumber] # the block number where this log was in. null when its pending. null when its pending log.
address*: Address # address from which this log originated.
data*: seq[byte] # contains one or more 32 Bytes non-indexed arguments of the log.
topics*: seq[Topic] # array of 0 to 4 32 Bytes DATA of indexed log arguments.
# (In solidity: The first topic is the hash of the signature of the event.
# (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.)
address*: Address # address from which this log originated.
data*: seq[byte] # contains one or more 32 Bytes non-indexed arguments of the log.
topics*: seq[Topic] # array of 0 to 4 32 Bytes DATA of indexed log arguments.
# (In solidity: The first topic is the hash of the signature of the event.
# (e.g. Deposit(address,bytes32,uint256)), except you declared the event with the anonymous specifier.)

RlpEncodedBytes* = distinct seq[byte]

Expand Down