mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-12 23:54:29 +00:00
d3dbbc75fa
* don't force logging syncs * Add failing test * wip discovery engine * re-add chronicles sinks * wip * move network related stuff to own folder * move peer related stuff to own folder * extract discovery into it's own engine * update imports * move pending blocks into engine module * add top level exports * update imports * update import paths * update imports * support for inflight request filtering and tests * use `remove` instead of `del` * fix sorting in `selectCheapest` * re-org test file structure * fix to use discovery engine * file re-org * fix compilation * fixup discovery to use async handlers * more re-org * rework with support for discovery engine * add logging * use defaults * wip: reworking with discoveryengine * wip: more test fixes * more logging * use ordered table * use `bt` for blocktype Block * fix tests * make tests work with discovery engine * expose all node components * fix to work with discovery engine * wip * propagate cancellation in listBlocks * start/stop disc engine in blockexc engine * remove disc engine start/stop * wire up discovery engine * misc comments and imports * pass discovery to dagger node * set sleep timers * unused imports * misc * don't spawn a task, await it * don't await handlers * trace logging * reduce default sleep time Co-authored-by: Tanguy <tanguy@status.im>
58 lines
1.6 KiB
Nim
58 lines
1.6 KiB
Nim
import std/random
|
|
import std/sequtils
|
|
import pkg/libp2p
|
|
import pkg/nitro
|
|
import pkg/stint
|
|
import pkg/dagger/rng
|
|
import pkg/dagger/stores
|
|
import pkg/dagger/blocktype as bt
|
|
import pkg/dagger/sales
|
|
import ../examples
|
|
|
|
export examples
|
|
|
|
proc example*(_: type EthAddress): EthAddress =
|
|
EthPrivateKey.random().toPublicKey.toAddress
|
|
|
|
proc example*(_: type UInt48): UInt48 =
|
|
# workaround for https://github.com/nim-lang/Nim/issues/17670
|
|
uint64.rand mod (UInt48.high + 1)
|
|
|
|
proc example*(_: type Wallet): Wallet =
|
|
Wallet.init(EthPrivateKey.random())
|
|
|
|
proc example*(_: type WalletRef): WalletRef =
|
|
WalletRef.new(EthPrivateKey.random())
|
|
|
|
proc example*(_: type SignedState): SignedState =
|
|
var wallet = Wallet.example
|
|
let hub, asset, receiver = EthAddress.example
|
|
let chainId, amount = UInt256.example
|
|
let nonce = UInt48.example
|
|
let channel = wallet.openLedgerChannel(hub, chainId, nonce, asset, amount).get
|
|
wallet.pay(channel, asset, receiver, amount).get
|
|
|
|
proc example*(_: type Pricing): Pricing =
|
|
Pricing(
|
|
address: EthAddress.example,
|
|
price: uint32.rand.u256
|
|
)
|
|
|
|
proc example*(_: type bt.Block): bt.Block =
|
|
let length = rand(4096)
|
|
let bytes = newSeqWith(length, rand(uint8))
|
|
bt.Block.new(bytes).tryGet()
|
|
|
|
proc example*(_: type PeerId): PeerID =
|
|
let key = PrivateKey.random(Rng.instance[]).get
|
|
PeerId.init(key.getPublicKey().get).get
|
|
|
|
proc example*(_: type BlockExcPeerCtx): BlockExcPeerCtx =
|
|
BlockExcPeerCtx(id: PeerID.example)
|
|
|
|
proc example*(_: type Cid): Cid =
|
|
bt.Block.example.cid
|
|
|
|
proc example*(_: type Availability): Availability =
|
|
Availability.init(uint16.example, uint16.example, uint64.example.u256)
|