Avoid RpcRequest
This commit is contained in:
parent
c498775a3d
commit
a35ebe1186
|
@ -47,7 +47,7 @@ impl GenericRpcClientRequest for MockRpcClientRequest {
|
||||||
let str = if self.url == "account_in_use" {
|
let str = if self.url == "account_in_use" {
|
||||||
"AccountInUse"
|
"AccountInUse"
|
||||||
} else if self.url == "bad_sig_status" {
|
} else if self.url == "bad_sig_status" {
|
||||||
"Nonexistent"
|
"SignatureNotFound"
|
||||||
} else {
|
} else {
|
||||||
"Confirmed"
|
"Confirmed"
|
||||||
};
|
};
|
||||||
|
|
|
@ -280,24 +280,26 @@ impl RpcClient {
|
||||||
debug!("get_transaction_count");
|
debug!("get_transaction_count");
|
||||||
|
|
||||||
let mut num_retries = 5;
|
let mut num_retries = 5;
|
||||||
loop {
|
while num_retries > 0 {
|
||||||
let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0);
|
let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0);
|
||||||
|
|
||||||
match response {
|
match response {
|
||||||
Ok(value) => {
|
Ok(value) => {
|
||||||
debug!("transaction_count response: {:?}", value);
|
debug!("transaction_count response: {:?}", value);
|
||||||
let transaction_count = value.as_u64().unwrap();
|
if let Some(transaction_count) = value.as_u64() {
|
||||||
return Ok(transaction_count);
|
return Ok(transaction_count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
debug!("transaction_count failed: {:?}", err);
|
debug!("transaction_count failed: {:?}", err);
|
||||||
num_retries -= 1;
|
|
||||||
if num_retries == 0 {
|
|
||||||
return Err(err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
num_retries -= 1;
|
||||||
}
|
}
|
||||||
|
Err(io::Error::new(
|
||||||
|
io::ErrorKind::Other,
|
||||||
|
"Unable to get transaction count, too many retries",
|
||||||
|
))?
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_recent_blockhash(&self) -> io::Result<Hash> {
|
pub fn get_recent_blockhash(&self) -> io::Result<Hash> {
|
||||||
|
@ -623,8 +625,8 @@ mod tests {
|
||||||
|
|
||||||
let rpc_client = RpcClient::new_mock("bad_sig_status".to_string());
|
let rpc_client = RpcClient::new_mock("bad_sig_status".to_string());
|
||||||
let signature = "bad_status";
|
let signature = "bad_status";
|
||||||
let status = rpc_client.get_signature_status(&signature);
|
let status = dbg!(rpc_client.get_signature_status(&signature));
|
||||||
assert!(status.is_err());
|
assert_eq!(status.unwrap(), RpcSignatureStatus::SignatureNotFound);
|
||||||
|
|
||||||
let rpc_client = RpcClient::new_mock("fails".to_string());
|
let rpc_client = RpcClient::new_mock("fails".to_string());
|
||||||
let signature = "bad_status_fmt";
|
let signature = "bad_status_fmt";
|
||||||
|
|
|
@ -7,7 +7,6 @@ use serde_json::json;
|
||||||
use solana_budget_api;
|
use solana_budget_api;
|
||||||
use solana_budget_api::budget_transaction::BudgetTransaction;
|
use solana_budget_api::budget_transaction::BudgetTransaction;
|
||||||
use solana_client::rpc_client::{get_rpc_request_str, RpcClient};
|
use solana_client::rpc_client::{get_rpc_request_str, RpcClient};
|
||||||
use solana_client::rpc_request::RpcRequest;
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use solana_drone::drone::request_airdrop_transaction;
|
use solana_drone::drone::request_airdrop_transaction;
|
||||||
use solana_drone::drone::DRONE_PORT;
|
use solana_drone::drone::DRONE_PORT;
|
||||||
|
@ -409,21 +408,18 @@ fn process_balance(config: &WalletConfig, rpc_client: &RpcClient) -> ProcessResu
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_confirm(rpc_client: &RpcClient, signature: Signature) -> ProcessResult {
|
fn process_confirm(rpc_client: &RpcClient, signature: Signature) -> ProcessResult {
|
||||||
let params = json!([format!("{}", signature)]);
|
match rpc_client.get_signature_status(&signature.to_string()) {
|
||||||
let confirmation = rpc_client
|
Ok(status) => {
|
||||||
.retry_make_rpc_request(&RpcRequest::ConfirmTransaction, Some(params), 5)?
|
if status == solana_client::rpc_signature_status::RpcSignatureStatus::Confirmed {
|
||||||
.as_bool();
|
|
||||||
match confirmation {
|
|
||||||
Some(b) => {
|
|
||||||
if b {
|
|
||||||
Ok("Confirmed".to_string())
|
Ok("Confirmed".to_string())
|
||||||
} else {
|
} else {
|
||||||
Ok("Not found".to_string())
|
Ok("Not found".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => Err(WalletError::RpcRequestError(
|
Err(err) => Err(WalletError::RpcRequestError(format!(
|
||||||
"Received result of an unexpected type".to_string(),
|
"Unable to confirm: {:?}",
|
||||||
))?,
|
err
|
||||||
|
)))?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,15 +624,8 @@ fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_get_transaction_count(rpc_client: &RpcClient) -> ProcessResult {
|
fn process_get_transaction_count(rpc_client: &RpcClient) -> ProcessResult {
|
||||||
let transaction_count = rpc_client
|
let transaction_count = rpc_client.get_transaction_count()?;
|
||||||
.retry_make_rpc_request(&RpcRequest::GetTransactionCount, None, 5)?
|
Ok(transaction_count.to_string())
|
||||||
.as_u64();
|
|
||||||
match transaction_count {
|
|
||||||
Some(count) => Ok(count.to_string()),
|
|
||||||
None => Err(WalletError::RpcRequestError(
|
|
||||||
"Received result of an unexpected type".to_string(),
|
|
||||||
))?,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_time_elapsed(
|
fn process_time_elapsed(
|
||||||
|
@ -1300,9 +1289,6 @@ mod tests {
|
||||||
let good_signature = Signature::new(&bs58::decode(SIGNATURE).into_vec().unwrap());
|
let good_signature = Signature::new(&bs58::decode(SIGNATURE).into_vec().unwrap());
|
||||||
config.command = WalletCommand::Confirm(good_signature);
|
config.command = WalletCommand::Confirm(good_signature);
|
||||||
assert_eq!(process_command(&config).unwrap(), "Confirmed");
|
assert_eq!(process_command(&config).unwrap(), "Confirmed");
|
||||||
let missing_signature = Signature::new(&bs58::decode("5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW").into_vec().unwrap());
|
|
||||||
config.command = WalletCommand::Confirm(missing_signature);
|
|
||||||
assert_eq!(process_command(&config).unwrap(), "Not found");
|
|
||||||
|
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
config.command = WalletCommand::ConfigureStakingAccount(None, Some(bob_pubkey));
|
config.command = WalletCommand::ConfigureStakingAccount(None, Some(bob_pubkey));
|
||||||
|
@ -1387,7 +1373,13 @@ mod tests {
|
||||||
let signature = process_command(&config);
|
let signature = process_command(&config);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
|
||||||
// Failture cases
|
// bad_sig_status cases
|
||||||
|
config.rpc_client = Some(RpcClient::new_mock("bad_sig_status".to_string()));
|
||||||
|
let missing_signature = Signature::new(&bs58::decode("5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmQpjKhoR4tjF3ZpRzrFmBV6UjKdiSZkQUW").into_vec().unwrap());
|
||||||
|
config.command = WalletCommand::Confirm(missing_signature);
|
||||||
|
assert_eq!(process_command(&config).unwrap(), "Not found");
|
||||||
|
|
||||||
|
// Failure cases
|
||||||
config.rpc_client = Some(RpcClient::new_mock("fails".to_string()));
|
config.rpc_client = Some(RpcClient::new_mock("fails".to_string()));
|
||||||
|
|
||||||
config.command = WalletCommand::Airdrop(50);
|
config.command = WalletCommand::Airdrop(50);
|
||||||
|
|
Loading…
Reference in New Issue