Dmitriy Ryajov 56b80d6f6d
Por serialize (#106)
* move por into storage proofs

* use SeekableStream

* adding serialization for por

* remove leftovers

* add empty block support

* add basic por test

* rename block exchange for consistency

* add storageproofstests

* moving timing to storageproofs

* fix imports

* fix imports

* fix imports

* add top level exports

* move delete blocks helper to helpers

* more import/export fixes

* cleanup

* more import fixes

* fix unused warnings

* detect corrupt blocks tests

* add serialization tests

* move init method around

* bump asynctest

* fix CID version

* get rid of warning

* wip: fix CI

* increase CI timeout
2022-05-23 23:24:15 -06:00

52 lines
1.9 KiB
Nim

import pkg/ethers
import ../storageproofs/timing/proofs
import ./storage
export proofs
type
OnChainProofs* = ref object of Proofs
storage: Storage
pollInterval*: Duration
ProofsSubscription = proofs.Subscription
EventSubscription = ethers.Subscription
OnChainProofsSubscription = ref object of ProofsSubscription
eventSubscription: EventSubscription
const DefaultPollInterval = 3.seconds
proc new*(_: type OnChainProofs, storage: Storage): OnChainProofs =
OnChainProofs(storage: storage, pollInterval: DefaultPollInterval)
method periodicity*(proofs: OnChainProofs): Future[Periodicity] {.async.} =
let period = await proofs.storage.proofPeriod()
return Periodicity(seconds: period)
method isProofRequired*(proofs: OnChainProofs,
id: ContractId): Future[bool] {.async.} =
return await proofs.storage.isProofRequired(id)
method willProofBeRequired*(proofs: OnChainProofs,
id: ContractId): Future[bool] {.async.} =
return await proofs.storage.willProofBeRequired(id)
method getProofEnd*(proofs: OnChainProofs,
id: ContractId): Future[UInt256] {.async.} =
return await proofs.storage.proofEnd(id)
method submitProof*(proofs: OnChainProofs,
id: ContractId,
proof: seq[byte]) {.async.} =
await proofs.storage.submitProof(id, proof)
method subscribeProofSubmission*(proofs: OnChainProofs,
callback: OnProofSubmitted):
Future[ProofsSubscription] {.async.} =
proc onEvent(event: ProofSubmitted) {.upraises: [].} =
callback(event.id, event.proof)
let subscription = await proofs.storage.subscribe(ProofSubmitted, onEvent)
return OnChainProofsSubscription(eventSubscription: subscription)
method unsubscribe*(subscription: OnChainProofsSubscription) {.async, upraises:[].} =
await subscription.eventSubscription.unsubscribe()