mirror of
https://github.com/logos-storage/nim-ethers.git
synced 2026-01-06 23:53:10 +00:00
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:
parent
0f98528758
commit
26342d3e27
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
timeout-minutes: 30
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nim: [1.6.20, stable]
|
nim: [2.0.14]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@ -39,7 +39,7 @@ jobs:
|
|||||||
run: npm start &
|
run: npm start &
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: nimble install -y
|
run: nimble install -y --maximumtaggedversions=2
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
run: nimble test -y
|
run: nimble test -y
|
||||||
|
|||||||
@ -14,7 +14,13 @@ Use the [Nimble][2] package manager to add `ethers` to an existing
|
|||||||
project. Add the following to its .nimble file:
|
project. Add the following to its .nimble file:
|
||||||
|
|
||||||
```nim
|
```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
|
Usage
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
--styleCheck:usages
|
--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)
|
# begin Nimble config (version 1)
|
||||||
when fileExists("nimble.paths"):
|
when fileExists("nimble.paths"):
|
||||||
include "nimble.paths"
|
include "nimble.paths"
|
||||||
# end Nimble config
|
# end Nimble config
|
||||||
|
|
||||||
|
when (NimMajor, NimMinor) >= (2, 0):
|
||||||
|
--mm:refc
|
||||||
|
|||||||
@ -1,18 +1,18 @@
|
|||||||
version = "1.0.0"
|
version = "1.1.0"
|
||||||
author = "Nim Ethers Authors"
|
author = "Nim Ethers Authors"
|
||||||
description = "library for interacting with Ethereum"
|
description = "library for interacting with Ethereum"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
requires "nim >= 1.6.0"
|
requires "nim >= 2.0.14"
|
||||||
requires "chronicles >= 0.10.3 & < 0.11.0"
|
requires "chronicles >= 0.10.3 & < 0.11.0"
|
||||||
requires "chronos >= 4.0.0 & < 4.1.0"
|
requires "chronos >= 4.0.4 & < 4.1.0"
|
||||||
requires "contractabi >= 0.6.0 & < 0.7.0"
|
requires "contractabi >= 0.7.0 & < 0.8.0"
|
||||||
requires "questionable >= 0.10.2 & < 0.11.0"
|
requires "questionable >= 0.10.2 & < 0.11.0"
|
||||||
requires "json_rpc >= 0.5.0 & < 0.6.0"
|
requires "json_rpc >= 0.5.0 & < 0.6.0"
|
||||||
requires "serde >= 1.2.1 & < 1.3.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 "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":
|
task test, "Run the test suite":
|
||||||
# exec "nimble install -d -y"
|
# exec "nimble install -d -y"
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import std/tables
|
import std/tables
|
||||||
import std/uri
|
import std/uri
|
||||||
import pkg/chronicles
|
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/rpcclient
|
||||||
import pkg/json_rpc/errors
|
import pkg/json_rpc/errors
|
||||||
import pkg/serde
|
import pkg/serde
|
||||||
|
|||||||
@ -27,7 +27,7 @@ type Wallet* = ref object of Signer
|
|||||||
|
|
||||||
proc new*(_: type Wallet, privateKey: PrivateKey): Wallet =
|
proc new*(_: type Wallet, privateKey: PrivateKey): Wallet =
|
||||||
let publicKey = privateKey.toPublicKey()
|
let publicKey = privateKey.toPublicKey()
|
||||||
let address = Address.init(publicKey.toCanonicalAddress())
|
let address = Address(publicKey.toCanonicalAddress())
|
||||||
Wallet(privateKey: privateKey, publicKey: publicKey, address: address)
|
Wallet(privateKey: privateKey, publicKey: publicKey, address: address)
|
||||||
|
|
||||||
proc new*(_: type Wallet, privateKey: PrivateKey, provider: Provider): Wallet =
|
proc new*(_: type Wallet, privateKey: PrivateKey, provider: Provider): Wallet =
|
||||||
@ -53,13 +53,13 @@ proc createRandom*(_: type Wallet): Wallet =
|
|||||||
result = Wallet()
|
result = Wallet()
|
||||||
result.privateKey = PrivateKey.random(getRng()[])
|
result.privateKey = PrivateKey.random(getRng()[])
|
||||||
result.publicKey = result.privateKey.toPublicKey()
|
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 =
|
proc createRandom*(_: type Wallet, provider: Provider): Wallet =
|
||||||
result = Wallet()
|
result = Wallet()
|
||||||
result.privateKey = PrivateKey.random(getRng()[])
|
result.privateKey = PrivateKey.random(getRng()[])
|
||||||
result.publicKey = result.privateKey.toPublicKey()
|
result.publicKey = result.privateKey.toPublicKey()
|
||||||
result.address = Address.init(result.publicKey.toCanonicalAddress())
|
result.address = Address(result.publicKey.toCanonicalAddress())
|
||||||
result.provider = some provider
|
result.provider = some provider
|
||||||
|
|
||||||
method provider*(wallet: Wallet): Provider {.gcsafe, raises: [SignerError].} =
|
method provider*(wallet: Wallet): Provider {.gcsafe, raises: [SignerError].} =
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import ../../basics
|
|||||||
import ../../transaction as ethers
|
import ../../transaction as ethers
|
||||||
import ../../provider
|
import ../../provider
|
||||||
import ./error
|
import ./error
|
||||||
|
from pkg/eth/common/eth_types import EthAddress
|
||||||
|
|
||||||
type
|
type
|
||||||
Transaction = ethers.Transaction
|
Transaction = ethers.Transaction
|
||||||
@ -26,15 +27,16 @@ func toSignableTransaction(transaction: Transaction): SignableTransaction =
|
|||||||
signable.nonce = nonce.truncate(uint64)
|
signable.nonce = nonce.truncate(uint64)
|
||||||
signable.chainId = ChainId(chainId.truncate(uint64))
|
signable.chainId = ChainId(chainId.truncate(uint64))
|
||||||
signable.gasLimit = GasInt(gasLimit.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.value = transaction.value
|
||||||
signable.payload = transaction.data
|
signable.payload = transaction.data
|
||||||
|
|
||||||
if maxFee =? transaction.maxFee and
|
if maxFee =? transaction.maxFee and
|
||||||
maxPriorityFee =? transaction.maxPriorityFee:
|
maxPriorityFee =? transaction.maxPriorityFee:
|
||||||
signable.txType = TxEip1559
|
signable.txType = TxEip1559
|
||||||
signable.maxFee = GasInt(maxFee.truncate(uint64))
|
signable.maxFeePerGas = GasInt(maxFee.truncate(uint64))
|
||||||
signable.maxPriorityFee = GasInt(maxPriorityFee.truncate(uint64))
|
signable.maxPriorityFeePerGas = GasInt(maxPriorityFee.truncate(uint64))
|
||||||
elif gasPrice =? transaction.gasPrice:
|
elif gasPrice =? transaction.gasPrice:
|
||||||
signable.txType = TxLegacy
|
signable.txType = TxLegacy
|
||||||
signable.gasPrice = GasInt(gasPrice.truncate(uint64))
|
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
|
# Temporary V value, used to signal to the hashing function
|
||||||
# that we'd like to use an EIP-155 signature
|
# 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 hash = transaction.txHashNoSignature().data
|
||||||
let signature = key.sign(SkMessage(hash)).toRaw()
|
let signature = key.sign(SkMessage(hash)).toRaw()
|
||||||
|
|
||||||
transaction.R = UInt256.fromBytesBE(signature[0..<32])
|
transaction.R = UInt256.fromBytesBE(signature[0..<32])
|
||||||
transaction.S = UInt256.fromBytesBE(signature[32..<64])
|
transaction.S = UInt256.fromBytesBE(signature[32..<64])
|
||||||
transaction.V = int64(signature[64])
|
transaction.V = uint64(signature[64])
|
||||||
|
|
||||||
if transaction.txType == TxLegacy:
|
if transaction.txType == TxLegacy:
|
||||||
transaction.V += int64(uint64(transaction.chainId)) * 2 + 35
|
transaction.V += uint64(transaction.chainId) * 2 + 35
|
||||||
|
|
||||||
rlp.encode(transaction)
|
rlp.encode(transaction)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user