Update to latest contractabi

This commit is contained in:
Mark Spanbroek 2022-01-19 09:37:42 +01:00
parent ad95604c18
commit 9611c36c78
9 changed files with 13 additions and 29 deletions

View File

@ -1 +1 @@
nim 1.6.0
nim 1.6.2

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -17,7 +17,7 @@ suite "channel definition":
chainId: 9001.u256,
nonce: 1,
participants: @[
!EthAddress.parse("24b905Dcc8A11C0FE57C2592f3D25f0447402C10")
!EthAddress.init("24b905Dcc8A11C0FE57C2592f3D25f0447402C10")
]
)
let expected = !Destination.parse(

View File

@ -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(

View File

@ -40,7 +40,7 @@ suite "signature":
chainId: 0x1.u256,
nonce: 1,
participants: @[
!EthAddress.parse("0x8a64E10FF40Bc9C90EA5750313dB5e036495c10E")
!EthAddress.init("0x8a64E10FF40Bc9C90EA5750313dB5e036495c10E")
]
),
outcome: Outcome(@[]),

View File

@ -46,7 +46,7 @@ suite "state":
chainId: 0x1.u256,
nonce: 1,
participants: @[
!EthAddress.parse("DBE821484648c73C1996Da25f2355342B9803eBD")
!EthAddress.init("DBE821484648c73C1996Da25f2355342B9803eBD")
]
),
outcome: Outcome(@[]),