[WIP] minimum_confirmations = 10 (#1996)

* default to minimum_confirmation = 10
pass in minimum_confirmations to grin wallet info

* rustfmt

* rebase against master

* fixup wallet tests

* fixup server tests
This commit is contained in:
Antioch Peverell 2018-11-20 11:17:03 +00:00 committed by GitHub
parent 5ba163fa66
commit 458a980470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 178 additions and 91 deletions

View file

@ -314,7 +314,7 @@ impl LocalServerContainer {
wallet.keychain = Some(keychain); wallet.keychain = Some(keychain);
let parent_id = keychain::ExtKeychain::derive_key_id(2, 0, 0, 0, 0); let parent_id = keychain::ExtKeychain::derive_key_id(2, 0, 0, 0, 0);
let _ = wallet::libwallet::internal::updater::refresh_outputs(&mut wallet, &parent_id); let _ = wallet::libwallet::internal::updater::refresh_outputs(&mut wallet, &parent_id);
wallet::libwallet::internal::updater::retrieve_info(&mut wallet, &parent_id).unwrap() wallet::libwallet::internal::updater::retrieve_info(&mut wallet, &parent_id, 1).unwrap()
} }
pub fn send_amount_to( pub fn send_amount_to(

View file

@ -984,7 +984,7 @@ fn replicate_tx_fluff_failure() {
let wallet2 = create_wallet("target/tmp/tx_fluff/wallet2", client2.clone()); let wallet2 = create_wallet("target/tmp/tx_fluff/wallet2", client2.clone());
wallet::controller::owner_single_use(wallet2, |api| { wallet::controller::owner_single_use(wallet2, |api| {
let res = api.retrieve_summary_info(true).unwrap(); let res = api.retrieve_summary_info(true, 1).unwrap();
assert_eq!(res.1.amount_currently_spendable, amount); assert_eq!(res.1.amount_currently_spendable, amount);
Ok(()) Ok(())
}).unwrap(); }).unwrap();

View file

@ -15,7 +15,6 @@
use clap::ArgMatches; use clap::ArgMatches;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
/// Wallet commands processing
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
@ -433,8 +432,22 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
}); });
Ok(()) Ok(())
} }
("info", Some(_)) => { ("info", Some(args)) => {
let (validated, wallet_info) = api.retrieve_summary_info(true).map_err(|e| { let minimum_confirmations: u64 = args
.value_of("minimum_confirmations")
.ok_or_else(|| {
ErrorKind::GenericError("Minimum confirmations required".to_string())
}).and_then(|v| {
v.parse().map_err(|e| {
ErrorKind::GenericError(format!(
"Could not parse minimum_confirmations as a whole number. e={:?}",
e
))
})
})?;
let (validated, wallet_info) = api
.retrieve_summary_info(true, minimum_confirmations)
.map_err(|e| {
ErrorKind::GenericError(format!( ErrorKind::GenericError(format!(
"Error getting wallet info: {:?} Config: {:?}", "Error getting wallet info: {:?} Config: {:?}",
e, wallet_config e, wallet_config

View file

@ -216,7 +216,7 @@ fn real_main() -> i32 {
.help("Minimum number of confirmations required for an output to be spendable.") .help("Minimum number of confirmations required for an output to be spendable.")
.short("c") .short("c")
.long("min_conf") .long("min_conf")
.default_value("1") .default_value("10")
.takes_value(true)) .takes_value(true))
.arg(Arg::with_name("selection_strategy") .arg(Arg::with_name("selection_strategy")
.help("Coin/Output selection strategy.") .help("Coin/Output selection strategy.")
@ -284,7 +284,7 @@ fn real_main() -> i32 {
.help("Minimum number of confirmations required for an output to be spendable.") .help("Minimum number of confirmations required for an output to be spendable.")
.short("c") .short("c")
.long("min_conf") .long("min_conf")
.default_value("1") .default_value("10")
.takes_value(true))) .takes_value(true)))
.subcommand(SubCommand::with_name("outputs") .subcommand(SubCommand::with_name("outputs")
@ -329,7 +329,13 @@ fn real_main() -> i32 {
.takes_value(true))) .takes_value(true)))
.subcommand(SubCommand::with_name("info") .subcommand(SubCommand::with_name("info")
.about("basic wallet contents summary")) .about("basic wallet contents summary")
.arg(Arg::with_name("minimum_confirmations")
.help("Minimum number of confirmations required for an output to be spendable.")
.short("c")
.long("min_conf")
.default_value("10")
.takes_value(true)))
.subcommand(SubCommand::with_name("init") .subcommand(SubCommand::with_name("init")
.about("Initialize a new wallet seed file and database.") .about("Initialize a new wallet seed file and database.")

View file

@ -188,8 +188,8 @@ where
show_spent = true; show_spent = true;
} }
if let Some(ids) = params.get("tx_id") { if let Some(ids) = params.get("tx_id") {
for i in ids { if let Some(x) = ids.first() {
id = Some(i.parse().unwrap()); id = Some(x.parse().unwrap());
} }
} }
api.retrieve_outputs(show_spent, update_from_node, id) api.retrieve_outputs(show_spent, update_from_node, id)
@ -210,13 +210,13 @@ where
update_from_node = true; update_from_node = true;
} }
if let Some(ids) = params.get("id") { if let Some(ids) = params.get("id") {
for i in ids { if let Some(x) = ids.first() {
tx_id = Some(i.parse().unwrap()); tx_id = Some(x.parse().unwrap());
} }
} }
if let Some(tx_slate_ids) = params.get("tx_id") { if let Some(tx_slate_ids) = params.get("tx_id") {
for i in tx_slate_ids { if let Some(x) = tx_slate_ids.first() {
tx_slate_id = Some(i.parse().unwrap()); tx_slate_id = Some(x.parse().unwrap());
} }
} }
api.retrieve_txs(update_from_node, tx_id, tx_slate_id) api.retrieve_txs(update_from_node, tx_id, tx_slate_id)
@ -256,8 +256,17 @@ where
req: &Request<Body>, req: &Request<Body>,
mut api: APIOwner<T, C, K>, mut api: APIOwner<T, C, K>,
) -> Result<(bool, WalletInfo), Error> { ) -> Result<(bool, WalletInfo), Error> {
let update_from_node = param_exists(req, "refresh"); let mut minimum_confirmations = 1; // TODO - default needed here
api.retrieve_summary_info(update_from_node) let params = parse_params(req);
let update_from_node = params.get("refresh").is_some();
if let Some(confs) = params.get("minimum_confirmations") {
if let Some(x) = confs.first() {
minimum_confirmations = x.parse().unwrap();
}
}
api.retrieve_summary_info(update_from_node, minimum_confirmations)
} }
fn node_height( fn node_height(
@ -660,10 +669,6 @@ fn parse_params(req: &Request<Body>) -> HashMap<String, Vec<String>> {
} }
} }
fn param_exists(req: &Request<Body>, param: &str) -> bool {
parse_params(req).get(param).is_some()
}
fn parse_body<T>(req: Request<Body>) -> Box<Future<Item = T, Error = Error> + Send> fn parse_body<T>(req: Request<Body>) -> Box<Future<Item = T, Error = Error> + Send>
where where
for<'de> T: Deserialize<'de> + Send + 'static, for<'de> T: Deserialize<'de> + Send + 'static,

View file

@ -13,6 +13,7 @@
// limitations under the License. // limitations under the License.
use core::core::{self, amount_to_hr_string}; use core::core::{self, amount_to_hr_string};
use core::global;
use libwallet::types::{AcctPathMapping, OutputData, OutputStatus, TxLogEntry, WalletInfo}; use libwallet::types::{AcctPathMapping, OutputData, OutputStatus, TxLogEntry, WalletInfo};
use libwallet::Error; use libwallet::Error;
use prettytable; use prettytable;
@ -255,26 +256,69 @@ pub fn info(
) { ) {
println!( println!(
"\n____ Wallet Summary Info - Account '{}' as of height {} ____\n", "\n____ Wallet Summary Info - Account '{}' as of height {} ____\n",
account, wallet_info.last_confirmed_height account, wallet_info.last_confirmed_height,
); );
let mut table = if dark_background_color_scheme {
table!( let mut table = table!();
[bFG->"Total", FG->amount_to_hr_string(wallet_info.total, false)],
[bFY->"Awaiting Confirmation", FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)], if dark_background_color_scheme {
[bFY->"Immature Coinbase", FY->amount_to_hr_string(wallet_info.amount_immature, false)], table.add_row(row![
[bFG->"Currently Spendable", FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)], bFG->"Total",
[Fw->"--------------------------------", Fw->"-------------"], FG->amount_to_hr_string(wallet_info.total, false)
[Fr->"(Locked by previous transaction)", Fr->amount_to_hr_string(wallet_info.amount_locked, false)] ]);
) // Only dispay "Immature Coinbase" if we have related outputs in the wallet.
// This row just introduces confusion if the wallet does not receive coinbase rewards.
if wallet_info.amount_immature > 0 {
table.add_row(row![
bFY->format!("Immature Coinbase (< {})", global::coinbase_maturity()),
FY->amount_to_hr_string(wallet_info.amount_immature, false)
]);
}
table.add_row(row![
bFY->format!("Awaiting Confirmation (< {})", wallet_info.minimum_confirmations),
FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)
]);
table.add_row(row![
Fr->"Locked by previous transaction",
Fr->amount_to_hr_string(wallet_info.amount_locked, false)
]);
table.add_row(row![
Fw->"--------------------------------",
Fw->"-------------"
]);
table.add_row(row![
bFG->"Currently Spendable",
FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)
]);
} else { } else {
table!( table.add_row(row![
[bFG->"Total", FG->amount_to_hr_string(wallet_info.total, false)], bFG->"Total",
[bFB->"Awaiting Confirmation", FB->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)], FG->amount_to_hr_string(wallet_info.total, false)
[bFB->"Immature Coinbase", FB->amount_to_hr_string(wallet_info.amount_immature, false)], ]);
[bFG->"Currently Spendable", FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)], // Only dispay "Immature Coinbase" if we have related outputs in the wallet.
[Fw->"--------------------------------", Fw->"-------------"], // This row just introduces confusion if the wallet does not receive coinbase rewards.
[Fr->"(Locked by previous transaction)", Fr->amount_to_hr_string(wallet_info.amount_locked, false)] if wallet_info.amount_immature > 0 {
) table.add_row(row![
bFB->format!("Immature Coinbase (< {})", global::coinbase_maturity()),
FB->amount_to_hr_string(wallet_info.amount_immature, false)
]);
}
table.add_row(row![
bFB->format!("Awaiting Confirmation (< {})", wallet_info.minimum_confirmations),
FB->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)
]);
table.add_row(row![
Fr->"Locked by previous transaction",
Fr->amount_to_hr_string(wallet_info.amount_locked, false)
]);
table.add_row(row![
Fw->"--------------------------------",
Fw->"-------------"
]);
table.add_row(row![
bFG->"Currently Spendable",
FG->amount_to_hr_string(wallet_info.amount_currently_spendable, false)
]);
}; };
table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); table.set_format(*prettytable::format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
table.printstd(); table.printstd();

View file

@ -127,6 +127,7 @@ where
pub fn retrieve_summary_info( pub fn retrieve_summary_info(
&mut self, &mut self,
refresh_from_node: bool, refresh_from_node: bool,
minimum_confirmations: u64,
) -> Result<(bool, WalletInfo), Error> { ) -> Result<(bool, WalletInfo), Error> {
let mut w = self.wallet.lock(); let mut w = self.wallet.lock();
w.open_with_credentials()?; w.open_with_credentials()?;
@ -137,7 +138,7 @@ where
validated = self.update_outputs(&mut w); validated = self.update_outputs(&mut w);
} }
let wallet_info = updater::retrieve_info(&mut *w, &parent_key_id)?; let wallet_info = updater::retrieve_info(&mut *w, &parent_key_id, minimum_confirmations)?;
let res = Ok((validated, wallet_info)); let res = Ok((validated, wallet_info));
w.close()?; w.close()?;

View file

@ -323,6 +323,7 @@ where
pub fn retrieve_info<T: ?Sized, C, K>( pub fn retrieve_info<T: ?Sized, C, K>(
wallet: &mut T, wallet: &mut T,
parent_key_id: &Identifier, parent_key_id: &Identifier,
minimum_confirmations: u64,
) -> Result<WalletInfo, Error> ) -> Result<WalletInfo, Error>
where where
T: WalletBackend<C, K>, T: WalletBackend<C, K>,
@ -338,23 +339,39 @@ where
let mut immature_total = 0; let mut immature_total = 0;
let mut unconfirmed_total = 0; let mut unconfirmed_total = 0;
let mut locked_total = 0; let mut locked_total = 0;
for out in outputs { for out in outputs {
if out.status == OutputStatus::Unspent && out.lock_height <= current_height { match out.status {
OutputStatus::Unspent => {
if out.is_coinbase && out.lock_height > current_height {
immature_total += out.value;
} else if out.num_confirmations(current_height) < minimum_confirmations {
// Treat anything less than minimum confirmations as "unconfirmed".
unconfirmed_total += out.value;
} else {
unspent_total += out.value; unspent_total += out.value;
} }
if out.status == OutputStatus::Unspent && out.lock_height > current_height {
immature_total += out.value;
} }
if out.status == OutputStatus::Unconfirmed && !out.is_coinbase { OutputStatus::Unconfirmed => {
// We ignore unconfirmed coinbase outputs completely.
if !out.is_coinbase {
if minimum_confirmations == 0 {
unspent_total += out.value;
} else {
unconfirmed_total += out.value; unconfirmed_total += out.value;
} }
if out.status == OutputStatus::Locked { }
}
OutputStatus::Locked => {
locked_total += out.value; locked_total += out.value;
} }
OutputStatus::Spent => {}
}
} }
Ok(WalletInfo { Ok(WalletInfo {
last_confirmed_height: current_height, last_confirmed_height: current_height,
minimum_confirmations,
total: unspent_total + unconfirmed_total + immature_total, total: unspent_total + unconfirmed_total + immature_total,
amount_awaiting_confirmation: unconfirmed_total, amount_awaiting_confirmation: unconfirmed_total,
amount_immature: immature_total, amount_immature: immature_total,

View file

@ -31,7 +31,6 @@ use core::ser;
use keychain::{Identifier, Keychain}; use keychain::{Identifier, Keychain};
use libtx::aggsig; use libtx::aggsig;
use libtx::slate::Slate;
use libwallet::error::{Error, ErrorKind}; use libwallet::error::{Error, ErrorKind};
use util::secp::key::{PublicKey, SecretKey}; use util::secp::key::{PublicKey, SecretKey};
@ -519,6 +518,8 @@ pub struct CbData {
pub struct WalletInfo { pub struct WalletInfo {
/// height from which info was taken /// height from which info was taken
pub last_confirmed_height: u64, pub last_confirmed_height: u64,
/// Minimum number of confirmations for an output to be treated as "spendable".
pub minimum_confirmations: u64,
/// total amount in the wallet /// total amount in the wallet
pub total: u64, pub total: u64,
/// amount awaiting confirmation /// amount awaiting confirmation

View file

@ -128,7 +128,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable) // Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, 12); assert_eq!(wallet1_info.last_confirmed_height, 12);
assert_eq!(wallet1_info.total, 5 * reward); assert_eq!(wallet1_info.total, 5 * reward);
@ -145,9 +145,9 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
} }
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
// check last confirmed height on this account is different from above (should be 0) // check last confirmed height on this account is different from above (should be 0)
let (_, wallet1_info) = api.retrieve_summary_info(false)?; let (_, wallet1_info) = api.retrieve_summary_info(false, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, 0); assert_eq!(wallet1_info.last_confirmed_height, 0);
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, 12); assert_eq!(wallet1_info.last_confirmed_height, 12);
assert_eq!(wallet1_info.total, 7 * reward); assert_eq!(wallet1_info.total, 7 * reward);
@ -164,9 +164,9 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("default")?; w.set_parent_key_id_by_name("default")?;
} }
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (_, wallet1_info) = api.retrieve_summary_info(false)?; let (_, wallet1_info) = api.retrieve_summary_info(false, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, 0); assert_eq!(wallet1_info.last_confirmed_height, 0);
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, 12); assert_eq!(wallet1_info.last_confirmed_height, 12);
assert_eq!(wallet1_info.total, 0,); assert_eq!(wallet1_info.total, 0,);
@ -199,7 +199,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
})?; })?;
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, 13); assert_eq!(wallet1_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(true, None, None)?; let (_, txs) = api.retrieve_txs(true, None, None)?;
@ -213,9 +213,9 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("account2")?; w.set_parent_key_id_by_name("account2")?;
} }
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (_, wallet1_info) = api.retrieve_summary_info(false)?; let (_, wallet1_info) = api.retrieve_summary_info(false, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, 12); assert_eq!(wallet1_info.last_confirmed_height, 12);
let (_, wallet1_info) = api.retrieve_summary_info(true)?; let (_, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert_eq!(wallet1_info.last_confirmed_height, 13); assert_eq!(wallet1_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(true, None, None)?; let (_, txs) = api.retrieve_txs(true, None, None)?;
println!("{:?}", txs); println!("{:?}", txs);
@ -225,7 +225,7 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// wallet 2 should only have this tx on the listener account // wallet 2 should only have this tx on the listener account
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet2_refreshed); assert!(wallet2_refreshed);
assert_eq!(wallet2_info.last_confirmed_height, 13); assert_eq!(wallet2_info.last_confirmed_height, 13);
let (_, txs) = api.retrieve_txs(true, None, None)?; let (_, txs) = api.retrieve_txs(true, None, None)?;
@ -238,9 +238,9 @@ fn accounts_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("default")?; w.set_parent_key_id_by_name("default")?;
} }
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let (_, wallet2_info) = api.retrieve_summary_info(false)?; let (_, wallet2_info) = api.retrieve_summary_info(false, 1)?;
assert_eq!(wallet2_info.last_confirmed_height, 0); assert_eq!(wallet2_info.last_confirmed_height, 0);
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet2_refreshed); assert!(wallet2_refreshed);
assert_eq!(wallet2_info.last_confirmed_height, 13); assert_eq!(wallet2_info.last_confirmed_height, 13);
assert_eq!(wallet2_info.total, 0,); assert_eq!(wallet2_info.total, 0,);

