Skip to content

Commit

Permalink
Replace AccessTuple with AccessPair from nim-eth (#169)
Browse files Browse the repository at this point in the history
* Fix deprecated warnings related to eth/common

* Replace AccessTuple with AccessPair from nim-eth
  • Loading branch information
jangko authored Oct 11, 2024
1 parent 785991d commit 86448ed
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/test_contracts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ suite "Contracts":
# was not deployed yet:
try:
let balFirst = await ns.getBalance(web3.defaultAccount).call(
blockNumber = 1.BlockNumber)
blockNumber = 1.Quantity)
echo "getbalance (first block): ", balFirst.toHex
except CatchableError as err:
echo "getbalance (first block): ", err.msg
Expand All @@ -267,7 +267,7 @@ suite "Contracts":
echo "transfers: ", await ns.getJsonLogs(
Transfer,
fromBlock = Opt.some(blockId(deployedAtBlock)),
toBlock = Opt.some(blockId(1000.BlockNumber)))
toBlock = Opt.some(blockId(1000)))

await notifFut
await s.unsubscribe()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json_marshalling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ suite "JSON-RPC Quantity":
test "Random object encoding":
checkRandomObject(SyncObject)
checkRandomObject(WithdrawalObject)
checkRandomObject(AccessTuple)
checkRandomObject(AccessPair)
checkRandomObject(AccessListResult)
checkRandomObject(LogObject)
checkRandomObject(StorageProof)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_primitives.nim
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ suite "Primitives":

test "to bytes":
let
ab2 = addr2.bytes
tb2 = txhash2.bytes
bb2 = blob2.bytes
ab2 = addr2.data
tb2 = txhash2.data
bb2 = blob2.data

check ab2.toHex == "0000000000000000000000000000000000000002"
check tb2.toHex == "0000000000000000000000000000000000000000000000000000000000000002"
Expand Down
9 changes: 5 additions & 4 deletions web3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ proc subscribeForLogs*(w: Web3, options: FilterOptions,
else:
result.historicalEventsProcessed = true

func addAddressAndSignatureToOptions(options: FilterOptions, address: Address, topic: Topic): FilterOptions =
func addAddressAndSignatureToOptions(options: FilterOptions, address: Address, topic: Bytes32): FilterOptions =
result = options
if result.address.kind == slkNull:
result.address = AddressOrList(kind: slkSingle, single: address)
result.topics.insert(TopicOrList(kind: slkSingle, single: topic), 0)

proc subscribeForLogs*(s: Web3SenderImpl, options: FilterOptions,
topic: Topic,
topic: Bytes32,
logsHandler: SubscriptionEventHandler,
errorHandler: SubscriptionErrorHandler,
withHistoricEvents = true): Future[Subscription] =
Expand Down Expand Up @@ -258,7 +258,7 @@ proc unsubscribe*(s: Subscription): Future[void] {.async.} =
s.removed = true
discard await s.web3.provider.eth_unsubscribe(s.id)

proc getJsonLogs(s: Web3SenderImpl, topic: Topic,
proc getJsonLogs(s: Web3SenderImpl, topic: Bytes32,
fromBlock = Opt.none(RtBlockIdentifier),
toBlock = Opt.none(RtBlockIdentifier),
blockHash = Opt.none(Hash32)): Future[seq[JsonString]] =
Expand Down Expand Up @@ -310,7 +310,8 @@ proc send*(web3: Web3, c: TransactionArgs, chainId: ChainId): Future[Hash32] {.d
var cc = c
if cc.nonce.isNone:
cc.nonce = Opt.some(await web3.nextNonce())
let t = encodeTransaction(cc, web3.privateKey.get(), chainId)
cc.chainId = Opt.some(chainId.Quantity)
let t = encodeTransaction(cc, web3.privateKey.get())
return await web3.provider.eth_sendRawTransaction(t)

proc sendData(web3: Web3,
Expand Down
2 changes: 1 addition & 1 deletion web3/conversions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ template derefType(T: type): untyped =

SyncObject.useDefaultSerializationIn JrpcConv
WithdrawalObject.useDefaultSerializationIn JrpcConv
AccessTuple.useDefaultSerializationIn JrpcConv
AccessPair.useDefaultSerializationIn JrpcConv
AccessListResult.useDefaultSerializationIn JrpcConv
LogObject.useDefaultSerializationIn JrpcConv
StorageProof.useDefaultSerializationIn JrpcConv
Expand Down
15 changes: 7 additions & 8 deletions web3/eth_api_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import
stint,
./primitives

from eth/common/transactions import AccessPair

export
primitives
primitives,
AccessPair

type
SyncObject* = object
Expand Down Expand Up @@ -50,7 +53,7 @@ type
input*: Opt[seq[byte]]

# Introduced by EIP-2930.
accessList*: Opt[seq[AccessTuple]]
accessList*: Opt[seq[AccessPair]]
chainId*: Opt[Quantity]

# EIP-4844
Expand Down Expand Up @@ -157,12 +160,8 @@ type
of tohTx:
tx*: TransactionObject

AccessTuple* = object
address*: Address
storageKeys*: seq[Bytes32]

AccessListResult* = object
accessList*: seq[AccessTuple]
accessList*: seq[AccessPair]
error*: Opt[string]
gasUsed*: Quantity

Expand Down Expand Up @@ -192,7 +191,7 @@ type
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
accessList*: Opt[seq[AccessTuple]] # EIP-2930
accessList*: Opt[seq[AccessPair]] # EIP-2930
maxFeePerGas*: Opt[Quantity] # EIP-1559
maxPriorityFeePerGas*: Opt[Quantity] # EIP-1559
maxFeePerBlobGas*: Opt[UInt256] # EIP-4844
Expand Down

0 comments on commit 86448ed

Please sign in to comment.