From 90cd9bd5338141b9b9c30178971b574ebf4b9a05 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Mon, 2 Apr 2018 14:14:49 -0600 Subject: [PATCH] Move balance check so that log_* methods are only used to add logging --- src/accountant.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/accountant.rs b/src/accountant.rs index 7f7422686b..d459dc3322 100644 --- a/src/accountant.rs +++ b/src/accountant.rs @@ -111,10 +111,6 @@ impl Accountant { /// Process and log the given Transaction. pub fn log_verified_transaction(&mut self, tr: Transaction) -> Result<()> { - if self.get_balance(&tr.from).unwrap_or(0) < tr.tokens { - return Err(AccountingError::InsufficientFunds); - } - self.process_verified_transaction(&tr)?; if let Err(SendError(_)) = self.historian .sender @@ -144,7 +140,11 @@ impl Accountant { } /// Process a Transaction that has already been verified. - fn process_verified_transaction(&mut self, tr: &Transaction) -> Result<()> { + pub fn process_verified_transaction(&mut self, tr: &Transaction) -> Result<()> { + if self.get_balance(&tr.from).unwrap_or(0) < tr.tokens { + return Err(AccountingError::InsufficientFunds); + } + if !self.reserve_signature(&tr.sig) { return Err(AccountingError::InvalidTransferSignature); }