diff --git a/client/src/mock_rpc_client_request.rs b/client/src/mock_rpc_client_request.rs index fa119b92e..f0b0c8708 100644 --- a/client/src/mock_rpc_client_request.rs +++ b/client/src/mock_rpc_client_request.rs @@ -47,7 +47,7 @@ impl GenericRpcClientRequest for MockRpcClientRequest { let str = if self.url == "account_in_use" { "AccountInUse" } else if self.url == "bad_sig_status" { - "Nonexistent" + "SignatureNotFound" } else { "Confirmed" }; diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 9677dfb9f..673216cd1 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -280,24 +280,26 @@ impl RpcClient { debug!("get_transaction_count"); let mut num_retries = 5; - loop { + while num_retries > 0 { let response = self.client.send(&RpcRequest::GetTransactionCount, None, 0); match response { Ok(value) => { debug!("transaction_count response: {:?}", value); - let transaction_count = value.as_u64().unwrap(); - return Ok(transaction_count); + if let Some(transaction_count) = value.as_u64() { + return Ok(transaction_count); + } } Err(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 { @@ -623,8 +625,8 @@ mod tests { let rpc_client = RpcClient::new_mock("bad_sig_status".to_string()); let signature = "bad_status"; - let status = rpc_client.get_signature_status(&signature); - assert!(status.is_err()); + let status = dbg!(rpc_client.get_signature_status(&signature)); + assert_eq!(status.unwrap(), RpcSignatureStatus::SignatureNotFound); let rpc_client = RpcClient::new_mock("fails".to_string()); let signature = "bad_status_fmt"; diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 8cfa2bc92..3f6b9ac50 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -7,7 +7,6 @@ use serde_json::json; use solana_budget_api; use solana_budget_api::budget_transaction::BudgetTransaction; use solana_client::rpc_client::{get_rpc_request_str, RpcClient}; -use solana_client::rpc_request::RpcRequest; #[cfg(not(test))] use solana_drone::drone::request_airdrop_transaction; 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 { - let params = json!([format!("{}", signature)]); - let confirmation = rpc_client - .retry_make_rpc_request(&RpcRequest::ConfirmTransaction, Some(params), 5)? - .as_bool(); - match confirmation { - Some(b) => { - if b { + match rpc_client.get_signature_status(&signature.to_string()) { + Ok(status) => { + if status == solana_client::rpc_signature_status::RpcSignatureStatus::Confirmed { Ok("Confirmed".to_string()) } else { Ok("Not found".to_string()) } } - None => Err(WalletError::RpcRequestError( - "Received result of an unexpected type".to_string(), - ))?, + Err(err) => Err(WalletError::RpcRequestError(format!( + "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 { - let transaction_count = rpc_client - .retry_make_rpc_request(&RpcRequest::GetTransactionCount, None, 5)? - .as_u64(); - match transaction_count { - Some(count) => Ok(count.to_string()), - None => Err(WalletError::RpcRequestError( - "Received result of an unexpected type".to_string(), - ))?, - } + let transaction_count = rpc_client.get_transaction_count()?; + Ok(transaction_count.to_string()) } fn process_time_elapsed( @@ -1300,9 +1289,6 @@ mod tests { let good_signature = Signature::new(&bs58::decode(SIGNATURE).into_vec().unwrap()); config.command = WalletCommand::Confirm(good_signature); 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(); config.command = WalletCommand::ConfigureStakingAccount(None, Some(bob_pubkey)); @@ -1387,7 +1373,13 @@ mod tests { let signature = process_command(&config); 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.command = WalletCommand::Airdrop(50);