Return bool on signature check

This commit is contained in:
Tyera Eulberg
2018-06-28 18:59:02 -06:00
committed by Grimes
parent e4e1f8ec1e
commit d354e85a9a
4 changed files with 17 additions and 21 deletions

View File

@ -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]

View File

@ -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 => {

View File

@ -32,6 +32,6 @@ pub enum Response {
transaction_count: u64,
},
SignatureStatus {
signature_status: Option<(Hash, Signature)>,
signature_status: bool,
},
}

View File

@ -21,7 +21,7 @@ pub struct ThinClient {
last_id: Option<Hash>,
transaction_count: u64,
balances: HashMap<PublicKey, Option<i64>>,
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 {