catch and check revert reasons
Ensure specific contract reverts are handled and returned as booleans or default values # Conflicts: # codex/contracts/proofs.nim
This commit is contained in:
parent
10d4dcd70d
commit
5eb65336fd
|
@ -1,4 +1,6 @@
|
||||||
|
import std/strutils
|
||||||
import pkg/ethers
|
import pkg/ethers
|
||||||
|
import pkg/ethers/testing
|
||||||
import pkg/upraises
|
import pkg/upraises
|
||||||
import pkg/questionable
|
import pkg/questionable
|
||||||
import ../market
|
import ../market
|
||||||
|
@ -38,9 +40,10 @@ method getRequest(market: OnChainMarket,
|
||||||
id: RequestId): Future[?StorageRequest] {.async.} =
|
id: RequestId): Future[?StorageRequest] {.async.} =
|
||||||
try:
|
try:
|
||||||
return some await market.contract.getRequest(id)
|
return some await market.contract.getRequest(id)
|
||||||
except ValueError:
|
except JsonRpcProviderError as e:
|
||||||
# Unknown request
|
if e.revertReason.contains("Unknown request"):
|
||||||
return none StorageRequest
|
# Unknown request
|
||||||
|
return none StorageRequest
|
||||||
|
|
||||||
method getHost(market: OnChainMarket,
|
method getHost(market: OnChainMarket,
|
||||||
requestId: RequestId,
|
requestId: RequestId,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import std/strutils
|
||||||
import pkg/ethers
|
import pkg/ethers
|
||||||
import pkg/ethers/testing
|
import pkg/ethers/testing
|
||||||
import ../storageproofs/timing/proofs
|
import ../storageproofs/timing/proofs
|
||||||
|
@ -28,7 +29,7 @@ method isProofRequired*(proofs: OnChainProofs,
|
||||||
try:
|
try:
|
||||||
return await proofs.storage.isProofRequired(id)
|
return await proofs.storage.isProofRequired(id)
|
||||||
except JsonRpcProviderError as e:
|
except JsonRpcProviderError as e:
|
||||||
if e.revertReason == "Slot empty":
|
if e.revertReason.contains("Slot empty"):
|
||||||
return false
|
return false
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@ -37,7 +38,7 @@ method willProofBeRequired*(proofs: OnChainProofs,
|
||||||
try:
|
try:
|
||||||
return await proofs.storage.willProofBeRequired(id)
|
return await proofs.storage.willProofBeRequired(id)
|
||||||
except JsonRpcProviderError as e:
|
except JsonRpcProviderError as e:
|
||||||
if e.revertReason == "Slot empty":
|
if e.revertReason.contains("Slot empty"):
|
||||||
return false
|
return false
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
@ -45,8 +46,10 @@ method getProofEnd*(proofs: OnChainProofs,
|
||||||
id: SlotId): Future[UInt256] {.async.} =
|
id: SlotId): Future[UInt256] {.async.} =
|
||||||
try:
|
try:
|
||||||
return await proofs.storage.proofEnd(id)
|
return await proofs.storage.proofEnd(id)
|
||||||
except ValueError:
|
except JsonRpcProviderError as e:
|
||||||
return 0.u256
|
if e.revertReason.contains("Slot empty"):
|
||||||
|
return 0.u256
|
||||||
|
raise e
|
||||||
|
|
||||||
method submitProof*(proofs: OnChainProofs,
|
method submitProof*(proofs: OnChainProofs,
|
||||||
id: SlotId,
|
id: SlotId,
|
||||||
|
|
Loading…
Reference in New Issue