Skip to content

Commit

Permalink
Remove extra storage traits
Browse files Browse the repository at this point in the history
  • Loading branch information
OBorce committed Dec 10, 2024
1 parent fd89e56 commit f0dcbbc
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 39 deletions.
10 changes: 5 additions & 5 deletions wallet/src/account/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ use std::collections::{BTreeMap, BTreeSet};
use std::ops::{Add, Sub};
use std::sync::Arc;
use wallet_storage::{
StoreTxRw, WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteLocked,
WalletStorageWriteLocked, WalletStorageWriteUnlocked,
StoreTxRw, WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteLocked,
WalletStorageWriteUnlocked,
};
use wallet_types::utxo_types::{get_utxo_type, UtxoState, UtxoStates, UtxoType, UtxoTypes};
use wallet_types::wallet_tx::{BlockData, TxData, TxState};
Expand Down Expand Up @@ -1955,7 +1955,7 @@ impl<K: AccountKeyChains + Sync> Account<K> {
pub fn scan_new_inmempool_transactions(
&mut self,
transactions: &[SignedTransaction],
db_tx: &mut impl WalletStorageReadWriteLocked,
db_tx: &mut impl WalletStorageWriteLocked,
wallet_events: &impl WalletEvents,
) -> WalletResult<()> {
self.scan_new_unconfirmed_transactions(
Expand All @@ -1969,7 +1969,7 @@ impl<K: AccountKeyChains + Sync> Account<K> {
pub fn scan_new_inactive_transactions(
&mut self,
transactions: &[SignedTransaction],
db_tx: &mut impl WalletStorageReadWriteLocked,
db_tx: &mut impl WalletStorageWriteLocked,
wallet_events: &impl WalletEvents,
) -> WalletResult<()> {
self.scan_new_unconfirmed_transactions(
Expand All @@ -1984,7 +1984,7 @@ impl<K: AccountKeyChains + Sync> Account<K> {
&mut self,
transactions: &[SignedTransaction],
make_tx_state: fn(u64) -> TxState,
db_tx: &mut impl WalletStorageReadWriteLocked,
db_tx: &mut impl WalletStorageWriteLocked,
wallet_events: &impl WalletEvents,
) -> WalletResult<()> {
let account_id = self.get_account_id();
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/key_chain/master_key_chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crypto::vrf::ExtendedVRFPrivateKey;
use std::sync::Arc;
use wallet_storage::{
StoreTxRwUnlocked, WalletStorageReadLocked, WalletStorageReadUnlocked,
WalletStorageReadWriteUnlocked, WalletStorageWriteUnlocked,
WalletStorageWriteUnlocked,
};
use wallet_types::seed_phrase::{SerializableSeedPhrase, StoreSeedPhrase};

Expand Down Expand Up @@ -131,7 +131,7 @@ impl MasterKeyChain {

pub fn create_account_key_chain(
&self,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
account_index: U31,
lookahead_size: u32,
) -> KeyChainResult<AccountKeyChainImplSoftware> {
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crypto::key::{
SignatureError,
};
use wallet_storage::{
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteUnlocked,
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
};
use wallet_types::{
partially_signed_transaction::PartiallySignedTransaction, signature_status::SignatureStatus,
Expand Down Expand Up @@ -147,7 +147,7 @@ pub trait SignerProvider {
chain_config: Arc<ChainConfig>,
account_index: U31,
name: Option<String>,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
) -> WalletResult<Account<Self::K>>;

fn load_account_from_database(
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/signer/software_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use itertools::Itertools;
use randomness::make_true_rng;
use wallet_storage::{
StoreTxRwUnlocked, WalletStorageReadLocked, WalletStorageReadUnlocked,
WalletStorageReadWriteUnlocked,
WalletStorageWriteUnlocked,
};
use wallet_types::{
partially_signed_transaction::PartiallySignedTransaction, seed_phrase::StoreSeedPhrase,
Expand Down Expand Up @@ -463,7 +463,7 @@ impl SignerProvider for SoftwareSignerProvider {
chain_config: Arc<ChainConfig>,
next_account_index: U31,
name: Option<String>,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
) -> WalletResult<Account<AccountKeyChainImplSoftware>> {
let lookahead_size = db_tx.get_lookahead_size()?;
let account_key_chain = self.master_key_chain.create_account_key_chain(
Expand Down
4 changes: 2 additions & 2 deletions wallet/src/signer/trezor_signer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use trezor_client::{
};
use utils::ensure;
use wallet_storage::{
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteUnlocked,
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteUnlocked,
};
use wallet_types::{
account_info::DEFAULT_ACCOUNT_INDEX,
Expand Down Expand Up @@ -1151,7 +1151,7 @@ impl SignerProvider for TrezorSignerProvider {
chain_config: Arc<ChainConfig>,
account_index: U31,
name: Option<String>,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
) -> WalletResult<Account<Self::K>> {
let account_pubkey = self.fetch_extended_pub_key(&chain_config, account_index)?;

Expand Down
12 changes: 6 additions & 6 deletions wallet/src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ pub use wallet_storage::Error;
use wallet_storage::{
DefaultBackend, Store, StoreLocalReadWriteUnlocked, StoreTxRo, StoreTxRw, StoreTxRwUnlocked,
TransactionRoLocked, TransactionRwLocked, TransactionRwUnlocked, Transactional,
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageReadWriteLocked,
WalletStorageReadWriteUnlocked, WalletStorageWriteLocked, WalletStorageWriteUnlocked,
WalletStorageReadLocked, WalletStorageReadUnlocked, WalletStorageWriteLocked,
WalletStorageWriteUnlocked,
};
use wallet_types::account_info::{StandaloneAddressDetails, StandaloneAddresses};
use wallet_types::chain_info::ChainInfo;
Expand Down Expand Up @@ -672,7 +672,7 @@ where

fn reset_wallet_transactions(
chain_config: Arc<ChainConfig>,
db_tx: &mut impl WalletStorageReadWriteLocked,
db_tx: &mut impl WalletStorageWriteLocked,
) -> WalletResult<()> {
db_tx.clear_transactions()?;
db_tx.clear_addresses()?;
Expand Down Expand Up @@ -703,7 +703,7 @@ where

fn reset_wallet_transactions_and_load(
chain_config: Arc<ChainConfig>,
db_tx: &mut impl WalletStorageReadWriteLocked,
db_tx: &mut impl WalletStorageWriteLocked,
signer_provider: &P,
) -> WalletResult<BTreeMap<U31, Account<P::K>>> {
Self::reset_wallet_transactions(chain_config.clone(), db_tx)?;
Expand All @@ -725,7 +725,7 @@ where

fn migrate_next_unused_account(
chain_config: Arc<ChainConfig>,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
signer_provider: &mut P,
) -> Result<(), WalletError> {
let accounts_info = db_tx.get_accounts_info()?;
Expand Down Expand Up @@ -903,7 +903,7 @@ where
fn create_next_unused_account(
next_account_index: U31,
chain_config: Arc<ChainConfig>,
db_tx: &mut impl WalletStorageReadWriteUnlocked,
db_tx: &mut impl WalletStorageWriteUnlocked,
name: Option<String>,
signer_provider: &mut P,
) -> WalletResult<(U31, Account<P::K>)> {
Expand Down
5 changes: 0 additions & 5 deletions wallet/storage/src/internal/store_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,8 +1293,6 @@ impl<'st, B: storage::Backend> crate::TransactionRoUnlocked for StoreTxRoUnlocke
}
}

impl<'st, B: storage::Backend> crate::WalletStorageReadWriteLocked for StoreTxRw<'st, B> {}

impl<'st, B: storage::Backend> crate::TransactionRwLocked for StoreTxRw<'st, B> {
fn commit(self) -> crate::Result<()> {
self.storage.commit().map_err(Into::into)
Expand All @@ -1305,9 +1303,6 @@ impl<'st, B: storage::Backend> crate::TransactionRwLocked for StoreTxRw<'st, B>
}
}

impl<'st, B: storage::Backend> crate::WalletStorageReadWriteLocked for StoreTxRwUnlocked<'st, B> {}
impl<'st, B: storage::Backend> crate::WalletStorageReadWriteUnlocked for StoreTxRwUnlocked<'st, B> {}

impl<'st, B: storage::Backend> crate::TransactionRwUnlocked for StoreTxRwUnlocked<'st, B> {
fn commit(self) -> crate::Result<()> {
self.storage.commit().map_err(Into::into)
Expand Down
20 changes: 5 additions & 15 deletions wallet/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub trait WalletStorageEncryptionRead {
}

/// Modifying operations on persistent wallet data
pub trait WalletStorageWriteLocked {
pub trait WalletStorageWriteLocked: WalletStorageReadLocked {
/// Set storage version
fn set_storage_version(&mut self, version: u32) -> Result<()>;
fn set_wallet_type(&mut self, wallet_type: WalletType) -> Result<()>;
Expand Down Expand Up @@ -202,7 +202,7 @@ pub trait WalletStorageWriteLocked {
}

/// Modifying operations on persistent wallet data with access to encrypted data
pub trait WalletStorageWriteUnlocked: WalletStorageWriteLocked {
pub trait WalletStorageWriteUnlocked: WalletStorageWriteLocked + WalletStorageReadUnlocked {
fn set_root_key(&mut self, content: &RootKeys) -> Result<()>;
fn del_root_key(&mut self) -> Result<()>;
fn set_seed_phrase(&mut self, seed_phrase: SerializableSeedPhrase) -> Result<()>;
Expand All @@ -223,13 +223,6 @@ pub trait WalletStorageEncryptionWrite {
fn encrypt_seed_phrase(&mut self, new_encryption_key: &Option<SymmetricKey>) -> Result<()>;
}

pub trait WalletStorageReadWriteLocked: WalletStorageReadLocked + WalletStorageWriteLocked {}

pub trait WalletStorageReadWriteUnlocked:
WalletStorageReadUnlocked + WalletStorageWriteUnlocked + WalletStorageReadWriteLocked
{
}

/// Marker trait for types where read/write operations are run in a transaction
pub trait IsTransaction: is_transaction_seal::Seal {}

Expand All @@ -246,7 +239,7 @@ pub trait TransactionRoUnlocked: WalletStorageReadUnlocked + IsTransaction {
}

/// Operations on read-write transactions
pub trait TransactionRwLocked: WalletStorageReadWriteLocked + IsTransaction {
pub trait TransactionRwLocked: WalletStorageWriteLocked + IsTransaction {
/// Abort the transaction
fn abort(self);

Expand All @@ -255,7 +248,7 @@ pub trait TransactionRwLocked: WalletStorageReadWriteLocked + IsTransaction {
}

/// Operations on read-write transactions
pub trait TransactionRwUnlocked: WalletStorageReadWriteUnlocked + IsTransaction {
pub trait TransactionRwUnlocked: WalletStorageWriteUnlocked + IsTransaction {
/// Abort the transaction
fn abort(self);

Expand Down Expand Up @@ -293,10 +286,7 @@ pub trait Transactional<'t> {
) -> Result<Self::TransactionRwUnlocked>;
}

pub trait WalletStorage:
WalletStorageWriteLocked + WalletStorageReadLocked + for<'tx> Transactional<'tx> + Send
{
}
pub trait WalletStorage: WalletStorageWriteLocked + for<'tx> Transactional<'tx> + Send {}

pub type DefaultBackend = storage_sqlite::Sqlite;
pub type WalletStorageTxRwImpl<'st> = StoreTxRw<'st, storage_sqlite::Sqlite>;

0 comments on commit f0dcbbc

Please sign in to comment.