Fix method signatures

This commit is contained in:
Arnaud 2024-12-18 16:45:05 +01:00
parent 0ecf3f7a78
commit 4935494c29
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
3 changed files with 81 additions and 36 deletions

View File

@ -45,7 +45,7 @@ method start*(clock: OnChainClock) {.async.} =
if clock.started:
return
proc onBlock(_: Block) =
proc onBlock(_: ?!Block) =
# ignore block parameter; hardhat may call this with pending blocks
asyncSpawn clock.update()

View File

@ -277,10 +277,14 @@ method canReserveSlot*(
method subscribeRequests*(market: OnChainMarket,
callback: OnRequest):
Future[MarketSubscription] {.async.} =
proc onEvent(event: StorageRequested) {.upraises:[].} =
callback(event.requestId,
event.ask,
event.expiry)
proc onEvent(event: ?!StorageRequested) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId,
value.ask,
value.expiry)
convertEthersError:
let subscription = await market.contract.subscribe(StorageRequested, onEvent)
@ -289,8 +293,12 @@ method subscribeRequests*(market: OnChainMarket,
method subscribeSlotFilled*(market: OnChainMarket,
callback: OnSlotFilled):
Future[MarketSubscription] {.async.} =
proc onEvent(event: SlotFilled) {.upraises:[].} =
callback(event.requestId, event.slotIndex)
proc onEvent(event: ?!SlotFilled) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId, value.slotIndex)
convertEthersError:
let subscription = await market.contract.subscribe(SlotFilled, onEvent)
@ -311,8 +319,12 @@ method subscribeSlotFilled*(market: OnChainMarket,
method subscribeSlotFreed*(market: OnChainMarket,
callback: OnSlotFreed):
Future[MarketSubscription] {.async.} =
proc onEvent(event: SlotFreed) {.upraises:[].} =
callback(event.requestId, event.slotIndex)
proc onEvent(event: ?!SlotFreed) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId, value.slotIndex)
convertEthersError:
let subscription = await market.contract.subscribe(SlotFreed, onEvent)
@ -322,8 +334,12 @@ method subscribeSlotReservationsFull*(
market: OnChainMarket,
callback: OnSlotReservationsFull): Future[MarketSubscription] {.async.} =
proc onEvent(event: SlotReservationsFull) {.upraises:[].} =
callback(event.requestId, event.slotIndex)
proc onEvent(event: ?!SlotReservationsFull) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId, value.slotIndex)
convertEthersError:
let subscription = await market.contract.subscribe(SlotReservationsFull, onEvent)
@ -332,8 +348,12 @@ method subscribeSlotReservationsFull*(
method subscribeFulfillment(market: OnChainMarket,
callback: OnFulfillment):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestFulfilled) {.upraises:[].} =
callback(event.requestId)
proc onEvent(event: ?!RequestFulfilled) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestFulfilled, onEvent)
@ -343,9 +363,13 @@ method subscribeFulfillment(market: OnChainMarket,
requestId: RequestId,
callback: OnFulfillment):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestFulfilled) {.upraises:[].} =
if event.requestId == requestId:
callback(event.requestId)
proc onEvent(event: ?!RequestFulfilled) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
if value.requestId == requestId:
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestFulfilled, onEvent)
@ -354,8 +378,12 @@ method subscribeFulfillment(market: OnChainMarket,
method subscribeRequestCancelled*(market: OnChainMarket,
callback: OnRequestCancelled):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestCancelled) {.upraises:[].} =
callback(event.requestId)
proc onEvent(event: ?!RequestCancelled) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestCancelled, onEvent)
@ -365,9 +393,13 @@ method subscribeRequestCancelled*(market: OnChainMarket,
requestId: RequestId,
callback: OnRequestCancelled):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestCancelled) {.upraises:[].} =
if event.requestId == requestId:
callback(event.requestId)
proc onEvent(event: ?!RequestCancelled) {.upraises:[].} =
without value =? event:
error "The event object is not defined"
return
if value.requestId == requestId:
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestCancelled, onEvent)
@ -376,8 +408,12 @@ method subscribeRequestCancelled*(market: OnChainMarket,
method subscribeRequestFailed*(market: OnChainMarket,
callback: OnRequestFailed):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestFailed) {.upraises:[]} =
callback(event.requestId)
proc onEvent(event: ?!RequestFailed) {.upraises:[]} =
without value =? event:
error "The event object is not defined"
return
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestFailed, onEvent)
@ -387,9 +423,13 @@ method subscribeRequestFailed*(market: OnChainMarket,
requestId: RequestId,
callback: OnRequestFailed):
Future[MarketSubscription] {.async.} =
proc onEvent(event: RequestFailed) {.upraises:[]} =
if event.requestId == requestId:
callback(event.requestId)
proc onEvent(event: ?!RequestFailed) {.upraises:[]} =
without value =? event:
error "The event object is not defined"
return
if value.requestId == requestId:
callback(value.requestId)
convertEthersError:
let subscription = await market.contract.subscribe(RequestFailed, onEvent)
@ -398,8 +438,12 @@ method subscribeRequestFailed*(market: OnChainMarket,
method subscribeProofSubmission*(market: OnChainMarket,
callback: OnProofSubmitted):
Future[MarketSubscription] {.async.} =
proc onEvent(event: ProofSubmitted) {.upraises: [].} =
callback(event.id)
proc onEvent(event: ?!ProofSubmitted) {.upraises: [].} =
without value =? event:
error "The event object is not defined"
return
callback(value.id)
convertEthersError:
let subscription = await market.contract.subscribe(ProofSubmitted, onEvent)

View File

@ -323,15 +323,16 @@ method getBlockExpirations*(
return failure(err)
let
filteredIter = await asyncQueryIter.filterSuccess()
blockExpIter = await mapFilter[KeyVal[BlockMetadata], BlockExpiration](filteredIter,
proc (kv: KeyVal[BlockMetadata]): Future[?BlockExpiration] {.async.} =
without cid =? Cid.init(kv.key.value).mapFailure, err:
error "Failed decoding cid", err = err.msg
return BlockExpiration.none
filteredIter: AsyncIter[KeyVal[BlockMetadata]] = await asyncQueryIter.filterSuccess()
BlockExpiration(cid: cid, expiry: kv.value.expiry).some
)
proc mapping (kv: KeyVal[BlockMetadata]): Future[?BlockExpiration] {.async.} =
without cid =? Cid.init(kv.key.value).mapFailure, err:
error "Failed decoding cid", err = err.msg
return BlockExpiration.none
BlockExpiration(cid: cid, expiry: kv.value.expiry).some
let blockExpIter = await mapFilter[KeyVal[BlockMetadata], BlockExpiration](filteredIter, mapping)
success(blockExpIter)