Update RPC requestAirdrop endpoint to return airdrop tx signature
This commit is contained in:
committed by
Greg Fitzgerald
parent
513a934ff6
commit
e308a4279e
20
src/rpc.rs
20
src/rpc.rs
@@ -104,7 +104,7 @@ build_rpc_trait! {
|
|||||||
fn get_transaction_count(&self, Self::Metadata) -> Result<u64>;
|
fn get_transaction_count(&self, Self::Metadata) -> Result<u64>;
|
||||||
|
|
||||||
#[rpc(meta, name= "requestAirdrop")]
|
#[rpc(meta, name= "requestAirdrop")]
|
||||||
fn request_airdrop(&self, Self::Metadata, String, u64) -> Result<bool>;
|
fn request_airdrop(&self, Self::Metadata, String, u64) -> Result<String>;
|
||||||
|
|
||||||
#[rpc(meta, name = "sendTransaction")]
|
#[rpc(meta, name = "sendTransaction")]
|
||||||
fn send_transaction(&self, Self::Metadata, Vec<u8>) -> Result<String>;
|
fn send_transaction(&self, Self::Metadata, Vec<u8>) -> Result<String>;
|
||||||
@@ -144,7 +144,7 @@ impl RpcSol for RpcSolImpl {
|
|||||||
fn get_transaction_count(&self, meta: Self::Metadata) -> Result<u64> {
|
fn get_transaction_count(&self, meta: Self::Metadata) -> Result<u64> {
|
||||||
meta.request_processor.get_transaction_count()
|
meta.request_processor.get_transaction_count()
|
||||||
}
|
}
|
||||||
fn request_airdrop(&self, meta: Self::Metadata, id: String, tokens: u64) -> Result<bool> {
|
fn request_airdrop(&self, meta: Self::Metadata, id: String, tokens: u64) -> Result<String> {
|
||||||
let pubkey_vec = bs58::decode(id)
|
let pubkey_vec = bs58::decode(id)
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.map_err(|_| Error::invalid_request())?;
|
.map_err(|_| Error::invalid_request())?;
|
||||||
@@ -152,20 +152,18 @@ impl RpcSol for RpcSolImpl {
|
|||||||
return Err(Error::invalid_request());
|
return Err(Error::invalid_request());
|
||||||
}
|
}
|
||||||
let pubkey = Pubkey::new(&pubkey_vec);
|
let pubkey = Pubkey::new(&pubkey_vec);
|
||||||
let previous_balance = meta
|
let signature = request_airdrop(&meta.drone_addr, &pubkey, tokens)
|
||||||
.request_processor
|
|
||||||
.get_balance(pubkey)
|
|
||||||
.map_err(|_| Error::internal_error())?;
|
.map_err(|_| Error::internal_error())?;
|
||||||
request_airdrop(&meta.drone_addr, &pubkey, tokens).map_err(|_| Error::internal_error())?;
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let mut balance;
|
let mut signature_status;
|
||||||
loop {
|
loop {
|
||||||
balance = meta
|
signature_status = meta
|
||||||
.request_processor
|
.request_processor
|
||||||
.get_balance(pubkey)
|
.get_signature_status(signature)
|
||||||
.map_err(|_| Error::internal_error())?;
|
.map_err(|_| Error::internal_error())?;
|
||||||
if balance > previous_balance {
|
|
||||||
return Ok(true);
|
if signature_status {
|
||||||
|
return Ok(bs58::encode(signature).into_string());
|
||||||
} else if now.elapsed().as_secs() > 5 {
|
} else if now.elapsed().as_secs() > 5 {
|
||||||
return Err(Error::internal_error());
|
return Err(Error::internal_error());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user