Etan Kissling c4c37302b1
Introduce wrapper type for EIP-4844 transactions (#2177)
* Introduce wrapper type for EIP-4844 transactions

EIP-4844 blob sidecars are a concept that only exists in the mempool.
After inclusion of a transaction into an execution block, only the
versioned hash within the transaction remains. To improve type safety,
replace the `Transaction.networkPayload` member with a wrapper type
`PooledTransaction` that is used in contexts where blob sidecars exist.

* Bump nimbus-eth2 to 87605d08a7f9cfc3b223bd32143e93a6cdf351ac

* IPv6 'listen-address' in `nimbus_verified_proxy`

* Bump nim-libp2p to 21cbe3a91a70811522554e89e6a791172cebfef2

* Fix beacon_lc_bridge payload conversion and conf.listenAddress type

* Change nimbus_verified_proxy.asExecutionData param to SomeExecutionPayload

* Rerun nph to fix asExecutionData style format

* nimbus_verified_proxy listenAddress

* Use PooledTransaction in nimbus-eth1 tests

---------

Co-authored-by: jangko <jangko128@gmail.com>
2024-05-15 10:07:59 +07:00

81 lines
2.6 KiB
Nim

# Nimbus
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
# at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
import
eth/[common, rlp],
chronos, stint,
json_rpc/[rpcclient],
../../../nimbus/transaction,
../../../nimbus/utils/utils,
../../../nimbus/beacon/web3_eth_conv,
web3/eth_api
export eth_api
proc sendTransaction*(
client: RpcClient, tx: PooledTransaction): Future[bool] {.async.} =
let data = rlp.encode(tx)
let txHash = keccakHash(data)
let hex = await client.eth_sendRawTransaction(data)
let decodedHash = ethHash(hex)
result = decodedHash == txHash
proc blockNumber*(client: RpcClient): Future[uint64] {.async.} =
let hex = await client.eth_blockNumber()
result = hex.uint64
proc balanceAt*(client: RpcClient, address: EthAddress, number: uint64): Future[UInt256] {.async.} =
let hex = await client.eth_getBalance(w3Addr(address), blockId(number))
result = hex
proc balanceAt*(client: RpcClient, address: EthAddress): Future[UInt256] {.async.} =
let hex = await client.eth_getBalance(w3Addr(address), blockId("latest"))
result = hex
proc nonceAt*(client: RpcClient, address: EthAddress): Future[AccountNonce] {.async.} =
let hex = await client.eth_getTransactionCount(w3Addr(address), blockId("latest"))
result = hex.AccountNonce
func toTopics(list: openArray[Web3Hash]): seq[common.Topic] =
result = newSeqOfCap[common.Topic](list.len)
for x in list:
result.add common.Topic(x)
func toLogs(list: openArray[LogObject]): seq[Log] =
result = newSeqOfCap[Log](list.len)
for x in list:
result.add Log(
address: ethAddr x.address,
data: x.data,
topics: toTopics(x.topics)
)
proc txReceipt*(client: RpcClient, txHash: common.Hash256): Future[Option[Receipt]] {.async.} =
let rc = await client.eth_getTransactionReceipt(w3Hash txHash)
if rc.isNil:
return none(Receipt)
let rec = Receipt(
receiptType: LegacyReceipt,
isHash : rc.root.isSome,
status : rc.status.isSome,
hash : ethHash rc.root.get(w3Hash()),
cumulativeGasUsed: rc.cumulativeGasUsed.GasInt,
bloom : BloomFilter(rc.logsBloom),
logs : toLogs(rc.logs)
)
result = some(rec)
proc gasUsed*(client: RpcClient, txHash: common.Hash256): Future[Option[GasInt]] {.async.} =
let rc = await client.eth_getTransactionReceipt(w3Hash txHash)
if rc.isNil:
return none(GasInt)
result = some(rc.gasUsed.GasInt)