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
|
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
|
2024-01-17 13:24:34 -06:00
|
|
|
import pkg/codex/merkletree
|
2025-02-11 16:00:05 -03:00
|
|
|
import pkg/codex/manifest
|
2022-03-28 16:44:59 +02:00
|
|
|
import ../examples
|
|
|
|
|
|
|
|
|
|
export examples
|
2021-04-07 12:19:00 +02:00
|
|
|
|
2025-02-14 10:34:17 -03:00
|
|
|
proc example*(_: type bt.Block, size: int = 4096): bt.Block =
|
2025-11-13 07:47:02 +02:00
|
|
|
let bytes = newSeqWith(size, 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
|
|
|
|
2025-12-17 15:20:48 +11:00
|
|
|
proc example*(_: type BlockAddress): BlockAddress =
|
|
|
|
|
let cid = Cid.example
|
|
|
|
|
BlockAddress.init(cid)
|
|
|
|
|
|
2025-02-11 16:00:05 -03:00
|
|
|
proc example*(_: type Manifest): Manifest =
|
|
|
|
|
Manifest.new(
|
|
|
|
|
treeCid = Cid.example,
|
|
|
|
|
blockSize = 256.NBytes,
|
|
|
|
|
datasetSize = 4096.NBytes,
|
|
|
|
|
filename = "example.txt".some,
|
|
|
|
|
mimetype = "text/plain".some,
|
|
|
|
|
)
|
|
|
|
|
|
2023-12-22 06:04:01 -06:00
|
|
|
proc example*(_: type MultiHash, mcodec = Sha256HashCodec): MultiHash =
|
2023-11-14 13:02:17 +01:00
|
|
|
let bytes = newSeqWith(256, rand(uint8))
|
|
|
|
|
MultiHash.digest($mcodec, bytes).tryGet()
|
|
|
|
|
|
2024-01-17 13:24:34 -06:00
|
|
|
proc example*(_: type MerkleProof): MerkleProof =
|
|
|
|
|
MerkleProof.init(3, @[MultiHash.example]).tryget()
|