Improving proc/func formatting consistency (#454)
* Fixes/workarounds for nimsuggest failures in codex.nim. * remove rng prefix - it appears to work now * format new's to be more consistent * making proc formatting a bit more consistent
This commit is contained in:
parent
2a92dc9702
commit
e47b38af11
|
@ -242,19 +242,22 @@ proc stop*(b: DiscoveryEngine) {.async.} =
|
|||
trace "Discovery engine stopped"
|
||||
|
||||
proc new*(
|
||||
T: type DiscoveryEngine,
|
||||
localStore: BlockStore,
|
||||
peers: PeerCtxStore,
|
||||
network: BlockExcNetwork,
|
||||
discovery: Discovery,
|
||||
pendingBlocks: PendingBlocksManager,
|
||||
concurrentAdvReqs = DefaultConcurrentAdvertRequests,
|
||||
concurrentDiscReqs = DefaultConcurrentDiscRequests,
|
||||
discoveryLoopSleep = DefaultDiscoveryLoopSleep,
|
||||
advertiseLoopSleep = DefaultAdvertiseLoopSleep,
|
||||
minPeersPerBlock = DefaultMinPeersPerBlock,
|
||||
advertiseType = BlockType.Both): DiscoveryEngine =
|
||||
T(
|
||||
T: type DiscoveryEngine,
|
||||
localStore: BlockStore,
|
||||
peers: PeerCtxStore,
|
||||
network: BlockExcNetwork,
|
||||
discovery: Discovery,
|
||||
pendingBlocks: PendingBlocksManager,
|
||||
concurrentAdvReqs = DefaultConcurrentAdvertRequests,
|
||||
concurrentDiscReqs = DefaultConcurrentDiscRequests,
|
||||
discoveryLoopSleep = DefaultDiscoveryLoopSleep,
|
||||
advertiseLoopSleep = DefaultAdvertiseLoopSleep,
|
||||
minPeersPerBlock = DefaultMinPeersPerBlock,
|
||||
advertiseType = BlockType.Both
|
||||
): DiscoveryEngine =
|
||||
## Create a discovery engine instance for advertising services
|
||||
##
|
||||
DiscoveryEngine(
|
||||
localStore: localStore,
|
||||
peers: peers,
|
||||
network: network,
|
||||
|
|
|
@ -496,15 +496,18 @@ proc blockexcTaskRunner(b: BlockExcEngine) {.async.} =
|
|||
trace "Exiting blockexc task runner"
|
||||
|
||||
proc new*(
|
||||
T: type BlockExcEngine,
|
||||
localStore: BlockStore,
|
||||
wallet: WalletRef,
|
||||
network: BlockExcNetwork,
|
||||
discovery: DiscoveryEngine,
|
||||
peerStore: PeerCtxStore,
|
||||
pendingBlocks: PendingBlocksManager,
|
||||
concurrentTasks = DefaultConcurrentTasks,
|
||||
peersPerRequest = DefaultMaxPeersPerRequest): T =
|
||||
T: type BlockExcEngine,
|
||||
localStore: BlockStore,
|
||||
wallet: WalletRef,
|
||||
network: BlockExcNetwork,
|
||||
discovery: DiscoveryEngine,
|
||||
peerStore: PeerCtxStore,
|
||||
pendingBlocks: PendingBlocksManager,
|
||||
concurrentTasks = DefaultConcurrentTasks,
|
||||
peersPerRequest = DefaultMaxPeersPerRequest
|
||||
): BlockExcEngine =
|
||||
## Create new block exchange engine instance
|
||||
##
|
||||
|
||||
let
|
||||
engine = BlockExcEngine(
|
||||
|
|
|
@ -34,10 +34,11 @@ type
|
|||
blocks*: Table[Cid, BlockReq] # pending Block requests
|
||||
|
||||
proc getWantHandle*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
timeout = DefaultBlockTimeout,
|
||||
inFlight = false): Future[Block] {.async.} =
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
timeout = DefaultBlockTimeout,
|
||||
inFlight = false
|
||||
): Future[Block] {.async.} =
|
||||
## Add an event for a block
|
||||
##
|
||||
|
||||
|
@ -60,9 +61,8 @@ proc getWantHandle*(
|
|||
finally:
|
||||
p.blocks.del(cid)
|
||||
|
||||
proc resolve*(
|
||||
p: PendingBlocksManager,
|
||||
blocks: seq[Block]) =
|
||||
proc resolve*(p: PendingBlocksManager,
|
||||
blocks: seq[Block]) =
|
||||
## Resolve pending blocks
|
||||
##
|
||||
|
||||
|
@ -73,28 +73,25 @@ proc resolve*(
|
|||
trace "Resolving block", cid = blk.cid
|
||||
pending[].handle.complete(blk)
|
||||
|
||||
proc setInFlight*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
inFlight = true) =
|
||||
proc setInFlight*(p: PendingBlocksManager,
|
||||
cid: Cid,
|
||||
inFlight = true) =
|
||||
p.blocks.withValue(cid, pending):
|
||||
pending[].inFlight = inFlight
|
||||
trace "Setting inflight", cid, inFlight = pending[].inFlight
|
||||
|
||||
proc isInFlight*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool =
|
||||
proc isInFlight*(p: PendingBlocksManager,
|
||||
cid: Cid
|
||||
): bool =
|
||||
p.blocks.withValue(cid, pending):
|
||||
result = pending[].inFlight
|
||||
trace "Getting inflight", cid, inFlight = result
|
||||
|
||||
proc pending*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool = cid in p.blocks
|
||||
proc pending*(p: PendingBlocksManager, cid: Cid): bool =
|
||||
cid in p.blocks
|
||||
|
||||
proc contains*(
|
||||
p: PendingBlocksManager,
|
||||
cid: Cid): bool = p.pending(cid)
|
||||
proc contains*(p: PendingBlocksManager, cid: Cid): bool =
|
||||
p.pending(cid)
|
||||
|
||||
iterator wantList*(p: PendingBlocksManager): Cid =
|
||||
for k in p.blocks.keys:
|
||||
|
@ -107,5 +104,5 @@ iterator wantHandles*(p: PendingBlocksManager): Future[Block] =
|
|||
func len*(p: PendingBlocksManager): int =
|
||||
p.blocks.len
|
||||
|
||||
func new*(T: type PendingBlocksManager): T =
|
||||
T()
|
||||
func new*(T: type PendingBlocksManager): PendingBlocksManager =
|
||||
PendingBlocksManager()
|
||||
|
|
|
@ -102,12 +102,16 @@ proc handleWantList(
|
|||
|
||||
# TODO: make into a template
|
||||
proc makeWantList*(
|
||||
cids: seq[Cid],
|
||||
priority: int = 0,
|
||||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false): Wantlist =
|
||||
cids: seq[Cid],
|
||||
priority: int = 0,
|
||||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false
|
||||
): Wantlist =
|
||||
## make list of wanted entries
|
||||
##
|
||||
|
||||
Wantlist(
|
||||
entries: cids.mapIt(
|
||||
Entry(
|
||||
|
@ -119,14 +123,15 @@ proc makeWantList*(
|
|||
full: full)
|
||||
|
||||
proc sendWantList*(
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
cids: seq[Cid],
|
||||
priority: int32 = 0,
|
||||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false): Future[void] =
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
cids: seq[Cid],
|
||||
priority: int32 = 0,
|
||||
cancel: bool = false,
|
||||
wantType: WantType = WantType.WantHave,
|
||||
full: bool = false,
|
||||
sendDontHave: bool = false
|
||||
): Future[void] =
|
||||
## Send a want message to peer
|
||||
##
|
||||
|
||||
|
@ -142,9 +147,10 @@ proc sendWantList*(
|
|||
b.send(id, Message(wantlist: msg))
|
||||
|
||||
proc handleBlocks(
|
||||
b: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
blocks: seq[pb.Block]) {.async.} =
|
||||
b: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
blocks: seq[pb.Block]
|
||||
) {.async.} =
|
||||
## Handle incoming blocks
|
||||
##
|
||||
|
||||
|
@ -203,9 +209,10 @@ proc sendBlockPresence*(
|
|||
b.send(id, Message(blockPresences: @presence))
|
||||
|
||||
proc handleAccount(
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
account: Account) {.async.} =
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
account: Account
|
||||
) {.async.} =
|
||||
## Handle account info
|
||||
##
|
||||
|
||||
|
@ -213,34 +220,43 @@ proc handleAccount(
|
|||
await network.handlers.onAccount(peer.id, account)
|
||||
|
||||
proc sendAccount*(
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
account: Account): Future[void] =
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
account: Account
|
||||
): Future[void] =
|
||||
## Send account info to remote
|
||||
##
|
||||
|
||||
b.send(id, Message(account: AccountMessage.init(account)))
|
||||
|
||||
proc sendPayment*(
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
payment: SignedState): Future[void] =
|
||||
b: BlockExcNetwork,
|
||||
id: PeerId,
|
||||
payment: SignedState
|
||||
): Future[void] =
|
||||
## Send payment to remote
|
||||
##
|
||||
|
||||
b.send(id, Message(payment: StateChannelUpdate.init(payment)))
|
||||
|
||||
proc handlePayment(
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
payment: SignedState) {.async.} =
|
||||
network: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
payment: SignedState
|
||||
) {.async.} =
|
||||
## Handle payment
|
||||
##
|
||||
|
||||
if not network.handlers.onPayment.isNil:
|
||||
await network.handlers.onPayment(peer.id, payment)
|
||||
|
||||
proc rpcHandler(b: BlockExcNetwork, peer: NetworkPeer, msg: Message) {.async.} =
|
||||
proc rpcHandler(
|
||||
b: BlockExcNetwork,
|
||||
peer: NetworkPeer,
|
||||
msg: Message
|
||||
) {.async.} =
|
||||
## handle rpc messages
|
||||
##
|
||||
try:
|
||||
if msg.wantlist.entries.len > 0:
|
||||
asyncSpawn b.handleWantList(peer, msg.wantlist)
|
||||
|
@ -325,10 +341,11 @@ method init*(b: BlockExcNetwork) =
|
|||
b.codec = Codec
|
||||
|
||||
proc new*(
|
||||
T: type BlockExcNetwork,
|
||||
switch: Switch,
|
||||
connProvider: ConnProvider = nil,
|
||||
maxInflight = MaxInflight): T =
|
||||
T: type BlockExcNetwork,
|
||||
switch: Switch,
|
||||
connProvider: ConnProvider = nil,
|
||||
maxInflight = MaxInflight
|
||||
): BlockExcNetwork =
|
||||
## Create a new BlockExcNetwork instance
|
||||
##
|
||||
|
||||
|
|
|
@ -85,7 +85,8 @@ func new*(
|
|||
T: type NetworkPeer,
|
||||
peer: PeerId,
|
||||
connProvider: ConnProvider,
|
||||
rpcHandler: RPCHandler): T =
|
||||
rpcHandler: RPCHandler
|
||||
): NetworkPeer =
|
||||
|
||||
doAssert(not isNil(connProvider),
|
||||
"should supply connection provider")
|
||||
|
|
|
@ -93,5 +93,5 @@ func selectCheapest*(self: PeerCtxStore, cid: Cid): seq[BlockExcPeerCtx] =
|
|||
return peers
|
||||
|
||||
proc new*(T: type PeerCtxStore): PeerCtxStore =
|
||||
T(
|
||||
peers: initOrderedTable[PeerId, BlockExcPeerCtx]())
|
||||
## create new instance of a peer context store
|
||||
PeerCtxStore(peers: initOrderedTable[PeerId, BlockExcPeerCtx]())
|
||||
|
|
|
@ -126,11 +126,14 @@ proc `$`*(b: Block): string =
|
|||
result &= "\ndata: " & string.fromBytes(b.data)
|
||||
|
||||
func new*(
|
||||
T: type Block,
|
||||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
mcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw")): ?!T =
|
||||
T: type Block,
|
||||
data: openArray[byte] = [],
|
||||
version = CIDv1,
|
||||
mcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw")
|
||||
): ?!Block =
|
||||
## creates a new block for both storage and network IO
|
||||
##
|
||||
|
||||
let
|
||||
hash = ? MultiHash.digest($mcodec, data).mapFailure
|
||||
|
@ -143,10 +146,13 @@ func new*(
|
|||
data: @data).success
|
||||
|
||||
func new*(
|
||||
T: type Block,
|
||||
cid: Cid,
|
||||
data: openArray[byte],
|
||||
verify: bool = true): ?!T =
|
||||
T: type Block,
|
||||
cid: Cid,
|
||||
data: openArray[byte],
|
||||
verify: bool = true
|
||||
): ?!Block =
|
||||
## creates a new block for both storage and network IO
|
||||
##
|
||||
|
||||
let
|
||||
mhash = ? cid.mhash.mapFailure
|
||||
|
|
|
@ -60,21 +60,25 @@ proc getBytes*(c: Chunker): Future[seq[byte]] {.async.} =
|
|||
return move buff
|
||||
|
||||
func new*(
|
||||
T: type Chunker,
|
||||
reader: Reader,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
|
||||
T(reader: reader,
|
||||
T: type Chunker,
|
||||
reader: Reader,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true
|
||||
): Chunker =
|
||||
## create a new Chunker instance
|
||||
##
|
||||
Chunker(
|
||||
reader: reader,
|
||||
offset: 0,
|
||||
chunkSize: chunkSize,
|
||||
pad: pad)
|
||||
|
||||
proc new*(
|
||||
T: type LPStreamChunker,
|
||||
stream: LPStream,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
T: type LPStreamChunker,
|
||||
stream: LPStream,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true
|
||||
): LPStreamChunker =
|
||||
## create the default File chunker
|
||||
##
|
||||
|
||||
|
@ -92,16 +96,17 @@ proc new*(
|
|||
|
||||
return res
|
||||
|
||||
T.new(
|
||||
LPStreamChunker.new(
|
||||
reader = reader,
|
||||
chunkSize = chunkSize,
|
||||
pad = pad)
|
||||
|
||||
proc new*(
|
||||
T: type FileChunker,
|
||||
file: File,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true): T =
|
||||
T: type FileChunker,
|
||||
file: File,
|
||||
chunkSize = DefaultChunkSize,
|
||||
pad = true
|
||||
): FileChunker =
|
||||
## create the default File chunker
|
||||
##
|
||||
|
||||
|
@ -123,7 +128,7 @@ proc new*(
|
|||
|
||||
return total
|
||||
|
||||
T.new(
|
||||
FileChunker.new(
|
||||
reader = reader,
|
||||
chunkSize = chunkSize,
|
||||
pad = pad)
|
||||
|
|
|
@ -51,7 +51,13 @@ type
|
|||
|
||||
CodexPrivateKey* = libp2p.PrivateKey # alias
|
||||
|
||||
proc bootstrapInteractions(config: CodexConf, repo: RepoStore): Future[Contracts] {.async.} =
|
||||
proc bootstrapInteractions(
|
||||
config: CodexConf,
|
||||
repo: RepoStore
|
||||
): Future[Contracts] {.async.} =
|
||||
## bootstrap interactions and return contracts
|
||||
## using clients, hosts, validators pairings
|
||||
##
|
||||
|
||||
if not config.persistence and not config.validator:
|
||||
if config.ethAccount.isSome:
|
||||
|
@ -150,7 +156,8 @@ proc stop*(s: CodexServer) {.async.} =
|
|||
proc new*(
|
||||
T: type CodexServer,
|
||||
config: CodexConf,
|
||||
privateKey: CodexPrivateKey): CodexServer =
|
||||
privateKey: CodexPrivateKey
|
||||
): CodexServer =
|
||||
## create CodexServer including setting up datastore, repostore, etc
|
||||
let
|
||||
switch = SwitchBuilder
|
||||
|
@ -231,9 +238,10 @@ proc new*(
|
|||
|
||||
switch.mount(network)
|
||||
|
||||
T(
|
||||
CodexServer(
|
||||
config: config,
|
||||
codexNode: codexNode,
|
||||
restServer: restServer,
|
||||
repoStore: repoStore,
|
||||
maintenance: maintenance)
|
||||
maintenance: maintenance
|
||||
)
|
||||
|
|
|
@ -14,10 +14,14 @@ type
|
|||
sales*: Sales
|
||||
proving*: Proving
|
||||
|
||||
proc new*(_: type HostInteractions,
|
||||
clock: OnChainClock,
|
||||
sales: Sales,
|
||||
proving: Proving): HostInteractions =
|
||||
proc new*(
|
||||
_: type HostInteractions,
|
||||
clock: OnChainClock,
|
||||
sales: Sales,
|
||||
proving: Proving
|
||||
): HostInteractions =
|
||||
## Create a new HostInteractions instance
|
||||
##
|
||||
HostInteractions(clock: clock, sales: sales, proving: proving)
|
||||
|
||||
method start*(self: HostInteractions) {.async.} =
|
||||
|
|
|
@ -74,7 +74,7 @@ method getRequest(market: OnChainMarket,
|
|||
raise e
|
||||
|
||||
method requestState*(market: OnChainMarket,
|
||||
requestId: RequestId): Future[?RequestState] {.async.} =
|
||||
requestId: RequestId): Future[?RequestState] {.async.} =
|
||||
try:
|
||||
return some await market.contract.requestState(requestId)
|
||||
except ProviderError as e:
|
||||
|
@ -100,9 +100,8 @@ method getHost(market: OnChainMarket,
|
|||
else:
|
||||
return none Address
|
||||
|
||||
method getActiveSlot*(
|
||||
market: OnChainMarket,
|
||||
slotId: SlotId): Future[?Slot] {.async.} =
|
||||
method getActiveSlot*(market: OnChainMarket,
|
||||
slotId: SlotId): Future[?Slot] {.async.} =
|
||||
|
||||
try:
|
||||
return some await market.contract.getActiveSlot(slotId)
|
||||
|
@ -154,9 +153,11 @@ method markProofAsMissing*(market: OnChainMarket,
|
|||
period: Period) {.async.} =
|
||||
await market.contract.markProofAsMissing(id, period)
|
||||
|
||||
method canProofBeMarkedAsMissing*(market: OnChainMarket,
|
||||
id: SlotId,
|
||||
period: Period): Future[bool] {.async.} =
|
||||
method canProofBeMarkedAsMissing*(
|
||||
market: OnChainMarket,
|
||||
id: SlotId,
|
||||
period: Period
|
||||
): Future[bool] {.async.} =
|
||||
let provider = market.contract.provider
|
||||
let contractWithoutSigner = market.contract.connect(provider)
|
||||
let overrides = CallOverrides(blockTag: some BlockTag.pending)
|
||||
|
|
|
@ -56,25 +56,27 @@ proc toNodeId*(host: ca.Address): NodeId =
|
|||
readUintBE[256](keccak256.digest(host.toArray).data)
|
||||
|
||||
proc findPeer*(
|
||||
d: Discovery,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
d: Discovery,
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
trace "protocol.resolve..."
|
||||
## Find peer using the given Discovery object
|
||||
##
|
||||
let
|
||||
node = await d.protocol.resolve(toNodeId(peerId))
|
||||
|
||||
return
|
||||
if node.isSome():
|
||||
trace "protocol.resolve some data"
|
||||
node.get().record.data.some
|
||||
else:
|
||||
trace "protocol.resolve none"
|
||||
PeerRecord.none
|
||||
|
||||
method find*(
|
||||
d: Discovery,
|
||||
cid: Cid): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
d: Discovery,
|
||||
cid: Cid
|
||||
): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
## Find block providers
|
||||
##
|
||||
##
|
||||
|
||||
trace "Finding providers for block", cid
|
||||
without providers =?
|
||||
|
@ -98,8 +100,9 @@ method provide*(d: Discovery, cid: Cid) {.async, base.} =
|
|||
trace "Provided to nodes", nodes = nodes.len
|
||||
|
||||
method find*(
|
||||
d: Discovery,
|
||||
host: ca.Address): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
d: Discovery,
|
||||
host: ca.Address
|
||||
): Future[seq[SignedPeerRecord]] {.async, base.} =
|
||||
## Find host providers
|
||||
##
|
||||
|
||||
|
@ -129,11 +132,20 @@ method provide*(d: Discovery, host: ca.Address) {.async, base.} =
|
|||
if nodes.len > 0:
|
||||
trace "Provided to nodes", nodes = nodes.len
|
||||
|
||||
method removeProvider*(d: Discovery, peerId: PeerId): Future[void] {.base.} =
|
||||
method removeProvider*(
|
||||
d: Discovery,
|
||||
peerId: PeerId
|
||||
): Future[void] {.base.} =
|
||||
## Remove provider from providers table
|
||||
##
|
||||
|
||||
trace "Removing provider", peerId
|
||||
d.protocol.removeProvidersLocal(peerId)
|
||||
|
||||
proc updateAnnounceRecord*(d: Discovery, addrs: openArray[MultiAddress]) =
|
||||
## Update providers record
|
||||
##
|
||||
|
||||
d.announceAddrs = @addrs
|
||||
|
||||
trace "Updating announce record", addrs = d.announceAddrs
|
||||
|
@ -146,6 +158,9 @@ proc updateAnnounceRecord*(d: Discovery, addrs: openArray[MultiAddress]) =
|
|||
.expect("Should update SPR")
|
||||
|
||||
proc updateDhtRecord*(d: Discovery, ip: ValidIpAddress, port: Port) =
|
||||
## Update providers record
|
||||
##
|
||||
|
||||
trace "Updating Dht record", ip, port = $port
|
||||
d.dhtRecord = SignedPeerRecord.init(
|
||||
d.key, PeerRecord.init(d.peerId, @[
|
||||
|
@ -154,10 +169,6 @@ proc updateDhtRecord*(d: Discovery, ip: ValidIpAddress, port: Port) =
|
|||
IpTransportProtocol.udpProtocol,
|
||||
port)])).expect("Should construct signed record").some
|
||||
|
||||
if not d.protocol.isNil:
|
||||
d.protocol.updateRecord(d.dhtRecord)
|
||||
.expect("Should update SPR")
|
||||
|
||||
proc start*(d: Discovery) {.async.} =
|
||||
d.protocol.open()
|
||||
await d.protocol.start()
|
||||
|
@ -166,17 +177,19 @@ proc stop*(d: Discovery) {.async.} =
|
|||
await d.protocol.closeWait()
|
||||
|
||||
proc new*(
|
||||
T: type Discovery,
|
||||
key: PrivateKey,
|
||||
bindIp = ValidIpAddress.init(IPv4_any()),
|
||||
bindPort = 0.Port,
|
||||
announceAddrs: openArray[MultiAddress],
|
||||
bootstrapNodes: openArray[SignedPeerRecord] = [],
|
||||
store: Datastore = SQLiteDatastore.new(Memory)
|
||||
.expect("Should not fail!")): T =
|
||||
T: type Discovery,
|
||||
key: PrivateKey,
|
||||
bindIp = ValidIpAddress.init(IPv4_any()),
|
||||
bindPort = 0.Port,
|
||||
announceAddrs: openArray[MultiAddress],
|
||||
bootstrapNodes: openArray[SignedPeerRecord] = [],
|
||||
store: Datastore = SQLiteDatastore.new(Memory).expect("Should not fail!")
|
||||
): Discovery =
|
||||
## Create a new Discovery node instance for the given key and datastore
|
||||
##
|
||||
|
||||
var
|
||||
self = T(
|
||||
self = Discovery(
|
||||
key: key,
|
||||
peerId: PeerId.init(key).expect("Should construct PeerId"))
|
||||
|
||||
|
|
|
@ -12,8 +12,14 @@ import ./erasure/backends/leopard
|
|||
|
||||
export erasure
|
||||
|
||||
func leoEncoderProvider*(size, buffers, parity: int): EncoderBackend {.raises: [Defect].} =
|
||||
func leoEncoderProvider*(
|
||||
size, buffers, parity: int
|
||||
): EncoderBackend {.raises: [Defect].} =
|
||||
## create new Leo Encoder
|
||||
LeoEncoderBackend.new(size, buffers, parity)
|
||||
|
||||
func leoDecoderProvider*(size, buffers, parity: int): DecoderBackend {.raises: [Defect].} =
|
||||
LeoDecoderBackend.new(size, buffers, parity)
|
||||
func leoDecoderProvider*(
|
||||
size, buffers, parity: int
|
||||
): DecoderBackend {.raises: [Defect].} =
|
||||
## create new Leo Decoder
|
||||
LeoDecoderBackend.new(size, buffers, parity)
|
||||
|
|
|
@ -23,17 +23,25 @@ type
|
|||
DecoderBackend* = ref object of Backend
|
||||
|
||||
method release*(self: Backend) {.base.} =
|
||||
## release the backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
||||
method encode*(
|
||||
self: EncoderBackend,
|
||||
buffers,
|
||||
parity: var openArray[seq[byte]]): Result[void, cstring] {.base.} =
|
||||
self: EncoderBackend,
|
||||
buffers,
|
||||
parity: var openArray[seq[byte]]
|
||||
): Result[void, cstring] {.base.} =
|
||||
## encode buffers using a backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
||||
method decode*(
|
||||
self: DecoderBackend,
|
||||
buffers,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]): Result[void, cstring] {.base.} =
|
||||
self: DecoderBackend,
|
||||
buffers,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]
|
||||
): Result[void, cstring] {.base.} =
|
||||
## decode buffers using a backend
|
||||
##
|
||||
raiseAssert("not implemented!")
|
||||
|
|
|
@ -22,9 +22,11 @@ type
|
|||
decoder*: Option[LeoDecoder]
|
||||
|
||||
method encode*(
|
||||
self: LeoEncoderBackend,
|
||||
data,
|
||||
parity: var openArray[seq[byte]]): Result[void, cstring] =
|
||||
self: LeoEncoderBackend,
|
||||
data,
|
||||
parity: var openArray[seq[byte]]
|
||||
): Result[void, cstring] =
|
||||
## Encode data using Leopard backend
|
||||
|
||||
if parity.len == 0:
|
||||
return ok()
|
||||
|
@ -41,12 +43,15 @@ method encode*(
|
|||
encoder.encode(data, parity)
|
||||
|
||||
method decode*(
|
||||
self: LeoDecoderBackend,
|
||||
data,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]): Result[void, cstring] =
|
||||
self: LeoDecoderBackend,
|
||||
data,
|
||||
parity,
|
||||
recovered: var openArray[seq[byte]]
|
||||
): Result[void, cstring] =
|
||||
## Decode data using given Leopard backend
|
||||
|
||||
var decoder = if self.decoder.isNone:
|
||||
var decoder =
|
||||
if self.decoder.isNone:
|
||||
self.decoder = (? LeoDecoder.init(
|
||||
self.blockSize,
|
||||
self.buffers,
|
||||
|
@ -65,22 +70,28 @@ method release*(self: LeoDecoderBackend) =
|
|||
if self.decoder.isSome:
|
||||
self.decoder.get().free()
|
||||
|
||||
func new*(
|
||||
T: type LeoEncoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int): T =
|
||||
T(
|
||||
proc new*(
|
||||
T: type LeoEncoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int
|
||||
): LeoEncoderBackend =
|
||||
## Create an instance of an Leopard Encoder backend
|
||||
##
|
||||
LeoEncoderBackend(
|
||||
blockSize: blockSize,
|
||||
buffers: buffers,
|
||||
parity: parity)
|
||||
|
||||
func new*(
|
||||
T: type LeoDecoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int): T =
|
||||
T(
|
||||
proc new*(
|
||||
T: type LeoDecoderBackend,
|
||||
blockSize,
|
||||
buffers,
|
||||
parity: int
|
||||
): LeoDecoderBackend =
|
||||
## Create an instance of an Leopard Decoder backend
|
||||
##
|
||||
LeoDecoderBackend(
|
||||
blockSize: blockSize,
|
||||
buffers: buffers,
|
||||
parity: parity)
|
||||
|
|
|
@ -63,10 +63,11 @@ type
|
|||
store*: BlockStore
|
||||
|
||||
proc encode*(
|
||||
self: Erasure,
|
||||
manifest: Manifest,
|
||||
blocks: int,
|
||||
parity: int): Future[?!Manifest] {.async.} =
|
||||
self: Erasure,
|
||||
manifest: Manifest,
|
||||
blocks: int,
|
||||
parity: int
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Encode a manifest into one that is erasure protected.
|
||||
##
|
||||
## `manifest` - the original manifest to be encoded
|
||||
|
@ -153,8 +154,9 @@ proc encode*(
|
|||
return encoded.success
|
||||
|
||||
proc decode*(
|
||||
self: Erasure,
|
||||
encoded: Manifest): Future[?!Manifest] {.async.} =
|
||||
self: Erasure,
|
||||
encoded: Manifest
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Decode a protected manifest into it's original
|
||||
## manifest
|
||||
##
|
||||
|
@ -265,10 +267,12 @@ proc stop*(self: Erasure) {.async.} =
|
|||
return
|
||||
|
||||
proc new*(
|
||||
T: type Erasure,
|
||||
store: BlockStore,
|
||||
encoderProvider: EncoderProvider,
|
||||
decoderProvider: DecoderProvider): Erasure =
|
||||
T: type Erasure,
|
||||
store: BlockStore,
|
||||
encoderProvider: EncoderProvider,
|
||||
decoderProvider: DecoderProvider
|
||||
): Erasure =
|
||||
## Create a new Erasure instance for encoding and decoding manifests
|
||||
|
||||
Erasure(
|
||||
store: store,
|
||||
|
|
|
@ -14,8 +14,9 @@ type
|
|||
CodexResult*[T] = Result[T, ref CodexError]
|
||||
|
||||
template mapFailure*(
|
||||
exp: untyped,
|
||||
exc: typed = type CodexError): untyped =
|
||||
exp: untyped,
|
||||
exc: typed = type CodexError
|
||||
): untyped =
|
||||
## Convert `Result[T, E]` to `Result[E, ref CatchableError]`
|
||||
##
|
||||
|
||||
|
|
|
@ -166,8 +166,9 @@ func decode*(_: DagPBCoder, data: openArray[byte]): ?!Manifest =
|
|||
self.success
|
||||
|
||||
proc encode*(
|
||||
self: Manifest,
|
||||
encoder = ManifestContainers[$DagPBCodec]): ?!seq[byte] =
|
||||
self: Manifest,
|
||||
encoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!seq[byte] =
|
||||
## Encode a manifest using `encoder`
|
||||
##
|
||||
|
||||
|
@ -177,9 +178,10 @@ proc encode*(
|
|||
encoder.encode(self)
|
||||
|
||||
func decode*(
|
||||
_: type Manifest,
|
||||
data: openArray[byte],
|
||||
decoder = ManifestContainers[$DagPBCodec]): ?!Manifest =
|
||||
_: type Manifest,
|
||||
data: openArray[byte],
|
||||
decoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!Manifest =
|
||||
## Decode a manifest using `decoder`
|
||||
##
|
||||
|
||||
|
|
|
@ -159,14 +159,15 @@ proc cid*(self: Manifest): ?!Cid =
|
|||
############################################################
|
||||
|
||||
proc new*(
|
||||
T: type Manifest,
|
||||
blocks: openArray[Cid] = [],
|
||||
protected = false,
|
||||
version = CIDv1,
|
||||
hcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw"),
|
||||
blockSize = BlockSize): ?!T =
|
||||
## Create a manifest using array of `Cid`s
|
||||
T: type Manifest,
|
||||
blocks: openArray[Cid] = [],
|
||||
protected = false,
|
||||
version = CIDv1,
|
||||
hcodec = multiCodec("sha2-256"),
|
||||
codec = multiCodec("raw"),
|
||||
blockSize = BlockSize
|
||||
): ?!Manifest =
|
||||
## Create a manifest using an array of `Cid`s
|
||||
##
|
||||
|
||||
if hcodec notin EmptyDigests[version]:
|
||||
|
@ -182,9 +183,10 @@ proc new*(
|
|||
protected: protected).success
|
||||
|
||||
proc new*(
|
||||
T: type Manifest,
|
||||
manifest: Manifest,
|
||||
ecK, ecM: int): ?!Manifest =
|
||||
T: type Manifest,
|
||||
manifest: Manifest,
|
||||
ecK, ecM: int
|
||||
): ?!Manifest =
|
||||
## Create an erasure protected dataset from an
|
||||
## un-protected one
|
||||
##
|
||||
|
@ -223,5 +225,8 @@ proc new*(
|
|||
proc new*(
|
||||
T: type Manifest,
|
||||
data: openArray[byte],
|
||||
decoder = ManifestContainers[$DagPBCodec]): ?!T =
|
||||
decoder = ManifestContainers[$DagPBCodec]
|
||||
): ?!Manifest =
|
||||
## Create a manifest instance from given data
|
||||
##
|
||||
Manifest.decode(data, decoder)
|
||||
|
|
|
@ -60,18 +60,23 @@ type
|
|||
|
||||
proc findPeer*(
|
||||
node: CodexNodeRef,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
## Find peer using the discovery service from the given CodexNode
|
||||
##
|
||||
return await node.discovery.findPeer(peerId)
|
||||
|
||||
proc connect*(
|
||||
node: CodexNodeRef,
|
||||
peerId: PeerId,
|
||||
addrs: seq[MultiAddress]): Future[void] =
|
||||
node: CodexNodeRef,
|
||||
peerId: PeerId,
|
||||
addrs: seq[MultiAddress]
|
||||
): Future[void] =
|
||||
node.switch.connect(peerId, addrs)
|
||||
|
||||
proc fetchManifest*(
|
||||
node: CodexNodeRef,
|
||||
cid: Cid): Future[?!Manifest] {.async.} =
|
||||
node: CodexNodeRef,
|
||||
cid: Cid
|
||||
): Future[?!Manifest] {.async.} =
|
||||
## Fetch and decode a manifest block
|
||||
##
|
||||
|
||||
|
@ -93,10 +98,11 @@ proc fetchManifest*(
|
|||
return manifest.success
|
||||
|
||||
proc fetchBatched*(
|
||||
node: CodexNodeRef,
|
||||
manifest: Manifest,
|
||||
batchSize = FetchBatch,
|
||||
onBatch: BatchProc = nil): Future[?!void] {.async, gcsafe.} =
|
||||
node: CodexNodeRef,
|
||||
manifest: Manifest,
|
||||
batchSize = FetchBatch,
|
||||
onBatch: BatchProc = nil
|
||||
): Future[?!void] {.async, gcsafe.} =
|
||||
## Fetch manifest in batches of `batchSize`
|
||||
##
|
||||
|
||||
|
@ -122,8 +128,9 @@ proc fetchBatched*(
|
|||
return success()
|
||||
|
||||
proc retrieve*(
|
||||
node: CodexNodeRef,
|
||||
cid: Cid): Future[?!LPStream] {.async.} =
|
||||
node: CodexNodeRef,
|
||||
cid: Cid
|
||||
): Future[?!LPStream] {.async.} =
|
||||
## Retrieve by Cid a single block or an entire dataset described by manifest
|
||||
##
|
||||
|
||||
|
@ -175,9 +182,10 @@ proc retrieve*(
|
|||
return failure("Unable to retrieve Cid!")
|
||||
|
||||
proc store*(
|
||||
self: CodexNodeRef,
|
||||
stream: LPStream,
|
||||
blockSize = BlockSize): Future[?!Cid] {.async.} =
|
||||
self: CodexNodeRef,
|
||||
stream: LPStream,
|
||||
blockSize = BlockSize
|
||||
): Future[?!Cid] {.async.} =
|
||||
## Save stream contents as dataset with given blockSize
|
||||
## to nodes's BlockStore, and return Cid of its manifest
|
||||
##
|
||||
|
@ -238,15 +246,17 @@ proc store*(
|
|||
|
||||
return manifest.cid.success
|
||||
|
||||
proc requestStorage*(self: CodexNodeRef,
|
||||
cid: Cid,
|
||||
duration: UInt256,
|
||||
proofProbability: UInt256,
|
||||
nodes: uint,
|
||||
tolerance: uint,
|
||||
reward: UInt256,
|
||||
collateral: UInt256,
|
||||
expiry = UInt256.none): Future[?!PurchaseId] {.async.} =
|
||||
proc requestStorage*(
|
||||
self: CodexNodeRef,
|
||||
cid: Cid,
|
||||
duration: UInt256,
|
||||
proofProbability: UInt256,
|
||||
nodes: uint,
|
||||
tolerance: uint,
|
||||
reward: UInt256,
|
||||
collateral: UInt256,
|
||||
expiry = UInt256.none
|
||||
): Future[?!PurchaseId] {.async.} =
|
||||
## Initiate a request for storage sequence, this might
|
||||
## be a multistep procedure.
|
||||
##
|
||||
|
@ -311,14 +321,17 @@ proc requestStorage*(self: CodexNodeRef,
|
|||
return success purchase.id
|
||||
|
||||
proc new*(
|
||||
T: type CodexNodeRef,
|
||||
switch: Switch,
|
||||
store: BlockStore,
|
||||
engine: BlockExcEngine,
|
||||
erasure: Erasure,
|
||||
discovery: Discovery,
|
||||
contracts = Contracts.default): T =
|
||||
T(
|
||||
T: type CodexNodeRef,
|
||||
switch: Switch,
|
||||
store: BlockStore,
|
||||
engine: BlockExcEngine,
|
||||
erasure: Erasure,
|
||||
discovery: Discovery,
|
||||
contracts = Contracts.default
|
||||
): CodexNodeRef =
|
||||
## Create new instance of a Codex node, call `start` to run it
|
||||
##
|
||||
CodexNodeRef(
|
||||
switch: switch,
|
||||
blockStore: store,
|
||||
engine: engine,
|
||||
|
|
|
@ -47,7 +47,8 @@ proc stop*(purchasing: Purchasing) {.async.} =
|
|||
discard
|
||||
|
||||
proc populate*(purchasing: Purchasing,
|
||||
request: StorageRequest): Future[StorageRequest] {.async.} =
|
||||
request: StorageRequest
|
||||
): Future[StorageRequest] {.async.} =
|
||||
result = request
|
||||
if result.ask.proofProbability == 0.u256:
|
||||
result.ask.proofProbability = purchasing.proofProbability
|
||||
|
@ -60,7 +61,8 @@ proc populate*(purchasing: Purchasing,
|
|||
result.client = await purchasing.market.getSigner()
|
||||
|
||||
proc purchase*(purchasing: Purchasing,
|
||||
request: StorageRequest): Future[Purchase] {.async.} =
|
||||
request: StorageRequest
|
||||
): Future[Purchase] {.async.} =
|
||||
let request = await purchasing.populate(request)
|
||||
let purchase = Purchase.new(request, purchasing.market, purchasing.clock)
|
||||
purchase.start()
|
||||
|
|
|
@ -24,10 +24,14 @@ export Purchase
|
|||
export purchaseid
|
||||
export statemachine
|
||||
|
||||
func new*(_: type Purchase,
|
||||
requestId: RequestId,
|
||||
market: Market,
|
||||
clock: Clock): Purchase =
|
||||
func new*(
|
||||
_: type Purchase,
|
||||
requestId: RequestId,
|
||||
market: Market,
|
||||
clock: Clock
|
||||
): Purchase =
|
||||
## create a new instance of a Purchase
|
||||
##
|
||||
Purchase(
|
||||
future: Future[void].new(),
|
||||
requestId: requestId,
|
||||
|
@ -35,10 +39,13 @@ func new*(_: type Purchase,
|
|||
clock: clock
|
||||
)
|
||||
|
||||
func new*(_: type Purchase,
|
||||
request: StorageRequest,
|
||||
market: Market,
|
||||
clock: Clock): Purchase =
|
||||
func new*(
|
||||
_: type Purchase,
|
||||
request: StorageRequest,
|
||||
market: Market,
|
||||
clock: Clock
|
||||
): Purchase =
|
||||
## Create a new purchase using the given market and clock
|
||||
let purchase = Purchase.new(request.id, market, clock)
|
||||
purchase.request = some request
|
||||
return purchase
|
||||
|
|
|
@ -18,7 +18,10 @@ type
|
|||
nodes*: ?uint
|
||||
tolerance*: ?uint
|
||||
|
||||
proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
|
||||
proc fromJson*(
|
||||
_: type Availability,
|
||||
bytes: seq[byte]
|
||||
): ?!Availability =
|
||||
let json = ?catch parseJson(string.fromBytes(bytes))
|
||||
let size = ?catch UInt256.fromDecimal(json["size"].getStr)
|
||||
let duration = ?catch UInt256.fromDecimal(json["duration"].getStr)
|
||||
|
@ -26,8 +29,10 @@ proc fromJson*(_: type Availability, bytes: seq[byte]): ?!Availability =
|
|||
let maxCollateral = ?catch UInt256.fromDecimal(json["maxCollateral"].getStr)
|
||||
success Availability.init(size, duration, minPrice, maxCollateral)
|
||||
|
||||
proc fromJson*(_: type StorageRequestParams,
|
||||
bytes: seq[byte]): ?! StorageRequestParams =
|
||||
proc fromJson*(
|
||||
_: type StorageRequestParams,
|
||||
bytes: seq[byte]
|
||||
): ?! StorageRequestParams =
|
||||
let json = ?catch parseJson(string.fromBytes(bytes))
|
||||
let duration = ?catch UInt256.fromDecimal(json["duration"].getStr)
|
||||
let proofProbability = ?catch UInt256.fromDecimal(json["proofProbability"].getStr)
|
||||
|
|
|
@ -58,9 +58,8 @@ const
|
|||
SalesKey = (CodexMetaKey / "sales").tryGet # TODO: move to sales module
|
||||
ReservationsKey = (SalesKey / "reservations").tryGet
|
||||
|
||||
proc new*(
|
||||
T: type Reservations,
|
||||
repo: RepoStore): Reservations =
|
||||
proc new*(T: type Reservations,
|
||||
repo: RepoStore): Reservations =
|
||||
|
||||
T(repo: repo)
|
||||
|
||||
|
|
|
@ -321,10 +321,11 @@ proc generateQuery*(tau: Tau, l: int): seq[QElement] =
|
|||
result.add(q)
|
||||
|
||||
proc generateProof*(
|
||||
stream: SeekableStream,
|
||||
q: seq[QElement],
|
||||
authenticators: seq[blst_p1],
|
||||
s: int64): Future[Proof] {.async.} =
|
||||
stream: SeekableStream,
|
||||
q: seq[QElement],
|
||||
authenticators: seq[blst_p1],
|
||||
s: int64
|
||||
): Future[Proof] {.async.} =
|
||||
## Generata BLS proofs for a given query
|
||||
##
|
||||
|
||||
|
@ -432,11 +433,12 @@ proc verifyProof*(
|
|||
return verifyPairings(sum, self.spk.key, sigma, g)
|
||||
|
||||
proc init*(
|
||||
T: type PoR,
|
||||
stream: SeekableStream,
|
||||
ssk: SecretKey,
|
||||
spk: PublicKey,
|
||||
blockSize: int64): Future[PoR] {.async.} =
|
||||
T: type PoR,
|
||||
stream: SeekableStream,
|
||||
ssk: SecretKey,
|
||||
spk: PublicKey,
|
||||
blockSize: int64
|
||||
): Future[PoR] {.async.} =
|
||||
## Set up the POR scheme by generating tags and metadata
|
||||
##
|
||||
|
||||
|
|
|
@ -32,10 +32,11 @@ type
|
|||
stpStore*: StpStore
|
||||
|
||||
proc upload*(
|
||||
self: StorageProofs,
|
||||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
host: ca.Address): Future[?!void] {.async.} =
|
||||
self: StorageProofs,
|
||||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
host: ca.Address
|
||||
): Future[?!void] {.async.} =
|
||||
## Upload authenticators
|
||||
##
|
||||
|
||||
|
@ -56,8 +57,9 @@ proc upload*(
|
|||
# discard
|
||||
|
||||
proc setupProofs*(
|
||||
self: StorageProofs,
|
||||
manifest: Manifest): Future[?!void] {.async.} =
|
||||
self: StorageProofs,
|
||||
manifest: Manifest
|
||||
): Future[?!void] {.async.} =
|
||||
## Setup storage authentication
|
||||
##
|
||||
|
||||
|
@ -75,10 +77,11 @@ proc setupProofs*(
|
|||
return await self.stpStore.store(por.toMessage(), cid)
|
||||
|
||||
proc init*(
|
||||
T: type StorageProofs,
|
||||
network: StpNetwork,
|
||||
store: BlockStore,
|
||||
stpStore: StpStore): StorageProofs =
|
||||
T: type StorageProofs,
|
||||
network: StpNetwork,
|
||||
store: BlockStore,
|
||||
stpStore: StpStore
|
||||
): StorageProofs =
|
||||
|
||||
var
|
||||
self = T(
|
||||
|
|
|
@ -36,11 +36,12 @@ type
|
|||
tagsHandle*: TagsHandler
|
||||
|
||||
proc uploadTags*(
|
||||
self: StpNetwork,
|
||||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
tags: seq[seq[byte]],
|
||||
host: ca.Address): Future[?!void] {.async.} =
|
||||
self: StpNetwork,
|
||||
cid: Cid,
|
||||
indexes: seq[int],
|
||||
tags: seq[seq[byte]],
|
||||
host: ca.Address
|
||||
): Future[?!void] {.async.} =
|
||||
# Upload tags to `host`
|
||||
#
|
||||
|
||||
|
@ -93,7 +94,9 @@ method init*(self: StpNetwork) =
|
|||
proc new*(
|
||||
T: type StpNetwork,
|
||||
switch: Switch,
|
||||
discovery: Discovery): StpNetwork =
|
||||
discovery: Discovery
|
||||
): StpNetwork =
|
||||
## create a new StpNetwork instance
|
||||
let
|
||||
self = StpNetwork(
|
||||
switch: switch,
|
||||
|
|
|
@ -33,7 +33,8 @@ template stpPath*(self: StpStore, cid: Cid): string =
|
|||
|
||||
proc retrieve*(
|
||||
self: StpStore,
|
||||
cid: Cid): Future[?!PorMessage] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!PorMessage] {.async.} =
|
||||
## Retrieve authenticators from data store
|
||||
##
|
||||
|
||||
|
@ -51,7 +52,8 @@ proc retrieve*(
|
|||
proc store*(
|
||||
self: StpStore,
|
||||
por: PorMessage,
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
cid: Cid
|
||||
): Future[?!void] {.async.} =
|
||||
## Persist storage proofs
|
||||
##
|
||||
|
||||
|
@ -74,9 +76,10 @@ proc store*(
|
|||
return success()
|
||||
|
||||
proc retrieve*(
|
||||
self: StpStore,
|
||||
cid: Cid,
|
||||
blocks: seq[int]): Future[?!seq[Tag]] {.async.} =
|
||||
self: StpStore,
|
||||
cid: Cid,
|
||||
blocks: seq[int]
|
||||
): Future[?!seq[Tag]] {.async.} =
|
||||
var tags: seq[Tag]
|
||||
for b in blocks:
|
||||
var tag = Tag(idx: b)
|
||||
|
@ -92,9 +95,10 @@ proc retrieve*(
|
|||
return tags.success
|
||||
|
||||
proc store*(
|
||||
self: StpStore,
|
||||
tags: seq[Tag],
|
||||
cid: Cid): Future[?!void] {.async.} =
|
||||
self: StpStore,
|
||||
tags: seq[Tag],
|
||||
cid: Cid
|
||||
): Future[?!void] {.async.} =
|
||||
let
|
||||
dir = self.stpPath(cid)
|
||||
|
||||
|
@ -117,7 +121,10 @@ proc store*(
|
|||
proc init*(
|
||||
T: type StpStore,
|
||||
authDir: string,
|
||||
postfixLen: int = 2): StpStore =
|
||||
T(
|
||||
postfixLen: int = 2
|
||||
): StpStore =
|
||||
## Init StpStore
|
||||
##
|
||||
StpStore(
|
||||
authDir: authDir,
|
||||
postfixLen: postfixLen)
|
||||
|
|
|
@ -45,9 +45,10 @@ method getBlock*(self: BlockStore, cid: Cid): Future[?!Block] {.base.} =
|
|||
raiseAssert("Not implemented!")
|
||||
|
||||
method putBlock*(
|
||||
self: BlockStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none): Future[?!void] {.base.} =
|
||||
self: BlockStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.base.} =
|
||||
## Put a block to the blockstore
|
||||
##
|
||||
|
||||
|
|
|
@ -79,8 +79,9 @@ func cids(self: CacheStore): (iterator: Cid {.gcsafe.}) =
|
|||
yield cid
|
||||
|
||||
method listBlocks*(
|
||||
self: CacheStore,
|
||||
blockType = BlockType.Manifest): Future[?!BlocksIter] {.async.} =
|
||||
self: CacheStore,
|
||||
blockType = BlockType.Manifest
|
||||
): Future[?!BlocksIter] {.async.} =
|
||||
## Get the list of blocks in the BlockStore. This is an intensive operation
|
||||
##
|
||||
|
||||
|
@ -193,7 +194,11 @@ func new*(
|
|||
blocks: openArray[Block] = [],
|
||||
cacheSize: Positive = DefaultCacheSize, # in bytes
|
||||
chunkSize: Positive = DefaultChunkSize # in bytes
|
||||
): CacheStore {.raises: [Defect, ValueError].} =
|
||||
): CacheStore {.raises: [Defect, ValueError].} =
|
||||
## Create a new CacheStore instance
|
||||
##
|
||||
## `cacheSize` and `chunkSize` are both in bytes
|
||||
##
|
||||
|
||||
if cacheSize < chunkSize:
|
||||
raise newException(ValueError, "cacheSize cannot be less than chunkSize")
|
||||
|
|
|
@ -33,14 +33,19 @@ type
|
|||
numberOfBlocksPerInterval: int
|
||||
offset: int
|
||||
|
||||
proc new*(T: type BlockMaintainer,
|
||||
proc new*(
|
||||
T: type BlockMaintainer,
|
||||
repoStore: RepoStore,
|
||||
interval: Duration,
|
||||
numberOfBlocksPerInterval = 100,
|
||||
timer = Timer.new(),
|
||||
clock: Clock = SystemClock.new()
|
||||
): T =
|
||||
T(
|
||||
): BlockMaintainer =
|
||||
## Create new BlockMaintainer instance
|
||||
##
|
||||
## Call `start` to begin looking for for expired blocks
|
||||
##
|
||||
BlockMaintainer(
|
||||
repoStore: repoStore,
|
||||
interval: interval,
|
||||
numberOfBlocksPerInterval: numberOfBlocksPerInterval,
|
||||
|
|
|
@ -47,9 +47,10 @@ method getBlock*(self: NetworkStore, cid: Cid): Future[?!bt.Block] {.async.} =
|
|||
return success blk
|
||||
|
||||
method putBlock*(
|
||||
self: NetworkStore,
|
||||
blk: bt.Block,
|
||||
ttl = Duration.none): Future[?!void] {.async.} =
|
||||
self: NetworkStore,
|
||||
blk: bt.Block,
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.async.} =
|
||||
## Store block locally and notify the network
|
||||
##
|
||||
|
||||
|
@ -88,11 +89,10 @@ method close*(self: NetworkStore): Future[void] {.async.} =
|
|||
proc new*(
|
||||
T: type NetworkStore,
|
||||
engine: BlockExcEngine,
|
||||
localStore: BlockStore): T =
|
||||
|
||||
let
|
||||
self = NetworkStore(
|
||||
localStore: BlockStore
|
||||
): NetworkStore =
|
||||
## Create new instance of a NetworkStore
|
||||
##
|
||||
NetworkStore(
|
||||
localStore: localStore,
|
||||
engine: engine)
|
||||
|
||||
return self
|
||||
|
|
|
@ -92,7 +92,13 @@ proc getBlockExpirationTimestamp(self: RepoStore, ttl: ?Duration): SecondsSince1
|
|||
let duration = ttl |? self.blockTtl
|
||||
self.clock.now() + duration.seconds
|
||||
|
||||
proc getBlockExpirationEntry(self: RepoStore, batch: var seq[BatchEntry], cid: Cid, ttl: ?Duration): ?!BatchEntry =
|
||||
proc getBlockExpirationEntry(
|
||||
self: RepoStore,
|
||||
batch: var seq[BatchEntry],
|
||||
cid: Cid,
|
||||
ttl: ?Duration
|
||||
): ?!BatchEntry =
|
||||
## Get an expiration entry for a batch
|
||||
without key =? createBlockExpirationMetadataKey(cid), err:
|
||||
return failure(err)
|
||||
|
||||
|
@ -100,9 +106,10 @@ proc getBlockExpirationEntry(self: RepoStore, batch: var seq[BatchEntry], cid: C
|
|||
return success((key, value))
|
||||
|
||||
method putBlock*(
|
||||
self: RepoStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none): Future[?!void] {.async.} =
|
||||
self: RepoStore,
|
||||
blk: Block,
|
||||
ttl = Duration.none
|
||||
): Future[?!void] {.async.} =
|
||||
## Put a block to the blockstore
|
||||
##
|
||||
|
||||
|
@ -201,8 +208,9 @@ method hasBlock*(self: RepoStore, cid: Cid): Future[?!bool] {.async.} =
|
|||
return await self.repoDs.has(key)
|
||||
|
||||
method listBlocks*(
|
||||
self: RepoStore,
|
||||
blockType = BlockType.Manifest): Future[?!BlocksIter] {.async.} =
|
||||
self: RepoStore,
|
||||
blockType = BlockType.Manifest
|
||||
): Future[?!BlocksIter] {.async.} =
|
||||
## Get the list of blocks in the RepoStore.
|
||||
## This is an intensive operation
|
||||
##
|
||||
|
@ -237,7 +245,13 @@ proc createBlockExpirationQuery(maxNumber: int, offset: int): ?!Query =
|
|||
let queryKey = ? createBlockExpirationMetadataQueryKey()
|
||||
success Query.init(queryKey, offset = offset, limit = maxNumber)
|
||||
|
||||
method getBlockExpirations*(self: RepoStore, maxNumber: int, offset: int): Future[?!BlockExpirationIter] {.async, base.} =
|
||||
method getBlockExpirations*(
|
||||
self: RepoStore,
|
||||
maxNumber: int,
|
||||
offset: int
|
||||
): Future[?!BlockExpirationIter] {.async, base.} =
|
||||
## Get block experiartions from the given RepoStore
|
||||
##
|
||||
without query =? createBlockExpirationQuery(maxNumber, offset), err:
|
||||
trace "Unable to format block expirations query"
|
||||
return failure(err)
|
||||
|
@ -388,14 +402,17 @@ proc stop*(self: RepoStore): Future[void] {.async.} =
|
|||
self.started = false
|
||||
|
||||
func new*(
|
||||
T: type RepoStore,
|
||||
repoDs: Datastore,
|
||||
metaDs: Datastore,
|
||||
clock: Clock = SystemClock.new(),
|
||||
postFixLen = 2,
|
||||
quotaMaxBytes = DefaultQuotaBytes,
|
||||
blockTtl = DefaultBlockTtl): T =
|
||||
T(
|
||||
T: type RepoStore,
|
||||
repoDs: Datastore,
|
||||
metaDs: Datastore,
|
||||
clock: Clock = SystemClock.new(),
|
||||
postFixLen = 2,
|
||||
quotaMaxBytes = DefaultQuotaBytes,
|
||||
blockTtl = DefaultBlockTtl
|
||||
): RepoStore =
|
||||
## Create new instance of a RepoStore
|
||||
##
|
||||
RepoStore(
|
||||
repoDs: repoDs,
|
||||
metaDs: metaDs,
|
||||
clock: clock,
|
||||
|
|
|
@ -32,9 +32,12 @@ method initStream*(self: AsyncStreamWrapper) =
|
|||
procCall LPStream(self).initStream()
|
||||
|
||||
proc new*(
|
||||
C: type AsyncStreamWrapper,
|
||||
reader: AsyncStreamReader = nil,
|
||||
writer: AsyncStreamWriter = nil): AsyncStreamWrapper =
|
||||
C: type AsyncStreamWrapper,
|
||||
reader: AsyncStreamReader = nil,
|
||||
writer: AsyncStreamWriter = nil
|
||||
): AsyncStreamWrapper =
|
||||
## Create new instance of an asynchronous stream wrapper
|
||||
##
|
||||
let
|
||||
stream = C(reader: reader, writer: writer)
|
||||
|
||||
|
@ -57,9 +60,10 @@ template withExceptions(body: untyped) =
|
|||
raise newException(LPStreamError, exc.msg)
|
||||
|
||||
method readOnce*(
|
||||
self: AsyncStreamWrapper,
|
||||
pbytes: pointer,
|
||||
nbytes: int): Future[int] {.async.} =
|
||||
self: AsyncStreamWrapper,
|
||||
pbytes: pointer,
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
|
||||
trace "Reading bytes from reader", bytes = nbytes
|
||||
if isNil(self.reader):
|
||||
|
@ -75,7 +79,8 @@ method readOnce*(
|
|||
proc completeWrite(
|
||||
self: AsyncStreamWrapper,
|
||||
fut: Future[void],
|
||||
msgLen: int): Future[void] {.async.} =
|
||||
msgLen: int
|
||||
): Future[void] {.async.} =
|
||||
|
||||
withExceptions:
|
||||
await fut
|
||||
|
|
|
@ -38,12 +38,14 @@ type
|
|||
pad*: bool # Pad last block to manifest.blockSize?
|
||||
|
||||
proc new*(
|
||||
T: type StoreStream,
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
pad = true): T =
|
||||
|
||||
result = T(
|
||||
T: type StoreStream,
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
pad = true
|
||||
): StoreStream =
|
||||
## Create a new StoreStream instance for a given store and manifest
|
||||
##
|
||||
result = StoreStream(
|
||||
store: store,
|
||||
manifest: manifest,
|
||||
pad: pad,
|
||||
|
@ -62,12 +64,14 @@ method atEof*(self: StoreStream): bool =
|
|||
self.offset >= self.size
|
||||
|
||||
method readOnce*(
|
||||
self: StoreStream,
|
||||
pbytes: pointer,
|
||||
nbytes: int): Future[int] {.async.} =
|
||||
self: StoreStream,
|
||||
pbytes: pointer,
|
||||
nbytes: int
|
||||
): Future[int] {.async.} =
|
||||
## Read `nbytes` from current position in the StoreStream into output buffer pointed by `pbytes`.
|
||||
## Return how many bytes were actually read before EOF was encountered.
|
||||
## Raise exception if we are already at EOF.
|
||||
##
|
||||
|
||||
trace "Reading from manifest", cid = self.manifest.cid.get(), blocks = self.manifest.len
|
||||
if self.atEof:
|
||||
|
|
|
@ -17,9 +17,10 @@ import pkg/libp2p
|
|||
import pkg/stew/shims/net
|
||||
|
||||
func remapAddr*(
|
||||
address: MultiAddress,
|
||||
ip: Option[ValidIpAddress] = ValidIpAddress.none,
|
||||
port: Option[Port] = Port.none): MultiAddress =
|
||||
address: MultiAddress,
|
||||
ip: Option[ValidIpAddress] = ValidIpAddress.none,
|
||||
port: Option[Port] = Port.none
|
||||
): MultiAddress =
|
||||
## Remap addresses to new IP and/or Port
|
||||
##
|
||||
|
||||
|
|
|
@ -34,8 +34,9 @@ type
|
|||
Empty, Full
|
||||
|
||||
proc newAsyncHeapQueue*[T](
|
||||
maxsize: int = 0,
|
||||
queueType: QueueType = QueueType.Min): AsyncHeapQueue[T] =
|
||||
maxsize: int = 0,
|
||||
queueType: QueueType = QueueType.Min
|
||||
): AsyncHeapQueue[T] =
|
||||
## Creates a new asynchronous queue ``AsyncHeapQueue``.
|
||||
##
|
||||
|
||||
|
|
|
@ -22,10 +22,9 @@ type
|
|||
name: string
|
||||
loopFuture: Future[void]
|
||||
|
||||
proc new*(T: type Timer, timerName = "Unnamed Timer"): T =
|
||||
T(
|
||||
name: timerName
|
||||
)
|
||||
proc new*(T: type Timer, timerName = "Unnamed Timer"): Timer =
|
||||
## Create a new Timer intance with the given name
|
||||
Timer(name: timerName)
|
||||
|
||||
proc timerLoop(timer: Timer) {.async.} =
|
||||
try:
|
||||
|
|
|
@ -22,10 +22,13 @@ type
|
|||
logScope:
|
||||
topics = "codex validator"
|
||||
|
||||
proc new*(_: type Validation,
|
||||
clock: Clock,
|
||||
market: Market,
|
||||
maxSlots: int): Validation =
|
||||
proc new*(
|
||||
_: type Validation,
|
||||
clock: Clock,
|
||||
market: Market,
|
||||
maxSlots: int
|
||||
): Validation =
|
||||
## Create a new Validation instance
|
||||
Validation(clock: clock, market: market, maxSlots: maxSlots)
|
||||
|
||||
proc slots*(validation: Validation): seq[SlotId] =
|
||||
|
|
|
@ -31,9 +31,10 @@ proc lenPrefix*(msg: openArray[byte]): seq[byte] =
|
|||
return buf
|
||||
|
||||
proc corruptBlocks*(
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
blks, bytes: int): Future[seq[int]] {.async.} =
|
||||
store: BlockStore,
|
||||
manifest: Manifest,
|
||||
blks, bytes: int
|
||||
): Future[seq[int]] {.async.} =
|
||||
var pos: seq[int]
|
||||
|
||||
doAssert blks < manifest.len
|
||||
|
|
|
@ -12,8 +12,11 @@ type
|
|||
until: SecondsSince1970
|
||||
future: Future[void]
|
||||
|
||||
func new*(_: type MockClock,
|
||||
time: SecondsSince1970 = getTime().toUnix): MockClock =
|
||||
func new*(
|
||||
_: type MockClock,
|
||||
time: SecondsSince1970 = getTime().toUnix
|
||||
): MockClock =
|
||||
## Create a mock clock instance
|
||||
MockClock(time: time)
|
||||
|
||||
proc set*(clock: MockClock, time: SecondsSince1970) =
|
||||
|
|
|
@ -24,17 +24,21 @@ type
|
|||
publishHostProvideHandler*: proc(d: MockDiscovery, host: ca.Address):
|
||||
Future[void] {.gcsafe.}
|
||||
|
||||
proc new*(T: type MockDiscovery): T =
|
||||
T()
|
||||
proc new*(T: type MockDiscovery): MockDiscovery =
|
||||
MockDiscovery()
|
||||
|
||||
proc findPeer*(
|
||||
d: Discovery,
|
||||
peerId: PeerId): Future[?PeerRecord] {.async.} =
|
||||
d: Discovery,
|
||||
peerId: PeerId
|
||||
): Future[?PeerRecord] {.async.} =
|
||||
## mock find a peer - always return none
|
||||
##
|
||||
return none(PeerRecord)
|
||||
|
||||
method find*(
|
||||
d: MockDiscovery,
|
||||
cid: Cid): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
d: MockDiscovery,
|
||||
cid: Cid
|
||||
): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
if isNil(d.findBlockProvidersHandler):
|
||||
return
|
||||
|
||||
|
@ -47,8 +51,9 @@ method provide*(d: MockDiscovery, cid: Cid): Future[void] {.async.} =
|
|||
await d.publishBlockProvideHandler(d, cid)
|
||||
|
||||
method find*(
|
||||
d: MockDiscovery,
|
||||
host: ca.Address): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
d: MockDiscovery,
|
||||
host: ca.Address
|
||||
): Future[seq[SignedPeerRecord]] {.async.} =
|
||||
if isNil(d.findHostProvidersHandler):
|
||||
return
|
||||
|
||||
|
|
|
@ -82,6 +82,8 @@ proc hash*(requestId: RequestId): Hash =
|
|||
hash(requestId.toArray)
|
||||
|
||||
proc new*(_: type MockMarket): MockMarket =
|
||||
## Create a new mocked Market instance
|
||||
##
|
||||
let config = MarketplaceConfig(
|
||||
collateral: CollateralConfig(
|
||||
repairRewardPercentage: 10,
|
||||
|
@ -136,7 +138,7 @@ method getActiveSlot*(
|
|||
return none Slot
|
||||
|
||||
method requestState*(market: MockMarket,
|
||||
requestId: RequestId): Future[?RequestState] {.async.} =
|
||||
requestId: RequestId): Future[?RequestState] {.async.} =
|
||||
return market.requestState.?[requestId]
|
||||
|
||||
method slotState*(market: MockMarket,
|
||||
|
@ -320,9 +322,9 @@ method subscribeSlotFreed*(market: MockMarket,
|
|||
return subscription
|
||||
|
||||
method subscribeRequestCancelled*(market: MockMarket,
|
||||
requestId: RequestId,
|
||||
callback: OnRequestCancelled):
|
||||
Future[Subscription] {.async.} =
|
||||
requestId: RequestId,
|
||||
callback: OnRequestCancelled):
|
||||
Future[Subscription] {.async.} =
|
||||
let subscription = RequestCancelledSubscription(
|
||||
market: market,
|
||||
requestId: requestId,
|
||||
|
|
|
@ -18,13 +18,18 @@ type
|
|||
mockInterval*: Duration
|
||||
mockCallback: timer.TimerCallback
|
||||
|
||||
proc new*(T: type MockTimer): T =
|
||||
T(
|
||||
proc new*(T: type MockTimer): MockTimer =
|
||||
## Create a mocked Timer instance
|
||||
MockTimer(
|
||||
startCalled: 0,
|
||||
stopCalled: 0
|
||||
)
|
||||
|
||||
method start*(mockTimer: MockTimer, callback: timer.TimerCallback, interval: Duration) =
|
||||
method start*(
|
||||
mockTimer: MockTimer,
|
||||
callback: timer.TimerCallback,
|
||||
interval: Duration
|
||||
) =
|
||||
mockTimer.mockCallback = callback
|
||||
mockTimer.mockInterval = interval
|
||||
inc mockTimer.startCalled
|
||||
|
|
|
@ -24,8 +24,9 @@ type
|
|||
networkStore: NetworkStore]
|
||||
|
||||
proc generateNodes*(
|
||||
num: Natural,
|
||||
blocks: openArray[bt.Block] = []): seq[NodesComponents] =
|
||||
num: Natural,
|
||||
blocks: openArray[bt.Block] = []
|
||||
): seq[NodesComponents] =
|
||||
for i in 0..<num:
|
||||
let
|
||||
switch = newStandardSwitch(transportFlags = {ServerFlags.ReuseAddr})
|
||||
|
|
|
@ -11,13 +11,13 @@ type
|
|||
RandomChunker* = Chunker
|
||||
|
||||
proc new*(
|
||||
T: type RandomChunker,
|
||||
rng: Rng,
|
||||
chunkSize = DefaultChunkSize,
|
||||
size: int,
|
||||
pad = false): T =
|
||||
## create a chunker that produces
|
||||
## random data
|
||||
T: type RandomChunker,
|
||||
rng: Rng,
|
||||
chunkSize = DefaultChunkSize,
|
||||
size: int,
|
||||
pad = false
|
||||
): RandomChunker =
|
||||
## Create a chunker that produces random data
|
||||
##
|
||||
|
||||
var consumed = 0
|
||||
|
|
|
@ -18,11 +18,10 @@ type
|
|||
Before* = proc(): Future[void] {.gcsafe.}
|
||||
After* = proc(): Future[void] {.gcsafe.}
|
||||
|
||||
proc commonBlockStoreTests*(
|
||||
name: string,
|
||||
provider: StoreProvider,
|
||||
before: Before = nil,
|
||||
after: After = nil) =
|
||||
proc commonBlockStoreTests*(name: string,
|
||||
provider: StoreProvider,
|
||||
before: Before = nil,
|
||||
after: After = nil) =
|
||||
|
||||
suite name & " Store Common":
|
||||
var
|
||||
|
|
|
@ -26,13 +26,17 @@ proc upload*(client: CodexClient, contents: string): string =
|
|||
assert response.status == "200 OK"
|
||||
response.body
|
||||
|
||||
proc requestStorage*(client: CodexClient,
|
||||
cid: string,
|
||||
duration: uint64,
|
||||
reward: uint64,
|
||||
proofProbability: uint64,
|
||||
expiry: UInt256,
|
||||
collateral: uint64): string =
|
||||
proc requestStorage*(
|
||||
client: CodexClient,
|
||||
cid: string,
|
||||
duration: uint64,
|
||||
reward: uint64,
|
||||
proofProbability: uint64,
|
||||
expiry: UInt256,
|
||||
collateral: uint64
|
||||
): string =
|
||||
## Call request storage REST endpoint
|
||||
##
|
||||
let url = client.baseurl & "/storage/request/" & cid
|
||||
let json = %*{
|
||||
"duration": $duration,
|
||||
|
@ -55,8 +59,13 @@ proc getSlots*(client: CodexClient): JsonNode =
|
|||
let body = client.http.getContent(url)
|
||||
parseJson(body).catch |? nil
|
||||
|
||||
proc postAvailability*(client: CodexClient,
|
||||
size, duration, minPrice: uint64, maxCollateral: uint64): JsonNode =
|
||||
proc postAvailability*(
|
||||
client: CodexClient,
|
||||
size, duration, minPrice: uint64,
|
||||
maxCollateral: uint64
|
||||
): JsonNode =
|
||||
## Post sales availability endpoint
|
||||
##
|
||||
let url = client.baseurl & "/sales/availability"
|
||||
let json = %*{
|
||||
"size": $size,
|
||||
|
@ -69,6 +78,7 @@ proc postAvailability*(client: CodexClient,
|
|||
parseJson(response.body)
|
||||
|
||||
proc getAvailabilities*(client: CodexClient): JsonNode =
|
||||
## Call sales availability REST endpoint
|
||||
let url = client.baseurl & "/sales/availability"
|
||||
let body = client.http.getContent(url)
|
||||
parseJson(body)
|
||||
|
|
Loading…
Reference in New Issue