diff --git a/src/miner.rs b/src/miner.rs index 92a63f7..7a6b0d3 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -1,3 +1,4 @@ +```rust use crate::comms_handler::Node; use crate::comms_handler::{CommsError, Event, TcpTlsConfig}; use crate::configurations::{ExtraNodeParams, MinerNodeConfig, TlsPrivateInfo}; @@ -1789,3 +1790,5 @@ fn log_received_blockchain_item(_key: &str, item: &BlockchainItem, _peer: &Socke SerializationErr(e) => warn!("Failed to deserialize blockchain item {:?}", e), } } + +``` \ No newline at end of file diff --git a/src/storage.rs b/src/storage.rs index 54d5513..ab948ee 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -1,3 +1,4 @@ +```rust use crate::comms_handler::{CommsError, Event, Node, TcpTlsConfig}; use crate::configurations::{ExtraNodeParams, StorageNodeConfig, TlsPrivateInfo}; use crate::constants::{ @@ -142,6 +143,7 @@ pub struct StorageNode { whitelisted: HashMap, shutdown_group: BTreeSet, blockchain_item_fetched: Option<(String, BlockchainItem, SocketAddr)>, + wallet_db: Arc>, // New WalletDb member } impl StorageNode { @@ -196,6 +198,12 @@ impl StorageNode { Arc::new(Mutex::new(raw_db)) }; + // Initialize the new WalletDb + let wallet_db = { + let raw_wallet_db = db_utils::new_wallet_db(config.storage_db_mode, extra.wallet_db.take(), None); + Arc::new(Mutex::new(raw_wallet_db)) + }; + let shutdown_group = { let mempool = std::iter::once(mempool_addr); let raft_peers = node_raft.raft_peer_addrs().copied(); @@ -207,6 +215,7 @@ impl StorageNode { node_raft, catchup_fetch, db, + wallet_db, // Assign wallet_db to the structure api_info: (api_addr, api_tls_info, api_keys, api_pow_info), local_events: Default::default(), mempool_addr, @@ -232,13 +241,14 @@ impl StorageNode { &self, ) -> ( Arc>, + Arc>, // Update to return WalletDb SocketAddr, Option, ApiKeys, RoutesPoWInfo, ) { let (api_addr, api_tls, api_keys, api_pow_info) = self.api_info.clone(); - (self.db.clone(), api_addr, api_tls, api_keys, api_pow_info) + (self.db.clone(), self.wallet_db.clone(), api_addr, api_tls, api_keys, api_pow_info) } ///Adds a uses data as the payload to create a frame, from the peer address, in the node object of this class. @@ -291,10 +301,12 @@ impl StorageNode { pub async fn take_closed_extra_params(&mut self) -> ExtraNodeParams { let raft_db = self.node_raft.take_closed_persistent_store().await; let mut self_db = self.db.lock().unwrap(); + let mut wallet_db = self.wallet_db.lock().unwrap(); // New wallet_db extraction ExtraNodeParams { db: self_db.take().in_memory(), raft_db: raft_db.in_memory(), + wallet_db: wallet_db.take().in_memory(), // Add wallet_db to extraced params ..Default::default() } } @@ -306,6 +318,10 @@ impl StorageNode { if let Err(e) = self_db.file_backup() { error!("Error bakup up main db: {:?}", e); } + let wallet_db = self.wallet_db.lock().unwrap(); // Backup wallet_db + if let Err(e) = wallet_db.file_backup() { + error!("Error backing up wallet db: {:?}", e); + } } } @@ -1307,3 +1323,4 @@ fn ok_or_warn(r: std::result::Result, E>, tag: &st None }) } +``` \ No newline at end of file