2021-03-09 09:37:27 +01:00
|
|
|
import pkg/questionable
|
2021-03-15 11:23:02 +01:00
|
|
|
import pkg/questionable/results
|
2021-02-25 09:11:46 +01:00
|
|
|
import pkg/stew/byteutils
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-03-09 09:37:27 +01:00
|
|
|
export questionable
|
2021-02-22 15:32:48 +01:00
|
|
|
|
2021-03-09 11:07:35 +01:00
|
|
|
type EthAddress* = distinct array[20, byte]
|
2021-02-23 10:23:42 +01:00
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func zero*(_: type EthAddress): EthAddress =
|
2021-03-09 16:50:08 +01:00
|
|
|
EthAddress.default
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func toArray*(address: EthAddress): array[20, byte] =
|
2021-02-23 10:23:42 +01:00
|
|
|
array[20, byte](address)
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func `$`*(a: EthAddress): string =
|
2021-03-09 16:50:08 +01:00
|
|
|
a.toArray().toHex()
|
|
|
|
|
|
2021-03-17 12:22:00 +01:00
|
|
|
func parse*(_: type EthAddress, hex: string): ?EthAddress =
|
2021-03-15 11:23:02 +01:00
|
|
|
EthAddress(array[20, byte].fromHex(hex)).catch.option
|
2021-02-25 09:11:46 +01:00
|
|
|
|
2021-03-17 15:34:55 +01:00
|
|
|
proc `==`*(a, b: EthAddress): bool {.borrow.}
|