retry transfer and poll

This commit is contained in:
Anatoly Yakovenko 2018-08-26 15:58:22 -07:00 committed by Grimes
parent 90ae662e4d
commit a002148098
2 changed files with 22 additions and 1 deletions

View File

@ -141,7 +141,7 @@ impl Drone {
) )
.to_owned(), .to_owned(),
); );
client.transfer_signed(&tx) client.retry_transfer_signed(&tx, 10)
} else { } else {
Err(Error::new(ErrorKind::Other, "token limit reached")) Err(Error::new(ErrorKind::Other, "token limit reached"))
} }

View File

@ -114,6 +114,27 @@ impl ThinClient {
Ok(tx.signature) Ok(tx.signature)
} }
/// Retry a sending a signed Transaction to the server for processing.
pub fn retry_transfer_signed(
&mut self,
tx: &Transaction,
tries: usize,
) -> io::Result<Signature> {
let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed");
for x in 0..tries {
self.transactions_socket
.send_to(&data, &self.transactions_addr)?;
if self.poll_for_signature(&tx.signature).is_ok() {
return Ok(tx.signature);
}
info!("{} tries failed transfer to {}", x, self.transactions_addr);
}
Err(io::Error::new(
io::ErrorKind::Other,
"retry_transfer_signed failed",
))
}
/// Creates, signs, and processes a Transaction. Useful for writing unit-tests. /// Creates, signs, and processes a Transaction. Useful for writing unit-tests.
pub fn transfer( pub fn transfer(
&self, &self,