Return confirmation-status (#14709)
This commit is contained in:
@ -50,7 +50,9 @@ use solana_stake_program::{
|
|||||||
stake_instruction::LockupArgs,
|
stake_instruction::LockupArgs,
|
||||||
stake_state::{Lockup, StakeAuthorize},
|
stake_state::{Lockup, StakeAuthorize},
|
||||||
};
|
};
|
||||||
use solana_transaction_status::{EncodedTransaction, UiTransactionEncoding};
|
use solana_transaction_status::{
|
||||||
|
EncodedTransaction, TransactionConfirmationStatus, UiTransactionEncoding,
|
||||||
|
};
|
||||||
use solana_vote_program::vote_state::VoteAuthorize;
|
use solana_vote_program::vote_state::VoteAuthorize;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
@ -973,13 +975,9 @@ fn process_confirm(
|
|||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
signature: &Signature,
|
signature: &Signature,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
match rpc_client.get_signature_status_with_commitment_and_history(
|
match rpc_client.get_signature_statuses_with_history(&[*signature]) {
|
||||||
&signature,
|
|
||||||
CommitmentConfig::max(),
|
|
||||||
true,
|
|
||||||
) {
|
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if let Some(transaction_status) = status {
|
if let Some(transaction_status) = &status.value[0] {
|
||||||
if config.verbose {
|
if config.verbose {
|
||||||
match rpc_client
|
match rpc_client
|
||||||
.get_confirmed_transaction(signature, UiTransactionEncoding::Base64)
|
.get_confirmed_transaction(signature, UiTransactionEncoding::Base64)
|
||||||
@ -1000,15 +998,24 @@ fn process_confirm(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Unable to get confirmed transaction details: {}", err)
|
if transaction_status.confirmation_status()
|
||||||
|
!= TransactionConfirmationStatus::Finalized
|
||||||
|
{
|
||||||
|
println!();
|
||||||
|
println!("Unable to get finalized transaction details: not yet finalized")
|
||||||
|
} else {
|
||||||
|
println!();
|
||||||
|
println!("Unable to get finalized transaction details: {}", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!();
|
println!();
|
||||||
}
|
}
|
||||||
|
|
||||||
match transaction_status {
|
if let Some(err) = &transaction_status.err {
|
||||||
Ok(_) => Ok("Confirmed".to_string()),
|
Ok(format!("Transaction failed: {}", err))
|
||||||
Err(err) => Ok(format!("Transaction failed: {}", err)),
|
} else {
|
||||||
|
Ok(format!("{:?}", transaction_status.confirmation_status()))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Ok("Not found".to_string())
|
Ok("Not found".to_string())
|
||||||
@ -2436,7 +2443,10 @@ 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 = CliCommand::Confirm(good_signature);
|
config.command = CliCommand::Confirm(good_signature);
|
||||||
assert_eq!(process_command(&config).unwrap(), "Confirmed");
|
assert_eq!(
|
||||||
|
process_command(&config).unwrap(),
|
||||||
|
format!("{:?}", TransactionConfirmationStatus::Finalized)
|
||||||
|
);
|
||||||
|
|
||||||
let bob_keypair = Keypair::new();
|
let bob_keypair = Keypair::new();
|
||||||
let bob_pubkey = bob_keypair.pubkey();
|
let bob_pubkey = bob_keypair.pubkey();
|
||||||
|
@ -298,6 +298,23 @@ impl TransactionStatus {
|
|||||||
CommitmentLevel::Recent => true,
|
CommitmentLevel::Recent => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns `confirmation_status`, or if is_none, determines the status from confirmations.
|
||||||
|
// Facilitates querying nodes on older software
|
||||||
|
pub fn confirmation_status(&self) -> TransactionConfirmationStatus {
|
||||||
|
match &self.confirmation_status {
|
||||||
|
Some(status) => status.clone(),
|
||||||
|
None => {
|
||||||
|
if self.confirmations.is_none() {
|
||||||
|
TransactionConfirmationStatus::Finalized
|
||||||
|
} else if self.confirmations.unwrap() > 0 {
|
||||||
|
TransactionConfirmationStatus::Confirmed
|
||||||
|
} else {
|
||||||
|
TransactionConfirmationStatus::Processed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
Reference in New Issue
Block a user