2021-04-07 10:19:00 +00:00
|
|
|
import std/random
|
2021-04-14 14:07:49 +00:00
|
|
|
import std/sequtils
|
|
|
|
import pkg/libp2p
|
2021-04-07 10:19:00 +00:00
|
|
|
import pkg/nitro
|
2022-03-23 12:57:48 +00:00
|
|
|
import pkg/stint
|
2022-05-19 19:56:03 +00:00
|
|
|
import pkg/codex/rng
|
|
|
|
import pkg/codex/stores
|
|
|
|
import pkg/codex/blocktype as bt
|
|
|
|
import pkg/codex/sales
|
2022-03-28 14:44:59 +00:00
|
|
|
import ../examples
|
|
|
|
|
|
|
|
export examples
|
2021-04-07 10:19:00 +00:00
|
|
|
|
|
|
|
proc example*(_: type EthAddress): EthAddress =
|
|
|
|
EthPrivateKey.random().toPublicKey.toAddress
|
|
|
|
|
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)
|
|
|
|
|
2021-04-08 13:05:04 +00:00
|
|
|
proc example*(_: type Wallet): Wallet =
|
|
|
|
Wallet.init(EthPrivateKey.random())
|
|
|
|
|
2021-04-19 14:37:38 +00:00
|
|
|
proc example*(_: type WalletRef): WalletRef =
|
|
|
|
WalletRef.new(EthPrivateKey.random())
|
|
|
|
|
2021-04-07 12:30:33 +00:00
|
|
|
proc example*(_: type SignedState): SignedState =
|
2021-04-08 13:05:04 +00:00
|
|
|
var wallet = Wallet.example
|
2021-04-07 12:30:33 +00:00
|
|
|
let hub, asset, receiver = EthAddress.example
|
|
|
|
let chainId, amount = UInt256.example
|
2021-04-07 14:53:00 +00:00
|
|
|
let nonce = UInt48.example
|
2021-04-07 12:30:33 +00:00
|
|
|
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,
|
2021-05-10 11:47:15 +00:00
|
|
|
price: uint32.rand.u256
|
2021-04-08 07:45:41 +00:00
|
|
|
)
|
2021-04-14 14:07:49 +00:00
|
|
|
|
2022-05-19 02:29:15 +00:00
|
|
|
proc example*(_: type bt.Block): bt.Block =
|
2021-04-14 14:07:49 +00:00
|
|
|
let length = rand(4096)
|
|
|
|
let bytes = newSeqWith(length, rand(uint8))
|
2022-05-19 02:29:15 +00:00
|
|
|
bt.Block.new(bytes).tryGet()
|
2021-04-14 14:07:49 +00:00
|
|
|
|
|
|
|
proc example*(_: type PeerId): PeerID =
|
|
|
|
let key = PrivateKey.random(Rng.instance[]).get
|
2021-10-29 19:30:52 +00:00
|
|
|
PeerId.init(key.getPublicKey().get).get
|
2021-04-14 14:07:49 +00:00
|
|
|
|
2021-08-30 19:25:20 +00:00
|
|
|
proc example*(_: type BlockExcPeerCtx): BlockExcPeerCtx =
|
|
|
|
BlockExcPeerCtx(id: PeerID.example)
|
2021-04-26 14:34:04 +00:00
|
|
|
|
|
|
|
proc example*(_: type Cid): Cid =
|
2022-05-19 02:29:15 +00:00
|
|
|
bt.Block.example.cid
|
2022-03-30 10:51:28 +00:00
|
|
|
|
|
|
|
proc example*(_: type Availability): Availability =
|
2022-05-09 14:51:08 +00:00
|
|
|
Availability.init(
|
|
|
|
size = uint16.example.u256,
|
|
|
|
duration = uint16.example.u256,
|
|
|
|
minPrice = uint64.example.u256
|
|
|
|
)
|