mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 20:45:38 +00:00
8f116cd01e
Make RequestId, SlotId, Nonce, PurcahseId distinct types. Add/modify conversions to support the distinct type (ABI encoding/decoding, JSON encoding, REST decoding). Update tests
22 lines
531 B
Nim
22 lines
531 B
Nim
import std/random
|
|
import std/sequtils
|
|
import pkg/codex/proving
|
|
import pkg/stint
|
|
|
|
proc example*[T: SomeInteger](_: type T): T =
|
|
rand(T)
|
|
|
|
proc example*[T,N](_: type array[N, T]): array[N, T] =
|
|
for item in result.mitems:
|
|
item = T.example
|
|
|
|
proc example*[T](_: type seq[T]): seq[T] =
|
|
let length = uint8.example.int
|
|
newSeqWith(length, T.example)
|
|
|
|
proc example*(_: type UInt256): UInt256 =
|
|
UInt256.fromBytes(array[32, byte].example)
|
|
|
|
proc example*[T: RequestId | SlotId | Nonce](_: type T): T =
|
|
T(array[32, byte].example)
|