2021-04-07 12:19:00 +02:00
|
|
|
import std/random
|
2021-04-14 16:07:49 +02:00
|
|
|
import std/sequtils
|
|
|
|
import pkg/libp2p
|
2021-04-07 12:19:00 +02:00
|
|
|
import pkg/nitro
|
2022-03-23 13:57:48 +01:00
|
|
|
import pkg/stint
|
2022-05-19 14:56:03 -05:00
|
|
|
import pkg/codex/rng
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/sales
|
2022-03-28 16:44:59 +02:00
|
|
|
import ../examples
|
|
|
|
|
|
|
|
export examples
|
2021-04-07 12:19:00 +02:00
|
|
|
|
|
|
|
proc example*(_: type EthAddress): EthAddress =
|
|
|
|
EthPrivateKey.random().toPublicKey.toAddress
|
|
|
|
|
2021-04-07 16:53:00 +02:00
|
|
|
proc example*(_: type UInt48): UInt48 =
|
|
|
|
# workaround for https://github.com/nim-lang/Nim/issues/17670
|
|
|
|
uint64.rand mod (UInt48.high + 1)
|
|
|
|
|
2021-04-08 15:05:04 +02:00
|
|
|
proc example*(_: type Wallet): Wallet =
|
|
|
|
Wallet.init(EthPrivateKey.random())
|
|
|
|
|
2021-04-19 16:37:38 +02:00
|
|
|
proc example*(_: type WalletRef): WalletRef =
|
|
|
|
WalletRef.new(EthPrivateKey.random())
|
|
|
|
|
2021-04-07 14:30:33 +02:00
|
|
|
proc example*(_: type SignedState): SignedState =
|
2021-04-08 15:05:04 +02:00
|
|
|
var wallet = Wallet.example
|
2021-04-07 14:30:33 +02:00
|
|
|
let hub, asset, receiver = EthAddress.example
|
|
|
|
let chainId, amount = UInt256.example
|
2021-04-07 16:53:00 +02:00
|
|
|
let nonce = UInt48.example
|
2021-04-07 14:30:33 +02:00
|
|
|
let channel = wallet.openLedgerChannel(hub, chainId, nonce, asset, amount).get
|
|
|
|
wallet.pay(channel, asset, receiver, amount).get
|
2021-04-08 09:45:41 +02:00
|
|
|
|
|
|
|
proc example*(_: type Pricing): Pricing =
|
|
|
|
Pricing(
|
|
|
|
address: EthAddress.example,
|
2021-05-10 13:47:15 +02:00
|
|
|
price: uint32.rand.u256
|
2021-04-08 09:45:41 +02:00
|
|
|
)
|
2021-04-14 16:07:49 +02:00
|
|
|
|
2022-05-18 20:29:15 -06:00
|
|
|
proc example*(_: type bt.Block): bt.Block =
|
2021-04-14 16:07:49 +02:00
|
|
|
let length = rand(4096)
|
|
|
|
let bytes = newSeqWith(length, rand(uint8))
|
2022-05-18 20:29:15 -06:00
|
|
|
bt.Block.new(bytes).tryGet()
|
2021-04-14 16:07:49 +02:00
|
|
|
|
2023-03-10 08:02:54 +01:00
|
|
|
proc example*(_: type PeerId): PeerId =
|
2021-04-14 16:07:49 +02:00
|
|
|
let key = PrivateKey.random(Rng.instance[]).get
|
2021-10-29 13:30:52 -06:00
|
|
|
PeerId.init(key.getPublicKey().get).get
|
2021-04-14 16:07:49 +02:00
|
|
|
|
2021-08-30 13:25:20 -06:00
|
|
|
proc example*(_: type BlockExcPeerCtx): BlockExcPeerCtx =
|
2023-03-10 08:02:54 +01:00
|
|
|
BlockExcPeerCtx(id: PeerId.example)
|
2021-04-26 16:34:04 +02:00
|
|
|
|
|
|
|
proc example*(_: type Cid): Cid =
|
2022-05-18 20:29:15 -06:00
|
|
|
bt.Block.example.cid
|
2022-03-30 12:51:28 +02:00
|
|
|
|
|
|
|
proc example*(_: type Availability): Availability =
|
2022-05-09 16:51:08 +02:00
|
|
|
Availability.init(
|
|
|
|
size = uint16.example.u256,
|
|
|
|
duration = uint16.example.u256,
|
2023-04-14 11:04:17 +02:00
|
|
|
minPrice = uint64.example.u256,
|
|
|
|
maxCollateral = uint16.example.u256
|
2022-05-09 16:51:08 +02:00
|
|
|
)
|