markspanbroek deccf3e1be
chore: update dependencies (#15)
* chore: update nimcrypto dependency

* chore: remove dependency 'upraises'
2025-12-10 21:08:17 +01:00

27 lines
578 B
Nim

import pkg/stew/byteutils
import pkg/questionable
{.push raises:[].}
type
Address* = distinct array[20, byte]
func init*(_: type Address, bytes: array[20, byte]): Address =
Address(bytes)
func init*(_: type Address, hex: string): ?Address =
try:
let bytes = array[20, byte].fromHex(hex)
some Address.init(bytes)
except ValueError:
none Address
func toArray*(address: Address): array[20, byte] =
array[20, byte](address)
func `$`*(address: Address): string =
"0x" & toHex(address.toArray)
func `==`*(a, b: Address): bool =
a.toArray == b.toArray