mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-02-08 12:54:41 +00:00
Simplify cid usage
This commit is contained in:
parent
9a4fc315db
commit
5c5bbd0d87
@ -495,16 +495,14 @@ proc onStore(
|
||||
## store data in local storage
|
||||
##
|
||||
|
||||
let cid = request.content.cid
|
||||
|
||||
logScope:
|
||||
cid = request.content.cid
|
||||
cid = $cid.data.buffer
|
||||
slotIdx = slotIdx
|
||||
|
||||
trace "Received a request to store a slot"
|
||||
|
||||
without cid =? Cid.init(request.content.cid.data.buffer).mapFailure, err:
|
||||
trace "Unable to parse Cid", cid
|
||||
return failure(err)
|
||||
|
||||
without manifest =? (await self.fetchManifest(cid)), err:
|
||||
trace "Unable to fetch manifest for cid", cid, err = err.msg
|
||||
return failure(err)
|
||||
@ -623,14 +621,9 @@ proc onProve(
|
||||
failure "Prover not enabled"
|
||||
|
||||
proc onExpiryUpdate(
|
||||
self: CodexNodeRef, rootCid: seq[byte], expiry: SecondsSince1970
|
||||
self: CodexNodeRef, rootCid: Cid, expiry: SecondsSince1970
|
||||
): Future[?!void] {.async.} =
|
||||
without cid =? Cid.init(rootCid):
|
||||
trace "Unable to parse Cid", cid
|
||||
let error = newException(CodexError, "Unable to parse Cid")
|
||||
return failure(error)
|
||||
|
||||
return await self.updateExpiry(cid, expiry)
|
||||
return await self.updateExpiry(rootCid, expiry)
|
||||
|
||||
proc onClear(self: CodexNodeRef, request: StorageRequest, slotIndex: UInt256) =
|
||||
# TODO: remove data from local storage
|
||||
@ -653,7 +646,7 @@ proc start*(self: CodexNodeRef) {.async.} =
|
||||
self.onStore(request, slot, onBatch)
|
||||
|
||||
hostContracts.sales.onExpiryUpdate = proc(
|
||||
rootCid: seq[byte], expiry: SecondsSince1970
|
||||
rootCid: Cid, expiry: SecondsSince1970
|
||||
): Future[?!void] =
|
||||
self.onExpiryUpdate(rootCid, expiry)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import pkg/questionable
|
||||
import pkg/questionable/results
|
||||
import pkg/upraises
|
||||
import pkg/libp2p/cid
|
||||
|
||||
import ../market
|
||||
import ../clock
|
||||
@ -30,7 +31,7 @@ type
|
||||
OnProve* = proc(slot: Slot, challenge: ProofChallenge): Future[?!Groth16Proof] {.
|
||||
gcsafe, upraises: []
|
||||
.}
|
||||
OnExpiryUpdate* = proc(rootCid: seq[byte], expiry: SecondsSince1970): Future[?!void] {.
|
||||
OnExpiryUpdate* = proc(rootCid: Cid, expiry: SecondsSince1970): Future[?!void] {.
|
||||
gcsafe, upraises: []
|
||||
.}
|
||||
OnClear* = proc(request: StorageRequest, slotIndex: UInt256) {.gcsafe, upraises: [].}
|
||||
|
@ -53,8 +53,7 @@ method run*(state: SaleFilled, machine: Machine): Future[?State] {.async.} =
|
||||
raiseAssert "onExpiryUpdate callback not set"
|
||||
|
||||
let requestEnd = await market.getRequestEnd(data.requestId)
|
||||
if err =?
|
||||
(await onExpiryUpdate(request.content.cid.data.buffer, requestEnd)).errorOption:
|
||||
if err =? (await onExpiryUpdate(request.content.cid, requestEnd)).errorOption:
|
||||
return some State(SaleErrored(error: err))
|
||||
|
||||
when codex_enable_proof_failures:
|
||||
|
@ -98,7 +98,7 @@ asyncchecksuite "Test Node - Host contracts":
|
||||
expectedExpiry: SecondsSince1970 = clock.now + DefaultBlockTtl.seconds + 11123
|
||||
expiryUpdateCallback = !sales.onExpiryUpdate
|
||||
|
||||
(await expiryUpdateCallback(manifestCid.data.buffer, expectedExpiry)).tryGet()
|
||||
(await expiryUpdateCallback(manifestCid, expectedExpiry)).tryGet()
|
||||
|
||||
for index in 0 ..< manifest.blocksCount:
|
||||
let
|
||||
|
@ -36,7 +36,7 @@ checksuite "sales state 'filled'":
|
||||
market.requestEnds[request.id] = 321
|
||||
onExpiryUpdatePassedExpiry = -1
|
||||
let onExpiryUpdate = proc(
|
||||
rootCid: seq[byte], expiry: SecondsSince1970
|
||||
rootCid: Cid, expiry: SecondsSince1970
|
||||
): Future[?!void] {.async.} =
|
||||
onExpiryUpdatePassedExpiry = expiry
|
||||
return success()
|
||||
|
@ -66,7 +66,7 @@ asyncchecksuite "Sales - start":
|
||||
return success()
|
||||
|
||||
sales.onExpiryUpdate = proc(
|
||||
rootCid: seq[byte], expiry: SecondsSince1970
|
||||
rootCid: Cid, expiry: SecondsSince1970
|
||||
): Future[?!void] {.async.} =
|
||||
return success()
|
||||
|
||||
@ -177,7 +177,7 @@ asyncchecksuite "Sales":
|
||||
return success()
|
||||
|
||||
sales.onExpiryUpdate = proc(
|
||||
rootCid: seq[byte], expiry: SecondsSince1970
|
||||
rootCid: Cid, expiry: SecondsSince1970
|
||||
): Future[?!void] {.async.} =
|
||||
return success()
|
||||
|
||||
|
@ -50,7 +50,7 @@ marketplacesuite "Bug #821 - node crashes during erasure coding":
|
||||
check eventually(requestId.isSome, timeout = expiry.int * 1000)
|
||||
|
||||
let request = await marketplace.getRequest(requestId.get)
|
||||
let cidFromRequest = Cid.init(request.content.cid).get()
|
||||
let cidFromRequest = request.content.cid
|
||||
let downloaded = await clientApi.downloadBytes(cidFromRequest, local = true)
|
||||
check downloaded.isOk
|
||||
check downloaded.get.toHex == data.toHex
|
||||
|
@ -48,7 +48,7 @@ twonodessuite "Purchasing":
|
||||
|
||||
let request = client1.getPurchase(id).get.request.get
|
||||
|
||||
check request.content.cid.len > 0
|
||||
check request.content.cid.data.buffer.len > 0
|
||||
check request.ask.duration == 100.u256
|
||||
check request.ask.reward == 2.u256
|
||||
check request.ask.proofProbability == 3.u256
|
||||
|
Loading…
x
Reference in New Issue
Block a user