mirror of
https://github.com/codex-storage/nim-codex.git
synced 2025-01-26 12:48:58 +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.
57 lines
2.4 KiB
Nim
57 lines
2.4 KiB
Nim
import pkg/ethers
|
|
import pkg/json_rpc/rpcclient
|
|
import pkg/stint
|
|
import pkg/chronos
|
|
import ./requests
|
|
|
|
export stint
|
|
export ethers
|
|
|
|
type
|
|
Storage* = ref object of Contract
|
|
StorageRequested* = object of Event
|
|
requestId*: RequestId
|
|
ask*: StorageAsk
|
|
SlotFilled* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
slotIndex* {.indexed.}: UInt256
|
|
slotId* {.indexed.}: SlotId
|
|
RequestFulfilled* = object of Event
|
|
requestId* {.indexed.}: RequestId
|
|
RequestCancelled* = object of Event
|
|
requestId* {.indexed.}: Id
|
|
ProofSubmitted* = object of Event
|
|
id*: SlotId
|
|
proof*: seq[byte]
|
|
|
|
|
|
proc collateralAmount*(storage: Storage): UInt256 {.contract, view.}
|
|
proc slashMisses*(storage: Storage): UInt256 {.contract, view.}
|
|
proc slashPercentage*(storage: Storage): UInt256 {.contract, view.}
|
|
|
|
proc deposit*(storage: Storage, amount: UInt256) {.contract.}
|
|
proc withdraw*(storage: Storage) {.contract.}
|
|
proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
|
|
|
|
proc requestStorage*(storage: Storage, request: StorageRequest) {.contract.}
|
|
proc fillSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256, proof: seq[byte]) {.contract.}
|
|
proc withdrawFunds*(storage: Storage, requestId: Id) {.contract.}
|
|
proc payoutSlot*(storage: Storage, requestId: RequestId, slotIndex: UInt256) {.contract.}
|
|
proc getRequest*(storage: Storage, id: RequestId): StorageRequest {.contract, view.}
|
|
proc getHost*(storage: Storage, id: SlotId): Address {.contract, view.}
|
|
|
|
proc proofPeriod*(storage: Storage): UInt256 {.contract, view.}
|
|
proc proofTimeout*(storage: Storage): UInt256 {.contract, view.}
|
|
|
|
proc proofEnd*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
|
|
proc missingProofs*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
|
|
proc isCancelled*(storage: Storage, id: Id): bool {.contract, view.}
|
|
proc isSlotCancelled*(storage: Storage, id: Id): bool {.contract, view.}
|
|
proc isProofRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
|
|
proc willProofBeRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
|
|
proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.}
|
|
proc getPointer*(storage: Storage, id: SlotId): uint8 {.contract, view.}
|
|
|
|
proc submitProof*(storage: Storage, id: SlotId, proof: seq[byte]) {.contract.}
|
|
proc markProofAsMissing*(storage: Storage, id: SlotId, period: UInt256) {.contract.}
|