View file

@ -99,7 +99,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable) // Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, bh); assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.total, bh * reward); assert_eq!(wallet1_info.total, bh * reward);
@ -151,7 +151,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Check total in mining account // Check total in mining account
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, bh); assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.total, bh * reward - reward * 2); assert_eq!(wallet1_info.total, bh * reward - reward * 2);
@ -160,7 +160,7 @@ fn file_exchange_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Check total in 'wallet 2' account // Check total in 'wallet 2' account
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet2_refreshed); assert!(wallet2_refreshed);
assert_eq!(wallet2_info.last_confirmed_height, bh); assert_eq!(wallet2_info.last_confirmed_height, bh);
assert_eq!(wallet2_info.total, 2 * reward); assert_eq!(wallet2_info.total, 2 * reward);

View file

@ -73,7 +73,7 @@ fn restore_wallet(base_dir: &str, wallet_dir: &str) -> Result<(), libwallet::Err
// perform the restore and update wallet info // perform the restore and update wallet info
wallet::controller::owner_single_use(wallet.clone(), |api| { wallet::controller::owner_single_use(wallet.clone(), |api| {
let _ = api.restore()?; let _ = api.restore()?;
let _ = api.retrieve_summary_info(true)?; let _ = api.retrieve_summary_info(true, 1)?;
Ok(()) Ok(())
})?; })?;
@ -135,14 +135,14 @@ fn compare_wallet_restore(
// Overall wallet info should be the same // Overall wallet info should be the same
wallet::controller::owner_single_use(wallet_source.clone(), |api| { wallet::controller::owner_single_use(wallet_source.clone(), |api| {
src_info = Some(api.retrieve_summary_info(true)?.1); src_info = Some(api.retrieve_summary_info(true, 1)?.1);
src_txs = Some(api.retrieve_txs(true, None, None)?.1); src_txs = Some(api.retrieve_txs(true, None, None)?.1);
src_accts = Some(api.accounts()?); src_accts = Some(api.accounts()?);
Ok(()) Ok(())
})?; })?;
wallet::controller::owner_single_use(wallet_dest.clone(), |api| { wallet::controller::owner_single_use(wallet_dest.clone(), |api| {
dest_info = Some(api.retrieve_summary_info(true)?.1); dest_info = Some(api.retrieve_summary_info(true, 1)?.1);
dest_txs = Some(api.retrieve_txs(true, None, None)?.1); dest_txs = Some(api.retrieve_txs(true, None, None)?.1);
dest_accts = Some(api.accounts()?); dest_accts = Some(api.accounts()?);
Ok(()) Ok(())
@ -318,15 +318,15 @@ fn setup_restore(test_dir: &str) -> Result<(), libwallet::Error> {
// update everyone // update everyone
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let _ = api.retrieve_summary_info(true)?; let _ = api.retrieve_summary_info(true, 1)?;
Ok(()) Ok(())
})?; })?;
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let _ = api.retrieve_summary_info(true)?; let _ = api.retrieve_summary_info(true, 1)?;
Ok(()) Ok(())
})?; })?;
wallet::controller::owner_single_use(wallet3.clone(), |api| { wallet::controller::owner_single_use(wallet3.clone(), |api| {
let _ = api.retrieve_summary_info(true)?; let _ = api.retrieve_summary_info(true, 1)?;
Ok(()) Ok(())
})?; })?;

