2021-02-22 15:32:48 +01:00
|
|
|
import std/math
|
2021-03-09 09:37:27 +01:00
|
|
|
import pkg/questionable
|
2021-02-22 15:32:48 +01:00
|
|
|
import pkg/stint
|
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
|
|
|
include questionable/errorban
|
2021-03-03 10:30:07 +01:00
|
|
|
|
2021-02-22 15:32:48 +01:00
|
|
|
export stint
|
2021-03-09 09:37:27 +01:00
|
|
|
export questionable
|
2021-02-22 15:32:48 +01:00
|
|
|
|
|
|
|
|
type
|
|
|
|
|
UInt48* = range[0'u64..2'u64^48-1]
|
2021-02-23 10:23:42 +01:00
|
|
|
EthAddress* = distinct array[20, byte]
|
|
|
|
|
|
|
|
|
|
proc toArray*(address: EthAddress): array[20, byte] =
|
|
|
|
|
array[20, byte](address)
|
|
|
|
|
|
2021-03-09 09:37:27 +01:00
|
|
|
proc fromHex*(_: type EthAddress, hex: string): ?EthAddress =
|
2021-03-03 09:57:03 +01:00
|
|
|
try:
|
|
|
|
|
EthAddress(array[20, byte].fromHex(hex)).some
|
|
|
|
|
except ValueError:
|
|
|
|
|
EthAddress.none
|
2021-02-25 09:11:46 +01:00
|
|
|
|
2021-02-23 10:23:42 +01:00
|
|
|
proc `==`*(a, b: EthAddress): bool {.borrow.}
|