chore(marketplace): define raises for async pragma (#1165)

* Define raises for async pragma

* Update nim ethers

* Replace CatchableError by MarketError
This commit is contained in:
Arnaud 2025-03-26 09:06:37 +01:00 committed by GitHub
parent a0d6fbaf02
commit 60b6996eb0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 65 additions and 29 deletions

View File

@ -76,7 +76,9 @@ proc config(
return resolvedConfig
proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
proc approveFunds(
market: OnChainMarket, amount: UInt256
) {.async: (raises: [CancelledError, MarketError]).} =
debug "Approving tokens", amount
convertEthersError("Failed to approve funds"):
let tokenAddress = await market.contract.token()
@ -105,7 +107,9 @@ method getZkeyHash*(
let config = await market.config()
return some config.proofs.zkeyHash
method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
method getSigner*(
market: OnChainMarket
): Future[Address] {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to get signer address"):
return await market.signer.getAddress()
@ -159,7 +163,9 @@ method mySlots*(market: OnChainMarket): Future[seq[SlotId]] {.async.} =
return slots
method requestStorage(market: OnChainMarket, request: StorageRequest) {.async.} =
method requestStorage(
market: OnChainMarket, request: StorageRequest
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to request storage"):
debug "Requesting storage"
await market.approveFunds(request.totalPrice())
@ -243,7 +249,7 @@ method fillSlot(
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
) {.async.} =
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to fill slot"):
logScope:
requestId
@ -260,7 +266,9 @@ method fillSlot(
parent,
)
method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} =
method freeSlot*(
market: OnChainMarket, slotId: SlotId
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to free slot"):
var freeSlot: Future[Confirmable]
if rewardRecipient =? market.rewardRecipient:
@ -279,7 +287,9 @@ method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} =
discard await freeSlot.confirm(1)
method withdrawFunds(market: OnChainMarket, requestId: RequestId) {.async.} =
method withdrawFunds(
market: OnChainMarket, requestId: RequestId
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to withdraw funds"):
discard await market.contract.withdrawFunds(requestId).confirm(1)
@ -306,13 +316,15 @@ method getChallenge*(
let overrides = CallOverrides(blockTag: some BlockTag.pending)
return await market.contract.getChallenge(id, overrides)
method submitProof*(market: OnChainMarket, id: SlotId, proof: Groth16Proof) {.async.} =
method submitProof*(
market: OnChainMarket, id: SlotId, proof: Groth16Proof
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to submit proof"):
discard await market.contract.submitProof(id, proof).confirm(1)
method markProofAsMissing*(
market: OnChainMarket, id: SlotId, period: Period
) {.async.} =
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to mark proof as missing"):
discard await market.contract.markProofAsMissing(id, period).confirm(1)
@ -331,7 +343,7 @@ method canProofBeMarkedAsMissing*(
method reserveSlot*(
market: OnChainMarket, requestId: RequestId, slotIndex: uint64
) {.async.} =
) {.async: (raises: [CancelledError, MarketError]).} =
convertEthersError("Failed to reserve slot"):
try:
discard await market.contract

View File

@ -74,7 +74,9 @@ method getZkeyHash*(
): Future[?string] {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method getSigner*(market: Market): Future[Address] {.base, async.} =
method getSigner*(
market: Market
): Future[Address] {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method periodicity*(
@ -108,7 +110,9 @@ proc inDowntime*(market: Market, slotId: SlotId): Future[bool] {.async.} =
let pntr = await market.getPointer(slotId)
return pntr < downtime
method requestStorage*(market: Market, request: StorageRequest) {.base, async.} =
method requestStorage*(
market: Market, request: StorageRequest
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method myRequests*(market: Market): Future[seq[RequestId]] {.base, async.} =
@ -161,13 +165,17 @@ method fillSlot*(
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
) {.base, async.} =
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method freeSlot*(market: Market, slotId: SlotId) {.base, async.} =
method freeSlot*(
market: Market, slotId: SlotId
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method withdrawFunds*(market: Market, requestId: RequestId) {.base, async.} =
method withdrawFunds*(
market: Market, requestId: RequestId
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method subscribeRequests*(
@ -186,10 +194,14 @@ method getChallenge*(
): Future[ProofChallenge] {.base, async.} =
raiseAssert("not implemented")
method submitProof*(market: Market, id: SlotId, proof: Groth16Proof) {.base, async.} =
method submitProof*(
market: Market, id: SlotId, proof: Groth16Proof
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method markProofAsMissing*(market: Market, id: SlotId, period: Period) {.base, async.} =
method markProofAsMissing*(
market: Market, id: SlotId, period: Period
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method canProofBeMarkedAsMissing*(
@ -199,7 +211,7 @@ method canProofBeMarkedAsMissing*(
method reserveSlot*(
market: Market, requestId: RequestId, slotIndex: uint64
) {.base, async.} =
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")
method canReserveSlot*(

View File

@ -47,7 +47,7 @@ type
config*: MarketplaceConfig
canReserveSlot*: bool
errorOnReserveSlot*: ?(ref MarketError)
errorOnFillSlot*: ?(ref CatchableError)
errorOnFillSlot*: ?(ref MarketError)
clock: ?Clock
Fulfillment* = object
@ -144,7 +144,9 @@ method loadConfig*(
): Future[?!void] {.async: (raises: [CancelledError]).} =
discard
method getSigner*(market: MockMarket): Future[Address] {.async.} =
method getSigner*(
market: MockMarket
): Future[Address] {.async: (raises: [CancelledError, MarketError]).} =
return market.signer
method periodicity*(
@ -173,7 +175,9 @@ method repairRewardPercentage*(
method getPointer*(market: MockMarket, slotId: SlotId): Future[uint8] {.async.} =
return market.proofPointer
method requestStorage*(market: MockMarket, request: StorageRequest) {.async.} =
method requestStorage*(
market: MockMarket, request: StorageRequest
) {.async: (raises: [CancelledError, MarketError]).} =
market.requested.add(request)
var subscriptions = market.subscriptions.onRequest
for subscription in subscriptions:
@ -311,10 +315,12 @@ method fillSlot*(
slotIndex: uint64,
proof: Groth16Proof,
collateral: UInt256,
) {.async.} =
) {.async: (raises: [CancelledError, MarketError]).} =
market.fillSlot(requestId, slotIndex, proof, market.signer, collateral)
method freeSlot*(market: MockMarket, slotId: SlotId) {.async.} =
method freeSlot*(
market: MockMarket, slotId: SlotId
) {.async: (raises: [CancelledError, MarketError]).} =
market.freed.add(slotId)
for s in market.filled:
if slotId(s.requestId, s.slotIndex) == slotId:
@ -322,7 +328,9 @@ method freeSlot*(market: MockMarket, slotId: SlotId) {.async.} =
break
market.slotState[slotId] = SlotState.Free
method withdrawFunds*(market: MockMarket, requestId: RequestId) {.async.} =
method withdrawFunds*(
market: MockMarket, requestId: RequestId
) {.async: (raises: [CancelledError, MarketError]).} =
market.withdrawn.add(requestId)
if state =? market.requestState .? [requestId] and state == RequestState.Cancelled:
@ -352,12 +360,16 @@ method getChallenge*(mock: MockMarket, id: SlotId): Future[ProofChallenge] {.asy
proc setProofEnd*(mock: MockMarket, id: SlotId, proofEnd: UInt256) =
mock.proofEnds[id] = proofEnd
method submitProof*(mock: MockMarket, id: SlotId, proof: Groth16Proof) {.async.} =
method submitProof*(
mock: MockMarket, id: SlotId, proof: Groth16Proof
) {.async: (raises: [CancelledError, MarketError]).} =
mock.submitted.add(proof)
for subscription in mock.subscriptions.onProofSubmitted:
subscription.callback(id)
method markProofAsMissing*(market: MockMarket, id: SlotId, period: Period) {.async.} =
method markProofAsMissing*(
market: MockMarket, id: SlotId, period: Period
) {.async: (raises: [CancelledError, MarketError]).} =
market.markedAsMissingProofs.add(id)
proc setCanProofBeMarkedAsMissing*(mock: MockMarket, id: SlotId, required: bool) =
@ -373,7 +385,7 @@ method canProofBeMarkedAsMissing*(
method reserveSlot*(
market: MockMarket, requestId: RequestId, slotIndex: uint64
) {.async.} =
) {.async: (raises: [CancelledError, MarketError]).} =
if error =? market.errorOnReserveSlot:
raise error
@ -392,10 +404,10 @@ func setErrorOnReserveSlot*(market: MockMarket, error: ref MarketError) =
else:
some error
func setErrorOnFillSlot*(market: MockMarket, error: ref CatchableError) =
func setErrorOnFillSlot*(market: MockMarket, error: ref MarketError) =
market.errorOnFillSlot =
if error.isNil:
none (ref CatchableError)
none (ref MarketError)
else:
some error

2
vendor/nim-ethers vendored

@ -1 +1 @@
Subproject commit b505ef1ab889be8161bb1efb4908e3dfde5bc1c9
Subproject commit 5d07b5dbcf584b020c732e84cc8b7229ab3e1083