From d354e85a9aa8fc52a6c625ef74fc7cca3ca32736 Mon Sep 17 00:00:00 2001 From: Tyera Eulberg Date: Thu, 28 Jun 2018 18:59:02 -0600 Subject: [PATCH] Return bool on signature check --- src/bank.rs | 12 ++++++------ src/bin/wallet.rs | 10 +++------- src/request.rs | 2 +- src/thin_client.rs | 14 +++++++------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index 8ea1e7ddac..563d7f67ab 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -434,16 +434,16 @@ impl Bank { self.transaction_count.load(Ordering::Relaxed) } - pub fn check_signature(&self, signature: &Signature) -> Option<(Hash, Signature)> { + pub fn check_signature(&self, signature: &Signature) -> bool { let last_ids_sigs = self.last_ids_sigs .read() .expect("'last_ids_sigs' read lock"); - for (hash, signatures) in last_ids_sigs.iter() { - if let Some(sig) = signatures.get(signature) { - return Some((*hash, *sig)); + for (_hash, signatures) in last_ids_sigs.iter() { + if let Some(_sig) = signatures.get(signature) { + return true; } } - return None; + return false; } } @@ -640,7 +640,7 @@ mod tests { let sig = Signature::default(); bank.reserve_signature_with_last_id(&sig, &mint.last_id()) .expect("reserve signature"); - assert_eq!(bank.check_signature(&sig), Some((mint.last_id(), sig))); + assert!(bank.check_signature(&sig)); } #[test] diff --git a/src/bin/wallet.rs b/src/bin/wallet.rs index 029da7b678..3dcec0edf6 100644 --- a/src/bin/wallet.rs +++ b/src/bin/wallet.rs @@ -143,14 +143,10 @@ fn main() -> io::Result<()> { // Confirm the last client transaction by signature "confirm" => match last_transaction_sig { Some(sig) => { - let check_signature = client.check_signature(&sig); - match check_signature { - Some((id, _sig)) => { - println!("Signature found at bank id {:?}", id); - } - None => { + if client.check_signature(&sig) { + println!("Signature found at bank id {:?}", id); + } else { println!("Uh oh... Signature not found!"); - } } } None => { diff --git a/src/request.rs b/src/request.rs index 847c8b54e0..0840245dfb 100644 --- a/src/request.rs +++ b/src/request.rs @@ -32,6 +32,6 @@ pub enum Response { transaction_count: u64, }, SignatureStatus { - signature_status: Option<(Hash, Signature)>, + signature_status: bool, }, } diff --git a/src/thin_client.rs b/src/thin_client.rs index 3d9339679a..a2920c9992 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -21,7 +21,7 @@ pub struct ThinClient { last_id: Option, transaction_count: u64, balances: HashMap>, - signature_status: Option<(Hash, Signature)>, + signature_status: bool, } impl ThinClient { @@ -42,7 +42,7 @@ impl ThinClient { last_id: None, transaction_count: 0, balances: HashMap::new(), - signature_status: None, + signature_status: false, }; client } @@ -73,10 +73,10 @@ impl ThinClient { Response::SignatureStatus { signature_status } => { self.signature_status = signature_status; match signature_status { - Some((_, signature)) => { - trace!("Response found signature: {:?}", signature); + true => { + trace!("Response found signature"); } - None => { + false => { trace!("Response signature not found"); } } @@ -195,7 +195,7 @@ impl ThinClient { /// Check a signature in the bank. This method blocks /// until the server sends a response. - pub fn check_signature(&mut self, sig: &Signature) -> Option<(Hash, Signature)> { + pub fn check_signature(&mut self, sig: &Signature) -> bool { trace!("check_signature"); let req = Request::GetSignature { signature: *sig }; let data = serialize(&req).expect("serialize GetSignature in pub fn check_signature"); @@ -378,7 +378,7 @@ mod tests { .unwrap(); sleep(Duration::from_millis(100)); - assert_eq!(client.check_signature(&sig), Some((last_id, sig))); + assert!(client.check_signature(&sig)); exit.store(true, Ordering::Relaxed); for t in server.thread_hdls {