View file

@ -87,7 +87,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Should have 5 in account1 (5 spendable), 5 in account (2 spendable) // Should have 5 in account1 (5 spendable), 5 in account (2 spendable)
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, bh); assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.total, bh * reward); assert_eq!(wallet1_info.total, bh * reward);
@ -119,7 +119,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
// Check total in mining account // Check total in mining account
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, bh); assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.total, bh * reward - reward * 2); assert_eq!(wallet1_info.total, bh * reward - reward * 2);
@ -132,7 +132,7 @@ fn self_send_test_impl(test_dir: &str) -> Result<(), libwallet::Error> {
w.set_parent_key_id_by_name("listener")?; w.set_parent_key_id_by_name("listener")?;
} }
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!(wallet1_info.last_confirmed_height, bh); assert_eq!(wallet1_info.last_confirmed_height, bh);
assert_eq!(wallet1_info.total, 2 * reward); assert_eq!(wallet1_info.total, 2 * reward);

View file

@ -84,7 +84,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// Check wallet 1 contents are as expected // Check wallet 1 contents are as expected
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
debug!( debug!(
"Wallet 1 Info Pre-Transaction, after {} blocks: {:?}", "Wallet 1 Info Pre-Transaction, after {} blocks: {:?}",
wallet1_info.last_confirmed_height, wallet1_info wallet1_info.last_confirmed_height, wallet1_info
@ -119,7 +119,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// Check transaction log for wallet 1 // Check transaction log for wallet 1
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (_, wallet1_info) = api.retrieve_summary_info(true)?; let (_, wallet1_info) = api.retrieve_summary_info(true, 1)?;
let (refreshed, txs) = api.retrieve_txs(true, None, None)?; let (refreshed, txs) = api.retrieve_txs(true, None, None)?;
assert!(refreshed); assert!(refreshed);
let fee = wallet::libtx::tx_fee( let fee = wallet::libtx::tx_fee(
@ -163,7 +163,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// Check wallet 1 contents are as expected // Check wallet 1 contents are as expected
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
debug!( debug!(
"Wallet 1 Info Post Transaction, after {} blocks: {:?}", "Wallet 1 Info Post Transaction, after {} blocks: {:?}",
wallet1_info.last_confirmed_height, wallet1_info wallet1_info.last_confirmed_height, wallet1_info
@ -203,7 +203,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// refresh wallets and retrieve info/tests for each wallet after maturity // refresh wallets and retrieve info/tests for each wallet after maturity
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (wallet1_refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
debug!("Wallet 1 Info: {:?}", wallet1_info); debug!("Wallet 1 Info: {:?}", wallet1_info);
assert!(wallet1_refreshed); assert!(wallet1_refreshed);
assert_eq!( assert_eq!(
@ -218,7 +218,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?; })?;
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet2_refreshed); assert!(wallet2_refreshed);
assert_eq!(wallet2_info.amount_currently_spendable, amount); assert_eq!(wallet2_info.amount_currently_spendable, amount);
@ -252,7 +252,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
})?; })?;
wallet::controller::owner_single_use(wallet1.clone(), |sender_api| { wallet::controller::owner_single_use(wallet1.clone(), |sender_api| {
let (refreshed, _wallet1_info) = sender_api.retrieve_summary_info(true)?; let (refreshed, _wallet1_info) = sender_api.retrieve_summary_info(true, 1)?;
assert!(refreshed); assert!(refreshed);
let (_, txs) = sender_api.retrieve_txs(true, None, None)?; let (_, txs) = sender_api.retrieve_txs(true, None, None)?;
@ -262,7 +262,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
.find(|t| t.tx_slate_id == Some(slate.id)) .find(|t| t.tx_slate_id == Some(slate.id))
.unwrap(); .unwrap();
sender_api.post_stored_tx(tx.id, false)?; sender_api.post_stored_tx(tx.id, false)?;
let (_, wallet1_info) = sender_api.retrieve_summary_info(true)?; let (_, wallet1_info) = sender_api.retrieve_summary_info(true, 1)?;
// should be mined now // should be mined now
assert_eq!( assert_eq!(
wallet1_info.total, wallet1_info.total,
@ -276,7 +276,7 @@ fn basic_transaction_api(test_dir: &str) -> Result<(), libwallet::Error> {
// check wallet2 has stored transaction // check wallet2 has stored transaction
wallet::controller::owner_single_use(wallet2.clone(), |api| { wallet::controller::owner_single_use(wallet2.clone(), |api| {
let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (wallet2_refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(wallet2_refreshed); assert!(wallet2_refreshed);
assert_eq!(wallet2_info.amount_currently_spendable, amount * 3); assert_eq!(wallet2_info.amount_currently_spendable, amount * 3);
@ -347,7 +347,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
// Check transaction log for wallet 1 // Check transaction log for wallet 1
wallet::controller::owner_single_use(wallet1.clone(), |api| { wallet::controller::owner_single_use(wallet1.clone(), |api| {
let (refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
println!( println!(
"last confirmed height: {}", "last confirmed height: {}",
wallet1_info.last_confirmed_height wallet1_info.last_confirmed_height
@ -392,7 +392,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
} }
assert_eq!(outputs.len(), 1); assert_eq!(outputs.len(), 1);
assert_eq!(unconfirmed_count, 1); assert_eq!(unconfirmed_count, 1);
let (refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(refreshed); assert!(refreshed);
assert_eq!(wallet2_info.amount_currently_spendable, 0,); assert_eq!(wallet2_info.amount_currently_spendable, 0,);
assert_eq!(wallet2_info.total, amount); assert_eq!(wallet2_info.total, amount);
@ -413,7 +413,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
.find(|t| t.tx_slate_id == Some(slate.id)) .find(|t| t.tx_slate_id == Some(slate.id))
.unwrap(); .unwrap();
api.cancel_tx(Some(tx.id), None)?; api.cancel_tx(Some(tx.id), None)?;
let (refreshed, wallet1_info) = api.retrieve_summary_info(true)?; let (refreshed, wallet1_info) = api.retrieve_summary_info(true, 1)?;
assert!(refreshed); assert!(refreshed);
println!( println!(
"last confirmed height: {}", "last confirmed height: {}",
@ -440,7 +440,7 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
.find(|t| t.tx_slate_id == Some(slate.id)) .find(|t| t.tx_slate_id == Some(slate.id))
.unwrap(); .unwrap();
api.cancel_tx(Some(tx.id), None)?; api.cancel_tx(Some(tx.id), None)?;
let (refreshed, wallet2_info) = api.retrieve_summary_info(true)?; let (refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
assert!(refreshed); assert!(refreshed);
// check all eligible inputs should be now be spendable // check all eligible inputs should be now be spendable
assert_eq!(wallet2_info.amount_currently_spendable, 0,); assert_eq!(wallet2_info.amount_currently_spendable, 0,);