Return bool on signature check
This commit is contained in:
12
src/bank.rs
12
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]
|
||||
|
@ -143,16 +143,12 @@ 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)) => {
|
||||
if client.check_signature(&sig) {
|
||||
println!("Signature found at bank id {:?}", id);
|
||||
}
|
||||
None => {
|
||||
} else {
|
||||
println!("Uh oh... Signature not found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
println!("No recent signature. Make a payment to get started.");
|
||||
}
|
||||
|
@ -32,6 +32,6 @@ pub enum Response {
|
||||
transaction_count: u64,
|
||||
},
|
||||
SignatureStatus {
|
||||
signature_status: Option<(Hash, Signature)>,
|
||||
signature_status: bool,
|
||||
},
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user