diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index e2c92751..0627b73a 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -42,19 +42,21 @@ method getRequest(market: OnChainMarket, else: return none StorageRequest -method getHost(market: OnChainMarket, - id: array[32, byte]): Future[?Address] {.async.} = - let address = await market.contract.getHost(id) - if address != Address.default: - return some address - else: - return none Address - method fulfillRequest(market: OnChainMarket, requestId: array[32, byte], proof: seq[byte]) {.async.} = await market.contract.fulfillRequest(requestId, proof) +method getHost(market: OnChainMarket, + requestId: array[32, byte], + slotIndex: UInt256): Future[?Address] {.async.} = + let slotId = slotId(requestId, slotIndex) + let address = await market.contract.getHost(slotId) + if address != Address.default: + return some address + else: + return none Address + method fillSlot(market: OnChainMarket, requestId: array[32, byte], slotIndex: UInt256, diff --git a/codex/contracts/requests.nim b/codex/contracts/requests.nim index 742f7109..8a39ea9b 100644 --- a/codex/contracts/requests.nim +++ b/codex/contracts/requests.nim @@ -120,9 +120,12 @@ func id*(request: StorageRequest): array[32, byte] = let encoding = AbiEncoder.encode((request, )) keccak256.digest(encoding).data -func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] = - let encoding = AbiEncoder.encode((request.id, slot)) +func slotId*(requestId: array[32, byte], slot: UInt256): array[32, byte] = + let encoding = AbiEncoder.encode((requestId, slot)) keccak256.digest(encoding).data +func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] = + slotId(request.id, slot) + func price*(request: StorageRequest): UInt256 = request.ask.slots.u256 * request.ask.duration * request.ask.reward diff --git a/codex/market.nim b/codex/market.nim index 1a3d5c91..6f152713 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -27,10 +27,6 @@ method getRequest*(market: Market, Future[?StorageRequest] {.base, async.} = raiseAssert("not implemented") -method getHost*(market: Market, - requestId: array[32, byte]): Future[?Address] {.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 0ffce3ce..0c3ebe7f 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -58,13 +58,6 @@ method getRequest(market: MockMarket, return some request return none StorageRequest -method getHost(market: MockMarket, - id: array[32, byte]): Future[?Address] {.async.} = - for fulfillment in market.fulfilled: - if fulfillment.requestId == id: - return some fulfillment.host - return none Address - proc fulfillRequest*(market: MockMarket, requestId: array[32, byte], proof: seq[byte], diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index bcf884b4..752bda88 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -77,9 +77,9 @@ ethersuite "On-Chain Market": test "can retrieve host that filled slot": await token.approve(storage.address, request.price) discard await market.requestStorage(request) - check (await market.getHost(request.slotId(slotIndex))) == none Address + check (await market.getHost(request.id, slotIndex)) == none Address await market.fillSlot(request.id, slotIndex, proof) - check (await market.getHost(request.slotId(slotIndex))) == some accounts[0] + check (await market.getHost(request.id, slotIndex)) == some accounts[0] test "support fulfillment subscriptions": await token.approve(storage.address, request.price)