mirror of
https://github.com/jwinterm/grin-wallet.git
synced 2026-10-26 18:38:32 +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:
@@ -267,7 +267,7 @@ where
|
||||
/// Check / repair wallet contents
|
||||
/// assume wallet contents have been freshly updated with contents
|
||||
/// of latest block
|
||||
pub fn check_repair<T, C, K>(wallet: &mut T) -> Result<(), Error>
|
||||
pub fn check_repair<T, C, K>(wallet: &mut T, delete_unconfirmed: bool) -> Result<(), Error>
|
||||
where
|
||||
T: WalletBackend<C, K>,
|
||||
C: NodeClient,
|
||||
@@ -335,37 +335,39 @@ where
|
||||
restore_missing_output(wallet, m, &mut found_parents, &mut None)?;
|
||||
}
|
||||
|
||||
// Unlock locked outputs
|
||||
for m in locked_outs.into_iter() {
|
||||
let mut o = m.0;
|
||||
warn!(
|
||||
"Confirmed output for {} with ID {} ({:?}) exists in UTXO set and is locked. \
|
||||
Unlocking and cancelling associated transaction log entries.",
|
||||
o.value, o.key_id, m.1.commit,
|
||||
);
|
||||
o.status = OutputStatus::Unspent;
|
||||
cancel_tx_log_entry(wallet, &o)?;
|
||||
let mut batch = wallet.batch()?;
|
||||
batch.save(o)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
if delete_unconfirmed {
|
||||
// Unlock locked outputs
|
||||
for m in locked_outs.into_iter() {
|
||||
let mut o = m.0;
|
||||
warn!(
|
||||
"Confirmed output for {} with ID {} ({:?}) exists in UTXO set and is locked. \
|
||||
Unlocking and cancelling associated transaction log entries.",
|
||||
o.value, o.key_id, m.1.commit,
|
||||
);
|
||||
o.status = OutputStatus::Unspent;
|
||||
cancel_tx_log_entry(wallet, &o)?;
|
||||
let mut batch = wallet.batch()?;
|
||||
batch.save(o)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
|
||||
let unconfirmed_outs: Vec<&(OutputData, pedersen::Commitment)> = wallet_outputs
|
||||
.iter()
|
||||
.filter(|o| o.0.status == OutputStatus::Unconfirmed)
|
||||
.collect();
|
||||
// Delete unconfirmed outputs
|
||||
for m in unconfirmed_outs.into_iter() {
|
||||
let o = m.0.clone();
|
||||
warn!(
|
||||
"Unconfirmed output for {} with ID {} ({:?}) not in UTXO set. \
|
||||
Deleting and cancelling associated transaction log entries.",
|
||||
o.value, o.key_id, m.1,
|
||||
);
|
||||
cancel_tx_log_entry(wallet, &o)?;
|
||||
let mut batch = wallet.batch()?;
|
||||
batch.delete(&o.key_id, &o.mmr_index)?;
|
||||
batch.commit()?;
|
||||
let unconfirmed_outs: Vec<&(OutputData, pedersen::Commitment)> = wallet_outputs
|
||||
.iter()
|
||||
.filter(|o| o.0.status == OutputStatus::Unconfirmed)
|
||||
.collect();
|
||||
// Delete unconfirmed outputs
|
||||
for m in unconfirmed_outs.into_iter() {
|
||||
let o = m.0.clone();
|
||||
warn!(
|
||||
"Unconfirmed output for {} with ID {} ({:?}) not in UTXO set. \
|
||||
Deleting and cancelling associated transaction log entries.",
|
||||
o.value, o.key_id, m.1,
|
||||
);
|
||||
cancel_tx_log_entry(wallet, &o)?;
|
||||
let mut batch = wallet.batch()?;
|
||||
batch.delete(&o.key_id, &o.mmr_index)?;
|
||||
batch.commit()?;
|
||||
}
|
||||
}
|
||||
|
||||
// restore labels, account paths and child derivation indices
|
||||
|
||||
@@ -384,6 +384,7 @@ where
|
||||
|
||||
let mut unspent_total = 0;
|
||||
let mut immature_total = 0;
|
||||
let mut awaiting_finalization_total = 0;
|
||||
let mut unconfirmed_total = 0;
|
||||
let mut locked_total = 0;
|
||||
|
||||
@@ -403,9 +404,9 @@ where
|
||||
// We ignore unconfirmed coinbase outputs completely.
|
||||
if !out.is_coinbase {
|
||||
if minimum_confirmations == 0 {
|
||||
unspent_total += out.value;
|
||||
} else {
|
||||
unconfirmed_total += out.value;
|
||||
} else {
|
||||
awaiting_finalization_total += out.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -420,6 +421,7 @@ where
|
||||
last_confirmed_height: current_height,
|
||||
minimum_confirmations,
|
||||
total: unspent_total + unconfirmed_total + immature_total,
|
||||
amount_awaiting_finalization: awaiting_finalization_total,
|
||||
amount_awaiting_confirmation: unconfirmed_total,
|
||||
amount_immature: immature_total,
|
||||
amount_locked: locked_total,
|
||||
|
||||
@@ -130,7 +130,7 @@ where
|
||||
fn restore(&mut self) -> Result<(), Error>;
|
||||
|
||||
/// Attempt to check and fix wallet state
|
||||
fn check_repair(&mut self) -> Result<(), Error>;
|
||||
fn check_repair(&mut self, delete_unconfirmed: bool) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
/// Batch trait to update the output data backend atomically. Trying to use a
|
||||
@@ -546,6 +546,8 @@ pub struct WalletInfo {
|
||||
pub minimum_confirmations: u64,
|
||||
/// total amount in the wallet
|
||||
pub total: u64,
|
||||
/// amount awaiting finalization
|
||||
pub amount_awaiting_finalization: u64,
|
||||
/// amount awaiting confirmation
|
||||
pub amount_awaiting_confirmation: u64,
|
||||
/// coinbases waiting for lock height
|
||||
|
||||
Reference in New Issue
Block a user