From c068ca4cb7ec8b85415adf2f3074e3d0875d39b8 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 20 Jul 2018 18:58:13 -0400 Subject: [PATCH] Return Signature from transfer_signed and send_airdrop --- src/drone.rs | 11 ++++++----- src/thin_client.rs | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/drone.rs b/src/drone.rs index d7a166c922..524ff18eed 100644 --- a/src/drone.rs +++ b/src/drone.rs @@ -6,6 +6,7 @@ use influx_db_client as influxdb; use metrics; +use signature::Signature; use signature::{KeyPair, PublicKey}; use std::io; use std::io::{Error, ErrorKind}; @@ -94,7 +95,7 @@ impl Drone { } } - pub fn send_airdrop(&mut self, req: DroneRequest) -> Result { + pub fn send_airdrop(&mut self, req: DroneRequest) -> Result { let tx: Transaction; let request_amount: u64; let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap(); @@ -302,15 +303,15 @@ mod tests { airdrop_request_amount: 50, client_public_key: bob_pubkey, }; - let bob_result = drone.send_airdrop(bob_req).expect("send airdrop test"); - assert!(bob_result > 0); + let bob_result = drone.send_airdrop(bob_req); + assert!(bob_result.is_ok()); let carlos_req = DroneRequest::GetAirdrop { airdrop_request_amount: 5_000_000, client_public_key: carlos_pubkey, }; - let carlos_result = drone.send_airdrop(carlos_req).expect("send airdrop test"); - assert!(carlos_result > 0); + let carlos_result = drone.send_airdrop(carlos_req); + assert!(carlos_result.is_ok()); let requests_socket = UdpSocket::bind("0.0.0.0:0").expect("drone bind to requests socket"); let transactions_socket = diff --git a/src/thin_client.rs b/src/thin_client.rs index 8f1665fa64..64bb251cc0 100644 --- a/src/thin_client.rs +++ b/src/thin_client.rs @@ -88,10 +88,11 @@ impl ThinClient { /// Send a signed Transaction to the server for processing. This method /// does not wait for a response. - pub fn transfer_signed(&self, tx: &Transaction) -> io::Result { + pub fn transfer_signed(&self, tx: &Transaction) -> io::Result { let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed"); self.transactions_socket - .send_to(&data, &self.transactions_addr) + .send_to(&data, &self.transactions_addr)?; + Ok(tx.sig) } /// Creates, signs, and processes a Transaction. Useful for writing unit-tests. @@ -104,8 +105,7 @@ impl ThinClient { ) -> io::Result { let now = Instant::now(); let tx = Transaction::new(keypair, to, n, *last_id); - let sig = tx.sig; - let result = self.transfer_signed(&tx).map(|_| sig); + let result = self.transfer_signed(&tx); metrics::submit( influxdb::Point::new("thinclient") .add_tag("op", influxdb::Value::String("transfer".to_string()))