nim-abc/tests/abc/examples.nim

33 lines
786 B
Nim
Raw Normal View History

import std/random
import pkg/questionable
import abc
2021-06-30 15:18:19 +00:00
import abc/acks
import ./alicebob
proc example*(_: type PrivateKey): PrivateKey =
PrivateKey.random
proc example*(_: type PublicKey): PublicKey =
PrivateKey.example.toPublicKey
2021-06-28 13:04:50 +00:00
proc example*(_: type Wallet): Wallet =
let key = PrivateKey.example
Wallet.init(key)
proc example*(_: type Transaction): Transaction =
let alice = PublicKey.alice
let carol = PublicKey.example
2021-06-30 11:49:19 +00:00
let victor = PublicKey.victor
let genesis = Transaction.genesis
let amount = rand(100).u256
var transaction = !Transaction.init(
{genesis.hash: alice},
{carol: amount, alice: 100.u256 - amount},
2021-06-30 11:49:19 +00:00
victor
)
transaction
2021-06-30 15:18:19 +00:00
proc example*(_: type Ack): Ack =
let tx1, tx2 = Transaction.example
!Ack.init([tx1.hash, tx2.hash])