From 9611c36c78b8c3149c7163bc6375b8f611c5960d Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 19 Jan 2022 09:37:42 +0100 Subject: [PATCH] Update to latest contractabi --- .tool-versions | 2 +- nitro.nimble | 2 +- nitro/basics/ethaddress.nim | 21 +++++---------------- nitro/json.nim | 2 +- nitro/protocol/abi.nim | 5 ----- tests/nitro/protocol/testChannel.nim | 2 +- tests/nitro/protocol/testOutcome.nim | 4 ++-- tests/nitro/protocol/testSignature.nim | 2 +- tests/nitro/protocol/testState.nim | 2 +- 9 files changed, 13 insertions(+), 29 deletions(-) diff --git a/.tool-versions b/.tool-versions index 40f67df..99ee015 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -nim 1.6.0 +nim 1.6.2 diff --git a/nitro.nimble b/nitro.nimble index f293951..98d80fe 100644 --- a/nitro.nimble +++ b/nitro.nimble @@ -7,7 +7,7 @@ requires "nim >= 1.2.6 & < 2.0.0" requires "nimcrypto >= 0.5.4 & < 0.6.0" requires "questionable >= 0.10.1 & < 0.11.0" requires "upraises >= 0.1.0 & < 0.2.0" -requires "https://github.com/status-im/nim-contract-abi >= 0.3.0 & < 0.4.0" +requires "contractabi >= 0.4.1 & < 0.5.0" requires "secp256k1" requires "stint" requires "stew" diff --git a/nitro/basics/ethaddress.nim b/nitro/basics/ethaddress.nim index 8202547..c2e0754 100644 --- a/nitro/basics/ethaddress.nim +++ b/nitro/basics/ethaddress.nim @@ -1,23 +1,12 @@ import std/hashes -import pkg/questionable -import pkg/questionable/results -import pkg/stew/byteutils +import pkg/contractabi/address -export questionable +export address -type EthAddress* = distinct array[20, byte] +type EthAddress* = Address func zero*(_: type EthAddress): EthAddress = EthAddress.default -func toArray*(address: EthAddress): array[20, byte] = - array[20, byte](address) - -func `$`*(a: EthAddress): string = - a.toArray().toHex() - -func parse*(_: type EthAddress, hex: string): ?EthAddress = - EthAddress(array[20, byte].fromHex(hex)).catch.option - -proc `==`*(a, b: EthAddress): bool {.borrow.} -proc `hash`*(a: EthAddress): Hash {.borrow.} +proc `hash`*(a: EthAddress): Hash = + hash(a.toArray) diff --git a/nitro/json.nim b/nitro/json.nim index 87330dd..433a274 100644 --- a/nitro/json.nim +++ b/nitro/json.nim @@ -52,7 +52,7 @@ func initFromJson*(bytes: var seq[byte], node: JsonNode, _: var string) = func initFromJson*(address: var EthAddress, node: JsonNode, _: var string) = node.expectKind(JString) - without parsed =? EthAddress.parse(node.getStr): + without parsed =? EthAddress.init(node.getStr): raise newException(ValueError, "invalid ethereum address") address = parsed diff --git a/nitro/protocol/abi.nim b/nitro/protocol/abi.nim index 9ac025d..bd882a1 100644 --- a/nitro/protocol/abi.nim +++ b/nitro/protocol/abi.nim @@ -6,10 +6,5 @@ push: {.upraises:[].} export basics export contractabi -func encode*(encoder: var AbiEncoder, address: EthAddress) = - var padded: array[32, byte] - padded[12..<32] = address.toArray - encoder.write(padded) - func encode*(encoder: var AbiEncoder, destination: Destination) = encoder.write(destination.toArray) diff --git a/tests/nitro/protocol/testChannel.nim b/tests/nitro/protocol/testChannel.nim index 84c9dd1..c51fbef 100644 --- a/tests/nitro/protocol/testChannel.nim +++ b/tests/nitro/protocol/testChannel.nim @@ -17,7 +17,7 @@ suite "channel definition": chainId: 9001.u256, nonce: 1, participants: @[ - !EthAddress.parse("24b905Dcc8A11C0FE57C2592f3D25f0447402C10") + !EthAddress.init("24b905Dcc8A11C0FE57C2592f3D25f0447402C10") ] ) let expected = !Destination.parse( diff --git a/tests/nitro/protocol/testOutcome.nim b/tests/nitro/protocol/testOutcome.nim index a89c78c..0933559 100644 --- a/tests/nitro/protocol/testOutcome.nim +++ b/tests/nitro/protocol/testOutcome.nim @@ -61,7 +61,7 @@ suite "outcome": let outcome = Outcome(@[ AssetOutcome( kind: allocationType, - assetHolder: !EthAddress.parse( + assetHolder: !EthAddress.init( "1E90B49563da16D2537CA1Ddd9b1285279103D93" ), allocation: Allocation(@[ @@ -75,7 +75,7 @@ suite "outcome": ), AssetOutcome( kind: guaranteeType, - assetHolder: !EthAddress.parse( + assetHolder: !EthAddress.init( "1E90B49563da16D2537CA1Ddd9b1285279103D93" ), guarantee: Guarantee( diff --git a/tests/nitro/protocol/testSignature.nim b/tests/nitro/protocol/testSignature.nim index 1686cd3..6f9c362 100644 --- a/tests/nitro/protocol/testSignature.nim +++ b/tests/nitro/protocol/testSignature.nim @@ -40,7 +40,7 @@ suite "signature": chainId: 0x1.u256, nonce: 1, participants: @[ - !EthAddress.parse("0x8a64E10FF40Bc9C90EA5750313dB5e036495c10E") + !EthAddress.init("0x8a64E10FF40Bc9C90EA5750313dB5e036495c10E") ] ), outcome: Outcome(@[]), diff --git a/tests/nitro/protocol/testState.nim b/tests/nitro/protocol/testState.nim index b5ec3f8..b80b92b 100644 --- a/tests/nitro/protocol/testState.nim +++ b/tests/nitro/protocol/testState.nim @@ -46,7 +46,7 @@ suite "state": chainId: 0x1.u256, nonce: 1, participants: @[ - !EthAddress.parse("DBE821484648c73C1996Da25f2355342B9803eBD") + !EthAddress.init("DBE821484648c73C1996Da25f2355342B9803eBD") ] ), outcome: Outcome(@[]),