[WIP sales] Generate proof of storage
This commit is contained in:
parent
07dbb6ae18
commit
dcb8f8a7f7
|
@ -19,6 +19,7 @@ type
|
||||||
available*: seq[Availability]
|
available*: seq[Availability]
|
||||||
offerExpiryInterval*: UInt256
|
offerExpiryInterval*: UInt256
|
||||||
retrieve: ?Retrieve
|
retrieve: ?Retrieve
|
||||||
|
prove: ?Prove
|
||||||
onSale: ?OnSale
|
onSale: ?OnSale
|
||||||
Availability* = object
|
Availability* = object
|
||||||
id*: array[32, byte]
|
id*: array[32, byte]
|
||||||
|
@ -35,6 +36,7 @@ type
|
||||||
waiting: ?Future[void]
|
waiting: ?Future[void]
|
||||||
finished: bool
|
finished: bool
|
||||||
Retrieve = proc(cid: string): Future[void] {.gcsafe, upraises: [].}
|
Retrieve = proc(cid: string): Future[void] {.gcsafe, upraises: [].}
|
||||||
|
Prove = proc(cid: string): Future[seq[byte]] {.gcsafe, upraises: [].}
|
||||||
OnSale = proc(offer: StorageOffer) {.gcsafe, upraises: [].}
|
OnSale = proc(offer: StorageOffer) {.gcsafe, upraises: [].}
|
||||||
|
|
||||||
func new*(_: type Sales, market: Market, clock: Clock): Sales =
|
func new*(_: type Sales, market: Market, clock: Clock): Sales =
|
||||||
|
@ -55,6 +57,9 @@ proc init*(_: type Availability,
|
||||||
proc `retrieve=`*(sales: Sales, retrieve: Retrieve) =
|
proc `retrieve=`*(sales: Sales, retrieve: Retrieve) =
|
||||||
sales.retrieve = some retrieve
|
sales.retrieve = some retrieve
|
||||||
|
|
||||||
|
proc `prove=`*(sales: Sales, prove: Prove) =
|
||||||
|
sales.prove = some prove
|
||||||
|
|
||||||
proc `onSale=`*(sales: Sales, callback: OnSale) =
|
proc `onSale=`*(sales: Sales, callback: OnSale) =
|
||||||
sales.onSale = some callback
|
sales.onSale = some callback
|
||||||
|
|
||||||
|
@ -130,6 +135,9 @@ proc start(negotiation: Negotiation) {.async.} =
|
||||||
without retrieve =? sales.retrieve:
|
without retrieve =? sales.retrieve:
|
||||||
raiseAssert "retrieve proc not set"
|
raiseAssert "retrieve proc not set"
|
||||||
|
|
||||||
|
without prove =? sales.prove:
|
||||||
|
raiseAssert "prove proc not set"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
sales.remove(availability)
|
sales.remove(availability)
|
||||||
|
|
||||||
|
@ -138,6 +146,7 @@ proc start(negotiation: Negotiation) {.async.} =
|
||||||
return
|
return
|
||||||
|
|
||||||
await retrieve(request.content.cid)
|
await retrieve(request.content.cid)
|
||||||
|
let proof = await prove(request.content.cid)
|
||||||
|
|
||||||
await negotiation.sendOffer()
|
await negotiation.sendOffer()
|
||||||
await negotiation.subscribeSelect()
|
await negotiation.subscribeSelect()
|
||||||
|
|
|
@ -33,6 +33,7 @@ suite "Sales":
|
||||||
clock = MockClock.new()
|
clock = MockClock.new()
|
||||||
sales = Sales.new(market, clock)
|
sales = Sales.new(market, clock)
|
||||||
sales.retrieve = proc(_: string) {.async.} = discard
|
sales.retrieve = proc(_: string) {.async.} = discard
|
||||||
|
sales.prove = proc(_: string): Future[seq[byte]] {.async.} = discard
|
||||||
await sales.start()
|
await sales.start()
|
||||||
|
|
||||||
teardown:
|
teardown:
|
||||||
|
@ -81,6 +82,13 @@ suite "Sales":
|
||||||
discard await market.requestStorage(request)
|
discard await market.requestStorage(request)
|
||||||
check sales.available.len == 0
|
check sales.available.len == 0
|
||||||
|
|
||||||
|
test "generates proof of storage":
|
||||||
|
var provingCid: string
|
||||||
|
sales.prove = proc(cid: string): Future[seq[byte]] {.async.} = provingCid = cid
|
||||||
|
sales.add(availability)
|
||||||
|
discard await market.requestStorage(request)
|
||||||
|
check provingCid == request.content.cid
|
||||||
|
|
||||||
# test "sets expiry time of offer":
|
# test "sets expiry time of offer":
|
||||||
# sales.add(availability)
|
# sales.add(availability)
|
||||||
# let now = clock.now().u256
|
# let now = clock.now().u256
|
||||||
|
|
Loading…
Reference in New Issue