[market] Remove old getHost() overload

Is superseded by the new overload that includes
a slot id parameter.
This commit is contained in:
Mark Spanbroek 2022-07-27 16:54:34 +02:00 committed by markspanbroek
parent 698baeef35
commit 04e0c54e95
5 changed files with 17 additions and 23 deletions

View File

@ -42,19 +42,21 @@ method getRequest(market: OnChainMarket,
else: else:
return none StorageRequest 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, method fulfillRequest(market: OnChainMarket,
requestId: array[32, byte], requestId: array[32, byte],
proof: seq[byte]) {.async.} = proof: seq[byte]) {.async.} =
await market.contract.fulfillRequest(requestId, proof) 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, method fillSlot(market: OnChainMarket,
requestId: array[32, byte], requestId: array[32, byte],
slotIndex: UInt256, slotIndex: UInt256,

View File

@ -120,9 +120,12 @@ func id*(request: StorageRequest): array[32, byte] =
let encoding = AbiEncoder.encode((request, )) let encoding = AbiEncoder.encode((request, ))
keccak256.digest(encoding).data keccak256.digest(encoding).data
func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] = func slotId*(requestId: array[32, byte], slot: UInt256): array[32, byte] =
let encoding = AbiEncoder.encode((request.id, slot)) let encoding = AbiEncoder.encode((requestId, slot))
keccak256.digest(encoding).data keccak256.digest(encoding).data
func slotId*(request: StorageRequest, slot: UInt256): array[32, byte] =
slotId(request.id, slot)
func price*(request: StorageRequest): UInt256 = func price*(request: StorageRequest): UInt256 =
request.ask.slots.u256 * request.ask.duration * request.ask.reward request.ask.slots.u256 * request.ask.duration * request.ask.reward

View File

@ -27,10 +27,6 @@ method getRequest*(market: Market,
Future[?StorageRequest] {.base, async.} = Future[?StorageRequest] {.base, async.} =
raiseAssert("not implemented") raiseAssert("not implemented")
method getHost*(market: Market,
requestId: array[32, byte]): Future[?Address] {.base, async.} =
raiseAssert("not implemented")
method fulfillRequest*(market: Market, method fulfillRequest*(market: Market,
requestId: array[32, byte], requestId: array[32, byte],
proof: seq[byte]) {.base, async.} = proof: seq[byte]) {.base, async.} =

View File

@ -58,13 +58,6 @@ method getRequest(market: MockMarket,
return some request return some request
return none StorageRequest 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, proc fulfillRequest*(market: MockMarket,
requestId: array[32, byte], requestId: array[32, byte],
proof: seq[byte], proof: seq[byte],

View File

@ -77,9 +77,9 @@ ethersuite "On-Chain Market":
test "can retrieve host that filled slot": test "can retrieve host that filled slot":
await token.approve(storage.address, request.price) await token.approve(storage.address, request.price)
discard await market.requestStorage(request) 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) 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": test "support fulfillment subscriptions":
await token.approve(storage.address, request.price) await token.approve(storage.address, request.price)