From 4935494c2982cfb189e970de68e32b15481227cd Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 18 Dec 2024 16:45:05 +0100 Subject: [PATCH] Fix method signatures --- codex/contracts/clock.nim | 2 +- codex/contracts/market.nim | 98 +++++++++++++++++++++++--------- codex/stores/repostore/store.nim | 17 +++--- 3 files changed, 81 insertions(+), 36 deletions(-) diff --git a/codex/contracts/clock.nim b/codex/contracts/clock.nim index 937745bf..1d03c1d6 100644 --- a/codex/contracts/clock.nim +++ b/codex/contracts/clock.nim @@ -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() diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index fdddcb22..a6a23b7c 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -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) diff --git a/codex/stores/repostore/store.nim b/codex/stores/repostore/store.nim index 5ff99e64..63c59d2b 100644 --- a/codex/stores/repostore/store.nim +++ b/codex/stores/repostore/store.nim @@ -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)