mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-20 00:28:07 +00:00
[marketplace] use requestId for mySlots
This commit is contained in:
parent
3db7b49537
commit
19fe1b85e3
@ -31,8 +31,8 @@ method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
|
|||||||
method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} =
|
method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} =
|
||||||
return await market.contract.myRequests
|
return await market.contract.myRequests
|
||||||
|
|
||||||
method mySlots*(market: OnChainMarket): Future[seq[SlotId]] {.async.} =
|
method mySlots*(market: OnChainMarket, requestId: RequestId): Future[seq[SlotId]] {.async.} =
|
||||||
return await market.contract.mySlots
|
return await market.contract.mySlots(requestId)
|
||||||
|
|
||||||
method requestStorage(market: OnChainMarket, request: StorageRequest){.async.} =
|
method requestStorage(market: OnChainMarket, request: StorageRequest){.async.} =
|
||||||
await market.contract.requestStorage(request)
|
await market.contract.requestStorage(request)
|
||||||
|
@ -28,7 +28,7 @@ method requestStorage*(market: Market,
|
|||||||
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
|
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method mySlots*(market: Market): Future[seq[SlotId]] {.base, async.} =
|
method mySlots*(market: Market, requestId: RequestId): Future[seq[SlotId]] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method getRequest*(market: Market,
|
method getRequest*(market: Market,
|
||||||
|
@ -61,6 +61,7 @@ proc handleRequest(sales: Sales,
|
|||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
ask: StorageAsk) {.async.} =
|
ask: StorageAsk) {.async.} =
|
||||||
let availability = sales.findAvailability(ask)
|
let availability = sales.findAvailability(ask)
|
||||||
|
# TODO: check if random slot is actually available (not already filled)
|
||||||
let slotIndex = randomSlotIndex(ask.slots)
|
let slotIndex = randomSlotIndex(ask.slots)
|
||||||
let agent = newSalesAgent(
|
let agent = newSalesAgent(
|
||||||
sales,
|
sales,
|
||||||
@ -78,13 +79,18 @@ proc load*(sales: Sales) {.async.} =
|
|||||||
let market = sales.market
|
let market = sales.market
|
||||||
|
|
||||||
# TODO: restore availability from disk
|
# TODO: restore availability from disk
|
||||||
|
let requestIds = await market.myRequests()
|
||||||
let slotIds = await market.mySlots()
|
var slotIds: seq[SlotId]
|
||||||
|
# TODO: this needs to be optimised
|
||||||
|
for requestId in requestIds:
|
||||||
|
let reqSlotIds = await market.mySlots(requestId)
|
||||||
|
slotIds.add reqSlotIds
|
||||||
for slotId in slotIds:
|
for slotId in slotIds:
|
||||||
# TODO: this needs to be optimised
|
# TODO: this needs to be optimised
|
||||||
if slot =? await market.getSlot(slotId):
|
if slot =? await market.getSlot(slotId):
|
||||||
if request =? await market.getRequest(slot.requestId):
|
if request =? await market.getRequest(slot.requestId):
|
||||||
let availability = sales.findAvailability(request.ask)
|
let availability = sales.findAvailability(request.ask)
|
||||||
|
# TODO: restore slot index from chain, do not assign a new index
|
||||||
let slotIndex = randomSlotIndex(request.ask.slots)
|
let slotIndex = randomSlotIndex(request.ask.slots)
|
||||||
let agent = newSalesAgent(
|
let agent = newSalesAgent(
|
||||||
sales,
|
sales,
|
||||||
|
@ -32,7 +32,7 @@ type
|
|||||||
ask*: StorageAsk
|
ask*: StorageAsk
|
||||||
availability*: ?Availability # TODO: when availability persistence is added, change this to not optional
|
availability*: ?Availability # TODO: when availability persistence is added, change this to not optional
|
||||||
request*: ?StorageRequest
|
request*: ?StorageRequest
|
||||||
slotIndex*: ?UInt256
|
slotIndex*: ?UInt256 # TODO: disallow optional; SalesAgents should always have a slotIndex
|
||||||
failed*: market.Subscription
|
failed*: market.Subscription
|
||||||
fulfilled*: market.Subscription
|
fulfilled*: market.Subscription
|
||||||
slotFilled*: market.Subscription
|
slotFilled*: market.Subscription
|
||||||
|
@ -74,7 +74,7 @@ method requestStorage*(market: MockMarket, request: StorageRequest) {.async.} =
|
|||||||
method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} =
|
method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} =
|
||||||
return market.activeRequests[market.signer]
|
return market.activeRequests[market.signer]
|
||||||
|
|
||||||
method mySlots*(market: MockMarket): Future[seq[SlotId]] {.async.} =
|
method mySlots*(market: MockMarket, requestId: RequestId): Future[seq[SlotId]] {.async.} =
|
||||||
return market.activeSlots[market.signer]
|
return market.activeSlots[market.signer]
|
||||||
|
|
||||||
method getRequest(market: MockMarket,
|
method getRequest(market: MockMarket,
|
||||||
|
@ -550,6 +550,8 @@ suite "Sales state machine":
|
|||||||
host: me)
|
host: me)
|
||||||
await fillSlot(slot1.slotIndex)
|
await fillSlot(slot1.slotIndex)
|
||||||
market.activeSlots[me] = @[request.slotId(0.u256), request.slotId(1.u256)]
|
market.activeSlots[me] = @[request.slotId(0.u256), request.slotId(1.u256)]
|
||||||
|
market.requested = @[request]
|
||||||
|
market.activeRequests[me] = @[request.id]
|
||||||
|
|
||||||
await sales.load()
|
await sales.load()
|
||||||
let expected = SalesAgent(sales: sales,
|
let expected = SalesAgent(sales: sales,
|
||||||
@ -560,6 +562,8 @@ suite "Sales state machine":
|
|||||||
# randomly selected for the agent, and we also won't know the value of
|
# randomly selected for the agent, and we also won't know the value of
|
||||||
# `failed`/`fulfilled`/`cancelled` futures, so we need to compare
|
# `failed`/`fulfilled`/`cancelled` futures, so we need to compare
|
||||||
# the properties we know
|
# the properties we know
|
||||||
|
# TODO: when calling sales.load(), slot index should be restored and not
|
||||||
|
# randomly re-assigned, so this may no longer be needed
|
||||||
proc `==` (agent0, agent1: SalesAgent): bool =
|
proc `==` (agent0, agent1: SalesAgent): bool =
|
||||||
return agent0.sales == agent1.sales and
|
return agent0.sales == agent1.sales and
|
||||||
agent0.requestId == agent1.requestId and
|
agent0.requestId == agent1.requestId and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user