mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-02-20 08:38:29 +00:00
[marketplace] update to work with latest contracts
This commit is contained in:
parent
7a85350fad
commit
7eba2f46b3
@ -31,8 +31,8 @@ method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
|
|||||||
method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} =
|
method myRequests*(market: OnChainMarket): Future[seq[RequestId]] {.async.} =
|
||||||
return await market.contract.myRequests
|
return await market.contract.myRequests
|
||||||
|
|
||||||
method mySlots*(market: OnChainMarket, requestId: RequestId): Future[seq[SlotId]] {.async.} =
|
method mySlots*(market: OnChainMarket): Future[seq[SlotId]] {.async.} =
|
||||||
return await market.contract.mySlots(requestId)
|
return await market.contract.mySlots()
|
||||||
|
|
||||||
method requestStorage(market: OnChainMarket, request: StorageRequest){.async.} =
|
method requestStorage(market: OnChainMarket, request: StorageRequest){.async.} =
|
||||||
await market.contract.requestStorage(request)
|
await market.contract.requestStorage(request)
|
||||||
|
@ -118,8 +118,8 @@ func solidityType*(_: type StorageRequest): string =
|
|||||||
func solidityType*(_: type Slot): string =
|
func solidityType*(_: type Slot): string =
|
||||||
solidityType(Slot.fieldTypes)
|
solidityType(Slot.fieldTypes)
|
||||||
|
|
||||||
func solidityType*[T: RequestId | SlotId | Nonce](_: type T): string =
|
# func solidityType*[T: RequestId | SlotId | Nonce](_: type T): string =
|
||||||
solidityType(array[32, byte])
|
# solidityType(array[32, byte])
|
||||||
func encode*(encoder: var AbiEncoder, por: StoragePoR) =
|
func encode*(encoder: var AbiEncoder, por: StoragePoR) =
|
||||||
encoder.write(por.fieldValues)
|
encoder.write(por.fieldValues)
|
||||||
|
|
||||||
@ -140,10 +140,10 @@ func encode*(encoder: var AbiEncoder, request: StorageRequest) =
|
|||||||
func encode*(encoder: var AbiEncoder, slot: Slot) =
|
func encode*(encoder: var AbiEncoder, slot: Slot) =
|
||||||
encoder.write(slot.fieldValues)
|
encoder.write(slot.fieldValues)
|
||||||
|
|
||||||
func decode*[T: RequestId | SlotId | Nonce](decoder: var AbiDecoder,
|
# func decode*[T: RequestId | SlotId | Nonce](decoder: var AbiDecoder,
|
||||||
_: type T): ?!T =
|
# _: type T): ?!T =
|
||||||
let nonce = ?decoder.read(type array[32, byte])
|
# let nonce = ?decoder.read(type array[32, byte])
|
||||||
success T(nonce)
|
# success T(nonce)
|
||||||
|
|
||||||
func decode*(decoder: var AbiDecoder, T: type StoragePoR): ?!T =
|
func decode*(decoder: var AbiDecoder, T: type StoragePoR): ?!T =
|
||||||
let tupl = ?decoder.read(StoragePoR.fieldTypes)
|
let tupl = ?decoder.read(StoragePoR.fieldTypes)
|
||||||
|
@ -28,7 +28,7 @@ method requestStorage*(market: Market,
|
|||||||
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
|
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method mySlots*(market: Market, requestId: RequestId): Future[seq[SlotId]] {.base, async.} =
|
method mySlots*(market: Market): Future[seq[SlotId]] {.base, async.} =
|
||||||
raiseAssert("not implemented")
|
raiseAssert("not implemented")
|
||||||
|
|
||||||
method getRequest*(market: Market,
|
method getRequest*(market: Market,
|
||||||
|
@ -89,11 +89,8 @@ proc load*(sales: Sales) {.async.} =
|
|||||||
|
|
||||||
# TODO: restore availability from disk
|
# TODO: restore availability from disk
|
||||||
let requestIds = await market.myRequests()
|
let requestIds = await market.myRequests()
|
||||||
var slotIds: seq[SlotId]
|
let slotIds = await market.mySlots()
|
||||||
# TODO: this needs to be optimised
|
|
||||||
for requestId in requestIds:
|
|
||||||
let reqSlotIds = await market.mySlots(requestId)
|
|
||||||
slotIds.add reqSlotIds
|
|
||||||
for slotId in slotIds:
|
for slotId in slotIds:
|
||||||
# TODO: this needs to be optimised
|
# TODO: this needs to be optimised
|
||||||
if slot =? await market.getSlot(slotId):
|
if slot =? await market.getSlot(slotId):
|
||||||
|
@ -74,7 +74,7 @@ method requestStorage*(market: MockMarket, request: StorageRequest) {.async.} =
|
|||||||
method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} =
|
method myRequests*(market: MockMarket): Future[seq[RequestId]] {.async.} =
|
||||||
return market.activeRequests[market.signer]
|
return market.activeRequests[market.signer]
|
||||||
|
|
||||||
method mySlots*(market: MockMarket, requestId: RequestId): Future[seq[SlotId]] {.async.} =
|
method mySlots*(market: MockMarket): Future[seq[SlotId]] {.async.} =
|
||||||
return market.activeSlots[market.signer]
|
return market.activeSlots[market.signer]
|
||||||
|
|
||||||
method getRequest(market: MockMarket,
|
method getRequest(market: MockMarket,
|
||||||
|
@ -82,10 +82,11 @@ ethersuite "Marketplace contracts":
|
|||||||
let requestEnd = await marketplace.requestEnd(request.id)
|
let requestEnd = await marketplace.requestEnd(request.id)
|
||||||
await provider.advanceTimeTo(requestEnd.u256)
|
await provider.advanceTimeTo(requestEnd.u256)
|
||||||
let startBalance = await token.balanceOf(address)
|
let startBalance = await token.balanceOf(address)
|
||||||
await marketplace.freeSlot(slotId)
|
await storage.payoutSlot(request.id, 0.u256)
|
||||||
let endBalance = await token.balanceOf(address)
|
let endBalance = await token.balanceOf(address)
|
||||||
check endBalance == (startBalance + request.ask.duration * request.ask.reward)
|
check endBalance == (startBalance + request.ask.duration * request.ask.reward)
|
||||||
|
|
||||||
|
|
||||||
test "cannot mark proofs missing for cancelled request":
|
test "cannot mark proofs missing for cancelled request":
|
||||||
await provider.advanceTimeTo(request.expiry + 1)
|
await provider.advanceTimeTo(request.expiry + 1)
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user