mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-11-27 01:23:58 +01:00
'Awaiting finalization' status and changes to 'wallet check' (#8)
* add awaiting confirmation status and change check to not remove unconfirmed transactions by default * test fixes
This commit is contained in:
@@ -530,13 +530,19 @@ pub fn restore(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// wallet check
|
||||
pub struct CheckArgs {
|
||||
pub delete_unconfirmed: bool,
|
||||
}
|
||||
|
||||
pub fn check_repair(
|
||||
wallet: Arc<Mutex<WalletInst<impl NodeClient + 'static, keychain::ExtKeychain>>>,
|
||||
args: CheckArgs,
|
||||
) -> Result<(), Error> {
|
||||
controller::owner_single_use(wallet.clone(), |api| {
|
||||
warn!("Starting wallet check...",);
|
||||
warn!("Updating all wallet outputs, please wait ...",);
|
||||
let result = api.check_repair();
|
||||
let result = api.check_repair(args.delete_unconfirmed);
|
||||
match result {
|
||||
Ok(_) => {
|
||||
warn!("Wallet check complete",);
|
||||
|
||||
@@ -270,7 +270,7 @@ pub fn info(
|
||||
|
||||
if dark_background_color_scheme {
|
||||
table.add_row(row![
|
||||
bFG->"Total",
|
||||
bFG->"Confirmed Total",
|
||||
FG->amount_to_hr_string(wallet_info.total, false)
|
||||
]);
|
||||
// Only dispay "Immature Coinbase" if we have related outputs in the wallet.
|
||||
@@ -285,6 +285,10 @@ pub fn info(
|
||||
bFY->format!("Awaiting Confirmation (< {})", wallet_info.minimum_confirmations),
|
||||
FY->amount_to_hr_string(wallet_info.amount_awaiting_confirmation, false)
|
||||
]);
|
||||
table.add_row(row![
|
||||
bFB->format!("Awaiting Finalization"),
|
||||
FB->amount_to_hr_string(wallet_info.amount_awaiting_finalization, false)
|
||||
]);
|
||||
table.add_row(row![
|
||||
Fr->"Locked by previous transaction",
|
||||
Fr->amount_to_hr_string(wallet_info.amount_locked, false)
|
||||
|
||||
@@ -350,8 +350,8 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_repair(&mut self) -> Result<(), Error> {
|
||||
internal::restore::check_repair(self).context(ErrorKind::Restore)?;
|
||||
fn check_repair(&mut self, delete_unconfirmed: bool) -> Result<(), Error> {
|
||||
internal::restore::check_repair(self, delete_unconfirmed).context(ErrorKind::Restore)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// this should restore our missing outputs
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -181,7 +181,7 @@ fn check_repair_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// unlock/restore
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -327,7 +327,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// 0) Check repair when all is okay should leave wallet contents alone
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
let info = test_framework::wallet_info(api)?;
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 6);
|
||||
assert_eq!(info.total, base_amount * 6);
|
||||
@@ -381,7 +381,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// 2) check_repair should recover them into a single wallet
|
||||
wallet::controller::owner_single_use(wallet1.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -447,7 +447,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
})?;
|
||||
|
||||
wallet::controller::owner_single_use(wallet6.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
@@ -538,7 +538,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
let outputs = api.retrieve_outputs(true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 3);
|
||||
assert_eq!(info.amount_currently_spendable, base_amount * 15);
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
let info = test_framework::wallet_info(api)?;
|
||||
let outputs = api.retrieve_outputs(true, false, None)?.1;
|
||||
assert_eq!(outputs.len(), 6);
|
||||
@@ -556,7 +556,7 @@ fn two_wallets_one_seed_impl(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
|
||||
// 7) Ensure check_repair creates missing accounts
|
||||
wallet::controller::owner_single_use(wallet10.clone(), |api| {
|
||||
api.check_repair()?;
|
||||
api.check_repair(true)?;
|
||||
api.set_active_account("account_1")?;
|
||||
let info = test_framework::wallet_info(api)?;
|
||||
let outputs = api.retrieve_outputs(true, false, None)?.1;
|
||||
|
||||
@@ -420,11 +420,12 @@ fn tx_rollback(test_dir: &str) -> Result<(), libwallet::Error> {
|
||||
let (refreshed, wallet2_info) = api.retrieve_summary_info(true, 1)?;
|
||||
assert!(refreshed);
|
||||
assert_eq!(wallet2_info.amount_currently_spendable, 0,);
|
||||
assert_eq!(wallet2_info.total, amount);
|
||||
assert_eq!(wallet2_info.amount_awaiting_finalization, amount);
|
||||
Ok(())
|
||||
})?;
|
||||
|
||||
// wallet 1 is bold and doesn't ever post the transaction mine a few more blocks
|
||||
// wallet 1 is bold and doesn't ever post the transaction
|
||||
// mine a few more blocks
|
||||
let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), 5);
|
||||
|
||||
// Wallet 1 decides to roll back instead
|
||||
|
||||
Reference in New Issue
Block a user