Skip to content

Commit

Permalink
Use balance to verify requestAirdrop success
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 22, 2018
1 parent 4946fcf commit 6053d4e
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use std::mem;
use std::net::{SocketAddr, UdpSocket};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::thread::{self, Builder, JoinHandle};
use std::thread::{self, sleep, Builder, JoinHandle};
use std::time::Duration;
use std::time::Instant;
use transaction::Transaction;
use wallet::request_airdrop;

Expand Down Expand Up @@ -150,9 +152,25 @@ impl RpcSol for RpcSolImpl {
return Err(Error::invalid_request());
}
let pubkey = Pubkey::new(&pubkey_vec);
request_airdrop(&meta.drone_addr, &pubkey, tokens)
let previous_balance = meta
.request_processor
.get_balance(pubkey)
.map_err(|_| Error::internal_error())?;
Ok(true)
request_airdrop(&meta.drone_addr, &pubkey, tokens).map_err(|_| Error::internal_error())?;
let now = Instant::now();
let mut balance;
loop {
balance = meta
.request_processor
.get_balance(pubkey)
.map_err(|_| Error::internal_error())?;
if balance > previous_balance {
return Ok(true);
} else if now.elapsed().as_secs() > 5 {
return Err(Error::internal_error());
}
sleep(Duration::from_millis(100));
}
}
fn send_transaction(&self, meta: Self::Metadata, data: Vec<u8>) -> Result<String> {
let tx: Transaction = deserialize(&data).map_err(|_| Error::invalid_request())?;
Expand Down

0 comments on commit 6053d4e

Please sign in to comment.