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 influx_db_client as influxdb;
|
||||||
use metrics;
|
use metrics;
|
||||||
|
use signature::Signature;
|
||||||
use signature::{KeyPair, PublicKey};
|
use signature::{KeyPair, PublicKey};
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Error, ErrorKind};
|
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 tx: Transaction;
|
||||||
let request_amount: u64;
|
let request_amount: u64;
|
||||||
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let requests_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
|
@ -302,15 +303,15 @@ mod tests {
|
||||||
airdrop_request_amount: 50,
|
airdrop_request_amount: 50,
|
||||||
client_public_key: bob_pubkey,
|
client_public_key: bob_pubkey,
|
||||||
};
|
};
|
||||||
let bob_result = drone.send_airdrop(bob_req).expect("send airdrop test");
|
let bob_result = drone.send_airdrop(bob_req);
|
||||||
assert!(bob_result > 0);
|
assert!(bob_result.is_ok());
|
||||||
|
|
||||||
let carlos_req = DroneRequest::GetAirdrop {
|
let carlos_req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: 5_000_000,
|
airdrop_request_amount: 5_000_000,
|
||||||
client_public_key: carlos_pubkey,
|
client_public_key: carlos_pubkey,
|
||||||
};
|
};
|
||||||
let carlos_result = drone.send_airdrop(carlos_req).expect("send airdrop test");
|
let carlos_result = drone.send_airdrop(carlos_req);
|
||||||
assert!(carlos_result > 0);
|
assert!(carlos_result.is_ok());
|
||||||
|
|
||||||
let requests_socket = UdpSocket::bind("0.0.0.0:0").expect("drone bind to requests socket");
|
let requests_socket = UdpSocket::bind("0.0.0.0:0").expect("drone bind to requests socket");
|
||||||
let transactions_socket =
|
let transactions_socket =
|
||||||
|
|
|
@ -88,10 +88,11 @@ impl ThinClient {
|
||||||
|
|
||||||
/// Send a signed Transaction to the server for processing. This method
|
/// Send a signed Transaction to the server for processing. This method
|
||||||
/// does not wait for a response.
|
/// 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");
|
let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed");
|
||||||
self.transactions_socket
|
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.
|
/// Creates, signs, and processes a Transaction. Useful for writing unit-tests.
|
||||||
|
@ -104,8 +105,7 @@ impl ThinClient {
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let tx = Transaction::new(keypair, to, n, *last_id);
|
let tx = Transaction::new(keypair, to, n, *last_id);
|
||||||
let sig = tx.sig;
|
let result = self.transfer_signed(&tx);
|
||||||
let result = self.transfer_signed(&tx).map(|_| sig);
|
|
||||||
metrics::submit(
|
metrics::submit(
|
||||||
influxdb::Point::new("thinclient")
|
influxdb::Point::new("thinclient")
|
||||||
.add_tag("op", influxdb::Value::String("transfer".to_string()))
|
.add_tag("op", influxdb::Value::String("transfer".to_string()))
|
||||||
|
|
Loading…
Reference in New Issue