Update to nim 2 x (#103)

* Update dependencies for Nim 2.x

* Use refc as memory management and disable styleCheck because of testutils

* Fix ambiguous import

* Change Address init because eth introduced Byte20 type for Address type

* use uint64 instead of init64

* Rename properties after a change in eth to be closer to the spec

* Use Opt type instead of Option

* Add 2.0.12 version to CI

* Increment the version

* Update the Nim version in CI

* Update to Nim 2.0.14

* Use Nim 2.x commit hash for contractabi

* Remove stable on CI because we don't want to test with Nim 2.2.x

* Update Nim minimum version to 2.0.14

* fix version deps

* remove fq typename

* Add debug flag

* Define maximumtaggedversions

* Update readme

---------

Co-authored-by: Eric <5089238+emizzle@users.noreply.github.com>
This commit is contained in:
Arnaud 2025-02-14 04:18:19 +01:00 committed by GitHub
parent 0f98528758
commit 26342d3e27
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 34 additions and 20 deletions

View File

@ -13,7 +13,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
nim: [1.6.20, stable]
nim: [2.0.14]
steps:
- name: Checkout
uses: actions/checkout@v4
@ -39,7 +39,7 @@ jobs:
run: npm start &
- name: Build
run: nimble install -y
run: nimble install -y --maximumtaggedversions=2
- name: Test
run: nimble test -y

View File

@ -14,7 +14,13 @@ Use the [Nimble][2] package manager to add `ethers` to an existing
project. Add the following to its .nimble file:
```nim
requires "ethers >= 1.0.0 & < 2.0.0"
requires "ethers >= 1.1.0 & < 2.0.0"
```
To avoid conflicts with previous versions of `contractabi`, use the following command to install dependencies:
```bash
nimble install --maximumtaggedversions=2
```
Usage

View File

@ -1,7 +1,13 @@
--styleCheck:usages
--styleCheck:error
# Disable styleCheck temporarily because Nim 2.x is checking that
# getopt is used instead of
# https://github.com/status-im/nim-testutils/pull/54/commits/a1b07a11dd6a0c537a72e5ebf70df438c80f920a
#--styleCheck:error
# begin Nimble config (version 1)
when fileExists("nimble.paths"):
include "nimble.paths"
# end Nimble config
when (NimMajor, NimMinor) >= (2, 0):
--mm:refc

View File

@ -1,18 +1,18 @@
version = "1.0.0"
version = "1.1.0"
author = "Nim Ethers Authors"
description = "library for interacting with Ethereum"
license = "MIT"
requires "nim >= 1.6.0"
requires "nim >= 2.0.14"
requires "chronicles >= 0.10.3 & < 0.11.0"
requires "chronos >= 4.0.0 & < 4.1.0"
requires "contractabi >= 0.6.0 & < 0.7.0"
requires "chronos >= 4.0.4 & < 4.1.0"
requires "contractabi >= 0.7.0 & < 0.8.0"
requires "questionable >= 0.10.2 & < 0.11.0"
requires "json_rpc >= 0.5.0 & < 0.6.0"
requires "serde >= 1.2.1 & < 1.3.0"
requires "stint >= 0.8.0 & < 0.9.0"
requires "stint >= 0.8.1 & < 0.9.0"
requires "stew >= 0.2.0 & < 0.3.0"
requires "https://github.com/codex-storage/nim-eth-versioned >= 1.0.0 & < 2.0.0"
requires "eth >= 0.5.0 & < 0.6.0"
task test, "Run the test suite":
# exec "nimble install -d -y"

View File

@ -1,7 +1,7 @@
import std/tables
import std/uri
import pkg/chronicles
import pkg/eth/common/eth_types_json_serialization
import pkg/eth/common/eth_types except Block, Log, Address, Transaction
import pkg/json_rpc/rpcclient
import pkg/json_rpc/errors
import pkg/serde

View File

@ -27,7 +27,7 @@ type Wallet* = ref object of Signer
proc new*(_: type Wallet, privateKey: PrivateKey): Wallet =
let publicKey = privateKey.toPublicKey()
let address = Address.init(publicKey.toCanonicalAddress())
let address = Address(publicKey.toCanonicalAddress())
Wallet(privateKey: privateKey, publicKey: publicKey, address: address)
proc new*(_: type Wallet, privateKey: PrivateKey, provider: Provider): Wallet =
@ -53,13 +53,13 @@ proc createRandom*(_: type Wallet): Wallet =
result = Wallet()
result.privateKey = PrivateKey.random(getRng()[])
result.publicKey = result.privateKey.toPublicKey()
result.address = Address.init(result.publicKey.toCanonicalAddress())
result.address = Address(result.publicKey.toCanonicalAddress())
proc createRandom*(_: type Wallet, provider: Provider): Wallet =
result = Wallet()
result.privateKey = PrivateKey.random(getRng()[])
result.publicKey = result.privateKey.toPublicKey()
result.address = Address.init(result.publicKey.toCanonicalAddress())
result.address = Address(result.publicKey.toCanonicalAddress())
result.provider = some provider
method provider*(wallet: Wallet): Provider {.gcsafe, raises: [SignerError].} =

View File

@ -6,6 +6,7 @@ import ../../basics
import ../../transaction as ethers
import ../../provider
import ./error
from pkg/eth/common/eth_types import EthAddress
type
Transaction = ethers.Transaction
@ -26,15 +27,16 @@ func toSignableTransaction(transaction: Transaction): SignableTransaction =
signable.nonce = nonce.truncate(uint64)
signable.chainId = ChainId(chainId.truncate(uint64))
signable.gasLimit = GasInt(gasLimit.truncate(uint64))
signable.to = some EthAddress(transaction.to)
signable.to = Opt.some(EthAddress(transaction.to))
signable.value = transaction.value
signable.payload = transaction.data
if maxFee =? transaction.maxFee and
maxPriorityFee =? transaction.maxPriorityFee:
signable.txType = TxEip1559
signable.maxFee = GasInt(maxFee.truncate(uint64))
signable.maxPriorityFee = GasInt(maxPriorityFee.truncate(uint64))
signable.maxFeePerGas = GasInt(maxFee.truncate(uint64))
signable.maxPriorityFeePerGas = GasInt(maxPriorityFee.truncate(uint64))
elif gasPrice =? transaction.gasPrice:
signable.txType = TxLegacy
signable.gasPrice = GasInt(gasPrice.truncate(uint64))
@ -48,17 +50,17 @@ func sign(key: PrivateKey, transaction: SignableTransaction): seq[byte] =
# Temporary V value, used to signal to the hashing function
# that we'd like to use an EIP-155 signature
transaction.V = int64(uint64(transaction.chainId)) * 2 + 35
transaction.V = uint64(transaction.chainId) * 2 + 35
let hash = transaction.txHashNoSignature().data
let signature = key.sign(SkMessage(hash)).toRaw()
transaction.R = UInt256.fromBytesBE(signature[0..<32])
transaction.S = UInt256.fromBytesBE(signature[32..<64])
transaction.V = int64(signature[64])
transaction.V = uint64(signature[64])
if transaction.txType == TxLegacy:
transaction.V += int64(uint64(transaction.chainId)) * 2 + 35
transaction.V += uint64(transaction.chainId) * 2 + 35
rlp.encode(transaction)