mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-09 12:35:51 +00:00
372f827982
Add or remove proof requirements when a request contract’s state changes. When a request sale has completed (for a slot), the host who purchased that slot now must provide regular proofs for the data they are contracted to hold. This is now enforced by adding the slotId to the HashSet of Ids for which to require proofs. When a request has been cancelled (not all slots were filled before the request expired), proofs no longer need to be provided and the slotId is removed from teh HashSet. Add `isCancelled` and `isSlotCancelled` checks to query the contract state without relying the on the state context variable in the contract. Because contract state can only be updated in a transaction, and the client withdrawing funds is responsible for changing the contract state to “Cancelled”, the `isCancelled` and `isSlotCancelled` functions were introduced to check the state regardless of whether or not the client had already withdrawn their funds.
77 lines
2.1 KiB
Nim
77 lines
2.1 KiB
Nim
import pkg/ethers
|
|
import pkg/chronicles
|
|
import ../purchasing
|
|
import ../sales
|
|
import ../proving
|
|
import ./deployment
|
|
import ./storage
|
|
import ./market
|
|
import ./proofs
|
|
import ./clock
|
|
|
|
export purchasing
|
|
export sales
|
|
export proving
|
|
export chronicles
|
|
|
|
type
|
|
ContractInteractions* = ref object
|
|
purchasing*: Purchasing
|
|
sales*: Sales
|
|
proving*: Proving
|
|
clock: OnChainClock
|
|
|
|
proc new*(_: type ContractInteractions,
|
|
signer: Signer,
|
|
deployment: Deployment): ?ContractInteractions =
|
|
|
|
without address =? deployment.address(Storage):
|
|
error "Unable to determine address of the Storage smart contract"
|
|
return none ContractInteractions
|
|
|
|
let contract = Storage.new(address, signer)
|
|
let market = OnChainMarket.new(contract)
|
|
let proofs = OnChainProofs.new(contract)
|
|
let clock = OnChainClock.new(signer.provider)
|
|
let proving = Proving.new(proofs, clock)
|
|
some ContractInteractions(
|
|
purchasing: Purchasing.new(market, clock),
|
|
sales: Sales.new(market, clock, proving),
|
|
proving: proving,
|
|
clock: clock
|
|
)
|
|
|
|
proc new*(_: type ContractInteractions,
|
|
providerUrl: string,
|
|
account: Address,
|
|
deploymentFile: string = string.default): ?ContractInteractions =
|
|
|
|
let provider = JsonRpcProvider.new(providerUrl)
|
|
let signer = provider.getSigner(account)
|
|
|
|
var deploy: Deployment
|
|
try:
|
|
if deploymentFile == string.default:
|
|
deploy = deployment()
|
|
else:
|
|
deploy = deployment(deploymentFile)
|
|
except IOError as e:
|
|
error "Unable to read deployment json", msg = e.msg
|
|
return none ContractInteractions
|
|
|
|
ContractInteractions.new(signer, deploy)
|
|
|
|
proc new*(_: type ContractInteractions,
|
|
account: Address): ?ContractInteractions =
|
|
ContractInteractions.new("ws://localhost:8545", account)
|
|
|
|
proc start*(interactions: ContractInteractions) {.async.} =
|
|
await interactions.clock.start()
|
|
await interactions.sales.start()
|
|
await interactions.proving.start()
|
|
|
|
proc stop*(interactions: ContractInteractions) {.async.} =
|
|
await interactions.sales.stop()
|
|
await interactions.proving.stop()
|
|
await interactions.clock.stop()
|