mirror of
https://github.com/logos-storage/nim-nitro.git
synced 2026-01-02 13:43:06 +00:00
There's a new byteutils in newer versions of stew - also, remove upraises and disable windows testing which requires SSL library install
28 lines
750 B
Nim
28 lines
750 B
Nim
import std/hashes
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
import pkg/stew/byteutils
|
|
import ./ethaddress
|
|
|
|
{.push raises: [].}
|
|
|
|
type Destination* = distinct array[32, byte]
|
|
|
|
func toArray*(destination: Destination): array[32, byte] =
|
|
array[32, byte](destination)
|
|
|
|
func `$`*(destination: Destination): string =
|
|
destination.toArray().toHex()
|
|
|
|
func parse*(_: type Destination, s: string): ?Destination =
|
|
Destination(array[32, byte].fromHex(s)).catch.option
|
|
|
|
proc `==`*(a, b: Destination): bool {.borrow.}
|
|
proc hash*(destination: Destination): Hash {.borrow.}
|
|
|
|
func toDestination*(address: EthAddress): Destination =
|
|
var bytes: array[32, byte]
|
|
for i in 0..<20:
|
|
bytes[12 + i] = array[20, byte](address)[i]
|
|
Destination(bytes)
|