From 8297cfe4b75b6e057d5c24ac2ede2c06b2a845a8 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Thu, 13 Dec 2018 16:15:38 +0000 Subject: [PATCH 1/6] attempt to store tx log entries stored transactions in files --- src/bin/cmd/wallet_tests.rs | 4 +- wallet/src/display.rs | 2 +- wallet/src/libwallet/internal/selection.rs | 2 + wallet/src/libwallet/internal/tx.rs | 2 +- wallet/src/libwallet/types.rs | 2 +- wallet/src/lmdb_wallet.rs | 72 ++++++++++++++++++++-- 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/src/bin/cmd/wallet_tests.rs b/src/bin/cmd/wallet_tests.rs index 4ab313d045..cc3bc49f22 100644 --- a/src/bin/cmd/wallet_tests.rs +++ b/src/bin/cmd/wallet_tests.rs @@ -408,7 +408,7 @@ mod wallet_tests { Ok(()) })?; - // Try using the self-send method + // Try using the self-send method, splitting up outputs for the fun of it let arg_vec = vec![ "grin", "wallet", @@ -423,6 +423,8 @@ mod wallet_tests { "mining", "-g", "Self love", + "-o", + "75", "-s", "smallest", "10", diff --git a/wallet/src/display.rs b/wallet/src/display.rs index 86e1e331c6..f5e24dbae6 100644 --- a/wallet/src/display.rs +++ b/wallet/src/display.rs @@ -178,7 +178,7 @@ pub fn txs( ) }; let tx_data = match t.tx_hex { - Some(_) => format!("Exists"), + Some(t) => format!("{}", t), None => "None".to_owned(), }; if dark_background_color_scheme { diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index 2a747dc879..e204962f1d 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -113,6 +113,7 @@ where t.amount_debited = amount_debited; // write the output representing our change + error!("OUTTING LOADS OF OUTPUTS"); for (change_amount, id) in &change_amounts_derivations { t.num_outputs += 1; t.amount_credited += change_amount; @@ -128,6 +129,7 @@ where tx_log_entry: Some(log_id), })?; } + error!("SAVING TX LOG ENTRY: {}", t.tx_slate_id.as_ref().unwrap()); batch.save_tx_log_entry(t, &parent_key_id)?; batch.commit()?; Ok(()) diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index acbca76752..93c3631577 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -228,7 +228,7 @@ where None => return Err(ErrorKind::TransactionDoesntExist(slate.id.to_string()))?, }; tx.tx_hex = Some(tx_hex); - let batch = wallet.batch()?; + let mut batch = wallet.batch()?; batch.save_tx_log_entry(tx.clone(), &tx.parent_key_id)?; batch.commit()?; Ok(()) diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index 88978cde5f..2257b3f0cb 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -156,7 +156,7 @@ where fn tx_log_iter(&self) -> Box>; /// save a tx log entry - fn save_tx_log_entry(&self, t: TxLogEntry, parent_id: &Identifier) -> Result<(), Error>; + fn save_tx_log_entry(&mut self, t: TxLogEntry, parent_id: &Identifier) -> Result<(), Error>; /// save an account label -> path mapping fn save_acct_path(&mut self, mapping: AcctPathMapping) -> Result<(), Error>; diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 306136e2c4..3688f82ce8 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -16,6 +16,11 @@ use std::cell::RefCell; use std::sync::Arc; use std::{fs, path}; +// for writing storedtransaction files +use std::fs::File; +use std::io::{Read, Write}; +use std::path::Path; + use failure::ResultExt; use uuid::Uuid; @@ -28,6 +33,7 @@ use crate::types::{WalletConfig, WalletSeed}; use crate::util::secp::pedersen; pub const DB_DIR: &'static str = "db"; +pub const TX_SAVE_DIR: &'static str = "saved_txs"; const COMMITMENT_PREFIX: u8 = 'C' as u8; const OUTPUT_PREFIX: u8 = 'o' as u8; @@ -38,6 +44,8 @@ const TX_LOG_ENTRY_PREFIX: u8 = 't' as u8; const TX_LOG_ID_PREFIX: u8 = 'i' as u8; const ACCOUNT_PATH_MAPPING_PREFIX: u8 = 'a' as u8; +const DATA_PATH_KEY: &'static str = "root_data_path"; + impl From for Error { fn from(error: store::Error) -> Error { Error::from(ErrorKind::Backend(format!("{:?}", error))) @@ -69,10 +77,15 @@ impl LMDBBackend { let db_path = path::Path::new(&config.data_file_dir).join(DB_DIR); fs::create_dir_all(&db_path).expect("Couldn't create wallet backend directory!"); + let stored_tx_path = path::Path::new(&config.data_file_dir).join(TX_SAVE_DIR); + fs::create_dir_all(&stored_tx_path).expect("Couldn't create wallet backend tx storage directory!"); + let lmdb_env = Arc::new(store::new_env(db_path.to_str().unwrap().to_string())); let store = store::Store::open(lmdb_env, DB_DIR); // Make sure default wallet derivation path always exists + // as well as path (so it can be retrieved by batches to know where to store + // completed transactions, for reference let default_account = AcctPathMapping { label: "default".to_owned(), path: LMDBBackend::::default_path(), @@ -85,6 +98,7 @@ impl LMDBBackend { { let batch = store.batch()?; batch.put_ser(&acct_key, &default_account)?; + batch.put(&DATA_PATH_KEY.as_bytes(), stored_tx_path.to_str().unwrap().to_owned().into_bytes())?; batch.commit()?; } @@ -203,8 +217,34 @@ where fn get_tx_log_entry(&self, u: &Uuid) -> Result, Error> { let key = to_key(TX_LOG_ENTRY_PREFIX, &mut u.as_bytes().to_vec()); - self.db.get_ser(&key).map_err(|e| e.into()) - } + let entry: Result, Error> = self.db.get_ser(&key).map_err(|e| e.into()); + match entry { + Ok(tx_entry) => { + if let Some(mut tx) = tx_entry { + if let Some(t) = tx.tx_hex { + let path = match self.db.get(&DATA_PATH_KEY.as_bytes())? { + Some(p) => match String::from_utf8(p){ + Ok(u) => u, + Err(_) => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + }, + None => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + }; + error!("STORAGE PATH: {}", path); + let mut tx_file = Path::new(&path).to_path_buf(); + tx_file.push(t); + let mut tx_f = File::open(tx_file)?; + let mut content = String::new(); + tx_f.read_to_string(&mut content)?; + tx.tx_hex = Some(content); + } + Ok(Some(tx)) + } else { + Ok(tx_entry) + } + }, + Err(e) => Err(e), + } +} fn tx_log_iter<'a>(&'a self) -> Box + 'a> { Box::new(self.db.iter(&[TX_LOG_ENTRY_PREFIX]).unwrap()) @@ -403,17 +443,39 @@ where Ok(()) } - fn save_tx_log_entry(&self, t: TxLogEntry, parent_id: &Identifier) -> Result<(), Error> { + fn save_tx_log_entry(&mut self, mut tx_in: TxLogEntry, parent_id: &Identifier) -> Result<(), Error> { let tx_log_key = to_key_u64( TX_LOG_ENTRY_PREFIX, &mut parent_id.to_bytes().to_vec(), - t.id as u64, + tx_in.id as u64, ); + error!("TX LOG KEY: {:?}", tx_log_key); + // Fun Hack: Save tx log entries to files on the system instead of directly in the DB + if let Some(tx_hex) = tx_in.clone().tx_hex { + let path = match self.db.borrow().as_ref().unwrap().get(&DATA_PATH_KEY.as_bytes())? { + Some(p) => match String::from_utf8(p){ + Ok(u) => u, + Err(_) => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + }, + None => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + }; + error!("STORAGE PATH: {}", path); + let mut path_buf = Path::new(&path).to_path_buf(); + let tx_file_name = format!("{}.grintx", tx_in.tx_slate_id.unwrap()); + path_buf.push(tx_file_name.clone()); + let mut stored_tx = File::create(path_buf)?; + error!("STORING: {}", tx_hex); + stored_tx.write_all(&tx_hex.as_bytes())?; + stored_tx.sync_all()?; + tx_in.tx_hex = Some(tx_file_name); + } + error!("T: {:?}", tx_in); self.db .borrow() .as_ref() .unwrap() - .put_ser(&tx_log_key, &t)?; + .put_ser(&tx_log_key, &tx_in)?; + error!("TX_LOG OKAY"); Ok(()) } From a93a19656e7f062b475aa81ef2c471a813791160 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Thu, 13 Dec 2018 16:15:53 +0000 Subject: [PATCH 2/6] rustfmt --- wallet/src/lmdb_wallet.rs | 58 +++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 3688f82ce8..2f3a2da834 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -78,7 +78,8 @@ impl LMDBBackend { fs::create_dir_all(&db_path).expect("Couldn't create wallet backend directory!"); let stored_tx_path = path::Path::new(&config.data_file_dir).join(TX_SAVE_DIR); - fs::create_dir_all(&stored_tx_path).expect("Couldn't create wallet backend tx storage directory!"); + fs::create_dir_all(&stored_tx_path) + .expect("Couldn't create wallet backend tx storage directory!"); let lmdb_env = Arc::new(store::new_env(db_path.to_str().unwrap().to_string())); let store = store::Store::open(lmdb_env, DB_DIR); @@ -98,7 +99,10 @@ impl LMDBBackend { { let batch = store.batch()?; batch.put_ser(&acct_key, &default_account)?; - batch.put(&DATA_PATH_KEY.as_bytes(), stored_tx_path.to_str().unwrap().to_owned().into_bytes())?; + batch.put( + &DATA_PATH_KEY.as_bytes(), + stored_tx_path.to_str().unwrap().to_owned().into_bytes(), + )?; batch.commit()?; } @@ -223,11 +227,21 @@ where if let Some(mut tx) = tx_entry { if let Some(t) = tx.tx_hex { let path = match self.db.get(&DATA_PATH_KEY.as_bytes())? { - Some(p) => match String::from_utf8(p){ + Some(p) => match String::from_utf8(p) { Ok(u) => u, - Err(_) => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + Err(_) => { + return Err(ErrorKind::GenericError( + "Couldn't get tx storage path from db".to_owned(), + ) + .into()) + } }, - None => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + None => { + return Err(ErrorKind::GenericError( + "Couldn't get tx storage path from db".to_owned(), + ) + .into()) + } }; error!("STORAGE PATH: {}", path); let mut tx_file = Path::new(&path).to_path_buf(); @@ -241,10 +255,10 @@ where } else { Ok(tx_entry) } - }, + } Err(e) => Err(e), } -} + } fn tx_log_iter<'a>(&'a self) -> Box + 'a> { Box::new(self.db.iter(&[TX_LOG_ENTRY_PREFIX]).unwrap()) @@ -443,7 +457,11 @@ where Ok(()) } - fn save_tx_log_entry(&mut self, mut tx_in: TxLogEntry, parent_id: &Identifier) -> Result<(), Error> { + fn save_tx_log_entry( + &mut self, + mut tx_in: TxLogEntry, + parent_id: &Identifier, + ) -> Result<(), Error> { let tx_log_key = to_key_u64( TX_LOG_ENTRY_PREFIX, &mut parent_id.to_bytes().to_vec(), @@ -452,12 +470,28 @@ where error!("TX LOG KEY: {:?}", tx_log_key); // Fun Hack: Save tx log entries to files on the system instead of directly in the DB if let Some(tx_hex) = tx_in.clone().tx_hex { - let path = match self.db.borrow().as_ref().unwrap().get(&DATA_PATH_KEY.as_bytes())? { - Some(p) => match String::from_utf8(p){ + let path = match self + .db + .borrow() + .as_ref() + .unwrap() + .get(&DATA_PATH_KEY.as_bytes())? + { + Some(p) => match String::from_utf8(p) { Ok(u) => u, - Err(_) => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + Err(_) => { + return Err(ErrorKind::GenericError( + "Couldn't get tx storage path from db".to_owned(), + ) + .into()) + } }, - None => return Err(ErrorKind::GenericError("Couldn't get tx storage path from db".to_owned()).into()), + None => { + return Err(ErrorKind::GenericError( + "Couldn't get tx storage path from db".to_owned(), + ) + .into()) + } }; error!("STORAGE PATH: {}", path); let mut path_buf = Path::new(&path).to_path_buf(); From ac9a0e743007041ed1800a46b1fa5396450c0719 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Fri, 14 Dec 2018 09:48:59 +0000 Subject: [PATCH 3/6] complete storage of transactions as files instead of in DB --- wallet/src/command.rs | 2 +- wallet/src/controller.rs | 5 +- wallet/src/libwallet/api.rs | 6 ++ wallet/src/libwallet/internal/restore.rs | 2 +- wallet/src/libwallet/internal/selection.rs | 6 +- wallet/src/libwallet/internal/tx.rs | 4 +- wallet/src/libwallet/internal/updater.rs | 6 +- wallet/src/libwallet/types.rs | 17 ++---- wallet/src/lmdb_wallet.rs | 65 ++++++++-------------- wallet/tests/repost.rs | 6 +- wallet/tests/transaction.rs | 3 +- 11 files changed, 51 insertions(+), 71 deletions(-) diff --git a/wallet/src/command.rs b/wallet/src/command.rs index d1e1529e48..35d9b9fc3f 100644 --- a/wallet/src/command.rs +++ b/wallet/src/command.rs @@ -409,7 +409,7 @@ pub fn repost( ) -> Result<(), Error> { controller::owner_single_use(wallet.clone(), |api| { let (_, txs) = api.retrieve_txs(true, Some(args.id), None)?; - let stored_tx = txs[0].get_stored_tx(); + let stored_tx = api.get_stored_tx(&txs[0])?; if stored_tx.is_none() { error!( "Transaction with id {} does not have transaction data. Not reposting.", diff --git a/wallet/src/controller.rs b/wallet/src/controller.rs index ed91f6e914..be7027c321 100644 --- a/wallet/src/controller.rs +++ b/wallet/src/controller.rs @@ -231,7 +231,10 @@ where if let Some(id_string) = params.get("id") { match id_string[0].parse() { Ok(id) => match api.retrieve_txs(true, Some(id), None) { - Ok((_, txs)) => Ok((txs[0].confirmed, txs[0].get_stored_tx())), + Ok((_, txs)) => { + let stored_tx = api.get_stored_tx(&txs[0])?; + Ok((txs[0].confirmed, stored_tx)) + }, Err(e) => { error!("retrieve_stored_tx: failed with error: {}", e); Err(e) diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index 3447d41d46..4e31730fd6 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -706,6 +706,12 @@ where Ok(()) } + /// Retrieves a stored transaction from a TxLogEntry + pub fn get_stored_tx(&self, entry: &TxLogEntry) -> Result, Error> { + let w = self.wallet.lock(); + w.get_stored_tx(entry) + } + /// Posts a transaction to the chain pub fn post_tx(&self, tx: &Transaction, fluff: bool) -> Result<(), Error> { let tx_hex = util::to_hex(ser::ser_vec(tx).unwrap()); diff --git a/wallet/src/libwallet/internal/restore.rs b/wallet/src/libwallet/internal/restore.rs index 2b178fef25..28757b927a 100644 --- a/wallet/src/libwallet/internal/restore.rs +++ b/wallet/src/libwallet/internal/restore.rs @@ -162,7 +162,7 @@ where t.amount_credited = output.value; t.num_outputs = 1; t.update_confirmation_ts(); - batch.save_tx_log_entry(t, &parent_key_id)?; + batch.save_tx_log_entry(t, &parent_key_id, None)?; let _ = batch.save(OutputData { root_key_id: parent_key_id.clone(), diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index e204962f1d..d971d0635f 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -113,7 +113,6 @@ where t.amount_debited = amount_debited; // write the output representing our change - error!("OUTTING LOADS OF OUTPUTS"); for (change_amount, id) in &change_amounts_derivations { t.num_outputs += 1; t.amount_credited += change_amount; @@ -129,8 +128,7 @@ where tx_log_entry: Some(log_id), })?; } - error!("SAVING TX LOG ENTRY: {}", t.tx_slate_id.as_ref().unwrap()); - batch.save_tx_log_entry(t, &parent_key_id)?; + batch.save_tx_log_entry(t, &parent_key_id, Some(tx_hex.to_owned()))?; batch.commit()?; Ok(()) }; @@ -201,7 +199,7 @@ where is_coinbase: false, tx_log_entry: Some(log_id), })?; - batch.save_tx_log_entry(t, &parent_key_id)?; + batch.save_tx_log_entry(t, &parent_key_id, None)?; batch.commit()?; Ok(()) }; diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index 93c3631577..d1063ec2f1 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -227,9 +227,9 @@ where Some(t) => t, None => return Err(ErrorKind::TransactionDoesntExist(slate.id.to_string()))?, }; - tx.tx_hex = Some(tx_hex); + tx.tx_hex = Some(tx_hex.clone()); let mut batch = wallet.batch()?; - batch.save_tx_log_entry(tx.clone(), &tx.parent_key_id)?; + batch.save_tx_log_entry(tx.clone(), &tx.parent_key_id, Some(tx_hex.to_owned()))?; batch.commit()?; Ok(()) } diff --git a/wallet/src/libwallet/internal/updater.rs b/wallet/src/libwallet/internal/updater.rs index 6c425e152e..ff395b4b35 100644 --- a/wallet/src/libwallet/internal/updater.rs +++ b/wallet/src/libwallet/internal/updater.rs @@ -191,7 +191,7 @@ where if tx.tx_type == TxLogEntryType::TxReceived { tx.tx_type = TxLogEntryType::TxReceivedCancelled; } - batch.save_tx_log_entry(tx, parent_key_id)?; + batch.save_tx_log_entry(tx, parent_key_id, None)?; batch.commit()?; Ok(()) } @@ -243,7 +243,7 @@ where t.num_outputs = 1; t.update_confirmation_ts(); output.tx_log_entry = Some(log_id); - batch.save_tx_log_entry(t, &parent_key_id)?; + batch.save_tx_log_entry(t, &parent_key_id, None)?; } // also mark the transaction in which this output is involved as confirmed // note that one involved input/output confirmation SHOULD be enough @@ -256,7 +256,7 @@ where if let Some(mut t) = tx { t.update_confirmation_ts(); t.confirmed = true; - batch.save_tx_log_entry(t, &parent_key_id)?; + batch.save_tx_log_entry(t, &parent_key_id, None)?; } } output.height = o.1; diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index 2257b3f0cb..e51ea111e5 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -21,7 +21,6 @@ use crate::core::libtx::aggsig; use crate::core::ser; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::error::{Error, ErrorKind}; -use crate::util; use crate::util::secp::key::{PublicKey, SecretKey}; use crate::util::secp::{self, pedersen, Secp256k1}; use chrono::prelude::*; @@ -102,6 +101,9 @@ where /// Gets an account path for a given label fn get_acct_path(&self, label: String) -> Result, Error>; + /// Retrieves a stored transaction from a TxLogEntry + fn get_stored_tx(&self, entry: &TxLogEntry) -> Result, Error>; + /// Create a new write batch to update or remove output data fn batch<'a>(&'a mut self) -> Result + 'a>, Error>; @@ -156,7 +158,7 @@ where fn tx_log_iter(&self) -> Box>; /// save a tx log entry - fn save_tx_log_entry(&mut self, t: TxLogEntry, parent_id: &Identifier) -> Result<(), Error>; + fn save_tx_log_entry(&mut self, t: TxLogEntry, parent_id: &Identifier, tx_hex_in: Option) -> Result<(), Error>; /// save an account label -> path mapping fn save_acct_path(&mut self, mapping: AcctPathMapping) -> Result<(), Error>; @@ -636,17 +638,6 @@ impl TxLogEntry { pub fn update_confirmation_ts(&mut self) { self.confirmation_ts = Some(Utc::now()); } - - /// Retrieve the stored transaction, if any - pub fn get_stored_tx(&self) -> Option { - match self.tx_hex.as_ref() { - None => None, - Some(t) => { - let tx_bin = util::from_hex(t.clone()).unwrap(); - Some(ser::deserialize::(&mut &tx_bin[..]).unwrap()) - } - } - } } /// Map of named accounts to BIP32 paths diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 2f3a2da834..99765dd6aa 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -27,9 +27,12 @@ use uuid::Uuid; use crate::keychain::{ChildNumber, ExtKeychain, Identifier, Keychain}; use crate::store::{self, option_to_not_found, to_key, to_key_u64}; +use crate::core::core::Transaction; +use crate::core::ser; use crate::libwallet::types::*; use crate::libwallet::{internal, Error, ErrorKind}; use crate::types::{WalletConfig, WalletSeed}; +use crate::util; use crate::util::secp::pedersen; pub const DB_DIR: &'static str = "db"; @@ -221,43 +224,7 @@ where fn get_tx_log_entry(&self, u: &Uuid) -> Result, Error> { let key = to_key(TX_LOG_ENTRY_PREFIX, &mut u.as_bytes().to_vec()); - let entry: Result, Error> = self.db.get_ser(&key).map_err(|e| e.into()); - match entry { - Ok(tx_entry) => { - if let Some(mut tx) = tx_entry { - if let Some(t) = tx.tx_hex { - let path = match self.db.get(&DATA_PATH_KEY.as_bytes())? { - Some(p) => match String::from_utf8(p) { - Ok(u) => u, - Err(_) => { - return Err(ErrorKind::GenericError( - "Couldn't get tx storage path from db".to_owned(), - ) - .into()) - } - }, - None => { - return Err(ErrorKind::GenericError( - "Couldn't get tx storage path from db".to_owned(), - ) - .into()) - } - }; - error!("STORAGE PATH: {}", path); - let mut tx_file = Path::new(&path).to_path_buf(); - tx_file.push(t); - let mut tx_f = File::open(tx_file)?; - let mut content = String::new(); - tx_f.read_to_string(&mut content)?; - tx.tx_hex = Some(content); - } - Ok(Some(tx)) - } else { - Ok(tx_entry) - } - } - Err(e) => Err(e), - } + self.db.get_ser(&key).map_err(|e| e.into()) } fn tx_log_iter<'a>(&'a self) -> Box + 'a> { @@ -282,6 +249,22 @@ where self.db.get_ser(&acct_key).map_err(|e| e.into()) } + fn get_stored_tx(&self, entry: &TxLogEntry) -> Result, Error> { + let filename = match entry.tx_hex.clone() { + Some(f) => f, + None => return Ok(None), + }; + let path = path::Path::new(&self.config.data_file_dir) + .join(TX_SAVE_DIR) + .join(filename); + let tx_file = Path::new(&path).to_path_buf(); + let mut tx_f = File::open(tx_file)?; + let mut content = String::new(); + tx_f.read_to_string(&mut content)?; + let tx_bin = util::from_hex(content).unwrap(); + Ok(Some(ser::deserialize::(&mut &tx_bin[..]).unwrap())) + } + fn batch<'a>(&'a mut self) -> Result + 'a>, Error> { Ok(Box::new(Batch { _store: self, @@ -461,15 +444,15 @@ where &mut self, mut tx_in: TxLogEntry, parent_id: &Identifier, + tx_hex_in: Option, ) -> Result<(), Error> { let tx_log_key = to_key_u64( TX_LOG_ENTRY_PREFIX, &mut parent_id.to_bytes().to_vec(), tx_in.id as u64, ); - error!("TX LOG KEY: {:?}", tx_log_key); // Fun Hack: Save tx log entries to files on the system instead of directly in the DB - if let Some(tx_hex) = tx_in.clone().tx_hex { + if let Some(tx_hex) = tx_hex_in { let path = match self .db .borrow() @@ -493,23 +476,19 @@ where .into()) } }; - error!("STORAGE PATH: {}", path); let mut path_buf = Path::new(&path).to_path_buf(); let tx_file_name = format!("{}.grintx", tx_in.tx_slate_id.unwrap()); path_buf.push(tx_file_name.clone()); let mut stored_tx = File::create(path_buf)?; - error!("STORING: {}", tx_hex); stored_tx.write_all(&tx_hex.as_bytes())?; stored_tx.sync_all()?; tx_in.tx_hex = Some(tx_file_name); } - error!("T: {:?}", tx_in); self.db .borrow() .as_ref() .unwrap() .put_ser(&tx_log_key, &tx_in)?; - error!("TX_LOG OKAY"); Ok(()) } diff --git a/wallet/tests/repost.rs b/wallet/tests/repost.rs index 69f0820f7e..c2cc8ad818 100644 --- a/wallet/tests/repost.rs +++ b/wallet/tests/repost.rs @@ -148,7 +148,8 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> { // Now repost from cached wallet::controller::owner_single_use(wallet1.clone(), |api| { let (_, txs) = api.retrieve_txs(true, None, Some(slate.id))?; - api.post_tx(&txs[0].get_stored_tx().unwrap(), false)?; + let stored_tx = api.get_stored_tx(&txs[0])?; + api.post_tx(&stored_tx.unwrap(), false)?; bh += 1; Ok(()) })?; @@ -214,7 +215,8 @@ fn file_repost_test_impl(test_dir: &str) -> Result<(), libwallet::Error> { // Now repost from cached wallet::controller::owner_single_use(wallet1.clone(), |api| { let (_, txs) = api.retrieve_txs(true, None, Some(slate.id))?; - api.post_tx(&txs[0].get_stored_tx().unwrap(), false)?; + let stored_tx = api.get_stored_tx(&txs[0])?; + api.post_tx(&stored_tx.unwrap(), false)?; bh += 1; Ok(()) })?; diff --git a/wallet/tests/transaction.rs b/wallet/tests/transaction.rs index 8e725d4f42..9ad880ad56 100644 --- a/wallet/tests/transaction.rs +++ b/wallet/tests/transaction.rs @@ -252,7 +252,8 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> { .iter() .find(|t| t.tx_slate_id == Some(slate.id)) .unwrap(); - sender_api.post_tx(&tx.get_stored_tx().unwrap(), false)?; + let stored_tx = sender_api.get_stored_tx(&tx)?; + sender_api.post_tx(&stored_tx.unwrap(), false)?; let (_, wallet1_info) = sender_api.retrieve_summary_info(true, 1)?; // should be mined now assert_eq!( From 0d08e0a3b79c5d08f09a143befb59bbab05834b9 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Fri, 14 Dec 2018 09:49:08 +0000 Subject: [PATCH 4/6] rustfmt --- wallet/src/controller.rs | 2 +- wallet/src/libwallet/types.rs | 7 ++++++- wallet/src/lmdb_wallet.rs | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wallet/src/controller.rs b/wallet/src/controller.rs index be7027c321..b19014a499 100644 --- a/wallet/src/controller.rs +++ b/wallet/src/controller.rs @@ -234,7 +234,7 @@ where Ok((_, txs)) => { let stored_tx = api.get_stored_tx(&txs[0])?; Ok((txs[0].confirmed, stored_tx)) - }, + } Err(e) => { error!("retrieve_stored_tx: failed with error: {}", e); Err(e) diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index e51ea111e5..fcede9c0a5 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -158,7 +158,12 @@ where fn tx_log_iter(&self) -> Box>; /// save a tx log entry - fn save_tx_log_entry(&mut self, t: TxLogEntry, parent_id: &Identifier, tx_hex_in: Option) -> Result<(), Error>; + fn save_tx_log_entry( + &mut self, + t: TxLogEntry, + parent_id: &Identifier, + tx_hex_in: Option, + ) -> Result<(), Error>; /// save an account label -> path mapping fn save_acct_path(&mut self, mapping: AcctPathMapping) -> Result<(), Error>; diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 99765dd6aa..10a8b5dafe 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -262,7 +262,9 @@ where let mut content = String::new(); tx_f.read_to_string(&mut content)?; let tx_bin = util::from_hex(content).unwrap(); - Ok(Some(ser::deserialize::(&mut &tx_bin[..]).unwrap())) + Ok(Some( + ser::deserialize::(&mut &tx_bin[..]).unwrap(), + )) } fn batch<'a>(&'a mut self) -> Result + 'a>, Error> { From 510cbfd3b9d7396aa52349746c8dbed96dd9a83a Mon Sep 17 00:00:00 2001 From: yeastplume Date: Fri, 14 Dec 2018 10:44:28 +0000 Subject: [PATCH 5/6] complete testing --- wallet/src/libwallet/api.rs | 10 ++- wallet/src/libwallet/internal/restore.rs | 2 +- wallet/src/libwallet/internal/selection.rs | 80 ++++++++++++---------- wallet/src/libwallet/internal/tx.rs | 19 ++--- wallet/src/libwallet/internal/updater.rs | 6 +- wallet/src/libwallet/types.rs | 5 +- wallet/src/lmdb_wallet.rs | 62 +++++------------ 7 files changed, 79 insertions(+), 105 deletions(-) diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index 4e31730fd6..41a9e371f4 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -612,7 +612,7 @@ where num_change_outputs: usize, selection_strategy_is_use_all: bool, message: Option, - ) -> Result<(Slate, impl FnOnce(&mut W, &str) -> Result<(), Error>), Error> { + ) -> Result<(Slate, impl FnOnce(&mut W, &Transaction) -> Result<(), Error>), Error> { let mut w = self.wallet.lock(); w.open_with_credentials()?; let parent_key_id = match src_acct_name { @@ -653,12 +653,11 @@ where pub fn tx_lock_outputs( &mut self, slate: &Slate, - lock_fn: impl FnOnce(&mut W, &str) -> Result<(), Error>, + lock_fn: impl FnOnce(&mut W, &Transaction) -> Result<(), Error>, ) -> Result<(), Error> { let mut w = self.wallet.lock(); w.open_with_credentials()?; - let tx_hex = util::to_hex(ser::ser_vec(&slate.tx).unwrap()); - lock_fn(&mut *w, &tx_hex)?; + lock_fn(&mut *w, &slate.tx)?; Ok(()) } @@ -668,11 +667,10 @@ where /// propagation. pub fn finalize_tx(&mut self, slate: &mut Slate) -> Result<(), Error> { let mut w = self.wallet.lock(); - let parent_key_id = w.parent_key_id(); w.open_with_credentials()?; let context = w.get_private_context(slate.id.as_bytes())?; tx::complete_tx(&mut *w, slate, &context)?; - tx::update_tx_hex(&mut *w, &parent_key_id, slate)?; + tx::update_stored_tx(&mut *w, slate)?; { let mut batch = w.batch()?; batch.delete_private_context(slate.id.as_bytes())?; diff --git a/wallet/src/libwallet/internal/restore.rs b/wallet/src/libwallet/internal/restore.rs index 28757b927a..2b178fef25 100644 --- a/wallet/src/libwallet/internal/restore.rs +++ b/wallet/src/libwallet/internal/restore.rs @@ -162,7 +162,7 @@ where t.amount_credited = output.value; t.num_outputs = 1; t.update_confirmation_ts(); - batch.save_tx_log_entry(t, &parent_key_id, None)?; + batch.save_tx_log_entry(t, &parent_key_id)?; let _ = batch.save(OutputData { root_key_id: parent_key_id.clone(), diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index d971d0635f..e8193a0d28 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -15,6 +15,7 @@ //! Selection of inputs for building transactions use crate::core::libtx::{build, slate::Slate, tx_fee}; +use crate::core::core::Transaction; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::error::{Error, ErrorKind}; use crate::libwallet::internal::keys; @@ -40,7 +41,7 @@ pub fn build_send_tx_slate( ( Slate, Context, - impl FnOnce(&mut T, &str) -> Result<(), Error>, + impl FnOnce(&mut T, &Transaction) -> Result<(), Error>, ), Error, > @@ -94,42 +95,47 @@ where // Return a closure to acquire wallet lock and lock the coins being spent // so we avoid accidental double spend attempt. - let update_sender_wallet_fn = move |wallet: &mut T, tx_hex: &str| { - let mut batch = wallet.batch()?; - let log_id = batch.next_tx_log_id(&parent_key_id)?; - let mut t = TxLogEntry::new(parent_key_id.clone(), TxLogEntryType::TxSent, log_id); - t.tx_slate_id = Some(slate_id); - t.fee = Some(fee); - t.tx_hex = Some(tx_hex.to_owned()); - let mut amount_debited = 0; - t.num_inputs = lock_inputs.len(); - for id in lock_inputs { - let mut coin = batch.get(&id).unwrap(); - coin.tx_log_entry = Some(log_id); - amount_debited = amount_debited + coin.value; - batch.lock_output(&mut coin)?; - } + let update_sender_wallet_fn = move |wallet: &mut T, tx: &Transaction| { + let tx_entry = { + let mut batch = wallet.batch()?; + let log_id = batch.next_tx_log_id(&parent_key_id)?; + let mut t = TxLogEntry::new(parent_key_id.clone(), TxLogEntryType::TxSent, log_id); + t.tx_slate_id = Some(slate_id); + let filename = format!("{}.grintx", slate_id); + t.tx_hex = Some(filename); + t.fee = Some(fee); + let mut amount_debited = 0; + t.num_inputs = lock_inputs.len(); + for id in lock_inputs { + let mut coin = batch.get(&id).unwrap(); + coin.tx_log_entry = Some(log_id); + amount_debited = amount_debited + coin.value; + batch.lock_output(&mut coin)?; + } - t.amount_debited = amount_debited; - - // write the output representing our change - for (change_amount, id) in &change_amounts_derivations { - t.num_outputs += 1; - t.amount_credited += change_amount; - batch.save(OutputData { - root_key_id: parent_key_id.clone(), - key_id: id.clone(), - n_child: id.to_path().last_path_index(), - value: change_amount.clone(), - status: OutputStatus::Unconfirmed, - height: current_height, - lock_height: 0, - is_coinbase: false, - tx_log_entry: Some(log_id), - })?; - } - batch.save_tx_log_entry(t, &parent_key_id, Some(tx_hex.to_owned()))?; - batch.commit()?; + t.amount_debited = amount_debited; + + // write the output representing our change + for (change_amount, id) in &change_amounts_derivations { + t.num_outputs += 1; + t.amount_credited += change_amount; + batch.save(OutputData { + root_key_id: parent_key_id.clone(), + key_id: id.clone(), + n_child: id.to_path().last_path_index(), + value: change_amount.clone(), + status: OutputStatus::Unconfirmed, + height: current_height, + lock_height: 0, + is_coinbase: false, + tx_log_entry: Some(log_id), + })?; + } + batch.save_tx_log_entry(t.clone(), &parent_key_id)?; + batch.commit()?; + t + }; + wallet.store_tx(&format!("{}", tx_entry.tx_slate_id.unwrap()), tx)?; Ok(()) }; @@ -199,7 +205,7 @@ where is_coinbase: false, tx_log_entry: Some(log_id), })?; - batch.save_tx_log_entry(t, &parent_key_id, None)?; + batch.save_tx_log_entry(t, &parent_key_id)?; batch.commit()?; Ok(()) }; diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index d1063ec2f1..565f923cf7 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -14,11 +14,10 @@ //! Transaction building functions -use crate::util; use uuid::Uuid; use crate::core::libtx::slate::Slate; -use crate::core::ser; +use crate::core::core::Transaction; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::internal::{selection, updater}; use crate::libwallet::types::{Context, NodeClient, TxLogEntryType, WalletBackend}; @@ -74,7 +73,7 @@ pub fn create_send_tx( ( Slate, Context, - impl FnOnce(&mut T, &str) -> Result<(), Error>, + impl FnOnce(&mut T, &Transaction) -> Result<(), Error>, ), Error, > @@ -200,10 +199,9 @@ where Ok((tx.confirmed, tx.tx_hex)) } -/// Update the stored hex transaction (this update needs to happen when the TX is finalised) -pub fn update_tx_hex( +/// Update the stored transaction (this update needs to happen when the TX is finalised) +pub fn update_stored_tx( wallet: &mut T, - _parent_key_id: &Identifier, slate: &Slate, ) -> Result<(), Error> where @@ -211,8 +209,6 @@ where C: NodeClient, K: Keychain, { - let tx_hex = util::to_hex(ser::ser_vec(&slate.tx).unwrap()); - // This will ignore the parent key, so no need to specify account on the // finalize command let tx_vec = updater::retrieve_txs(wallet, None, Some(slate.id), None)?; let mut tx = None; @@ -223,14 +219,11 @@ where break; } } - let mut tx = match tx { + let tx = match tx { Some(t) => t, None => return Err(ErrorKind::TransactionDoesntExist(slate.id.to_string()))?, }; - tx.tx_hex = Some(tx_hex.clone()); - let mut batch = wallet.batch()?; - batch.save_tx_log_entry(tx.clone(), &tx.parent_key_id, Some(tx_hex.to_owned()))?; - batch.commit()?; + wallet.store_tx(&format!("{}", tx.tx_slate_id.unwrap()), &slate.tx)?; Ok(()) } diff --git a/wallet/src/libwallet/internal/updater.rs b/wallet/src/libwallet/internal/updater.rs index ff395b4b35..6c425e152e 100644 --- a/wallet/src/libwallet/internal/updater.rs +++ b/wallet/src/libwallet/internal/updater.rs @@ -191,7 +191,7 @@ where if tx.tx_type == TxLogEntryType::TxReceived { tx.tx_type = TxLogEntryType::TxReceivedCancelled; } - batch.save_tx_log_entry(tx, parent_key_id, None)?; + batch.save_tx_log_entry(tx, parent_key_id)?; batch.commit()?; Ok(()) } @@ -243,7 +243,7 @@ where t.num_outputs = 1; t.update_confirmation_ts(); output.tx_log_entry = Some(log_id); - batch.save_tx_log_entry(t, &parent_key_id, None)?; + batch.save_tx_log_entry(t, &parent_key_id)?; } // also mark the transaction in which this output is involved as confirmed // note that one involved input/output confirmation SHOULD be enough @@ -256,7 +256,7 @@ where if let Some(mut t) = tx { t.update_confirmation_ts(); t.confirmed = true; - batch.save_tx_log_entry(t, &parent_key_id, None)?; + batch.save_tx_log_entry(t, &parent_key_id)?; } } output.height = o.1; diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index fcede9c0a5..13866e33be 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -101,6 +101,9 @@ where /// Gets an account path for a given label fn get_acct_path(&self, label: String) -> Result, Error>; + /// Stores a transaction + fn store_tx(&self, uuid: &str, tx: &Transaction) -> Result<(), Error>; + /// Retrieves a stored transaction from a TxLogEntry fn get_stored_tx(&self, entry: &TxLogEntry) -> Result, Error>; @@ -162,7 +165,6 @@ where &mut self, t: TxLogEntry, parent_id: &Identifier, - tx_hex_in: Option, ) -> Result<(), Error>; /// save an account label -> path mapping @@ -602,6 +604,7 @@ pub struct TxLogEntry { pub amount_debited: u64, /// Fee pub fee: Option, + // TODO: rename this to 'stored_tx_file' or something for mainnet /// The transaction json itself, stored for reference or resending pub tx_hex: Option, } diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 10a8b5dafe..7cf040f11c 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -21,6 +21,8 @@ use std::fs::File; use std::io::{Read, Write}; use std::path::Path; +use serde_json; + use failure::ResultExt; use uuid::Uuid; @@ -32,8 +34,8 @@ use crate::core::ser; use crate::libwallet::types::*; use crate::libwallet::{internal, Error, ErrorKind}; use crate::types::{WalletConfig, WalletSeed}; -use crate::util; use crate::util::secp::pedersen; +use crate::util; pub const DB_DIR: &'static str = "db"; pub const TX_SAVE_DIR: &'static str = "saved_txs"; @@ -47,8 +49,6 @@ const TX_LOG_ENTRY_PREFIX: u8 = 't' as u8; const TX_LOG_ID_PREFIX: u8 = 'i' as u8; const ACCOUNT_PATH_MAPPING_PREFIX: u8 = 'a' as u8; -const DATA_PATH_KEY: &'static str = "root_data_path"; - impl From for Error { fn from(error: store::Error) -> Error { Error::from(ErrorKind::Backend(format!("{:?}", error))) @@ -81,8 +81,7 @@ impl LMDBBackend { fs::create_dir_all(&db_path).expect("Couldn't create wallet backend directory!"); let stored_tx_path = path::Path::new(&config.data_file_dir).join(TX_SAVE_DIR); - fs::create_dir_all(&stored_tx_path) - .expect("Couldn't create wallet backend tx storage directory!"); + fs::create_dir_all(&stored_tx_path).expect("Couldn't create wallet backend tx storage directory!"); let lmdb_env = Arc::new(store::new_env(db_path.to_str().unwrap().to_string())); let store = store::Store::open(lmdb_env, DB_DIR); @@ -102,10 +101,6 @@ impl LMDBBackend { { let batch = store.batch()?; batch.put_ser(&acct_key, &default_account)?; - batch.put( - &DATA_PATH_KEY.as_bytes(), - stored_tx_path.to_str().unwrap().to_owned().into_bytes(), - )?; batch.commit()?; } @@ -249,6 +244,19 @@ where self.db.get_ser(&acct_key).map_err(|e| e.into()) } + fn store_tx(&self, uuid: &str, tx: &Transaction) -> Result<(), Error> { + let filename = format!("{}.grintx", uuid); + let path = path::Path::new(&self.config.data_file_dir) + .join(TX_SAVE_DIR) + .join(filename); + let path_buf = Path::new(&path).to_path_buf(); + let mut stored_tx = File::create(path_buf)?; + let tx_hex = util::to_hex(ser::ser_vec(tx).unwrap());; + stored_tx.write_all(&tx_hex.as_bytes())?; + stored_tx.sync_all()?; + Ok(()) + } + fn get_stored_tx(&self, entry: &TxLogEntry) -> Result, Error> { let filename = match entry.tx_hex.clone() { Some(f) => f, @@ -444,48 +452,14 @@ where fn save_tx_log_entry( &mut self, - mut tx_in: TxLogEntry, + tx_in: TxLogEntry, parent_id: &Identifier, - tx_hex_in: Option, ) -> Result<(), Error> { let tx_log_key = to_key_u64( TX_LOG_ENTRY_PREFIX, &mut parent_id.to_bytes().to_vec(), tx_in.id as u64, ); - // Fun Hack: Save tx log entries to files on the system instead of directly in the DB - if let Some(tx_hex) = tx_hex_in { - let path = match self - .db - .borrow() - .as_ref() - .unwrap() - .get(&DATA_PATH_KEY.as_bytes())? - { - Some(p) => match String::from_utf8(p) { - Ok(u) => u, - Err(_) => { - return Err(ErrorKind::GenericError( - "Couldn't get tx storage path from db".to_owned(), - ) - .into()) - } - }, - None => { - return Err(ErrorKind::GenericError( - "Couldn't get tx storage path from db".to_owned(), - ) - .into()) - } - }; - let mut path_buf = Path::new(&path).to_path_buf(); - let tx_file_name = format!("{}.grintx", tx_in.tx_slate_id.unwrap()); - path_buf.push(tx_file_name.clone()); - let mut stored_tx = File::create(path_buf)?; - stored_tx.write_all(&tx_hex.as_bytes())?; - stored_tx.sync_all()?; - tx_in.tx_hex = Some(tx_file_name); - } self.db .borrow() .as_ref() From f91774998b98e33bd0be7a28837fbbc196164ca1 Mon Sep 17 00:00:00 2001 From: yeastplume Date: Fri, 14 Dec 2018 10:44:34 +0000 Subject: [PATCH 6/6] rustfmt --- wallet/src/libwallet/api.rs | 8 +++++++- wallet/src/libwallet/internal/selection.rs | 2 +- wallet/src/libwallet/internal/tx.rs | 7 ++----- wallet/src/libwallet/types.rs | 6 +----- wallet/src/lmdb_wallet.rs | 5 +++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wallet/src/libwallet/api.rs b/wallet/src/libwallet/api.rs index 41a9e371f4..2dd9f88d12 100644 --- a/wallet/src/libwallet/api.rs +++ b/wallet/src/libwallet/api.rs @@ -612,7 +612,13 @@ where num_change_outputs: usize, selection_strategy_is_use_all: bool, message: Option, - ) -> Result<(Slate, impl FnOnce(&mut W, &Transaction) -> Result<(), Error>), Error> { + ) -> Result< + ( + Slate, + impl FnOnce(&mut W, &Transaction) -> Result<(), Error>, + ), + Error, + > { let mut w = self.wallet.lock(); w.open_with_credentials()?; let parent_key_id = match src_acct_name { diff --git a/wallet/src/libwallet/internal/selection.rs b/wallet/src/libwallet/internal/selection.rs index e8193a0d28..be2160ecb7 100644 --- a/wallet/src/libwallet/internal/selection.rs +++ b/wallet/src/libwallet/internal/selection.rs @@ -14,8 +14,8 @@ //! Selection of inputs for building transactions -use crate::core::libtx::{build, slate::Slate, tx_fee}; use crate::core::core::Transaction; +use crate::core::libtx::{build, slate::Slate, tx_fee}; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::error::{Error, ErrorKind}; use crate::libwallet::internal::keys; diff --git a/wallet/src/libwallet/internal/tx.rs b/wallet/src/libwallet/internal/tx.rs index 565f923cf7..caac3359fe 100644 --- a/wallet/src/libwallet/internal/tx.rs +++ b/wallet/src/libwallet/internal/tx.rs @@ -16,8 +16,8 @@ use uuid::Uuid; -use crate::core::libtx::slate::Slate; use crate::core::core::Transaction; +use crate::core::libtx::slate::Slate; use crate::keychain::{Identifier, Keychain}; use crate::libwallet::internal::{selection, updater}; use crate::libwallet::types::{Context, NodeClient, TxLogEntryType, WalletBackend}; @@ -200,10 +200,7 @@ where } /// Update the stored transaction (this update needs to happen when the TX is finalised) -pub fn update_stored_tx( - wallet: &mut T, - slate: &Slate, -) -> Result<(), Error> +pub fn update_stored_tx(wallet: &mut T, slate: &Slate) -> Result<(), Error> where T: WalletBackend, C: NodeClient, diff --git a/wallet/src/libwallet/types.rs b/wallet/src/libwallet/types.rs index 13866e33be..e499981118 100644 --- a/wallet/src/libwallet/types.rs +++ b/wallet/src/libwallet/types.rs @@ -161,11 +161,7 @@ where fn tx_log_iter(&self) -> Box>; /// save a tx log entry - fn save_tx_log_entry( - &mut self, - t: TxLogEntry, - parent_id: &Identifier, - ) -> Result<(), Error>; + fn save_tx_log_entry(&mut self, t: TxLogEntry, parent_id: &Identifier) -> Result<(), Error>; /// save an account label -> path mapping fn save_acct_path(&mut self, mapping: AcctPathMapping) -> Result<(), Error>; diff --git a/wallet/src/lmdb_wallet.rs b/wallet/src/lmdb_wallet.rs index 7cf040f11c..acadf3651f 100644 --- a/wallet/src/lmdb_wallet.rs +++ b/wallet/src/lmdb_wallet.rs @@ -34,8 +34,8 @@ use crate::core::ser; use crate::libwallet::types::*; use crate::libwallet::{internal, Error, ErrorKind}; use crate::types::{WalletConfig, WalletSeed}; -use crate::util::secp::pedersen; use crate::util; +use crate::util::secp::pedersen; pub const DB_DIR: &'static str = "db"; pub const TX_SAVE_DIR: &'static str = "saved_txs"; @@ -81,7 +81,8 @@ impl LMDBBackend { fs::create_dir_all(&db_path).expect("Couldn't create wallet backend directory!"); let stored_tx_path = path::Path::new(&config.data_file_dir).join(TX_SAVE_DIR); - fs::create_dir_all(&stored_tx_path).expect("Couldn't create wallet backend tx storage directory!"); + fs::create_dir_all(&stored_tx_path) + .expect("Couldn't create wallet backend tx storage directory!"); let lmdb_env = Arc::new(store::new_env(db_path.to_str().unwrap().to_string())); let store = store::Store::open(lmdb_env, DB_DIR);