From b965599a47ac6d85422e0f847cdef01a985af74d Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 20 Jan 2022 12:48:59 +0100 Subject: [PATCH] Use Address implementation from contractabi --- ethers.nimble | 2 +- ethers/address.nim | 26 -------------------------- ethers/basics.nim | 2 +- testmodule/test.nim | 1 - testmodule/testAddress.nim | 25 ------------------------- 5 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 ethers/address.nim delete mode 100644 testmodule/testAddress.nim diff --git a/ethers.nimble b/ethers.nimble index 97abc71..f7a0f3c 100644 --- a/ethers.nimble +++ b/ethers.nimble @@ -4,7 +4,7 @@ description = "library for interacting with Ethereum" license = "MIT" requires "chronos >= 3.0.0 & < 4.0.0" -requires "contractabi >= 0.4.0 & < 0.5.0" +requires "contractabi >= 0.4.1 & < 0.5.0" requires "questionable >= 0.10.2 & < 0.11.0" requires "upraises >= 0.1.0 & < 0.2.0" requires "json_rpc" diff --git a/ethers/address.nim b/ethers/address.nim deleted file mode 100644 index c6d1c7d..0000000 --- a/ethers/address.nim +++ /dev/null @@ -1,26 +0,0 @@ -import pkg/stew/byteutils -import pkg/questionable -import pkg/upraises - -push: {.upraises: [].} - -type - Address* = distinct array[20, byte] - -func init*(_: type Address, bytes: array[20, byte]): Address = - Address(bytes) - -func init*(_: type Address, hex: string): ?Address = - try: - let bytes = array[20, byte].fromHex(hex) - some Address.init(bytes) - except ValueError: - none Address - -func toArray(address: Address): array[20, byte] = - array[20, byte](address) - -func `$`*(address: Address): string = - "0x" & toHex(address.toArray) - -func `==`*(a, b: Address): bool {.borrow.} diff --git a/ethers/basics.nim b/ethers/basics.nim index da75339..ddd07fd 100644 --- a/ethers/basics.nim +++ b/ethers/basics.nim @@ -2,7 +2,7 @@ import pkg/chronos import pkg/questionable import pkg/stint import pkg/upraises -import ./address +import pkg/contractabi/address export chronos export questionable diff --git a/testmodule/test.nim b/testmodule/test.nim index ae6d0fc..8504cbf 100644 --- a/testmodule/test.nim +++ b/testmodule/test.nim @@ -1,4 +1,3 @@ -import ./testAddress import ./testJsonRpcProvider {.warning[UnusedImport]:off.} diff --git a/testmodule/testAddress.nim b/testmodule/testAddress.nim deleted file mode 100644 index a3e23b5..0000000 --- a/testmodule/testAddress.nim +++ /dev/null @@ -1,25 +0,0 @@ -import std/unittest -import pkg/ethers/address -import pkg/questionable - -suite "Address": - - let address = Address.init [ - 0x1'u8, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, - 0x1 , 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa - ] - - test "can be converted to string": - check $address == "0x0102030405060708090a0102030405060708090a" - - test "can be parsed from string": - check: - Address.init("0x0102030405060708090a0102030405060708090a") == some address - - test "parsing fails when string does not contain proper hex": - check: - Address.init("0xfoo2030405060708090a0102030405060708090a") == none Address - - test "parsing fails when string does not contain 20 bytes": - check: - Address.init("0x0102030405060708090a010203040506070809") == none Address