diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index ad0e0b2b..be15bcd1 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -59,7 +59,7 @@ method fillSlot(market: OnChainMarket, await market.contract.fillSlot(requestId, slotIndex, proof) method withdrawFunds(market: OnChainMarket, - requestId: array[32, byte]) {.async.} = + requestId: RequestId) {.async.} = await market.contract.withdrawFunds(requestId) method subscribeRequests(market: OnChainMarket, @@ -92,7 +92,7 @@ method subscribeFulfillment(market: OnChainMarket, return OnChainMarketSubscription(eventSubscription: subscription) method subscribeRequestCancelled*(market: OnChainMarket, - requestId: array[32, byte], + requestId: RequestId, callback: OnRequestCancelled): Future[MarketSubscription] {.async.} = proc onEvent(event: RequestCancelled) {.upraises:[].} = diff --git a/codex/contracts/proofs.nim b/codex/contracts/proofs.nim index b28262d8..a33f5550 100644 --- a/codex/contracts/proofs.nim +++ b/codex/contracts/proofs.nim @@ -23,11 +23,11 @@ method periodicity*(proofs: OnChainProofs): Future[Periodicity] {.async.} = return Periodicity(seconds: period) method isSlotCancelled*(proofs: OnChainProofs, - id: ContractId): Future[bool] {.async.} = + id: SlotId): Future[bool] {.async.} = return await proofs.storage.isSlotCancelled(id) method isCancelled*(proofs: OnChainProofs, - id: array[32, byte]): Future[bool] {.async.} = + id: RequestId): Future[bool] {.async.} = return await proofs.storage.isCancelled(id) method isProofRequired*(proofs: OnChainProofs, diff --git a/codex/contracts/storage.nim b/codex/contracts/storage.nim index f6d529b9..62610b01 100644 --- a/codex/contracts/storage.nim +++ b/codex/contracts/storage.nim @@ -19,7 +19,7 @@ type RequestFulfilled* = object of Event requestId* {.indexed.}: RequestId RequestCancelled* = object of Event - requestId* {.indexed.}: Id + requestId* {.indexed.}: RequestId ProofSubmitted* = object of Event id*: SlotId proof*: seq[byte] @@ -35,7 +35,7 @@ proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.} proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.} proc fillSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256, proof: seq[byte]) {.contract.} -proc withdrawFunds*(storage: Storage, requestId: Id) {.contract.} +proc withdrawFunds*(storage: Storage, requestId: RequestId) {.contract.} proc payoutSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256) {.contract.} proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.} proc getHost*(storage: Storage, id: SlotId): Address {.contract, view.} @@ -45,8 +45,8 @@ proc proofTimeout*(storage: Storage): UInt256 {.contract, view.} proc proofEnd*(storage: Storage, id: SlotId): UInt256 {.contract, view.} proc missingProofs*(storage: Storage, id: SlotId): UInt256 {.contract, view.} -proc isCancelled*(storage: Storage, id: Id): bool {.contract, view.} -proc isSlotCancelled*(storage: Storage, id: Id): bool {.contract, view.} +proc isCancelled*(storage: Storage, id: RequestId): bool {.contract, view.} +proc isSlotCancelled*(storage: Storage, id: SlotId): bool {.contract, view.} proc isProofRequired*(storage: Storage, id: SlotId): bool {.contract, view.} proc willProofBeRequired*(storage: Storage, id: SlotId): bool {.contract, view.} proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.} diff --git a/codex/market.nim b/codex/market.nim index 906fb5c2..ff185f62 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -10,10 +10,10 @@ export requests type Market* = ref object of RootObj Subscription* = ref object of RootObj - OnRequest* = proc(id: array[32, byte], ask: StorageAsk) {.gcsafe, upraises:[].} - OnFulfillment* = proc(requestId: array[32, byte]) {.gcsafe, upraises: [].} - OnSlotFilled* = proc(requestId: array[32, byte], slotIndex: UInt256) {.gcsafe, upraises:[].} - OnRequestCancelled* = proc(requestId: array[32, byte]) {.gcsafe, upraises:[].} + OnRequest* = proc(id: RequestId, ask: StorageAsk) {.gcsafe, upraises:[].} + OnFulfillment* = proc(requestId: RequestId) {.gcsafe, upraises: [].} + OnSlotFilled* = proc(requestId: RequestId, slotIndex: UInt256) {.gcsafe, upraises:[].} + OnRequestCancelled* = proc(requestId: RequestId) {.gcsafe, upraises:[].} method getSigner*(market: Market): Future[Address] {.base, async.} = raiseAssert("not implemented") @@ -40,7 +40,7 @@ method fillSlot*(market: Market, raiseAssert("not implemented") method withdrawFunds*(market: Market, - requestId: array[32, byte]) {.base, async.} = + requestId: RequestId) {.base, async.} = raiseAssert("not implemented") method subscribeRequests*(market: Market, @@ -62,7 +62,7 @@ method subscribeSlotFilled*(market: Market, raiseAssert("not implemented") method subscribeRequestCancelled*(market: Market, - requestId: array[32, byte], + requestId: RequestId, callback: OnRequestCancelled): Future[Subscription] {.base, async.} = raiseAssert("not implemented") diff --git a/codex/proving.nim b/codex/proving.nim index f15b8730..a97fd120 100644 --- a/codex/proving.nim +++ b/codex/proving.nim @@ -43,11 +43,11 @@ proc removeEndedContracts(proving: Proving) {.async.} = proving.slots.excl(ended) proc removeCancelledContracts(proving: Proving) {.async.} = - var cancelled: HashSet[ContractId] - for id in proving.contracts: + var cancelled: HashSet[SlotId] + for id in proving.slots: if (await proving.proofs.isSlotCancelled(id)): cancelled.incl(id) - proving.contracts.excl(cancelled) + proving.slots.excl(cancelled) proc run(proving: Proving) {.async.} = try: diff --git a/codex/storageproofs/timing/proofs.nim b/codex/storageproofs/timing/proofs.nim index 74afb16a..d0456a1b 100644 --- a/codex/storageproofs/timing/proofs.nim +++ b/codex/storageproofs/timing/proofs.nim @@ -19,11 +19,11 @@ method periodicity*(proofs: Proofs): raiseAssert("not implemented") method isSlotCancelled*(proofs: Proofs, - id: ContractId): Future[bool] {.base, async.} = + id: SlotId): Future[bool] {.base, async.} = raiseAssert("not implemented") method isCancelled*(proofs: Proofs, - id: array[32, byte]): Future[bool] {.base, async.} = + id: RequestId): Future[bool] {.base, async.} = raiseAssert("not implemented") method isProofRequired*(proofs: Proofs, diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 9a2febaa..cad26691 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -38,7 +38,7 @@ type callback: OnSlotFilled RequestCancelledSubscription* = ref object of Subscription market: MockMarket - requestId: array[32, byte] + requestId: RequestId callback: OnRequestCancelled proc new*(_: type MockMarket): MockMarket = @@ -81,7 +81,7 @@ proc emitSlotFilled*(market: MockMarket, subscription.callback(requestId, slotIndex) proc emitRequestCancelled*(market: MockMarket, - requestId: array[32, byte]) = + requestId: RequestId) = var subscriptions = market.subscriptions.onRequestCancelled for subscription in subscriptions: if subscription.requestId == requestId: @@ -114,7 +114,7 @@ method fillSlot*(market: MockMarket, market.fillSlot(requestId, slotIndex, proof, market.signer) method withdrawFunds*(market: MockMarket, - requestId: array[32, byte]) {.async.} = + requestId: RequestId) {.async.} = market.emitRequestCancelled(requestId) method subscribeRequests*(market: MockMarket, @@ -154,7 +154,7 @@ method subscribeSlotFilled*(market: MockMarket, return subscription method subscribeRequestCancelled*(market: MockMarket, - requestId: array[32, byte], + requestId: RequestId, callback: OnRequestCancelled): Future[Subscription] {.async.} = let subscription = RequestCancelledSubscription( diff --git a/tests/codex/helpers/mockproofs.nim b/tests/codex/helpers/mockproofs.nim index cce22f93..cb73f786 100644 --- a/tests/codex/helpers/mockproofs.nim +++ b/tests/codex/helpers/mockproofs.nim @@ -7,7 +7,7 @@ import pkg/codex/storageproofs type MockProofs* = ref object of Proofs periodicity: Periodicity - cancelledRequests: HashSet[ContractId] + cancelledRequests: HashSet[SlotId] proofsRequired: HashSet[SlotId] proofsToBeRequired: HashSet[SlotId] proofEnds: Table[SlotId, UInt256] @@ -33,18 +33,18 @@ proc setProofRequired*(mock: MockProofs, id: SlotId, required: bool) = else: mock.proofsRequired.excl(id) -proc setCancelled*(mock: MockProofs, id: ContractId, required: bool) = +proc setCancelled*(mock: MockProofs, id: SlotId, required: bool) = if required: mock.cancelledRequests.incl(id) else: mock.cancelledRequests.excl(id) method isCancelled*(mock: MockProofs, - id: array[32, byte]): Future[bool] {.async.} = + id: RequestId): Future[bool] {.async.} = return mock.cancelledRequests.contains(id) method isSlotCancelled*(mock: MockProofs, - id: ContractId): Future[bool] {.async.} = + id: SlotId): Future[bool] {.async.} = return mock.cancelledRequests.contains(id) method isProofRequired*(mock: MockProofs, diff --git a/tests/codex/testproving.nim b/tests/codex/testproving.nim index 03b7b885..a24d8263 100644 --- a/tests/codex/testproving.nim +++ b/tests/codex/testproving.nim @@ -93,17 +93,17 @@ suite "Proving": check not called test "stops watching when contract is cancelled": - let id = ContractId.example + let id = SlotId.example proving.add(id) var called: bool - proc onProofRequired(id: ContractId) = + proc onProofRequired(id: SlotId) = called = true proofs.setProofRequired(id, true) await proofs.advanceToNextPeriod() proving.onProofRequired = onProofRequired proofs.setCancelled(id, true) await proofs.advanceToNextPeriod() - check not proving.contracts.contains(id) + check not proving.slots.contains(id) check not called test "submits proofs": diff --git a/tests/codex/testpurchasing.nim b/tests/codex/testpurchasing.nim index c1fd7289..658cf25e 100644 --- a/tests/codex/testpurchasing.nim +++ b/tests/codex/testpurchasing.nim @@ -92,9 +92,9 @@ suite "Purchasing": test "supports request cancelled subscription when request times out": let purchase = purchasing.purchase(request) let request = market.requested[0] - var receivedIds: seq[array[32, byte]] + var receivedIds: seq[RequestId] clock.set(request.expiry.truncate(int64)) - proc onRequestCancelled(id: array[32, byte]) {.gcsafe, upraises:[].} = + proc onRequestCancelled(id: RequestId) {.gcsafe, upraises:[].} = receivedIds.add(id) let subscription = await market.subscribeRequestCancelled( request.id, diff --git a/tests/codex/testsales.nim b/tests/codex/testsales.nim index d41142f7..81fbd21b 100644 --- a/tests/codex/testsales.nim +++ b/tests/codex/testsales.nim @@ -205,8 +205,8 @@ suite "Sales": request: StorageRequest, slotIndex: UInt256) = soldSlotIndex = slotIndex - check proving.contracts.len == 0 + check proving.slots.len == 0 sales.add(availability) discard await market.requestStorage(request) - check proving.contracts.len == 1 - check proving.contracts.contains(request.slotId(soldSlotIndex)) + check proving.slots.len == 1 + check proving.slots.contains(request.slotId(soldSlotIndex)) diff --git a/tests/contracts/testContracts.nim b/tests/contracts/testContracts.nim index d0daefdf..676a12b2 100644 --- a/tests/contracts/testContracts.nim +++ b/tests/contracts/testContracts.nim @@ -82,9 +82,9 @@ ethersuite "Storage contracts": check await storage.isCancelled(request.id) test "a slot is cancelled after expiry": - check not await storage.isSlotCancelled(id) + check not await storage.isSlotCancelled(slotId) await provider.advanceTimeTo(request.expiry + 1) - check await storage.isSlotCancelled(id) + check await storage.isSlotCancelled(slotId) test "cannot mark proofs missing for cancelled request": await provider.advanceTimeTo(request.expiry + 1) @@ -92,4 +92,4 @@ ethersuite "Storage contracts": let missingPeriod = periodicity.periodOf(await provider.currentTime()) await provider.advanceTime(periodicity.seconds) revertsWith "Request was cancelled": - await storage.markProofAsMissing(id, missingPeriod) + await storage.markProofAsMissing(slotId, missingPeriod)