nim-codex/tests/dagger/examples.nim

32 lines
961 B
Nim
Raw Normal View History

2021-04-07 10:19:00 +00:00
import std/random
import pkg/nitro
2021-04-08 07:45:41 +00:00
import pkg/dagger/bitswap/protobuf/payments
2021-04-07 10:19:00 +00:00
proc example*(_: type EthAddress): EthAddress =
EthPrivateKey.random().toPublicKey.toAddress
proc example*(_: type UInt256): UInt256 =
var bytes: array[32, byte]
for b in bytes.mitems:
b = rand(byte)
UInt256.fromBytes(bytes)
2021-04-07 14:53:00 +00:00
proc example*(_: type UInt48): UInt48 =
# workaround for https://github.com/nim-lang/Nim/issues/17670
uint64.rand mod (UInt48.high + 1)
proc example*(_: type SignedState): SignedState =
var wallet = Wallet.init(EthPrivateKey.random())
let hub, asset, receiver = EthAddress.example
let chainId, amount = UInt256.example
2021-04-07 14:53:00 +00:00
let nonce = UInt48.example
let channel = wallet.openLedgerChannel(hub, chainId, nonce, asset, amount).get
wallet.pay(channel, asset, receiver, amount).get
2021-04-08 07:45:41 +00:00
proc example*(_: type Pricing): Pricing =
Pricing(
address: EthAddress.example,
asset: EthAddress.example,
price: UInt256.example()
)