remove en/decoding for distinct types

The changes to `nim-contract-abi` in https://github.com/status-im/nim-contract-abi/pull/5 have allowed for distinct type en/decoding procs to not need to be defined.
This commit is contained in:
Eric Mastro 2022-09-14 16:54:19 +10:00 committed by Eric Mastro
parent 01d277f801
commit 4d7e40eb0e
1 changed files with 1 additions and 16 deletions

View File

@ -5,24 +5,12 @@ import ./examples
## Define outside the scope of the suite to allow for exporting
## To use custom distinct types, these procs will generally need
## to be defined in the application code anyway, to support ABI
## encoding/decoding
## to be defined in the application code anyway
type
DistinctAlias = distinct array[32, byte]
proc `==`*(x, y: DistinctAlias): bool {.borrow.}
func toArray(value: DistinctAlias): array[32, byte] =
array[32, byte](value)
func encode*(encoder: var AbiEncoder, value: DistinctAlias) =
encoder.write(value.toArray)
func decode*(decoder: var AbiDecoder,
T: type DistinctAlias): ?!T =
let d = ?decoder.read(type array[32, byte])
success DistinctAlias(d)
suite "Events":
type
@ -75,9 +63,6 @@ suite "Events":
a: DistinctAlias(array[32, byte].example)
)
func encode(_: type AbiEncoder, value: DistinctAlias): seq[byte] =
@(value.toArray)
func encode[T](_: type Topic, value: T): Topic =
let encoded = AbiEncoder.encode(value)
result[0..<Topic.len] = encoded[0..<Topic.len]