Update drone to allow TPS-sized airdrops
This commit is contained in:
parent
4701540cc9
commit
96c321da76
|
@ -321,6 +321,7 @@ fn request_airdrop(
|
||||||
let req = DroneRequest::GetAirdrop {
|
let req = DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount: tokens,
|
airdrop_request_amount: tokens,
|
||||||
client_public_key: id.pubkey(),
|
client_public_key: id.pubkey(),
|
||||||
|
tps_demo: false,
|
||||||
};
|
};
|
||||||
let tx = serialize(&req).expect("serialize drone request");
|
let tx = serialize(&req).expect("serialize drone request");
|
||||||
stream.write_all(&tx).unwrap();
|
stream.write_all(&tx).unwrap();
|
||||||
|
|
10
src/drone.rs
10
src/drone.rs
|
@ -20,6 +20,7 @@ pub enum DroneRequest {
|
||||||
GetAirdrop {
|
GetAirdrop {
|
||||||
airdrop_request_amount: u64,
|
airdrop_request_amount: u64,
|
||||||
client_public_key: PublicKey,
|
client_public_key: PublicKey,
|
||||||
|
tps_demo: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +33,7 @@ pub struct Drone {
|
||||||
pub time_slice: Duration,
|
pub time_slice: Duration,
|
||||||
request_cap: u64,
|
request_cap: u64,
|
||||||
pub request_current: u64,
|
pub request_current: u64,
|
||||||
|
pub tps_request_current: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drone {
|
impl Drone {
|
||||||
|
@ -60,6 +62,7 @@ impl Drone {
|
||||||
time_slice,
|
time_slice,
|
||||||
request_cap,
|
request_cap,
|
||||||
request_current: 0,
|
request_current: 0,
|
||||||
|
tps_request_current: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,6 +72,7 @@ impl Drone {
|
||||||
|
|
||||||
pub fn clear_request_count(&mut self) {
|
pub fn clear_request_count(&mut self) {
|
||||||
self.request_current = 0;
|
self.request_current = 0;
|
||||||
|
self.tps_request_current = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_ip_to_cache(&mut self, ip: IpAddr) {
|
pub fn add_ip_to_cache(&mut self, ip: IpAddr) {
|
||||||
|
@ -104,11 +108,13 @@ impl Drone {
|
||||||
transactions_socket,
|
transactions_socket,
|
||||||
);
|
);
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
|
let tps_check: bool;
|
||||||
|
|
||||||
match req {
|
match req {
|
||||||
DroneRequest::GetAirdrop {
|
DroneRequest::GetAirdrop {
|
||||||
airdrop_request_amount,
|
airdrop_request_amount,
|
||||||
client_public_key,
|
client_public_key,
|
||||||
|
tps_demo,
|
||||||
} => {
|
} => {
|
||||||
request_amount = airdrop_request_amount.clone();
|
request_amount = airdrop_request_amount.clone();
|
||||||
tx = Transaction::new(
|
tx = Transaction::new(
|
||||||
|
@ -117,11 +123,15 @@ impl Drone {
|
||||||
airdrop_request_amount as i64,
|
airdrop_request_amount as i64,
|
||||||
last_id,
|
last_id,
|
||||||
);
|
);
|
||||||
|
tps_check = tps_demo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if self.check_request_limit(request_amount) {
|
if self.check_request_limit(request_amount) {
|
||||||
self.request_current += request_amount;
|
self.request_current += request_amount;
|
||||||
client.transfer_signed(tx)
|
client.transfer_signed(tx)
|
||||||
|
} else if tps_check && !self.tps_request_current {
|
||||||
|
self.tps_request_current = true;
|
||||||
|
client.transfer_signed(tx)
|
||||||
} else {
|
} else {
|
||||||
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
Err(Error::new(ErrorKind::Other, "token limit reached"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue