From de9753aeab8271ed1e4da74637c35edb767146ef Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 18 Sep 2024 20:32:34 +1000 Subject: [PATCH 1/8] feat(slot-reservations): Support reserving slots Closes #898. Wire up reserveSlot and canReserveSlot contract calls, but don't call them --- codex/contracts/market.nim | 6 ++++++ codex/contracts/marketplace.nim | 3 +++ codex/market.nim | 6 ++++++ vendor/codex-contracts-eth | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 1595b4497..e20657697 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -247,6 +247,12 @@ method canProofBeMarkedAsMissing*( trace "Proof cannot be marked as missing", msg = e.msg return false +method reserveSlot*(id: SlotId): Future[bool] {.async.} = + discard await market.contract.reserveSlot(id).confirm(0) + +method canReserveSlot*(id: SlotId): Future[bool] {.async.} = + discard await market.contract.canReserveSlot(id).confirm(0) + method subscribeRequests*(market: OnChainMarket, callback: OnRequest): Future[MarketSubscription] {.async.} = diff --git a/codex/contracts/marketplace.nim b/codex/contracts/marketplace.nim index f98b9a80e..6596c993c 100644 --- a/codex/contracts/marketplace.nim +++ b/codex/contracts/marketplace.nim @@ -51,3 +51,6 @@ proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.} proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): ?TransactionResponse {.contract.} proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): ?TransactionResponse {.contract.} + +proc reserveSlot*(marketplace: Marketplace, id: SlotId): bool {.contract.} +proc canReserveSlot*(marketplace: Marketplace, id: SlotId): bool {.contract, view.} diff --git a/codex/market.nim b/codex/market.nim index 245c28d51..1ebe237dd 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -161,6 +161,12 @@ method canProofBeMarkedAsMissing*(market: Market, period: Period): Future[bool] {.base, async.} = raiseAssert("not implemented") +method reserveSlot*(id: SlotId): Future[bool] {.base, async.} = + raiseAssert("not implemented") + +method canReserveSlot*(id: SlotId): Future[bool] {.base, async.} = + raiseAssert("not implemented") + method subscribeFulfillment*(market: Market, callback: OnFulfillment): Future[Subscription] {.base, async.} = diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index 558bf645c..b62c72b5e 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit 558bf645c3dc385437a3e695bba57e7dba1375fb +Subproject commit b62c72b5e1a348c2d47c9f3c31c1d712e37286b7 From c4cc2776edb81813d474a8f1152e9f03efb5c92b Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:33:38 +1000 Subject: [PATCH 2/8] Remove return value from `reserveSlot` --- codex/contracts/market.nim | 9 ++++++--- codex/contracts/marketplace.nim | 2 +- codex/market.nim | 10 ++++++++-- vendor/codex-contracts-eth | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index e20657697..6357ee732 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -247,11 +247,14 @@ method canProofBeMarkedAsMissing*( trace "Proof cannot be marked as missing", msg = e.msg return false -method reserveSlot*(id: SlotId): Future[bool] {.async.} = +method reserveSlot*(market: OnChainMarket, id: SlotId) {.async.} = discard await market.contract.reserveSlot(id).confirm(0) -method canReserveSlot*(id: SlotId): Future[bool] {.async.} = - discard await market.contract.canReserveSlot(id).confirm(0) +method canReserveSlot*( + market: OnChainMarket, + id: SlotId): Future[bool] {.async.} = + + await market.contract.canReserveSlot(id) method subscribeRequests*(market: OnChainMarket, callback: OnRequest): diff --git a/codex/contracts/marketplace.nim b/codex/contracts/marketplace.nim index 6596c993c..0c8b8b31f 100644 --- a/codex/contracts/marketplace.nim +++ b/codex/contracts/marketplace.nim @@ -52,5 +52,5 @@ proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.} proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): ?TransactionResponse {.contract.} proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): ?TransactionResponse {.contract.} -proc reserveSlot*(marketplace: Marketplace, id: SlotId): bool {.contract.} +proc reserveSlot*(marketplace: Marketplace, id: SlotId): ?TransactionResponse {.contract.} proc canReserveSlot*(marketplace: Marketplace, id: SlotId): bool {.contract, view.} diff --git a/codex/market.nim b/codex/market.nim index 1ebe237dd..94bf9c5af 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -161,10 +161,16 @@ method canProofBeMarkedAsMissing*(market: Market, period: Period): Future[bool] {.base, async.} = raiseAssert("not implemented") -method reserveSlot*(id: SlotId): Future[bool] {.base, async.} = +method reserveSlot*( + market: Market, + id: SlotId) {.base, async.} = + raiseAssert("not implemented") -method canReserveSlot*(id: SlotId): Future[bool] {.base, async.} = +method canReserveSlot*( + market: Market, + id: SlotId): Future[bool] {.base, async.} = + raiseAssert("not implemented") method subscribeFulfillment*(market: Market, diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index b62c72b5e..d2ba8693e 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit b62c72b5e1a348c2d47c9f3c31c1d712e37286b7 +Subproject commit d2ba8693e772b83e80746ffadc1efc36c836caf0 From e6fcb09615d78ebf75b3b1864ba9dfab57f07b9f Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:35:39 +1000 Subject: [PATCH 3/8] convert EthersError to MarketError --- codex/contracts/market.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 6357ee732..1f395fab1 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -254,7 +254,8 @@ method canReserveSlot*( market: OnChainMarket, id: SlotId): Future[bool] {.async.} = - await market.contract.canReserveSlot(id) + convertEthersError: + return await market.contract.canReserveSlot(id) method subscribeRequests*(market: OnChainMarket, callback: OnRequest): From fced1551aac252178f32deaf93904e3d7da6ab5e Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:47:08 +1000 Subject: [PATCH 4/8] Move convertEthersError to reserveSlot --- codex/contracts/market.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 1f395fab1..381ac9a9f 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -248,14 +248,14 @@ method canProofBeMarkedAsMissing*( return false method reserveSlot*(market: OnChainMarket, id: SlotId) {.async.} = - discard await market.contract.reserveSlot(id).confirm(0) + convertEthersError: + discard await market.contract.reserveSlot(id).confirm(0) method canReserveSlot*( market: OnChainMarket, id: SlotId): Future[bool] {.async.} = - convertEthersError: - return await market.contract.canReserveSlot(id) + await market.contract.canReserveSlot(id) method subscribeRequests*(market: OnChainMarket, callback: OnRequest): From e95f684188848436ea28dfde872c21047585da9e Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 25 Sep 2024 19:41:27 +1000 Subject: [PATCH 5/8] bump codex-contracts-eth after rebase --- vendor/codex-contracts-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index d2ba8693e..122e6858a 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit d2ba8693e772b83e80746ffadc1efc36c836caf0 +Subproject commit 122e6858a086bf61edc6763fb0eadce1c9ac3820 From ed4075c8260a78fc4659a1f6d52153317089dd8e Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 26 Sep 2024 17:20:18 +1000 Subject: [PATCH 6/8] change `canReserveSlot` and `reserveSlot` parameters Parameters for `canReserveSlot` and `reserveSlot` were changed from `SlotId` to `RequestId` and `UInt256 slotIndex`. --- codex/contracts/market.nim | 13 +++++++++---- codex/contracts/marketplace.nim | 4 ++-- codex/market.nim | 6 ++++-- vendor/codex-contracts-eth | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 381ac9a9f..3ca0d0e63 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -247,15 +247,20 @@ method canProofBeMarkedAsMissing*( trace "Proof cannot be marked as missing", msg = e.msg return false -method reserveSlot*(market: OnChainMarket, id: SlotId) {.async.} = +method reserveSlot*( + market: OnChainMarket, + requestId: RequestId, + slotIndex: UInt256) {.async.} = + convertEthersError: - discard await market.contract.reserveSlot(id).confirm(0) + discard await market.contract.reserveSlot(requestId, slotIndex).confirm(0) method canReserveSlot*( market: OnChainMarket, - id: SlotId): Future[bool] {.async.} = + requestId: RequestId, + slotIndex: UInt256): Future[bool] {.async.} = - await market.contract.canReserveSlot(id) + await market.contract.canReserveSlot(requestId, slotIndex) method subscribeRequests*(market: OnChainMarket, callback: OnRequest): diff --git a/codex/contracts/marketplace.nim b/codex/contracts/marketplace.nim index 0c8b8b31f..6425bfa0c 100644 --- a/codex/contracts/marketplace.nim +++ b/codex/contracts/marketplace.nim @@ -52,5 +52,5 @@ proc getPointer*(marketplace: Marketplace, id: SlotId): uint8 {.contract, view.} proc submitProof*(marketplace: Marketplace, id: SlotId, proof: Groth16Proof): ?TransactionResponse {.contract.} proc markProofAsMissing*(marketplace: Marketplace, id: SlotId, period: UInt256): ?TransactionResponse {.contract.} -proc reserveSlot*(marketplace: Marketplace, id: SlotId): ?TransactionResponse {.contract.} -proc canReserveSlot*(marketplace: Marketplace, id: SlotId): bool {.contract, view.} +proc reserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): ?TransactionResponse {.contract.} +proc canReserveSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256): bool {.contract, view.} diff --git a/codex/market.nim b/codex/market.nim index 94bf9c5af..89e6231a4 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -163,13 +163,15 @@ method canProofBeMarkedAsMissing*(market: Market, method reserveSlot*( market: Market, - id: SlotId) {.base, async.} = + requestId: RequestId, + slotIndex: UInt256) {.base, async.} = raiseAssert("not implemented") method canReserveSlot*( market: Market, - id: SlotId): Future[bool] {.base, async.} = + requestId: RequestId, + slotIndex: UInt256): Future[bool] {.base, async.} = raiseAssert("not implemented") diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index 122e6858a..733aab007 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit 122e6858a086bf61edc6763fb0eadce1c9ac3820 +Subproject commit 733aab007efdc6c28e6c40221561b31a5fe8c853 From 425dfb107faf5f658bf6837ac0ca1d1f3a3fc042 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Wed, 2 Oct 2024 19:56:15 +1000 Subject: [PATCH 7/8] bump codex-contracts-eth after rebase --- vendor/codex-contracts-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index 733aab007..7001e9ae9 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit 733aab007efdc6c28e6c40221561b31a5fe8c853 +Subproject commit 7001e9ae94e44f01747e400379742ecdeead2c9a From 1e5d21e27a19cd8985e93318400efb36be97d068 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Thu, 3 Oct 2024 11:13:32 +1000 Subject: [PATCH 8/8] bump codex-contracts-eth to master after codex-contracts-eth/pull/177 merged --- vendor/codex-contracts-eth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index 7001e9ae9..33010bd20 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit 7001e9ae94e44f01747e400379742ecdeead2c9a +Subproject commit 33010bd20cfdc3d589be25782052796af580ca83