From b414ecd67ee80096931a93c265ec63f15ef6cda3 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 15 Jun 2022 14:12:34 +0200 Subject: [PATCH] [market] Add market.getRequest() --- codex/contracts/market.nim | 8 ++++++++ codex/contracts/storage.nim | 1 + codex/market.nim | 7 +++++++ tests/codex/helpers/mockmarket.nim | 7 +++++++ tests/contracts/testMarket.nim | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 92aa1b69..128c9d63 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -31,6 +31,14 @@ method requestStorage(market: OnChainMarket, await market.contract.requestStorage(request) return request +method getRequest(market: OnChainMarket, + id: array[32, byte]): Future[?StorageRequest] {.async.} = + let request = await market.contract.getRequest(id) + if request != StorageRequest.default: + return some request + else: + return none StorageRequest + method fulfillRequest(market: OnChainMarket, requestId: array[32, byte], proof: seq[byte]) {.async.} = diff --git a/codex/contracts/storage.nim b/codex/contracts/storage.nim index b1c058c9..94e77065 100644 --- a/codex/contracts/storage.nim +++ b/codex/contracts/storage.nim @@ -30,6 +30,7 @@ proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.} proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.} proc fulfillRequest*(storage: Storage, id: Id, proof: seq[byte]) {.contract.} +proc getRequest*(storage: Storage, id: Id): StorageRequest {.contract, view.} proc finishContract*(storage: Storage, id: Id) {.contract.} diff --git a/codex/market.nim b/codex/market.nim index 9692f2cf..1d048f09 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -1,9 +1,11 @@ import pkg/chronos import pkg/upraises +import pkg/questionable import ./contracts/requests import ./contracts/offers export chronos +export questionable export requests export offers @@ -18,6 +20,11 @@ method requestStorage*(market: Market, Future[StorageRequest] {.base, async.} = raiseAssert("not implemented") +method getRequest*(market: Market, + id: array[32, byte]): + Future[?StorageRequest] {.base, async.} = + raiseAssert("not implemented") + method fulfillRequest*(market: Market, requestId: array[32, byte], proof: seq[byte]) {.base, async.} = diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 15f25a32..67faa7c4 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -30,6 +30,13 @@ method requestStorage*(market: MockMarket, subscription.callback(request.id, request.ask) return request +method getRequest(market: MockMarket, + id: array[32, byte]): Future[?StorageRequest] {.async.} = + for request in market.requested: + if request.id == id: + return some request + return none StorageRequest + method fulfillRequest*(market: MockMarket, requestId: array[32, byte], proof: seq[byte]) {.async.} = diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 7b92175d..f39c629a 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -49,6 +49,12 @@ ethersuite "On-Chain Market": let submitted = await market.requestStorage(requestWithoutClient) check submitted.client == accounts[0] + test "can retrieve previously submitted requests": + check (await market.getRequest(request.id)) == none StorageRequest + await token.approve(storage.address, request.ask.maxPrice) + discard await market.requestStorage(request) + check (await market.getRequest(request.id)) == some request + test "supports request subscriptions": var receivedIds: seq[array[32, byte]] var receivedAsks: seq[StorageAsk]