refactor: marketplace configuration is cached (#1029)
This commit is contained in:
parent
da234d503b
commit
d10072bf67
|
@ -20,6 +20,8 @@ type
|
||||||
contract: Marketplace
|
contract: Marketplace
|
||||||
signer: Signer
|
signer: Signer
|
||||||
rewardRecipient: ?Address
|
rewardRecipient: ?Address
|
||||||
|
configuration: ?MarketplaceConfig
|
||||||
|
|
||||||
MarketSubscription = market.Subscription
|
MarketSubscription = market.Subscription
|
||||||
EventSubscription = ethers.Subscription
|
EventSubscription = ethers.Subscription
|
||||||
OnChainMarketSubscription = ref object of MarketSubscription
|
OnChainMarketSubscription = ref object of MarketSubscription
|
||||||
|
@ -48,6 +50,14 @@ template convertEthersError(body) =
|
||||||
except EthersError as error:
|
except EthersError as error:
|
||||||
raiseMarketError(error.msgDetail)
|
raiseMarketError(error.msgDetail)
|
||||||
|
|
||||||
|
proc config(market: OnChainMarket): Future[MarketplaceConfig] {.async.} =
|
||||||
|
without resolvedConfig =? market.configuration:
|
||||||
|
let fetchedConfig = await market.contract.configuration()
|
||||||
|
market.configuration = some fetchedConfig
|
||||||
|
return fetchedConfig
|
||||||
|
|
||||||
|
return resolvedConfig
|
||||||
|
|
||||||
proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
|
proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
|
||||||
debug "Approving tokens", amount
|
debug "Approving tokens", amount
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
|
@ -56,7 +66,7 @@ proc approveFunds(market: OnChainMarket, amount: UInt256) {.async.} =
|
||||||
discard await token.increaseAllowance(market.contract.address(), amount).confirm(1)
|
discard await token.increaseAllowance(market.contract.address(), amount).confirm(1)
|
||||||
|
|
||||||
method getZkeyHash*(market: OnChainMarket): Future[?string] {.async.} =
|
method getZkeyHash*(market: OnChainMarket): Future[?string] {.async.} =
|
||||||
let config = await market.contract.configuration()
|
let config = await market.config()
|
||||||
return some config.proofs.zkeyHash
|
return some config.proofs.zkeyHash
|
||||||
|
|
||||||
method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
|
method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
|
||||||
|
@ -65,18 +75,18 @@ method getSigner*(market: OnChainMarket): Future[Address] {.async.} =
|
||||||
|
|
||||||
method periodicity*(market: OnChainMarket): Future[Periodicity] {.async.} =
|
method periodicity*(market: OnChainMarket): Future[Periodicity] {.async.} =
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
let config = await market.contract.configuration()
|
let config = await market.config()
|
||||||
let period = config.proofs.period
|
let period = config.proofs.period
|
||||||
return Periodicity(seconds: period)
|
return Periodicity(seconds: period)
|
||||||
|
|
||||||
method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} =
|
method proofTimeout*(market: OnChainMarket): Future[UInt256] {.async.} =
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
let config = await market.contract.configuration()
|
let config = await market.config()
|
||||||
return config.proofs.timeout
|
return config.proofs.timeout
|
||||||
|
|
||||||
method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} =
|
method proofDowntime*(market: OnChainMarket): Future[uint8] {.async.} =
|
||||||
convertEthersError:
|
convertEthersError:
|
||||||
let config = await market.contract.configuration()
|
let config = await market.config()
|
||||||
return config.proofs.downtime
|
return config.proofs.downtime
|
||||||
|
|
||||||
method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} =
|
method getPointer*(market: OnChainMarket, slotId: SlotId): Future[uint8] {.async.} =
|
||||||
|
|
|
@ -66,6 +66,11 @@ ethersuite "On-Chain Market":
|
||||||
):
|
):
|
||||||
await advanceToNextPeriod()
|
await advanceToNextPeriod()
|
||||||
|
|
||||||
|
test "caches marketplace configuration":
|
||||||
|
check isNone market.configuration
|
||||||
|
discard await market.periodicity()
|
||||||
|
check isSome market.configuration
|
||||||
|
|
||||||
test "fails to instantiate when contract does not have a signer":
|
test "fails to instantiate when contract does not have a signer":
|
||||||
let storageWithoutSigner = marketplace.connect(ethProvider)
|
let storageWithoutSigner = marketplace.connect(ethProvider)
|
||||||
expect AssertionDefect:
|
expect AssertionDefect:
|
||||||
|
|
Loading…
Reference in New Issue