From 257b6bf05a7f70f2ae1e4ee035e72a7d9bb6dc81 Mon Sep 17 00:00:00 2001 From: Ignotus Peverell Date: Tue, 22 May 2018 21:39:32 +0100 Subject: [PATCH] Minor refactor of OutputData mark_* functions --- wallet/src/checker.rs | 24 ++---------------------- wallet/src/types.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/wallet/src/checker.rs b/wallet/src/checker.rs index 823e95847..0e844a4d8 100644 --- a/wallet/src/checker.rs +++ b/wallet/src/checker.rs @@ -26,26 +26,6 @@ use util::secp::pedersen; use util; use util::LOGGER; -// Transitions a local wallet output from Unconfirmed -> Unspent. -fn mark_unspent_output(out: &mut OutputData) { - match out.status { - OutputStatus::Unconfirmed => out.status = OutputStatus::Unspent, - _ => (), - } -} - -// Transitions a local wallet output (based on it not being in the node output -// set) - -// Unspent -> Spent -// Locked -> Spent -fn mark_spent_output(out: &mut OutputData) { - match out.status { - OutputStatus::Unspent => out.status = OutputStatus::Spent, - OutputStatus::Locked => out.status = OutputStatus::Spent, - _ => (), - } -} - pub fn refresh_outputs(config: &WalletConfig, keychain: &Keychain) -> Result<(), Error> { refresh_output_state(config, keychain)?; refresh_missing_block_hashes(config, keychain)?; @@ -211,8 +191,8 @@ pub fn apply_api_outputs( let id = wallet_outputs.get(&commit).unwrap(); if let Entry::Occupied(mut output) = wallet_data.outputs.entry(id.to_hex()) { match api_outputs.get(&commit) { - Some(_) => mark_unspent_output(&mut output.get_mut()), - None => mark_spent_output(&mut output.get_mut()), + Some(_) => output.get_mut().mark_unspent(), + None => output.get_mut().mark_spent(), }; } } diff --git a/wallet/src/types.rs b/wallet/src/types.rs index 89a50bd0b..8ee5aa52a 100644 --- a/wallet/src/types.rs +++ b/wallet/src/types.rs @@ -394,6 +394,22 @@ impl OutputData { return false; } } + + /// Marks this output as unspent if it was previously unconfirmed + pub fn mark_unspent(&mut self) { + match self.status { + OutputStatus::Unconfirmed => self.status = OutputStatus::Unspent, + _ => (), + } + } + + pub fn mark_spent(&mut self) { + match self.status { + OutputStatus::Unspent => self.status = OutputStatus::Spent, + OutputStatus::Locked => self.status = OutputStatus::Spent, + _ => (), + } + } } #[derive(Clone, PartialEq)]