Skip to content

Commit

Permalink
Abort nicer on drone connection failure
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jul 2, 2018
1 parent 70a3f0b commit b8b3c73
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn process_command(
WalletCommand::AirDrop(tokens) => {
println!("Airdrop requested...");
println!("Airdropping {:?} tokens", tokens);
let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64);
let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64)?;
// TODO: return airdrop Result from Drone
sleep(Duration::from_millis(100));
println!(
Expand Down Expand Up @@ -313,15 +313,20 @@ fn mk_client(r: &ReplicatedData) -> io::Result<ThinClient> {
))
}

fn request_airdrop(drone_addr: &SocketAddr, id: &Mint, tokens: u64) {
let mut stream = TcpStream::connect(drone_addr).unwrap();
fn request_airdrop(
drone_addr: &SocketAddr,
id: &Mint,
tokens: u64,
) -> Result<(), Box<error::Error>> {
let mut stream = TcpStream::connect(drone_addr)?;
let req = DroneRequest::GetAirdrop {
airdrop_request_amount: tokens,
client_public_key: id.pubkey(),
};
let tx = serialize(&req).expect("serialize drone request");
stream.write_all(&tx).unwrap();
// TODO: add timeout to this function, in case of unresponsive drone
Ok(())
}

fn main() -> Result<(), Box<error::Error>> {
Expand Down

0 comments on commit b8b3c73

Please sign in to comment.