diff --git a/Cargo.lock b/Cargo.lock index 1b49b771..629ff1d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -588,7 +588,7 @@ checksum = "f2b8f3a258db515d5e91a904ce4ae3f73e091149b90cadbdb93d210bee07f63b" [[package]] name = "nonasync" version = "0.1.0" -source = "git+https://github.com/rust-amplify/amplify-nonasync#9c6ab8f0e19d80cc787633bad328e7817c256de4" +source = "git+https://github.com/rust-amplify/amplify-nonasync#d52db387df2282a73984d2d5ef238135d5267930" dependencies = [ "amplify 5.0.0-beta.1", ] diff --git a/src/persistence/index.rs b/src/persistence/index.rs index bc17a46d..5d0dfe38 100644 --- a/src/persistence/index.rs +++ b/src/persistence/index.rs @@ -24,7 +24,7 @@ use std::error::Error; use std::fmt::Debug; use amplify::confinement; -use nonasync::persistence::Persisting; +use nonasync::persistence::{CloneNoPersistence, Persisting}; use rgb::{ Assign, AssignmentType, BundleId, ContractId, ExposedState, Extension, Genesis, GenesisSeal, GraphSeal, OpId, Operation, Opout, TransitionBundle, TypedAssigns, XChain, XOutputSeal, @@ -124,11 +124,19 @@ pub enum IndexInconsistency { BundleWitnessUnknown(BundleId), } -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Index { provider: P, } +impl CloneNoPersistence for Index

{ + fn clone_no_persistence(&self) -> Self { + Self { + provider: self.provider.clone_no_persistence(), + } + } +} + impl Default for Index

where P: Default { @@ -350,7 +358,10 @@ impl StoreTransaction for Index

{ fn rollback_transaction(&mut self) { self.provider.rollback_transaction() } } -pub trait IndexProvider: Debug + Persisting + IndexReadProvider + IndexWriteProvider {} +pub trait IndexProvider: + Debug + CloneNoPersistence + Persisting + IndexReadProvider + IndexWriteProvider +{ +} pub trait IndexReadProvider { type Error: Clone + Eq + Error; diff --git a/src/persistence/memory.rs b/src/persistence/memory.rs index 96eb56c6..6630bb26 100644 --- a/src/persistence/memory.rs +++ b/src/persistence/memory.rs @@ -35,7 +35,7 @@ use amplify::confinement::{ use amplify::num::u24; use bp::dbc::tapret::TapretCommitment; use commit_verify::{CommitId, Conceal}; -use nonasync::persistence::{Persistence, PersistenceError, Persisting}; +use nonasync::persistence::{CloneNoPersistence, Persistence, PersistenceError, Persisting}; use rgb::validation::ResolveWitness; use rgb::vm::{ ContractStateAccess, ContractStateEvolve, GlobalContractState, GlobalOrd, GlobalStateIter, @@ -128,6 +128,27 @@ impl MemStash { } } +impl CloneNoPersistence for MemStash { + fn clone_no_persistence(&self) -> Self { + Self { + persistence: None, + schemata: self.schemata.clone(), + ifaces: self.ifaces.clone(), + geneses: self.geneses.clone(), + suppl: self.suppl.clone(), + bundles: self.bundles.clone(), + extensions: self.extensions.clone(), + witnesses: self.witnesses.clone(), + attachments: self.attachments.clone(), + secret_seals: self.secret_seals.clone(), + type_system: self.type_system.clone(), + identities: self.identities.clone(), + libs: self.libs.clone(), + sigs: self.sigs.clone(), + } + } +} + impl Persisting for MemStash { #[inline] fn persistence(&self) -> Option<&Persistence> { self.persistence.as_ref() } @@ -487,6 +508,16 @@ impl MemState { } } +impl CloneNoPersistence for MemState { + fn clone_no_persistence(&self) -> Self { + Self { + persistence: None, + witnesses: self.witnesses.clone(), + contracts: self.contracts.clone(), + } + } +} + impl Persisting for MemState { #[inline] fn persistence(&self) -> Option<&Persistence> { self.persistence.as_ref() } @@ -1191,6 +1222,19 @@ impl MemIndex { } } +impl CloneNoPersistence for MemIndex { + fn clone_no_persistence(&self) -> Self { + Self { + persistence: None, + op_bundle_index: self.op_bundle_index.clone(), + bundle_contract_index: self.bundle_contract_index.clone(), + bundle_witness_index: self.bundle_witness_index.clone(), + contract_index: self.contract_index.clone(), + terminal_index: self.terminal_index.clone(), + } + } +} + impl Persisting for MemIndex { #[inline] fn persistence(&self) -> Option<&Persistence> { self.persistence.as_ref() } diff --git a/src/persistence/stash.rs b/src/persistence/stash.rs index 535594d0..deda9605 100644 --- a/src/persistence/stash.rs +++ b/src/persistence/stash.rs @@ -29,7 +29,7 @@ use amplify::confinement::{Confined, MediumBlob, TinyOrdMap}; use bp::dbc::anchor::MergeError; use bp::dbc::tapret::TapretCommitment; use commit_verify::mpc; -use nonasync::persistence::Persisting; +use nonasync::persistence::{CloneNoPersistence, Persisting}; use rgb::validation::Scripts; use rgb::{ AttachId, BundleId, ContractId, Extension, Genesis, GraphSeal, Identity, OpId, Operation, @@ -186,11 +186,19 @@ impl SchemaIfaces { } } -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Stash { provider: P, } +impl CloneNoPersistence for Stash

{ + fn clone_no_persistence(&self) -> Self { + Self { + provider: self.provider.clone_no_persistence(), + } + } +} + impl Default for Stash

where P: Default { @@ -619,7 +627,10 @@ impl StoreTransaction for Stash

{ fn rollback_transaction(&mut self) { self.provider.rollback_transaction() } } -pub trait StashProvider: Debug + Persisting + StashReadProvider + StashWriteProvider {} +pub trait StashProvider: + Debug + CloneNoPersistence + Persisting + StashReadProvider + StashWriteProvider +{ +} pub trait StashReadProvider { /// Error type which must indicate problems on data retrieval. diff --git a/src/persistence/state.rs b/src/persistence/state.rs index 94a93fd2..866b5fea 100644 --- a/src/persistence/state.rs +++ b/src/persistence/state.rs @@ -26,7 +26,7 @@ use std::fmt::Debug; use std::iter; use invoice::Amount; -use nonasync::persistence::Persisting; +use nonasync::persistence::{CloneNoPersistence, Persisting}; use rgb::validation::{ResolveWitness, WitnessResolverError}; use rgb::vm::{ContractStateAccess, WitnessOrd}; use rgb::{ @@ -92,11 +92,19 @@ impl PersistedState { } } -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct State { provider: P, } +impl CloneNoPersistence for State

{ + fn clone_no_persistence(&self) -> Self { + Self { + provider: self.provider.clone_no_persistence(), + } + } +} + impl Default for State

where P: Default { @@ -255,7 +263,10 @@ impl StoreTransaction for State

{ fn rollback_transaction(&mut self) { self.provider.rollback_transaction() } } -pub trait StateProvider: Debug + Persisting + StateReadProvider + StateWriteProvider {} +pub trait StateProvider: + Debug + CloneNoPersistence + Persisting + StateReadProvider + StateWriteProvider +{ +} pub trait StateReadProvider { type ContractRead<'a>: ContractStateRead diff --git a/src/persistence/stock.rs b/src/persistence/stock.rs index 0951994b..10d1cbd1 100644 --- a/src/persistence/stock.rs +++ b/src/persistence/stock.rs @@ -32,7 +32,7 @@ use bp::seals::txout::CloseMethod; use bp::Vout; use chrono::Utc; use invoice::{Amount, Beneficiary, InvoiceState, NonFungible, RgbInvoice}; -use nonasync::persistence::{PersistenceError, PersistenceProvider}; +use nonasync::persistence::{CloneNoPersistence, PersistenceError, PersistenceProvider}; use rgb::validation::{DbcProof, EAnchor, ResolveWitness, WitnessResolverError}; use rgb::{ validation, AssignmentType, BlindingFactor, BundleId, ContractId, DataState, GraphSeal, @@ -343,7 +343,7 @@ stock_err_conv!(ContractIfaceError, InputError); pub type StockErrorMem = StockError; pub type StockErrorAll = StockError; -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Stock< S: StashProvider = MemStash, H: StateProvider = MemState, @@ -354,6 +354,16 @@ pub struct Stock< index: Index

, } +impl CloneNoPersistence for Stock { + fn clone_no_persistence(&self) -> Self { + Self { + stash: self.stash.clone_no_persistence(), + state: self.state.clone_no_persistence(), + index: self.index.clone_no_persistence(), + } + } +} + impl Default for Stock where S: Default,