Return Signature from transfer_signed and send_airdrop
This commit is contained in:
parent
6a8379109d
commit
c068ca4cb7
11
src/drone.rs
11
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<usize, io::Error> {
|
||||
pub fn send_airdrop(&mut self, req: DroneRequest) -> Result<Signature, io::Error> {
|
||||
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 =
|
||||
|
|
|
@ -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<usize> {
|
||||
pub fn transfer_signed(&self, tx: &Transaction) -> io::Result<Signature> {
|
||||
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<Signature> {
|
||||
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()))
|
||||
|
|
Loading…
Reference in New Issue