Move commitment to CliConfig to enable faster integration tests (#10627)
* Add commitment config to CliConfig * Use config.commitment in cluster_query * Use config.commitment in vote * Add method with spinner + commitment * Add send-transaction config to CliConfig * Remove superfluous nonce check * Add with_commitment helper fns * Update src to use commitment * Fix pay and transfer integration tests * Fix nonce int tests * Fix deploy int test * Fix vote int test * Fix stake int tests * Nightly clippy * Review comments
This commit is contained in:
parent
dac7dc2f10
commit
7a741bb79a
|
@ -4,7 +4,8 @@ use solana_client::{
|
||||||
rpc_client::RpcClient,
|
rpc_client::RpcClient,
|
||||||
};
|
};
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
fee_calculator::FeeCalculator, message::Message, native_token::lamports_to_sol, pubkey::Pubkey,
|
commitment_config::CommitmentConfig, fee_calculator::FeeCalculator, message::Message,
|
||||||
|
native_token::lamports_to_sol, pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn check_account_for_fee(
|
pub fn check_account_for_fee(
|
||||||
|
@ -16,14 +17,46 @@ pub fn check_account_for_fee(
|
||||||
check_account_for_multiple_fees(rpc_client, account_pubkey, fee_calculator, &[message])
|
check_account_for_multiple_fees(rpc_client, account_pubkey, fee_calculator, &[message])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_account_for_fee_with_commitment(
|
||||||
|
rpc_client: &RpcClient,
|
||||||
|
account_pubkey: &Pubkey,
|
||||||
|
fee_calculator: &FeeCalculator,
|
||||||
|
message: &Message,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
|
) -> Result<(), CliError> {
|
||||||
|
check_account_for_multiple_fees_with_commitment(
|
||||||
|
rpc_client,
|
||||||
|
account_pubkey,
|
||||||
|
fee_calculator,
|
||||||
|
&[message],
|
||||||
|
commitment,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check_account_for_multiple_fees(
|
pub fn check_account_for_multiple_fees(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
account_pubkey: &Pubkey,
|
account_pubkey: &Pubkey,
|
||||||
fee_calculator: &FeeCalculator,
|
fee_calculator: &FeeCalculator,
|
||||||
messages: &[&Message],
|
messages: &[&Message],
|
||||||
|
) -> Result<(), CliError> {
|
||||||
|
check_account_for_multiple_fees_with_commitment(
|
||||||
|
rpc_client,
|
||||||
|
account_pubkey,
|
||||||
|
fee_calculator,
|
||||||
|
messages,
|
||||||
|
CommitmentConfig::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_account_for_multiple_fees_with_commitment(
|
||||||
|
rpc_client: &RpcClient,
|
||||||
|
account_pubkey: &Pubkey,
|
||||||
|
fee_calculator: &FeeCalculator,
|
||||||
|
messages: &[&Message],
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<(), CliError> {
|
) -> Result<(), CliError> {
|
||||||
let fee = calculate_fee(fee_calculator, messages);
|
let fee = calculate_fee(fee_calculator, messages);
|
||||||
if !check_account_for_balance(rpc_client, account_pubkey, fee)
|
if !check_account_for_balance_with_commitment(rpc_client, account_pubkey, fee, commitment)
|
||||||
.map_err(Into::<ClientError>::into)?
|
.map_err(Into::<ClientError>::into)?
|
||||||
{
|
{
|
||||||
return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee)));
|
return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee)));
|
||||||
|
@ -43,7 +76,23 @@ pub fn check_account_for_balance(
|
||||||
account_pubkey: &Pubkey,
|
account_pubkey: &Pubkey,
|
||||||
balance: u64,
|
balance: u64,
|
||||||
) -> ClientResult<bool> {
|
) -> ClientResult<bool> {
|
||||||
let lamports = rpc_client.get_balance(account_pubkey)?;
|
check_account_for_balance_with_commitment(
|
||||||
|
rpc_client,
|
||||||
|
account_pubkey,
|
||||||
|
balance,
|
||||||
|
CommitmentConfig::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn check_account_for_balance_with_commitment(
|
||||||
|
rpc_client: &RpcClient,
|
||||||
|
account_pubkey: &Pubkey,
|
||||||
|
balance: u64,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
|
) -> ClientResult<bool> {
|
||||||
|
let lamports = rpc_client
|
||||||
|
.get_balance_with_commitment(account_pubkey, commitment)?
|
||||||
|
.value;
|
||||||
if lamports != 0 && lamports >= balance {
|
if lamports != 0 && lamports >= balance {
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|
255
cli/src/cli.rs
255
cli/src/cli.rs
|
@ -17,12 +17,8 @@ use num_traits::FromPrimitive;
|
||||||
use serde_json::{self, json, Value};
|
use serde_json::{self, json, Value};
|
||||||
use solana_budget_program::budget_instruction::{self, BudgetError};
|
use solana_budget_program::budget_instruction::{self, BudgetError};
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{
|
||||||
commitment::{commitment_arg_with_default, COMMITMENT_ARG},
|
commitment::commitment_arg_with_default, input_parsers::*, input_validators::*,
|
||||||
input_parsers::*,
|
keypair::signer_from_path, offline::SIGN_ONLY_ARG, ArgConstant,
|
||||||
input_validators::*,
|
|
||||||
keypair::signer_from_path,
|
|
||||||
offline::SIGN_ONLY_ARG,
|
|
||||||
ArgConstant,
|
|
||||||
};
|
};
|
||||||
use solana_client::{
|
use solana_client::{
|
||||||
client_error::{ClientError, ClientErrorKind, Result as ClientResult},
|
client_error::{ClientError, ClientErrorKind, Result as ClientResult},
|
||||||
|
@ -183,7 +179,6 @@ pub enum CliCommand {
|
||||||
Catchup {
|
Catchup {
|
||||||
node_pubkey: Pubkey,
|
node_pubkey: Pubkey,
|
||||||
node_json_rpc_url: Option<String>,
|
node_json_rpc_url: Option<String>,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
follow: bool,
|
follow: bool,
|
||||||
},
|
},
|
||||||
ClusterDate,
|
ClusterDate,
|
||||||
|
@ -197,30 +192,14 @@ pub enum CliCommand {
|
||||||
GetBlockTime {
|
GetBlockTime {
|
||||||
slot: Option<Slot>,
|
slot: Option<Slot>,
|
||||||
},
|
},
|
||||||
GetEpochInfo {
|
GetEpoch,
|
||||||
commitment_config: CommitmentConfig,
|
GetEpochInfo,
|
||||||
},
|
|
||||||
GetGenesisHash,
|
GetGenesisHash,
|
||||||
GetEpoch {
|
GetSlot,
|
||||||
commitment_config: CommitmentConfig,
|
GetTransactionCount,
|
||||||
},
|
|
||||||
GetSlot {
|
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
|
||||||
LargestAccounts {
|
LargestAccounts {
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
filter: Option<RpcLargestAccountsFilter>,
|
filter: Option<RpcLargestAccountsFilter>,
|
||||||
},
|
},
|
||||||
Supply {
|
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
print_accounts: bool,
|
|
||||||
},
|
|
||||||
TotalSupply {
|
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
|
||||||
GetTransactionCount {
|
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
|
||||||
LeaderSchedule,
|
LeaderSchedule,
|
||||||
LiveSlots,
|
LiveSlots,
|
||||||
Ping {
|
Ping {
|
||||||
|
@ -228,7 +207,6 @@ pub enum CliCommand {
|
||||||
interval: Duration,
|
interval: Duration,
|
||||||
count: Option<u64>,
|
count: Option<u64>,
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
},
|
||||||
ShowBlockProduction {
|
ShowBlockProduction {
|
||||||
epoch: Option<Epoch>,
|
epoch: Option<Epoch>,
|
||||||
|
@ -241,8 +219,11 @@ pub enum CliCommand {
|
||||||
},
|
},
|
||||||
ShowValidators {
|
ShowValidators {
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
},
|
||||||
|
Supply {
|
||||||
|
print_accounts: bool,
|
||||||
|
},
|
||||||
|
TotalSupply,
|
||||||
TransactionHistory {
|
TransactionHistory {
|
||||||
address: Pubkey,
|
address: Pubkey,
|
||||||
end_slot: Option<Slot>, // None == latest slot
|
end_slot: Option<Slot>, // None == latest slot
|
||||||
|
@ -393,7 +374,6 @@ pub enum CliCommand {
|
||||||
ShowVoteAccount {
|
ShowVoteAccount {
|
||||||
pubkey: Pubkey,
|
pubkey: Pubkey,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
},
|
||||||
WithdrawFromVoteAccount {
|
WithdrawFromVoteAccount {
|
||||||
vote_account_pubkey: Pubkey,
|
vote_account_pubkey: Pubkey,
|
||||||
|
@ -425,7 +405,6 @@ pub enum CliCommand {
|
||||||
Balance {
|
Balance {
|
||||||
pubkey: Option<Pubkey>,
|
pubkey: Option<Pubkey>,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
},
|
},
|
||||||
Cancel(Pubkey),
|
Cancel(Pubkey),
|
||||||
Confirm(Signature),
|
Confirm(Signature),
|
||||||
|
@ -512,6 +491,8 @@ pub struct CliConfig<'a> {
|
||||||
pub rpc_client: Option<RpcClient>,
|
pub rpc_client: Option<RpcClient>,
|
||||||
pub verbose: bool,
|
pub verbose: bool,
|
||||||
pub output_format: OutputFormat,
|
pub output_format: OutputFormat,
|
||||||
|
pub commitment: CommitmentConfig,
|
||||||
|
pub send_transaction_config: RpcSendTransactionConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CliConfig<'_> {
|
impl CliConfig<'_> {
|
||||||
|
@ -588,6 +569,15 @@ impl CliConfig<'_> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn recent_for_tests() -> Self {
|
||||||
|
let mut config = Self::default();
|
||||||
|
config.commitment = CommitmentConfig::recent();
|
||||||
|
config.send_transaction_config = RpcSendTransactionConfig {
|
||||||
|
skip_preflight: true,
|
||||||
|
};
|
||||||
|
config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CliConfig<'_> {
|
impl Default for CliConfig<'_> {
|
||||||
|
@ -596,7 +586,6 @@ impl Default for CliConfig<'_> {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(Pubkey::default()),
|
pubkey: Some(Pubkey::default()),
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
},
|
},
|
||||||
json_rpc_url: Self::default_json_rpc_url(),
|
json_rpc_url: Self::default_json_rpc_url(),
|
||||||
websocket_url: Self::default_websocket_url(),
|
websocket_url: Self::default_websocket_url(),
|
||||||
|
@ -605,6 +594,8 @@ impl Default for CliConfig<'_> {
|
||||||
rpc_client: None,
|
rpc_client: None,
|
||||||
verbose: false,
|
verbose: false,
|
||||||
output_format: OutputFormat::Display,
|
output_format: OutputFormat::Display,
|
||||||
|
commitment: CommitmentConfig::default(),
|
||||||
|
send_transaction_config: RpcSendTransactionConfig::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -810,7 +801,6 @@ pub fn parse_command(
|
||||||
}
|
}
|
||||||
("balance", Some(matches)) => {
|
("balance", Some(matches)) => {
|
||||||
let pubkey = pubkey_of_signer(matches, "pubkey", wallet_manager)?;
|
let pubkey = pubkey_of_signer(matches, "pubkey", wallet_manager)?;
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
let signers = if pubkey.is_some() {
|
let signers = if pubkey.is_some() {
|
||||||
vec![]
|
vec![]
|
||||||
} else {
|
} else {
|
||||||
|
@ -825,7 +815,6 @@ pub fn parse_command(
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey,
|
pubkey,
|
||||||
use_lamports_unit: matches.is_present("lamports"),
|
use_lamports_unit: matches.is_present("lamports"),
|
||||||
commitment_config,
|
|
||||||
},
|
},
|
||||||
signers,
|
signers,
|
||||||
})
|
})
|
||||||
|
@ -1154,7 +1143,6 @@ fn process_balance(
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
pubkey: &Option<Pubkey>,
|
pubkey: &Option<Pubkey>,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let pubkey = if let Some(pubkey) = pubkey {
|
let pubkey = if let Some(pubkey) = pubkey {
|
||||||
*pubkey
|
*pubkey
|
||||||
|
@ -1162,7 +1150,7 @@ fn process_balance(
|
||||||
config.pubkey()?
|
config.pubkey()?
|
||||||
};
|
};
|
||||||
let balance = rpc_client
|
let balance = rpc_client
|
||||||
.get_balance_with_commitment(&pubkey, commitment_config)?
|
.get_balance_with_commitment(&pubkey, config.commitment)?
|
||||||
.value;
|
.value;
|
||||||
Ok(build_balance_message(balance, use_lamports_unit, true))
|
Ok(build_balance_message(balance, use_lamports_unit, true))
|
||||||
}
|
}
|
||||||
|
@ -1375,7 +1363,9 @@ fn process_deploy(
|
||||||
|
|
||||||
// Build transactions to calculate fees
|
// Build transactions to calculate fees
|
||||||
let mut messages: Vec<&Message> = Vec::new();
|
let mut messages: Vec<&Message> = Vec::new();
|
||||||
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(program_data.len())?;
|
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(program_data.len())?;
|
||||||
let ix = system_instruction::create_account(
|
let ix = system_instruction::create_account(
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
|
@ -1412,15 +1402,20 @@ fn process_deploy(
|
||||||
finalize_tx.try_sign(&signers, blockhash)?;
|
finalize_tx.try_sign(&signers, blockhash)?;
|
||||||
messages.push(&finalize_tx.message);
|
messages.push(&finalize_tx.message);
|
||||||
|
|
||||||
check_account_for_multiple_fees(
|
check_account_for_multiple_fees_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&messages,
|
&messages,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
trace!("Creating program account");
|
trace!("Creating program account");
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&create_account_tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&create_account_tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config).map_err(|_| {
|
log_instruction_custom_error::<SystemError>(result, &config).map_err(|_| {
|
||||||
CliError::DynamicProgramError("Program account allocation failed".to_string())
|
CliError::DynamicProgramError("Program account allocation failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
@ -1434,6 +1429,7 @@ fn process_deploy(
|
||||||
rpc_client
|
rpc_client
|
||||||
.send_and_confirm_transaction_with_spinner_and_config(
|
.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
&finalize_tx,
|
&finalize_tx,
|
||||||
|
config.commitment,
|
||||||
RpcSendTransactionConfig {
|
RpcSendTransactionConfig {
|
||||||
skip_preflight: true,
|
skip_preflight: true,
|
||||||
},
|
},
|
||||||
|
@ -1469,7 +1465,7 @@ fn process_pay(
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let (blockhash, fee_calculator) =
|
let (blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let cancelable = if cancelable {
|
let cancelable = if cancelable {
|
||||||
Some(config.signers[0].pubkey())
|
Some(config.signers[0].pubkey())
|
||||||
|
@ -1495,6 +1491,7 @@ fn process_pay(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
|
@ -1503,12 +1500,20 @@ fn process_pay(
|
||||||
return_signers(&tx, &config)
|
return_signers(&tx, &config)
|
||||||
} else {
|
} else {
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account = nonce::get_account_with_commitment(
|
||||||
|
rpc_client,
|
||||||
|
nonce_account,
|
||||||
|
config.commitment,
|
||||||
|
)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &blockhash)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
} else if *witnesses == None {
|
} else if *witnesses == None {
|
||||||
|
@ -1540,6 +1545,7 @@ fn process_pay(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
if sign_only {
|
if sign_only {
|
||||||
|
@ -1547,7 +1553,11 @@ fn process_pay(
|
||||||
return_signers(&tx, &config)
|
return_signers(&tx, &config)
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&[config.signers[0], &contract_state], blockhash)?;
|
tx.try_sign(&[config.signers[0], &contract_state], blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
let signature = log_instruction_custom_error::<BudgetError>(result, &config)?;
|
let signature = log_instruction_custom_error::<BudgetError>(result, &config)?;
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"signature": signature,
|
"signature": signature,
|
||||||
|
@ -1586,6 +1596,7 @@ fn process_pay(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
if sign_only {
|
if sign_only {
|
||||||
|
@ -1593,7 +1604,11 @@ fn process_pay(
|
||||||
return_signers(&tx, &config)
|
return_signers(&tx, &config)
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&[config.signers[0], &contract_state], blockhash)?;
|
tx.try_sign(&[config.signers[0], &contract_state], blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
let signature = log_instruction_custom_error::<BudgetError>(result, &config)?;
|
let signature = log_instruction_custom_error::<BudgetError>(result, &config)?;
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"signature": signature,
|
"signature": signature,
|
||||||
|
@ -1607,7 +1622,9 @@ fn process_pay(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -> ProcessResult {
|
fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -> ProcessResult {
|
||||||
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let ix = budget_instruction::apply_signature(
|
let ix = budget_instruction::apply_signature(
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
pubkey,
|
pubkey,
|
||||||
|
@ -1616,13 +1633,18 @@ fn process_cancel(rpc_client: &RpcClient, config: &CliConfig, pubkey: &Pubkey) -
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix]);
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<BudgetError>(result, &config)
|
log_instruction_custom_error::<BudgetError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1633,19 +1655,26 @@ fn process_time_elapsed(
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
|
|
||||||
let ix = budget_instruction::apply_timestamp(&config.signers[0].pubkey(), pubkey, to, dt);
|
let ix = budget_instruction::apply_timestamp(&config.signers[0].pubkey(), pubkey, to, dt);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix]);
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<BudgetError>(result, &config)
|
log_instruction_custom_error::<BudgetError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1666,7 +1695,7 @@ fn process_transfer(
|
||||||
let from = config.signers[from];
|
let from = config.signers[from];
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let fee_payer = config.signers[fee_payer];
|
let fee_payer = config.signers[fee_payer];
|
||||||
|
@ -1694,6 +1723,7 @@ fn process_transfer(
|
||||||
&from.pubkey(),
|
&from.pubkey(),
|
||||||
&fee_payer.pubkey(),
|
&fee_payer.pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
|
|
||||||
|
@ -1702,19 +1732,20 @@ fn process_transfer(
|
||||||
return_signers(&tx, &config)
|
return_signers(&tx, &config)
|
||||||
} else {
|
} else {
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
|
||||||
}
|
|
||||||
let result = if no_wait {
|
let result = if no_wait {
|
||||||
rpc_client.send_transaction(&tx)
|
rpc_client.send_transaction(&tx)
|
||||||
} else {
|
} else {
|
||||||
rpc_client.send_and_confirm_transaction_with_spinner(&tx)
|
rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
|
@ -1726,19 +1757,26 @@ fn process_witness(
|
||||||
to: &Pubkey,
|
to: &Pubkey,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())?
|
||||||
|
.value;
|
||||||
|
|
||||||
let ix = budget_instruction::apply_signature(&config.signers[0].pubkey(), pubkey, to);
|
let ix = budget_instruction::apply_signature(&config.signers[0].pubkey(), pubkey, to);
|
||||||
let message = Message::new(&[ix]);
|
let message = Message::new(&[ix]);
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<BudgetError>(result, &config)
|
log_instruction_custom_error::<BudgetError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1769,15 +1807,8 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
CliCommand::Catchup {
|
CliCommand::Catchup {
|
||||||
node_pubkey,
|
node_pubkey,
|
||||||
node_json_rpc_url,
|
node_json_rpc_url,
|
||||||
commitment_config,
|
|
||||||
follow,
|
follow,
|
||||||
} => process_catchup(
|
} => process_catchup(&rpc_client, config, node_pubkey, node_json_rpc_url, *follow),
|
||||||
&rpc_client,
|
|
||||||
node_pubkey,
|
|
||||||
node_json_rpc_url,
|
|
||||||
*commitment_config,
|
|
||||||
*follow,
|
|
||||||
),
|
|
||||||
CliCommand::ClusterDate => process_cluster_date(&rpc_client, config),
|
CliCommand::ClusterDate => process_cluster_date(&rpc_client, config),
|
||||||
CliCommand::ClusterVersion => process_cluster_version(&rpc_client),
|
CliCommand::ClusterVersion => process_cluster_version(&rpc_client),
|
||||||
CliCommand::CreateAddressWithSeed {
|
CliCommand::CreateAddressWithSeed {
|
||||||
|
@ -1787,30 +1818,14 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
} => process_create_address_with_seed(config, from_pubkey.as_ref(), &seed, &program_id),
|
} => process_create_address_with_seed(config, from_pubkey.as_ref(), &seed, &program_id),
|
||||||
CliCommand::Fees => process_fees(&rpc_client, config),
|
CliCommand::Fees => process_fees(&rpc_client, config),
|
||||||
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, config, *slot),
|
CliCommand::GetBlockTime { slot } => process_get_block_time(&rpc_client, config, *slot),
|
||||||
|
CliCommand::GetEpoch => process_get_epoch(&rpc_client, config),
|
||||||
|
CliCommand::GetEpochInfo => process_get_epoch_info(&rpc_client, config),
|
||||||
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
|
CliCommand::GetGenesisHash => process_get_genesis_hash(&rpc_client),
|
||||||
CliCommand::GetEpochInfo { commitment_config } => {
|
CliCommand::GetSlot => process_get_slot(&rpc_client, config),
|
||||||
process_get_epoch_info(&rpc_client, config, *commitment_config)
|
CliCommand::LargestAccounts { filter } => {
|
||||||
}
|
process_largest_accounts(&rpc_client, config, filter.clone())
|
||||||
CliCommand::GetEpoch { commitment_config } => {
|
|
||||||
process_get_epoch(&rpc_client, *commitment_config)
|
|
||||||
}
|
|
||||||
CliCommand::GetSlot { commitment_config } => {
|
|
||||||
process_get_slot(&rpc_client, *commitment_config)
|
|
||||||
}
|
|
||||||
CliCommand::LargestAccounts {
|
|
||||||
commitment_config,
|
|
||||||
filter,
|
|
||||||
} => process_largest_accounts(&rpc_client, config, *commitment_config, filter.clone()),
|
|
||||||
CliCommand::Supply {
|
|
||||||
commitment_config,
|
|
||||||
print_accounts,
|
|
||||||
} => process_supply(&rpc_client, config, *commitment_config, *print_accounts),
|
|
||||||
CliCommand::TotalSupply { commitment_config } => {
|
|
||||||
process_total_supply(&rpc_client, *commitment_config)
|
|
||||||
}
|
|
||||||
CliCommand::GetTransactionCount { commitment_config } => {
|
|
||||||
process_get_transaction_count(&rpc_client, *commitment_config)
|
|
||||||
}
|
}
|
||||||
|
CliCommand::GetTransactionCount => process_get_transaction_count(&rpc_client, config),
|
||||||
CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client),
|
CliCommand::LeaderSchedule => process_leader_schedule(&rpc_client),
|
||||||
CliCommand::LiveSlots => process_live_slots(&config.websocket_url),
|
CliCommand::LiveSlots => process_live_slots(&config.websocket_url),
|
||||||
CliCommand::Ping {
|
CliCommand::Ping {
|
||||||
|
@ -1818,16 +1833,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
interval,
|
interval,
|
||||||
count,
|
count,
|
||||||
timeout,
|
timeout,
|
||||||
commitment_config,
|
} => process_ping(&rpc_client, config, *lamports, interval, count, timeout),
|
||||||
} => process_ping(
|
|
||||||
&rpc_client,
|
|
||||||
config,
|
|
||||||
*lamports,
|
|
||||||
interval,
|
|
||||||
count,
|
|
||||||
timeout,
|
|
||||||
*commitment_config,
|
|
||||||
),
|
|
||||||
CliCommand::ShowBlockProduction { epoch, slot_limit } => {
|
CliCommand::ShowBlockProduction { epoch, slot_limit } => {
|
||||||
process_show_block_production(&rpc_client, config, *epoch, *slot_limit)
|
process_show_block_production(&rpc_client, config, *epoch, *slot_limit)
|
||||||
}
|
}
|
||||||
|
@ -1841,10 +1847,13 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
*use_lamports_unit,
|
*use_lamports_unit,
|
||||||
vote_account_pubkeys.as_deref(),
|
vote_account_pubkeys.as_deref(),
|
||||||
),
|
),
|
||||||
CliCommand::ShowValidators {
|
CliCommand::ShowValidators { use_lamports_unit } => {
|
||||||
use_lamports_unit,
|
process_show_validators(&rpc_client, config, *use_lamports_unit)
|
||||||
commitment_config,
|
}
|
||||||
} => process_show_validators(&rpc_client, config, *use_lamports_unit, *commitment_config),
|
CliCommand::Supply { print_accounts } => {
|
||||||
|
process_supply(&rpc_client, config, *print_accounts)
|
||||||
|
}
|
||||||
|
CliCommand::TotalSupply => process_total_supply(&rpc_client, config),
|
||||||
CliCommand::TransactionHistory {
|
CliCommand::TransactionHistory {
|
||||||
address,
|
address,
|
||||||
end_slot,
|
end_slot,
|
||||||
|
@ -1881,7 +1890,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
),
|
),
|
||||||
// Get the current nonce
|
// Get the current nonce
|
||||||
CliCommand::GetNonce(nonce_account_pubkey) => {
|
CliCommand::GetNonce(nonce_account_pubkey) => {
|
||||||
process_get_nonce(&rpc_client, &nonce_account_pubkey)
|
process_get_nonce(&rpc_client, config, &nonce_account_pubkey)
|
||||||
}
|
}
|
||||||
// Get a new nonce
|
// Get a new nonce
|
||||||
CliCommand::NewNonce {
|
CliCommand::NewNonce {
|
||||||
|
@ -2159,13 +2168,11 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
CliCommand::ShowVoteAccount {
|
CliCommand::ShowVoteAccount {
|
||||||
pubkey: vote_account_pubkey,
|
pubkey: vote_account_pubkey,
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
commitment_config,
|
|
||||||
} => process_show_vote_account(
|
} => process_show_vote_account(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
config,
|
config,
|
||||||
&vote_account_pubkey,
|
&vote_account_pubkey,
|
||||||
*use_lamports_unit,
|
*use_lamports_unit,
|
||||||
*commitment_config,
|
|
||||||
),
|
),
|
||||||
CliCommand::WithdrawFromVoteAccount {
|
CliCommand::WithdrawFromVoteAccount {
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
|
@ -2234,14 +2241,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult {
|
||||||
CliCommand::Balance {
|
CliCommand::Balance {
|
||||||
pubkey,
|
pubkey,
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
commitment_config,
|
} => process_balance(&rpc_client, config, &pubkey, *use_lamports_unit),
|
||||||
} => process_balance(
|
|
||||||
&rpc_client,
|
|
||||||
config,
|
|
||||||
&pubkey,
|
|
||||||
*use_lamports_unit,
|
|
||||||
*commitment_config,
|
|
||||||
),
|
|
||||||
// Cancel a contract by contract Pubkey
|
// Cancel a contract by contract Pubkey
|
||||||
CliCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey),
|
CliCommand::Cancel(pubkey) => process_cancel(&rpc_client, config, &pubkey),
|
||||||
// Confirm the last client transaction by signature
|
// Confirm the last client transaction by signature
|
||||||
|
@ -2384,7 +2384,8 @@ pub fn request_and_confirm_airdrop(
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
let tx = keypair.airdrop_transaction();
|
let tx = keypair.airdrop_transaction();
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result =
|
||||||
|
rpc_client.send_and_confirm_transaction_with_spinner_and_commitment(&tx, config.commitment);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2913,7 +2914,6 @@ mod tests {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(keypair.pubkey()),
|
pubkey: Some(keypair.pubkey()),
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
|
@ -2930,7 +2930,6 @@ mod tests {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: Some(keypair.pubkey()),
|
pubkey: Some(keypair.pubkey()),
|
||||||
use_lamports_unit: true,
|
use_lamports_unit: true,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
|
@ -2945,7 +2944,6 @@ mod tests {
|
||||||
command: CliCommand::Balance {
|
command: CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: true,
|
use_lamports_unit: true,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
},
|
},
|
||||||
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
|
signers: vec![read_keypair_file(&keypair_file).unwrap().into()],
|
||||||
}
|
}
|
||||||
|
@ -3442,14 +3440,12 @@ mod tests {
|
||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: true,
|
use_lamports_unit: true,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
};
|
||||||
assert_eq!(process_command(&config).unwrap(), "50 lamports");
|
assert_eq!(process_command(&config).unwrap(), "50 lamports");
|
||||||
|
|
||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
};
|
||||||
assert_eq!(process_command(&config).unwrap(), "0.00000005 SOL");
|
assert_eq!(process_command(&config).unwrap(), "0.00000005 SOL");
|
||||||
|
|
||||||
|
@ -3585,14 +3581,10 @@ mod tests {
|
||||||
let result = process_command(&config);
|
let result = process_command(&config);
|
||||||
assert!(dbg!(result).is_ok());
|
assert!(dbg!(result).is_ok());
|
||||||
|
|
||||||
config.command = CliCommand::GetSlot {
|
config.command = CliCommand::GetSlot;
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
|
||||||
assert_eq!(process_command(&config).unwrap(), "0");
|
assert_eq!(process_command(&config).unwrap(), "0");
|
||||||
|
|
||||||
config.command = CliCommand::GetTransactionCount {
|
config.command = CliCommand::GetTransactionCount;
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
|
||||||
assert_eq!(process_command(&config).unwrap(), "1234");
|
assert_eq!(process_command(&config).unwrap(), "1234");
|
||||||
|
|
||||||
config.signers = vec![&keypair];
|
config.signers = vec![&keypair];
|
||||||
|
@ -3700,7 +3692,6 @@ mod tests {
|
||||||
config.command = CliCommand::Balance {
|
config.command = CliCommand::Balance {
|
||||||
pubkey: None,
|
pubkey: None,
|
||||||
use_lamports_unit: false,
|
use_lamports_unit: false,
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
};
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
|
@ -3729,14 +3720,10 @@ mod tests {
|
||||||
};
|
};
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
config.command = CliCommand::GetSlot {
|
config.command = CliCommand::GetSlot;
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
config.command = CliCommand::GetTransactionCount {
|
config.command = CliCommand::GetTransactionCount;
|
||||||
commitment_config: CommitmentConfig::default(),
|
|
||||||
};
|
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
|
|
||||||
config.command = CliCommand::Pay(PayCommand {
|
config.command = CliCommand::Pay(PayCommand {
|
||||||
|
|
|
@ -7,10 +7,7 @@ use crate::{
|
||||||
use clap::{value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand};
|
use clap::{value_t, value_t_or_exit, App, AppSettings, Arg, ArgMatches, SubCommand};
|
||||||
use console::{style, Emoji};
|
use console::{style, Emoji};
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{
|
||||||
commitment::{commitment_arg, COMMITMENT_ARG},
|
commitment::commitment_arg, input_parsers::*, input_validators::*, keypair::signer_from_path,
|
||||||
input_parsers::*,
|
|
||||||
input_validators::*,
|
|
||||||
keypair::signer_from_path,
|
|
||||||
};
|
};
|
||||||
use solana_client::{
|
use solana_client::{
|
||||||
pubsub_client::{PubsubClient, SlotInfoMessage},
|
pubsub_client::{PubsubClient, SlotInfoMessage},
|
||||||
|
@ -296,13 +293,11 @@ pub fn parse_catchup(
|
||||||
) -> Result<CliCommandInfo, CliError> {
|
) -> Result<CliCommandInfo, CliError> {
|
||||||
let node_pubkey = pubkey_of_signer(matches, "node_pubkey", wallet_manager)?.unwrap();
|
let node_pubkey = pubkey_of_signer(matches, "node_pubkey", wallet_manager)?.unwrap();
|
||||||
let node_json_rpc_url = value_t!(matches, "node_json_rpc_url", String).ok();
|
let node_json_rpc_url = value_t!(matches, "node_json_rpc_url", String).ok();
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
let follow = matches.is_present("follow");
|
let follow = matches.is_present("follow");
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::Catchup {
|
command: CliCommand::Catchup {
|
||||||
node_pubkey,
|
node_pubkey,
|
||||||
node_json_rpc_url,
|
node_json_rpc_url,
|
||||||
commitment_config,
|
|
||||||
follow,
|
follow,
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
|
@ -322,14 +317,12 @@ pub fn parse_cluster_ping(
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64));
|
let timeout = Duration::from_secs(value_t_or_exit!(matches, "timeout", u64));
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::Ping {
|
command: CliCommand::Ping {
|
||||||
lamports,
|
lamports,
|
||||||
interval,
|
interval,
|
||||||
count,
|
count,
|
||||||
timeout,
|
timeout,
|
||||||
commitment_config,
|
|
||||||
},
|
},
|
||||||
signers: vec![signer_from_path(
|
signers: vec![signer_from_path(
|
||||||
matches,
|
matches,
|
||||||
|
@ -348,32 +341,28 @@ pub fn parse_get_block_time(matches: &ArgMatches<'_>) -> Result<CliCommandInfo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_get_epoch_info(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_get_epoch(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::GetEpochInfo { commitment_config },
|
command: CliCommand::GetEpoch,
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_get_slot(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_get_epoch_info(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::GetSlot { commitment_config },
|
command: CliCommand::GetEpochInfo,
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_get_epoch(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_get_slot(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::GetEpoch { commitment_config },
|
command: CliCommand::GetSlot,
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
let filter = if matches.is_present("circulating") {
|
let filter = if matches.is_present("circulating") {
|
||||||
Some(RpcLargestAccountsFilter::Circulating)
|
Some(RpcLargestAccountsFilter::Circulating)
|
||||||
} else if matches.is_present("non_circulating") {
|
} else if matches.is_present("non_circulating") {
|
||||||
|
@ -382,38 +371,29 @@ pub fn parse_largest_accounts(matches: &ArgMatches<'_>) -> Result<CliCommandInfo
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::LargestAccounts {
|
command: CliCommand::LargestAccounts { filter },
|
||||||
commitment_config,
|
|
||||||
filter,
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_supply(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_supply(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
let print_accounts = matches.is_present("print_accounts");
|
let print_accounts = matches.is_present("print_accounts");
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::Supply {
|
command: CliCommand::Supply { print_accounts },
|
||||||
commitment_config,
|
|
||||||
print_accounts,
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_total_supply(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_total_supply(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::TotalSupply { commitment_config },
|
command: CliCommand::TotalSupply,
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_get_transaction_count(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_get_transaction_count(_matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::GetTransactionCount { commitment_config },
|
command: CliCommand::GetTransactionCount,
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -437,13 +417,9 @@ pub fn parse_show_stakes(
|
||||||
|
|
||||||
pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_show_validators(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let use_lamports_unit = matches.is_present("lamports");
|
let use_lamports_unit = matches.is_present("lamports");
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::ShowValidators {
|
command: CliCommand::ShowValidators { use_lamports_unit },
|
||||||
use_lamports_unit,
|
|
||||||
commitment_config,
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -468,9 +444,9 @@ pub fn parse_transaction_history(
|
||||||
|
|
||||||
pub fn process_catchup(
|
pub fn process_catchup(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
|
config: &CliConfig,
|
||||||
node_pubkey: &Pubkey,
|
node_pubkey: &Pubkey,
|
||||||
node_json_rpc_url: &Option<String>,
|
node_json_rpc_url: &Option<String>,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
follow: bool,
|
follow: bool,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let sleep_interval = 5;
|
let sleep_interval = 5;
|
||||||
|
@ -519,8 +495,8 @@ pub fn process_catchup(
|
||||||
let mut previous_rpc_slot = std::u64::MAX;
|
let mut previous_rpc_slot = std::u64::MAX;
|
||||||
let mut previous_slot_distance = 0;
|
let mut previous_slot_distance = 0;
|
||||||
loop {
|
loop {
|
||||||
let rpc_slot = rpc_client.get_slot_with_commitment(commitment_config)?;
|
let rpc_slot = rpc_client.get_slot_with_commitment(config.commitment)?;
|
||||||
let node_slot = node_client.get_slot_with_commitment(commitment_config)?;
|
let node_slot = node_client.get_slot_with_commitment(config.commitment)?;
|
||||||
if !follow && node_slot > std::cmp::min(previous_rpc_slot, rpc_slot) {
|
if !follow && node_slot > std::cmp::min(previous_rpc_slot, rpc_slot) {
|
||||||
progress_bar.finish_and_clear();
|
progress_bar.finish_and_clear();
|
||||||
return Ok(format!(
|
return Ok(format!(
|
||||||
|
@ -653,13 +629,14 @@ pub fn process_get_block_time(
|
||||||
Ok(config.output_format.formatted_string(&block_time))
|
Ok(config.output_format.formatted_string(&block_time))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_get_epoch_info(
|
pub fn process_get_epoch(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
rpc_client: &RpcClient,
|
let epoch_info = rpc_client.get_epoch_info_with_commitment(config.commitment)?;
|
||||||
config: &CliConfig,
|
Ok(epoch_info.epoch.to_string())
|
||||||
commitment_config: CommitmentConfig,
|
}
|
||||||
) -> ProcessResult {
|
|
||||||
|
pub fn process_get_epoch_info(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
let epoch_info: CliEpochInfo = rpc_client
|
let epoch_info: CliEpochInfo = rpc_client
|
||||||
.get_epoch_info_with_commitment(commitment_config)?
|
.get_epoch_info_with_commitment(config.commitment)?
|
||||||
.into();
|
.into();
|
||||||
Ok(config.output_format.formatted_string(&epoch_info))
|
Ok(config.output_format.formatted_string(&epoch_info))
|
||||||
}
|
}
|
||||||
|
@ -669,22 +646,11 @@ pub fn process_get_genesis_hash(rpc_client: &RpcClient) -> ProcessResult {
|
||||||
Ok(genesis_hash.to_string())
|
Ok(genesis_hash.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_get_slot(
|
pub fn process_get_slot(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
rpc_client: &RpcClient,
|
let slot = rpc_client.get_slot_with_commitment(config.commitment)?;
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
|
||||||
let slot = rpc_client.get_slot_with_commitment(commitment_config)?;
|
|
||||||
Ok(slot.to_string())
|
Ok(slot.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_get_epoch(
|
|
||||||
rpc_client: &RpcClient,
|
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
|
||||||
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config)?;
|
|
||||||
Ok(epoch_info.epoch.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn parse_show_block_production(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
pub fn parse_show_block_production(matches: &ArgMatches<'_>) -> Result<CliCommandInfo, CliError> {
|
||||||
let epoch = value_t!(matches, "epoch", Epoch).ok();
|
let epoch = value_t!(matches, "epoch", Epoch).ok();
|
||||||
let slot_limit = value_t!(matches, "slot_limit", u64).ok();
|
let slot_limit = value_t!(matches, "slot_limit", u64).ok();
|
||||||
|
@ -849,12 +815,11 @@ pub fn process_show_block_production(
|
||||||
pub fn process_largest_accounts(
|
pub fn process_largest_accounts(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
filter: Option<RpcLargestAccountsFilter>,
|
filter: Option<RpcLargestAccountsFilter>,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let accounts = rpc_client
|
let accounts = rpc_client
|
||||||
.get_largest_accounts_with_config(RpcLargestAccountsConfig {
|
.get_largest_accounts_with_config(RpcLargestAccountsConfig {
|
||||||
commitment: Some(commitment_config),
|
commitment: Some(config.commitment),
|
||||||
filter,
|
filter,
|
||||||
})?
|
})?
|
||||||
.value;
|
.value;
|
||||||
|
@ -865,28 +830,21 @@ pub fn process_largest_accounts(
|
||||||
pub fn process_supply(
|
pub fn process_supply(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
print_accounts: bool,
|
print_accounts: bool,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let supply_response = rpc_client.supply_with_commitment(commitment_config)?;
|
let supply_response = rpc_client.supply_with_commitment(config.commitment)?;
|
||||||
let mut supply: CliSupply = supply_response.value.into();
|
let mut supply: CliSupply = supply_response.value.into();
|
||||||
supply.print_accounts = print_accounts;
|
supply.print_accounts = print_accounts;
|
||||||
Ok(config.output_format.formatted_string(&supply))
|
Ok(config.output_format.formatted_string(&supply))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_total_supply(
|
pub fn process_total_supply(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
rpc_client: &RpcClient,
|
let total_supply = rpc_client.total_supply_with_commitment(config.commitment)?;
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
|
||||||
let total_supply = rpc_client.total_supply_with_commitment(commitment_config)?;
|
|
||||||
Ok(format!("{} SOL", lamports_to_sol(total_supply)))
|
Ok(format!("{} SOL", lamports_to_sol(total_supply)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_get_transaction_count(
|
pub fn process_get_transaction_count(rpc_client: &RpcClient, config: &CliConfig) -> ProcessResult {
|
||||||
rpc_client: &RpcClient,
|
let transaction_count = rpc_client.get_transaction_count_with_commitment(config.commitment)?;
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
|
||||||
let transaction_count = rpc_client.get_transaction_count_with_commitment(commitment_config)?;
|
|
||||||
Ok(transaction_count.to_string())
|
Ok(transaction_count.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -897,7 +855,6 @@ pub fn process_ping(
|
||||||
interval: &Duration,
|
interval: &Duration,
|
||||||
count: &Option<u64>,
|
count: &Option<u64>,
|
||||||
timeout: &Duration,
|
timeout: &Duration,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
println_name_value("Source Account:", &config.signers[0].pubkey().to_string());
|
println_name_value("Source Account:", &config.signers[0].pubkey().to_string());
|
||||||
println!();
|
println!();
|
||||||
|
@ -943,6 +900,7 @@ pub fn process_ping(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, blockhash)?;
|
tx.try_sign(&config.signers, blockhash)?;
|
||||||
|
@ -952,7 +910,7 @@ pub fn process_ping(
|
||||||
let transaction_sent = Instant::now();
|
let transaction_sent = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
let signature_status = rpc_client
|
let signature_status = rpc_client
|
||||||
.get_signature_status_with_commitment(&signature, commitment_config)?;
|
.get_signature_status_with_commitment(&signature, config.commitment)?;
|
||||||
let elapsed_time = Instant::now().duration_since(transaction_sent);
|
let elapsed_time = Instant::now().duration_since(transaction_sent);
|
||||||
if let Some(transaction_status) = signature_status {
|
if let Some(transaction_status) = signature_status {
|
||||||
match transaction_status {
|
match transaction_status {
|
||||||
|
@ -1235,10 +1193,9 @@ pub fn process_show_validators(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let epoch_info = rpc_client.get_epoch_info_with_commitment(commitment_config)?;
|
let epoch_info = rpc_client.get_epoch_info_with_commitment(config.commitment)?;
|
||||||
let vote_accounts = rpc_client.get_vote_accounts_with_commitment(commitment_config)?;
|
let vote_accounts = rpc_client.get_vote_accounts_with_commitment(config.commitment)?;
|
||||||
let total_active_stake = vote_accounts
|
let total_active_stake = vote_accounts
|
||||||
.current
|
.current
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1379,15 +1336,24 @@ mod tests {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let test_get_epoch = test_commands
|
||||||
|
.clone()
|
||||||
|
.get_matches_from(vec!["test", "epoch"]);
|
||||||
|
assert_eq!(
|
||||||
|
parse_command(&test_get_epoch, &default_keypair_file, &mut None).unwrap(),
|
||||||
|
CliCommandInfo {
|
||||||
|
command: CliCommand::GetEpoch,
|
||||||
|
signers: vec![],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let test_get_epoch_info = test_commands
|
let test_get_epoch_info = test_commands
|
||||||
.clone()
|
.clone()
|
||||||
.get_matches_from(vec!["test", "epoch-info"]);
|
.get_matches_from(vec!["test", "epoch-info"]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(&test_get_epoch_info, &default_keypair_file, &mut None).unwrap(),
|
parse_command(&test_get_epoch_info, &default_keypair_file, &mut None).unwrap(),
|
||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::GetEpochInfo {
|
command: CliCommand::GetEpochInfo,
|
||||||
commitment_config: CommitmentConfig::recent(),
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1407,22 +1373,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(&test_get_slot, &default_keypair_file, &mut None).unwrap(),
|
parse_command(&test_get_slot, &default_keypair_file, &mut None).unwrap(),
|
||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::GetSlot {
|
command: CliCommand::GetSlot,
|
||||||
commitment_config: CommitmentConfig::recent(),
|
|
||||||
},
|
|
||||||
signers: vec![],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let test_get_epoch = test_commands
|
|
||||||
.clone()
|
|
||||||
.get_matches_from(vec!["test", "epoch"]);
|
|
||||||
assert_eq!(
|
|
||||||
parse_command(&test_get_epoch, &default_keypair_file, &mut None).unwrap(),
|
|
||||||
CliCommandInfo {
|
|
||||||
command: CliCommand::GetEpoch {
|
|
||||||
commitment_config: CommitmentConfig::recent(),
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1433,9 +1384,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(&test_total_supply, &default_keypair_file, &mut None).unwrap(),
|
parse_command(&test_total_supply, &default_keypair_file, &mut None).unwrap(),
|
||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::TotalSupply {
|
command: CliCommand::TotalSupply,
|
||||||
commitment_config: CommitmentConfig::recent(),
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1446,9 +1395,7 @@ mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
parse_command(&test_transaction_count, &default_keypair_file, &mut None).unwrap(),
|
parse_command(&test_transaction_count, &default_keypair_file, &mut None).unwrap(),
|
||||||
CliCommandInfo {
|
CliCommandInfo {
|
||||||
command: CliCommand::GetTransactionCount {
|
command: CliCommand::GetTransactionCount,
|
||||||
commitment_config: CommitmentConfig::recent(),
|
|
||||||
},
|
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -1473,7 +1420,6 @@ mod tests {
|
||||||
interval: Duration::from_secs(1),
|
interval: Duration::from_secs(1),
|
||||||
count: Some(2),
|
count: Some(2),
|
||||||
timeout: Duration::from_secs(3),
|
timeout: Duration::from_secs(3),
|
||||||
commitment_config: CommitmentConfig::max(),
|
|
||||||
},
|
},
|
||||||
signers: vec![default_keypair.into()],
|
signers: vec![default_keypair.into()],
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,8 @@ use clap::{crate_description, crate_name, AppSettings, Arg, ArgGroup, ArgMatches
|
||||||
use console::style;
|
use console::style;
|
||||||
|
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{
|
||||||
input_validators::is_url, keypair::SKIP_SEED_PHRASE_VALIDATION_ARG, DisplayError,
|
commitment::COMMITMENT_ARG, input_parsers::commitment_of, input_validators::is_url,
|
||||||
|
keypair::SKIP_SEED_PHRASE_VALIDATION_ARG, DisplayError,
|
||||||
};
|
};
|
||||||
use solana_cli::{
|
use solana_cli::{
|
||||||
cli::{app, parse_command, process_command, CliCommandInfo, CliConfig, CliSigners},
|
cli::{app, parse_command, process_command, CliCommandInfo, CliConfig, CliSigners},
|
||||||
|
@ -10,6 +11,7 @@ use solana_cli::{
|
||||||
display::{println_name_value, println_name_value_or},
|
display::{println_name_value, println_name_value_or},
|
||||||
};
|
};
|
||||||
use solana_cli_config::{Config, CONFIG_FILE};
|
use solana_cli_config::{Config, CONFIG_FILE};
|
||||||
|
use solana_client::rpc_config::RpcSendTransactionConfig;
|
||||||
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
||||||
use std::{error, sync::Arc};
|
use std::{error, sync::Arc};
|
||||||
|
|
||||||
|
@ -136,6 +138,12 @@ pub fn parse_args<'a>(
|
||||||
})
|
})
|
||||||
.unwrap_or(OutputFormat::Display);
|
.unwrap_or(OutputFormat::Display);
|
||||||
|
|
||||||
|
let commitment = matches
|
||||||
|
.subcommand_name()
|
||||||
|
.and_then(|name| matches.subcommand_matches(name))
|
||||||
|
.and_then(|sub_matches| commitment_of(sub_matches, COMMITMENT_ARG.long))
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
CliConfig {
|
CliConfig {
|
||||||
command,
|
command,
|
||||||
|
@ -146,6 +154,8 @@ pub fn parse_args<'a>(
|
||||||
rpc_client: None,
|
rpc_client: None,
|
||||||
verbose: matches.is_present("verbose"),
|
verbose: matches.is_present("verbose"),
|
||||||
output_format,
|
output_format,
|
||||||
|
commitment,
|
||||||
|
send_transaction_config: RpcSendTransactionConfig::default(),
|
||||||
},
|
},
|
||||||
signers,
|
signers,
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
checks::{check_account_for_fee, check_unique_pubkeys},
|
checks::{check_account_for_fee_with_commitment, check_unique_pubkeys},
|
||||||
cli::{
|
cli::{
|
||||||
generate_unique_signers, log_instruction_custom_error, CliCommand, CliCommandInfo,
|
generate_unique_signers, log_instruction_custom_error, CliCommand, CliCommandInfo,
|
||||||
CliConfig, CliError, ProcessResult, SignerIndex,
|
CliConfig, CliError, ProcessResult, SignerIndex,
|
||||||
|
@ -16,6 +16,7 @@ use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account::Account,
|
account::Account,
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
message::Message,
|
message::Message,
|
||||||
nonce::{
|
nonce::{
|
||||||
|
@ -222,10 +223,23 @@ impl NonceSubCommands for App<'_, '_> {
|
||||||
pub fn get_account(
|
pub fn get_account(
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
nonce_pubkey: &Pubkey,
|
nonce_pubkey: &Pubkey,
|
||||||
|
) -> Result<Account, CliNonceError> {
|
||||||
|
get_account_with_commitment(rpc_client, nonce_pubkey, CommitmentConfig::default())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_account_with_commitment(
|
||||||
|
rpc_client: &RpcClient,
|
||||||
|
nonce_pubkey: &Pubkey,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<Account, CliNonceError> {
|
) -> Result<Account, CliNonceError> {
|
||||||
rpc_client
|
rpc_client
|
||||||
.get_account(nonce_pubkey)
|
.get_account_with_commitment(nonce_pubkey, commitment)
|
||||||
.map_err(|e| CliNonceError::Client(format!("{}", e)))
|
.map_err(|e| CliNonceError::Client(format!("{}", e)))
|
||||||
|
.and_then(|result| {
|
||||||
|
result.value.ok_or_else(|| {
|
||||||
|
CliNonceError::Client(format!("AccountNotFound: pubkey={}", nonce_pubkey))
|
||||||
|
})
|
||||||
|
})
|
||||||
.and_then(|a| match account_identity_ok(&a) {
|
.and_then(|a| match account_identity_ok(&a) {
|
||||||
Ok(()) => Ok(a),
|
Ok(()) => Ok(a),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
|
@ -433,7 +447,9 @@ pub fn process_authorize_nonce_account(
|
||||||
nonce_authority: SignerIndex,
|
nonce_authority: SignerIndex,
|
||||||
new_authority: &Pubkey,
|
new_authority: &Pubkey,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
|
let ix = authorize_nonce_account(nonce_account, &nonce_authority.pubkey(), new_authority);
|
||||||
|
@ -441,13 +457,18 @@ pub fn process_authorize_nonce_account(
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
|
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<NonceError>(result, &config)
|
log_instruction_custom_error::<NonceError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +515,9 @@ pub fn process_create_nonce_account(
|
||||||
Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()))
|
Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()))
|
||||||
};
|
};
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
|
|
||||||
let (message, lamports) = resolve_spend_tx_and_check_account_balance(
|
let (message, lamports) = resolve_spend_tx_and_check_account_balance(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
|
@ -503,9 +526,12 @@ pub fn process_create_nonce_account(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if let Ok(nonce_account) = get_account(rpc_client, &nonce_account_address) {
|
if let Ok(nonce_account) =
|
||||||
|
get_account_with_commitment(rpc_client, &nonce_account_address, config.commitment)
|
||||||
|
{
|
||||||
let err_msg = if state_from_account(&nonce_account).is_ok() {
|
let err_msg = if state_from_account(&nonce_account).is_ok() {
|
||||||
format!("Nonce account {} already exists", nonce_account_address)
|
format!("Nonce account {} already exists", nonce_account_address)
|
||||||
} else {
|
} else {
|
||||||
|
@ -528,12 +554,22 @@ pub fn process_create_nonce_account(
|
||||||
|
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_get_nonce(rpc_client: &RpcClient, nonce_account_pubkey: &Pubkey) -> ProcessResult {
|
pub fn process_get_nonce(
|
||||||
match get_account(rpc_client, nonce_account_pubkey).and_then(|ref a| state_from_account(a))? {
|
rpc_client: &RpcClient,
|
||||||
|
config: &CliConfig,
|
||||||
|
nonce_account_pubkey: &Pubkey,
|
||||||
|
) -> ProcessResult {
|
||||||
|
match get_account_with_commitment(rpc_client, nonce_account_pubkey, config.commitment)
|
||||||
|
.and_then(|ref a| state_from_account(a))?
|
||||||
|
{
|
||||||
State::Uninitialized => Ok("Nonce account is uninitialized".to_string()),
|
State::Uninitialized => Ok("Nonce account is uninitialized".to_string()),
|
||||||
State::Initialized(ref data) => Ok(format!("{:?}", data.blockhash)),
|
State::Initialized(ref data) => Ok(format!("{:?}", data.blockhash)),
|
||||||
}
|
}
|
||||||
|
@ -550,7 +586,9 @@ pub fn process_new_nonce(
|
||||||
(&nonce_account, "nonce_account_pubkey".to_string()),
|
(&nonce_account, "nonce_account_pubkey".to_string()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if rpc_client.get_account(&nonce_account).is_err() {
|
let nonce_account_check =
|
||||||
|
rpc_client.get_account_with_commitment(&nonce_account, config.commitment);
|
||||||
|
if nonce_account_check.is_err() || nonce_account_check.unwrap().value.is_none() {
|
||||||
return Err(CliError::BadParameter(
|
return Err(CliError::BadParameter(
|
||||||
"Unable to create new nonce, no nonce account found".to_string(),
|
"Unable to create new nonce, no nonce account found".to_string(),
|
||||||
)
|
)
|
||||||
|
@ -559,17 +597,24 @@ pub fn process_new_nonce(
|
||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let ix = advance_nonce_account(&nonce_account, &nonce_authority.pubkey());
|
let ix = advance_nonce_account(&nonce_account, &nonce_authority.pubkey());
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +624,8 @@ pub fn process_show_nonce_account(
|
||||||
nonce_account_pubkey: &Pubkey,
|
nonce_account_pubkey: &Pubkey,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let nonce_account = get_account(rpc_client, nonce_account_pubkey)?;
|
let nonce_account =
|
||||||
|
get_account_with_commitment(rpc_client, nonce_account_pubkey, config.commitment)?;
|
||||||
let print_account = |data: Option<&nonce::state::Data>| {
|
let print_account = |data: Option<&nonce::state::Data>| {
|
||||||
let mut nonce_account = CliNonceAccount {
|
let mut nonce_account = CliNonceAccount {
|
||||||
balance: nonce_account.lamports,
|
balance: nonce_account.lamports,
|
||||||
|
@ -610,7 +656,9 @@ pub fn process_withdraw_from_nonce_account(
|
||||||
destination_account_pubkey: &Pubkey,
|
destination_account_pubkey: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let ix = withdraw_nonce_account(
|
let ix = withdraw_nonce_account(
|
||||||
|
@ -622,13 +670,18 @@ pub fn process_withdraw_from_nonce_account(
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<NonceError>(result, &config)
|
log_instruction_custom_error::<NonceError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use solana_sdk::commitment_config::CommitmentConfig;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum Source {
|
pub enum Source {
|
||||||
|
@ -10,14 +11,17 @@ impl Source {
|
||||||
pub fn get_blockhash_and_fee_calculator(
|
pub fn get_blockhash_and_fee_calculator(
|
||||||
&self,
|
&self,
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Cluster => {
|
Self::Cluster => {
|
||||||
let res = rpc_client.get_recent_blockhash()?;
|
let res = rpc_client
|
||||||
Ok(res)
|
.get_recent_blockhash_with_commitment(commitment)?
|
||||||
|
.value;
|
||||||
|
Ok((res.0, res.1))
|
||||||
}
|
}
|
||||||
Self::NonceAccount(ref pubkey) => {
|
Self::NonceAccount(ref pubkey) => {
|
||||||
let data = nonce::get_account(rpc_client, pubkey)
|
let data = nonce::get_account_with_commitment(rpc_client, pubkey, commitment)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))?;
|
.and_then(|ref a| nonce::data_from_account(a))?;
|
||||||
Ok((data.blockhash, data.fee_calculator))
|
Ok((data.blockhash, data.fee_calculator))
|
||||||
}
|
}
|
||||||
|
@ -28,14 +32,17 @@ impl Source {
|
||||||
&self,
|
&self,
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
blockhash: &Hash,
|
blockhash: &Hash,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<Option<FeeCalculator>, Box<dyn std::error::Error>> {
|
) -> Result<Option<FeeCalculator>, Box<dyn std::error::Error>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Cluster => {
|
Self::Cluster => {
|
||||||
let res = rpc_client.get_fee_calculator_for_blockhash(blockhash)?;
|
let res = rpc_client
|
||||||
|
.get_fee_calculator_for_blockhash_with_commitment(blockhash, commitment)?
|
||||||
|
.value;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
Self::NonceAccount(ref pubkey) => {
|
Self::NonceAccount(ref pubkey) => {
|
||||||
let res = nonce::get_account(rpc_client, pubkey)?;
|
let res = nonce::get_account_with_commitment(rpc_client, pubkey, commitment)?;
|
||||||
let res = nonce::data_from_account(&res)?;
|
let res = nonce::data_from_account(&res)?;
|
||||||
Ok(Some(res)
|
Ok(Some(res)
|
||||||
.filter(|d| d.blockhash == *blockhash)
|
.filter(|d| d.blockhash == *blockhash)
|
||||||
|
@ -75,16 +82,19 @@ impl BlockhashQuery {
|
||||||
pub fn get_blockhash_and_fee_calculator(
|
pub fn get_blockhash_and_fee_calculator(
|
||||||
&self,
|
&self,
|
||||||
rpc_client: &RpcClient,
|
rpc_client: &RpcClient,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
) -> Result<(Hash, FeeCalculator), Box<dyn std::error::Error>> {
|
||||||
match self {
|
match self {
|
||||||
BlockhashQuery::None(hash) => Ok((*hash, FeeCalculator::default())),
|
BlockhashQuery::None(hash) => Ok((*hash, FeeCalculator::default())),
|
||||||
BlockhashQuery::FeeCalculator(source, hash) => {
|
BlockhashQuery::FeeCalculator(source, hash) => {
|
||||||
let fee_calculator = source
|
let fee_calculator = source
|
||||||
.get_fee_calculator(rpc_client, hash)?
|
.get_fee_calculator(rpc_client, hash, commitment)?
|
||||||
.ok_or(format!("Hash has expired {:?}", hash))?;
|
.ok_or(format!("Hash has expired {:?}", hash))?;
|
||||||
Ok((*hash, fee_calculator))
|
Ok((*hash, fee_calculator))
|
||||||
}
|
}
|
||||||
BlockhashQuery::All(source) => source.get_blockhash_and_fee_calculator(rpc_client),
|
BlockhashQuery::All(source) => {
|
||||||
|
source.get_blockhash_and_fee_calculator(rpc_client, commitment)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,7 +297,7 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::default()
|
BlockhashQuery::default()
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(rpc_blockhash, rpc_fee_calc.clone()),
|
(rpc_blockhash, rpc_fee_calc.clone()),
|
||||||
);
|
);
|
||||||
|
@ -303,7 +313,7 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::FeeCalculator(Source::Cluster, test_blockhash)
|
BlockhashQuery::FeeCalculator(Source::Cluster, test_blockhash)
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(test_blockhash, rpc_fee_calc),
|
(test_blockhash, rpc_fee_calc),
|
||||||
);
|
);
|
||||||
|
@ -315,13 +325,13 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::None(test_blockhash)
|
BlockhashQuery::None(test_blockhash)
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(test_blockhash, FeeCalculator::default()),
|
(test_blockhash, FeeCalculator::default()),
|
||||||
);
|
);
|
||||||
let rpc_client = RpcClient::new_mock("fails".to_string());
|
let rpc_client = RpcClient::new_mock("fails".to_string());
|
||||||
assert!(BlockhashQuery::default()
|
assert!(BlockhashQuery::default()
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.is_err());
|
.is_err());
|
||||||
|
|
||||||
let nonce_blockhash = Hash::new(&[2u8; 32]);
|
let nonce_blockhash = Hash::new(&[2u8; 32]);
|
||||||
|
@ -350,7 +360,7 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::All(Source::NonceAccount(nonce_pubkey))
|
BlockhashQuery::All(Source::NonceAccount(nonce_pubkey))
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(nonce_blockhash, nonce_fee_calc.clone()),
|
(nonce_blockhash, nonce_fee_calc.clone()),
|
||||||
);
|
);
|
||||||
|
@ -359,7 +369,7 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::FeeCalculator(Source::NonceAccount(nonce_pubkey), nonce_blockhash)
|
BlockhashQuery::FeeCalculator(Source::NonceAccount(nonce_pubkey), nonce_blockhash)
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(nonce_blockhash, nonce_fee_calc),
|
(nonce_blockhash, nonce_fee_calc),
|
||||||
);
|
);
|
||||||
|
@ -368,7 +378,7 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert!(
|
assert!(
|
||||||
BlockhashQuery::FeeCalculator(Source::NonceAccount(nonce_pubkey), test_blockhash)
|
BlockhashQuery::FeeCalculator(Source::NonceAccount(nonce_pubkey), test_blockhash)
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.is_err()
|
.is_err()
|
||||||
);
|
);
|
||||||
let mut mocks = HashMap::new();
|
let mut mocks = HashMap::new();
|
||||||
|
@ -376,14 +386,14 @@ mod tests {
|
||||||
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BlockhashQuery::None(nonce_blockhash)
|
BlockhashQuery::None(nonce_blockhash)
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
(nonce_blockhash, FeeCalculator::default()),
|
(nonce_blockhash, FeeCalculator::default()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let rpc_client = RpcClient::new_mock("fails".to_string());
|
let rpc_client = RpcClient::new_mock("fails".to_string());
|
||||||
assert!(BlockhashQuery::All(Source::NonceAccount(nonce_pubkey))
|
assert!(BlockhashQuery::All(Source::NonceAccount(nonce_pubkey))
|
||||||
.get_blockhash_and_fee_calculator(&rpc_client)
|
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
|
||||||
.is_err());
|
.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
checks::{calculate_fee, check_account_for_balance},
|
checks::{calculate_fee, check_account_for_balance_with_commitment},
|
||||||
cli::CliError,
|
cli::CliError,
|
||||||
};
|
};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use solana_clap_utils::{input_parsers::lamports_of_sol, offline::SIGN_ONLY_ARG};
|
use solana_clap_utils::{input_parsers::lamports_of_sol, offline::SIGN_ONLY_ARG};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
fee_calculator::FeeCalculator, message::Message, native_token::lamports_to_sol, pubkey::Pubkey,
|
commitment_config::CommitmentConfig, fee_calculator::FeeCalculator, message::Message,
|
||||||
|
native_token::lamports_to_sol, pubkey::Pubkey,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
|
@ -49,6 +50,7 @@ pub fn resolve_spend_tx_and_check_account_balance<F>(
|
||||||
fee_calculator: &FeeCalculator,
|
fee_calculator: &FeeCalculator,
|
||||||
from_pubkey: &Pubkey,
|
from_pubkey: &Pubkey,
|
||||||
build_message: F,
|
build_message: F,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<(Message, u64), CliError>
|
) -> Result<(Message, u64), CliError>
|
||||||
where
|
where
|
||||||
F: Fn(u64) -> Message,
|
F: Fn(u64) -> Message,
|
||||||
|
@ -61,6 +63,7 @@ where
|
||||||
from_pubkey,
|
from_pubkey,
|
||||||
from_pubkey,
|
from_pubkey,
|
||||||
build_message,
|
build_message,
|
||||||
|
commitment,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +75,7 @@ pub fn resolve_spend_tx_and_check_account_balances<F>(
|
||||||
from_pubkey: &Pubkey,
|
from_pubkey: &Pubkey,
|
||||||
fee_pubkey: &Pubkey,
|
fee_pubkey: &Pubkey,
|
||||||
build_message: F,
|
build_message: F,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
) -> Result<(Message, u64), CliError>
|
) -> Result<(Message, u64), CliError>
|
||||||
where
|
where
|
||||||
F: Fn(u64) -> Message,
|
F: Fn(u64) -> Message,
|
||||||
|
@ -87,7 +91,9 @@ where
|
||||||
);
|
);
|
||||||
Ok((message, spend))
|
Ok((message, spend))
|
||||||
} else {
|
} else {
|
||||||
let from_balance = rpc_client.get_balance(&from_pubkey)?;
|
let from_balance = rpc_client
|
||||||
|
.get_balance_with_commitment(&from_pubkey, commitment)?
|
||||||
|
.value;
|
||||||
let (message, SpendAndFee { spend, fee }) = resolve_spend_message(
|
let (message, SpendAndFee { spend, fee }) = resolve_spend_message(
|
||||||
amount,
|
amount,
|
||||||
fee_calculator,
|
fee_calculator,
|
||||||
|
@ -107,7 +113,8 @@ where
|
||||||
if from_balance < spend {
|
if from_balance < spend {
|
||||||
return Err(CliError::InsufficientFundsForSpend(lamports_to_sol(spend)));
|
return Err(CliError::InsufficientFundsForSpend(lamports_to_sol(spend)));
|
||||||
}
|
}
|
||||||
if !check_account_for_balance(rpc_client, fee_pubkey, fee)? {
|
if !check_account_for_balance_with_commitment(rpc_client, fee_pubkey, fee, commitment)?
|
||||||
|
{
|
||||||
return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee)));
|
return Err(CliError::InsufficientFundsForFee(lamports_to_sol(fee)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
127
cli/src/stake.rs
127
cli/src/stake.rs
|
@ -1,12 +1,12 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
checks::{check_account_for_fee, check_unique_pubkeys},
|
checks::{check_account_for_fee_with_commitment, check_unique_pubkeys},
|
||||||
cli::{
|
cli::{
|
||||||
fee_payer_arg, generate_unique_signers, log_instruction_custom_error, nonce_authority_arg,
|
fee_payer_arg, generate_unique_signers, log_instruction_custom_error, nonce_authority_arg,
|
||||||
return_signers, CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult,
|
return_signers, CliCommand, CliCommandInfo, CliConfig, CliError, ProcessResult,
|
||||||
SignerIndex, FEE_PAYER_ARG,
|
SignerIndex, FEE_PAYER_ARG,
|
||||||
},
|
},
|
||||||
cli_output::{CliStakeHistory, CliStakeHistoryEntry, CliStakeState, CliStakeType},
|
cli_output::{CliStakeHistory, CliStakeHistoryEntry, CliStakeState, CliStakeType},
|
||||||
nonce::{check_nonce_account, nonce_arg, NONCE_ARG, NONCE_AUTHORITY_ARG},
|
nonce::{self, check_nonce_account, nonce_arg, NONCE_ARG, NONCE_AUTHORITY_ARG},
|
||||||
offline::{blockhash_query::BlockhashQuery, *},
|
offline::{blockhash_query::BlockhashQuery, *},
|
||||||
spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount},
|
spend_utils::{resolve_spend_tx_and_check_account_balances, SpendAmount},
|
||||||
};
|
};
|
||||||
|
@ -896,7 +896,7 @@ pub fn process_create_stake_account(
|
||||||
};
|
};
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let (message, lamports) = resolve_spend_tx_and_check_account_balances(
|
let (message, lamports) = resolve_spend_tx_and_check_account_balances(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
|
@ -906,6 +906,7 @@ pub fn process_create_stake_account(
|
||||||
&from.pubkey(),
|
&from.pubkey(),
|
||||||
&fee_payer.pubkey(),
|
&fee_payer.pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if !sign_only {
|
if !sign_only {
|
||||||
|
@ -933,7 +934,8 @@ pub fn process_create_stake_account(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -944,7 +946,11 @@ pub fn process_create_stake_account(
|
||||||
return_signers(&tx, &config)
|
return_signers(&tx, &config)
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -977,7 +983,7 @@ pub fn process_stake_authorize(
|
||||||
}
|
}
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let nonce_authority = config.signers[nonce_authority];
|
let nonce_authority = config.signers[nonce_authority];
|
||||||
let fee_payer = config.signers[fee_payer];
|
let fee_payer = config.signers[fee_payer];
|
||||||
|
@ -1000,16 +1006,22 @@ pub fn process_stake_authorize(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1039,7 @@ pub fn process_deactivate_stake_account(
|
||||||
fee_payer: SignerIndex,
|
fee_payer: SignerIndex,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
let stake_authority = config.signers[stake_authority];
|
let stake_authority = config.signers[stake_authority];
|
||||||
let ixs = vec![stake_instruction::deactivate_stake(
|
let ixs = vec![stake_instruction::deactivate_stake(
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
|
@ -1054,16 +1066,22 @@ pub fn process_deactivate_stake_account(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1084,7 +1102,7 @@ pub fn process_withdraw_stake(
|
||||||
fee_payer: SignerIndex,
|
fee_payer: SignerIndex,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
let withdraw_authority = config.signers[withdraw_authority];
|
let withdraw_authority = config.signers[withdraw_authority];
|
||||||
let custodian = custodian.map(|index| config.signers[index]);
|
let custodian = custodian.map(|index| config.signers[index]);
|
||||||
|
|
||||||
|
@ -1117,16 +1135,22 @@ pub fn process_withdraw_stake(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1235,7 @@ pub fn process_split_stake(
|
||||||
}
|
}
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let ixs = if let Some(seed) = split_stake_account_seed {
|
let ixs = if let Some(seed) = split_stake_account_seed {
|
||||||
stake_instruction::split_with_seed(
|
stake_instruction::split_with_seed(
|
||||||
|
@ -1251,16 +1275,22 @@ pub fn process_split_stake(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1316,7 +1346,7 @@ pub fn process_merge_stake(
|
||||||
}
|
}
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let ixs = stake_instruction::merge(
|
let ixs = stake_instruction::merge(
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
|
@ -1344,16 +1374,22 @@ pub fn process_merge_stake(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1372,7 +1408,7 @@ pub fn process_stake_set_lockup(
|
||||||
fee_payer: SignerIndex,
|
fee_payer: SignerIndex,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
let custodian = config.signers[custodian];
|
let custodian = config.signers[custodian];
|
||||||
|
|
||||||
let ixs = vec![stake_instruction::set_lockup(
|
let ixs = vec![stake_instruction::set_lockup(
|
||||||
|
@ -1401,16 +1437,22 @@ pub fn process_stake_set_lockup(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1598,14 +1640,23 @@ pub fn process_delegate_stake(
|
||||||
if !sign_only {
|
if !sign_only {
|
||||||
// Sanity check the vote account to ensure it is attached to a validator that has recently
|
// Sanity check the vote account to ensure it is attached to a validator that has recently
|
||||||
// voted at the tip of the ledger
|
// voted at the tip of the ledger
|
||||||
let vote_account_data = rpc_client
|
let vote_account = rpc_client
|
||||||
.get_account_data(vote_account_pubkey)
|
.get_account_with_commitment(vote_account_pubkey, config.commitment)
|
||||||
.map_err(|_| {
|
.map_err(|_| {
|
||||||
CliError::RpcRequestError(format!(
|
CliError::RpcRequestError(format!(
|
||||||
"Vote account not found: {}",
|
"Vote account not found: {}",
|
||||||
vote_account_pubkey
|
vote_account_pubkey
|
||||||
))
|
))
|
||||||
})?;
|
})?;
|
||||||
|
let vote_account_data = if let Some(account) = vote_account.value {
|
||||||
|
account.data
|
||||||
|
} else {
|
||||||
|
return Err(CliError::RpcRequestError(format!(
|
||||||
|
"Vote account not found: {}",
|
||||||
|
vote_account_pubkey
|
||||||
|
))
|
||||||
|
.into());
|
||||||
|
};
|
||||||
|
|
||||||
let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| {
|
let vote_state = VoteState::deserialize(&vote_account_data).map_err(|_| {
|
||||||
CliError::RpcRequestError(
|
CliError::RpcRequestError(
|
||||||
|
@ -1643,7 +1694,7 @@ pub fn process_delegate_stake(
|
||||||
}
|
}
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) =
|
let (recent_blockhash, fee_calculator) =
|
||||||
blockhash_query.get_blockhash_and_fee_calculator(rpc_client)?;
|
blockhash_query.get_blockhash_and_fee_calculator(rpc_client, config.commitment)?;
|
||||||
|
|
||||||
let ixs = vec![stake_instruction::delegate_stake(
|
let ixs = vec![stake_instruction::delegate_stake(
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
|
@ -1671,16 +1722,22 @@ pub fn process_delegate_stake(
|
||||||
} else {
|
} else {
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
if let Some(nonce_account) = &nonce_account {
|
if let Some(nonce_account) = &nonce_account {
|
||||||
let nonce_account = rpc_client.get_account(nonce_account)?;
|
let nonce_account =
|
||||||
|
nonce::get_account_with_commitment(rpc_client, nonce_account, config.commitment)?;
|
||||||
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
check_nonce_account(&nonce_account, &nonce_authority.pubkey(), &recent_blockhash)?;
|
||||||
}
|
}
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<StakeError>(result, &config)
|
log_instruction_custom_error::<StakeError>(result, &config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::{clock::DEFAULT_MS_PER_SLOT, commitment_config::CommitmentConfig, pubkey::Pubkey};
|
||||||
use std::{thread::sleep, time::Duration};
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
pub fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
|
pub fn check_recent_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey) {
|
||||||
(0..5).for_each(|tries| {
|
(0..5).for_each(|tries| {
|
||||||
let balance = client.get_balance(pubkey).unwrap();
|
let balance = client
|
||||||
|
.get_balance_with_commitment(pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value;
|
||||||
if balance == expected_balance {
|
if balance == expected_balance {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -14,3 +17,13 @@ pub fn check_balance(expected_balance: u64, client: &RpcClient, pubkey: &Pubkey)
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn check_ready(rpc_client: &RpcClient) {
|
||||||
|
while rpc_client
|
||||||
|
.get_slot_with_commitment(CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
< 5
|
||||||
|
{
|
||||||
|
sleep(Duration::from_millis(DEFAULT_MS_PER_SLOT));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -372,6 +372,7 @@ pub fn process_set_validator_info(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&signers, recent_blockhash)?;
|
tx.try_sign(&signers, recent_blockhash)?;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
checks::{check_account_for_fee, check_unique_pubkeys},
|
checks::{check_account_for_fee_with_commitment, check_unique_pubkeys},
|
||||||
cli::{
|
cli::{
|
||||||
generate_unique_signers, log_instruction_custom_error, CliCommand, CliCommandInfo,
|
generate_unique_signers, log_instruction_custom_error, CliCommand, CliCommandInfo,
|
||||||
CliConfig, CliError, ProcessResult, SignerIndex,
|
CliConfig, CliError, ProcessResult, SignerIndex,
|
||||||
|
@ -8,11 +8,7 @@ use crate::{
|
||||||
spend_utils::{resolve_spend_tx_and_check_account_balance, SpendAmount},
|
spend_utils::{resolve_spend_tx_and_check_account_balance, SpendAmount},
|
||||||
};
|
};
|
||||||
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
|
use clap::{value_t_or_exit, App, Arg, ArgMatches, SubCommand};
|
||||||
use solana_clap_utils::{
|
use solana_clap_utils::{commitment::commitment_arg, input_parsers::*, input_validators::*};
|
||||||
commitment::{commitment_arg, COMMITMENT_ARG},
|
|
||||||
input_parsers::*,
|
|
||||||
input_validators::*,
|
|
||||||
};
|
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
use solana_remote_wallet::remote_wallet::RemoteWalletManager;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
@ -373,12 +369,10 @@ pub fn parse_vote_get_account_command(
|
||||||
let vote_account_pubkey =
|
let vote_account_pubkey =
|
||||||
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
|
pubkey_of_signer(matches, "vote_account_pubkey", wallet_manager)?.unwrap();
|
||||||
let use_lamports_unit = matches.is_present("lamports");
|
let use_lamports_unit = matches.is_present("lamports");
|
||||||
let commitment_config = commitment_of(matches, COMMITMENT_ARG.long).unwrap();
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::ShowVoteAccount {
|
command: CliCommand::ShowVoteAccount {
|
||||||
pubkey: vote_account_pubkey,
|
pubkey: vote_account_pubkey,
|
||||||
use_lamports_unit,
|
use_lamports_unit,
|
||||||
commitment_config,
|
|
||||||
},
|
},
|
||||||
signers: vec![],
|
signers: vec![],
|
||||||
})
|
})
|
||||||
|
@ -478,7 +472,10 @@ pub fn process_create_vote_account(
|
||||||
Message::new(&ixs)
|
Message::new(&ixs)
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(vote_account) = rpc_client.get_account(&vote_account_address) {
|
if let Ok(response) =
|
||||||
|
rpc_client.get_account_with_commitment(&vote_account_address, config.commitment)
|
||||||
|
{
|
||||||
|
if let Some(vote_account) = response.value {
|
||||||
let err_msg = if vote_account.owner == solana_vote_program::id() {
|
let err_msg = if vote_account.owner == solana_vote_program::id() {
|
||||||
format!("Vote account {} already exists", vote_account_address)
|
format!("Vote account {} already exists", vote_account_address)
|
||||||
} else {
|
} else {
|
||||||
|
@ -489,8 +486,11 @@ pub fn process_create_vote_account(
|
||||||
};
|
};
|
||||||
return Err(CliError::BadParameter(err_msg).into());
|
return Err(CliError::BadParameter(err_msg).into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
|
|
||||||
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
let (message, _) = resolve_spend_tx_and_check_account_balance(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
|
@ -499,10 +499,15 @@ pub fn process_create_vote_account(
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
build_message,
|
build_message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<SystemError>(result, &config)
|
log_instruction_custom_error::<SystemError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +530,9 @@ pub fn process_vote_authorize(
|
||||||
(&authorized.pubkey(), "authorized_account".to_string()),
|
(&authorized.pubkey(), "authorized_account".to_string()),
|
||||||
(new_authorized_pubkey, "new_authorized_pubkey".to_string()),
|
(new_authorized_pubkey, "new_authorized_pubkey".to_string()),
|
||||||
)?;
|
)?;
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let ixs = vec![vote_instruction::authorize(
|
let ixs = vec![vote_instruction::authorize(
|
||||||
vote_account_pubkey, // vote account to update
|
vote_account_pubkey, // vote account to update
|
||||||
&authorized.pubkey(), // current authorized
|
&authorized.pubkey(), // current authorized
|
||||||
|
@ -536,13 +543,18 @@ pub fn process_vote_authorize(
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<VoteError>(result, &config)
|
log_instruction_custom_error::<VoteError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,7 +571,9 @@ pub fn process_vote_update_validator(
|
||||||
(vote_account_pubkey, "vote_account_pubkey".to_string()),
|
(vote_account_pubkey, "vote_account_pubkey".to_string()),
|
||||||
(&new_identity_pubkey, "new_identity_account".to_string()),
|
(&new_identity_pubkey, "new_identity_account".to_string()),
|
||||||
)?;
|
)?;
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let ixs = vec![vote_instruction::update_validator_identity(
|
let ixs = vec![vote_instruction::update_validator_identity(
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
&authorized_withdrawer.pubkey(),
|
&authorized_withdrawer.pubkey(),
|
||||||
|
@ -569,13 +583,18 @@ pub fn process_vote_update_validator(
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<VoteError>(result, &config)
|
log_instruction_custom_error::<VoteError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,7 +605,9 @@ pub fn process_vote_update_commission(
|
||||||
commission: u8,
|
commission: u8,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let authorized_withdrawer = config.signers[1];
|
let authorized_withdrawer = config.signers[1];
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let ixs = vec![vote_instruction::update_commission(
|
let ixs = vec![vote_instruction::update_commission(
|
||||||
vote_account_pubkey,
|
vote_account_pubkey,
|
||||||
&authorized_withdrawer.pubkey(),
|
&authorized_withdrawer.pubkey(),
|
||||||
|
@ -596,13 +617,18 @@ pub fn process_vote_update_commission(
|
||||||
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&ixs, Some(&config.signers[0].pubkey()));
|
||||||
let mut tx = Transaction::new_unsigned(message);
|
let mut tx = Transaction::new_unsigned(message);
|
||||||
tx.try_sign(&config.signers, recent_blockhash)?;
|
tx.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&tx.message,
|
&tx.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&tx);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&tx,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<VoteError>(result, &config)
|
log_instruction_custom_error::<VoteError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -639,10 +665,9 @@ pub fn process_show_vote_account(
|
||||||
config: &CliConfig,
|
config: &CliConfig,
|
||||||
vote_account_pubkey: &Pubkey,
|
vote_account_pubkey: &Pubkey,
|
||||||
use_lamports_unit: bool,
|
use_lamports_unit: bool,
|
||||||
commitment_config: CommitmentConfig,
|
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (vote_account, vote_state) =
|
let (vote_account, vote_state) =
|
||||||
get_vote_account(rpc_client, vote_account_pubkey, commitment_config)?;
|
get_vote_account(rpc_client, vote_account_pubkey, config.commitment)?;
|
||||||
|
|
||||||
let epoch_schedule = rpc_client.get_epoch_schedule()?;
|
let epoch_schedule = rpc_client.get_epoch_schedule()?;
|
||||||
|
|
||||||
|
@ -688,10 +713,14 @@ pub fn process_withdraw_from_vote_account(
|
||||||
withdraw_amount: SpendAmount,
|
withdraw_amount: SpendAmount,
|
||||||
destination_account_pubkey: &Pubkey,
|
destination_account_pubkey: &Pubkey,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
|
let (recent_blockhash, fee_calculator, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(config.commitment)?
|
||||||
|
.value;
|
||||||
let withdraw_authority = config.signers[withdraw_authority];
|
let withdraw_authority = config.signers[withdraw_authority];
|
||||||
|
|
||||||
let current_balance = rpc_client.get_balance(&vote_account_pubkey)?;
|
let current_balance = rpc_client
|
||||||
|
.get_balance_with_commitment(&vote_account_pubkey, config.commitment)?
|
||||||
|
.value;
|
||||||
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
|
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(VoteState::size_of())?;
|
||||||
|
|
||||||
let lamports = match withdraw_amount {
|
let lamports = match withdraw_amount {
|
||||||
|
@ -717,13 +746,18 @@ pub fn process_withdraw_from_vote_account(
|
||||||
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
let message = Message::new_with_payer(&[ix], Some(&config.signers[0].pubkey()));
|
||||||
let mut transaction = Transaction::new_unsigned(message);
|
let mut transaction = Transaction::new_unsigned(message);
|
||||||
transaction.try_sign(&config.signers, recent_blockhash)?;
|
transaction.try_sign(&config.signers, recent_blockhash)?;
|
||||||
check_account_for_fee(
|
check_account_for_fee_with_commitment(
|
||||||
rpc_client,
|
rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
&fee_calculator,
|
&fee_calculator,
|
||||||
&transaction.message,
|
&transaction.message,
|
||||||
|
config.commitment,
|
||||||
)?;
|
)?;
|
||||||
let result = rpc_client.send_and_confirm_transaction_with_spinner(&transaction);
|
let result = rpc_client.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
&transaction,
|
||||||
|
config.commitment,
|
||||||
|
config.send_transaction_config,
|
||||||
|
);
|
||||||
log_instruction_custom_error::<VoteError>(result, &config)
|
log_instruction_custom_error::<VoteError>(result, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ use solana_core::validator::TestValidator;
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
bpf_loader,
|
bpf_loader,
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
};
|
};
|
||||||
|
@ -47,7 +48,7 @@ fn test_cli_deploy_program() {
|
||||||
.get_minimum_balance_for_rent_exemption(program_data.len())
|
.get_minimum_balance_for_rent_exemption(program_data.len())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.command = CliCommand::Airdrop {
|
config.command = CliCommand::Airdrop {
|
||||||
|
@ -74,7 +75,11 @@ fn test_cli_deploy_program() {
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let program_id = Pubkey::from_str(&program_id_str).unwrap();
|
let program_id = Pubkey::from_str(&program_id_str).unwrap();
|
||||||
let account0 = rpc_client.get_account(&program_id).unwrap();
|
let account0 = rpc_client
|
||||||
|
.get_account_with_commitment(&program_id, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
assert_eq!(account0.lamports, minimum_balance_for_rent_exemption);
|
assert_eq!(account0.lamports, minimum_balance_for_rent_exemption);
|
||||||
assert_eq!(account0.owner, bpf_loader::id());
|
assert_eq!(account0.owner, bpf_loader::id());
|
||||||
assert_eq!(account0.executable, true);
|
assert_eq!(account0.executable, true);
|
||||||
|
@ -94,7 +99,9 @@ fn test_cli_deploy_program() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let account1 = rpc_client
|
let account1 = rpc_client
|
||||||
.get_account(&custom_address_keypair.pubkey())
|
.get_account_with_commitment(&custom_address_keypair.pubkey(), CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(account1.lamports, minimum_balance_for_rent_exemption);
|
assert_eq!(account1.lamports, minimum_balance_for_rent_exemption);
|
||||||
assert_eq!(account1.owner, bpf_loader::id());
|
assert_eq!(account1.owner, bpf_loader::id());
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use solana_cli::test_utils::check_balance;
|
|
||||||
use solana_cli::{
|
use solana_cli::{
|
||||||
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
||||||
cli_output::OutputFormat,
|
cli_output::OutputFormat,
|
||||||
|
@ -8,12 +7,14 @@ use solana_cli::{
|
||||||
parse_sign_only_reply_string,
|
parse_sign_only_reply_string,
|
||||||
},
|
},
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
|
test_utils::{check_ready, check_recent_balance},
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::contact_info::ContactInfo;
|
use solana_core::contact_info::ContactInfo;
|
||||||
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{keypair_from_seed, Keypair, Signer},
|
signature::{keypair_from_seed, Keypair, Signer},
|
||||||
|
@ -83,7 +84,7 @@ fn full_battery_tests(
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
let json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
|
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.json_rpc_url = json_rpc_url.clone();
|
config_payer.json_rpc_url = json_rpc_url.clone();
|
||||||
let payer = Keypair::new();
|
let payer = Keypair::new();
|
||||||
config_payer.signers = vec![&payer];
|
config_payer.signers = vec![&payer];
|
||||||
|
@ -96,9 +97,9 @@ fn full_battery_tests(
|
||||||
&config_payer,
|
&config_payer,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(2000, &rpc_client, &config_payer.signers[0].pubkey());
|
check_recent_balance(2000, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
|
|
||||||
let mut config_nonce = CliConfig::default();
|
let mut config_nonce = CliConfig::recent_for_tests();
|
||||||
config_nonce.json_rpc_url = json_rpc_url;
|
config_nonce.json_rpc_url = json_rpc_url;
|
||||||
let nonce_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let nonce_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
config_nonce.signers = vec![&nonce_keypair];
|
config_nonce.signers = vec![&nonce_keypair];
|
||||||
|
@ -131,8 +132,8 @@ fn full_battery_tests(
|
||||||
};
|
};
|
||||||
|
|
||||||
process_command(&config_payer).unwrap();
|
process_command(&config_payer).unwrap();
|
||||||
check_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
check_balance(1000, &rpc_client, &nonce_account);
|
check_recent_balance(1000, &rpc_client, &nonce_account);
|
||||||
|
|
||||||
// Get nonce
|
// Get nonce
|
||||||
config_payer.signers.pop();
|
config_payer.signers.pop();
|
||||||
|
@ -181,9 +182,9 @@ fn full_battery_tests(
|
||||||
lamports: 100,
|
lamports: 100,
|
||||||
};
|
};
|
||||||
process_command(&config_payer).unwrap();
|
process_command(&config_payer).unwrap();
|
||||||
check_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
check_balance(900, &rpc_client, &nonce_account);
|
check_recent_balance(900, &rpc_client, &nonce_account);
|
||||||
check_balance(100, &rpc_client, &payee_pubkey);
|
check_recent_balance(100, &rpc_client, &payee_pubkey);
|
||||||
|
|
||||||
// Show nonce account
|
// Show nonce account
|
||||||
config_payer.command = CliCommand::ShowNonceAccount {
|
config_payer.command = CliCommand::ShowNonceAccount {
|
||||||
|
@ -224,9 +225,9 @@ fn full_battery_tests(
|
||||||
lamports: 100,
|
lamports: 100,
|
||||||
};
|
};
|
||||||
process_command(&config_payer).unwrap();
|
process_command(&config_payer).unwrap();
|
||||||
check_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
check_recent_balance(1000, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
check_balance(800, &rpc_client, &nonce_account);
|
check_recent_balance(800, &rpc_client, &nonce_account);
|
||||||
check_balance(200, &rpc_client, &payee_pubkey);
|
check_recent_balance(200, &rpc_client, &payee_pubkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -250,7 +251,7 @@ fn test_create_account_with_seed() {
|
||||||
let offline_nonce_authority_signer = keypair_from_seed(&[1u8; 32]).unwrap();
|
let offline_nonce_authority_signer = keypair_from_seed(&[1u8; 32]).unwrap();
|
||||||
let online_nonce_creator_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
let online_nonce_creator_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
||||||
let to_address = Pubkey::new(&[3u8; 32]);
|
let to_address = Pubkey::new(&[3u8; 32]);
|
||||||
let config = CliConfig::default();
|
let config = CliConfig::recent_for_tests();
|
||||||
|
|
||||||
// Setup accounts
|
// Setup accounts
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
@ -270,9 +271,11 @@ fn test_create_account_with_seed() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
check_recent_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
||||||
check_balance(4242, &rpc_client, &online_nonce_creator_signer.pubkey());
|
check_recent_balance(4242, &rpc_client, &online_nonce_creator_signer.pubkey());
|
||||||
check_balance(0, &rpc_client, &to_address);
|
check_recent_balance(0, &rpc_client, &to_address);
|
||||||
|
|
||||||
|
check_ready(&rpc_client);
|
||||||
|
|
||||||
// Create nonce account
|
// Create nonce account
|
||||||
let creator_pubkey = online_nonce_creator_signer.pubkey();
|
let creator_pubkey = online_nonce_creator_signer.pubkey();
|
||||||
|
@ -280,9 +283,9 @@ fn test_create_account_with_seed() {
|
||||||
let seed = authority_pubkey.to_string()[0..32].to_string();
|
let seed = authority_pubkey.to_string()[0..32].to_string();
|
||||||
let nonce_address =
|
let nonce_address =
|
||||||
Pubkey::create_with_seed(&creator_pubkey, &seed, &system_program::id()).unwrap();
|
Pubkey::create_with_seed(&creator_pubkey, &seed, &system_program::id()).unwrap();
|
||||||
check_balance(0, &rpc_client, &nonce_address);
|
check_recent_balance(0, &rpc_client, &nonce_address);
|
||||||
|
|
||||||
let mut creator_config = CliConfig::default();
|
let mut creator_config = CliConfig::recent_for_tests();
|
||||||
creator_config.json_rpc_url =
|
creator_config.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
creator_config.signers = vec![&online_nonce_creator_signer];
|
creator_config.signers = vec![&online_nonce_creator_signer];
|
||||||
|
@ -293,19 +296,20 @@ fn test_create_account_with_seed() {
|
||||||
amount: SpendAmount::Some(241),
|
amount: SpendAmount::Some(241),
|
||||||
};
|
};
|
||||||
process_command(&creator_config).unwrap();
|
process_command(&creator_config).unwrap();
|
||||||
check_balance(241, &rpc_client, &nonce_address);
|
check_recent_balance(241, &rpc_client, &nonce_address);
|
||||||
check_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
check_recent_balance(42, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
||||||
check_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
|
check_recent_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
|
||||||
check_balance(0, &rpc_client, &to_address);
|
check_recent_balance(0, &rpc_client, &to_address);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_address)
|
let nonce_hash =
|
||||||
|
nonce::get_account_with_commitment(&rpc_client, &nonce_address, CommitmentConfig::recent())
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
|
||||||
// Test by creating transfer TX with nonce, fully offline
|
// Test by creating transfer TX with nonce, fully offline
|
||||||
let mut authority_config = CliConfig::default();
|
let mut authority_config = CliConfig::recent_for_tests();
|
||||||
authority_config.json_rpc_url = String::default();
|
authority_config.json_rpc_url = String::default();
|
||||||
authority_config.signers = vec![&offline_nonce_authority_signer];
|
authority_config.signers = vec![&offline_nonce_authority_signer];
|
||||||
// Verify we cannot contact the cluster
|
// Verify we cannot contact the cluster
|
||||||
|
@ -329,7 +333,7 @@ fn test_create_account_with_seed() {
|
||||||
assert_eq!(sign_only.blockhash, nonce_hash);
|
assert_eq!(sign_only.blockhash, nonce_hash);
|
||||||
|
|
||||||
// And submit it
|
// And submit it
|
||||||
let mut submit_config = CliConfig::default();
|
let mut submit_config = CliConfig::recent_for_tests();
|
||||||
submit_config.json_rpc_url =
|
submit_config.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
submit_config.signers = vec![&authority_presigner];
|
submit_config.signers = vec![&authority_presigner];
|
||||||
|
@ -348,10 +352,10 @@ fn test_create_account_with_seed() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&submit_config).unwrap();
|
process_command(&submit_config).unwrap();
|
||||||
check_balance(241, &rpc_client, &nonce_address);
|
check_recent_balance(241, &rpc_client, &nonce_address);
|
||||||
check_balance(31, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
check_recent_balance(31, &rpc_client, &offline_nonce_authority_signer.pubkey());
|
||||||
check_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
|
check_recent_balance(4000, &rpc_client, &online_nonce_creator_signer.pubkey());
|
||||||
check_balance(10, &rpc_client, &to_address);
|
check_recent_balance(10, &rpc_client, &to_address);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use solana_cli::test_utils::check_balance;
|
|
||||||
use solana_cli::{
|
use solana_cli::{
|
||||||
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig, PayCommand},
|
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig, PayCommand},
|
||||||
cli_output::OutputFormat,
|
cli_output::OutputFormat,
|
||||||
|
@ -10,11 +9,13 @@ use solana_cli::{
|
||||||
parse_sign_only_reply_string,
|
parse_sign_only_reply_string,
|
||||||
},
|
},
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
|
test_utils::check_recent_balance,
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::validator::TestValidator;
|
use solana_core::validator::TestValidator;
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
nonce::State as NonceState,
|
nonce::State as NonceState,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
|
@ -40,12 +41,12 @@ fn test_cli_timestamp_tx() {
|
||||||
let default_signer0 = Keypair::new();
|
let default_signer0 = Keypair::new();
|
||||||
let default_signer1 = Keypair::new();
|
let default_signer1 = Keypair::new();
|
||||||
|
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.json_rpc_url =
|
config_payer.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_payer.signers = vec![&default_signer0];
|
config_payer.signers = vec![&default_signer0];
|
||||||
|
|
||||||
let mut config_witness = CliConfig::default();
|
let mut config_witness = CliConfig::recent_for_tests();
|
||||||
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
||||||
config_witness.signers = vec![&default_signer1];
|
config_witness.signers = vec![&default_signer1];
|
||||||
|
|
||||||
|
@ -62,7 +63,7 @@ fn test_cli_timestamp_tx() {
|
||||||
&config_witness,
|
&config_witness,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(50, &rpc_client, &config_payer.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config_payer.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(
|
request_and_confirm_airdrop(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
|
@ -92,17 +93,17 @@ fn test_cli_timestamp_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, &process_id); // contract balance
|
check_recent_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_witness.command = CliCommand::TimeElapsed(bob_pubkey, process_id, dt);
|
config_witness.command = CliCommand::TimeElapsed(bob_pubkey, process_id, dt);
|
||||||
process_command(&config_witness).unwrap();
|
process_command(&config_witness).unwrap();
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, &process_id); // contract balance
|
check_recent_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -127,12 +128,12 @@ fn test_cli_witness_tx() {
|
||||||
let default_signer0 = Keypair::new();
|
let default_signer0 = Keypair::new();
|
||||||
let default_signer1 = Keypair::new();
|
let default_signer1 = Keypair::new();
|
||||||
|
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.json_rpc_url =
|
config_payer.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_payer.signers = vec![&default_signer0];
|
config_payer.signers = vec![&default_signer0];
|
||||||
|
|
||||||
let mut config_witness = CliConfig::default();
|
let mut config_witness = CliConfig::recent_for_tests();
|
||||||
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
||||||
config_witness.signers = vec![&default_signer1];
|
config_witness.signers = vec![&default_signer1];
|
||||||
|
|
||||||
|
@ -174,17 +175,17 @@ fn test_cli_witness_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, &process_id); // contract balance
|
check_recent_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_witness.command = CliCommand::Witness(bob_pubkey, process_id);
|
config_witness.command = CliCommand::Witness(bob_pubkey, process_id);
|
||||||
process_command(&config_witness).unwrap();
|
process_command(&config_witness).unwrap();
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, &process_id); // contract balance
|
check_recent_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(10, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -209,12 +210,12 @@ fn test_cli_cancel_tx() {
|
||||||
let default_signer0 = Keypair::new();
|
let default_signer0 = Keypair::new();
|
||||||
let default_signer1 = Keypair::new();
|
let default_signer1 = Keypair::new();
|
||||||
|
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.json_rpc_url =
|
config_payer.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_payer.signers = vec![&default_signer0];
|
config_payer.signers = vec![&default_signer0];
|
||||||
|
|
||||||
let mut config_witness = CliConfig::default();
|
let mut config_witness = CliConfig::recent_for_tests();
|
||||||
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
config_witness.json_rpc_url = config_payer.json_rpc_url.clone();
|
||||||
config_witness.signers = vec![&default_signer1];
|
config_witness.signers = vec![&default_signer1];
|
||||||
|
|
||||||
|
@ -249,17 +250,17 @@ fn test_cli_cancel_tx() {
|
||||||
.expect("base58-encoded public key");
|
.expect("base58-encoded public key");
|
||||||
let process_id = Pubkey::new(&process_id_vec);
|
let process_id = Pubkey::new(&process_id_vec);
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(40, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(10, &rpc_client, &process_id); // contract balance
|
check_recent_balance(10, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
// Sign transaction by config_witness
|
// Sign transaction by config_witness
|
||||||
config_payer.command = CliCommand::Cancel(process_id);
|
config_payer.command = CliCommand::Cancel(process_id);
|
||||||
process_command(&config_payer).unwrap();
|
process_command(&config_payer).unwrap();
|
||||||
|
|
||||||
check_balance(50, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
check_recent_balance(50, &rpc_client, &config_payer.signers[0].pubkey()); // config_payer balance
|
||||||
check_balance(0, &rpc_client, &process_id); // contract balance
|
check_recent_balance(0, &rpc_client, &process_id); // contract balance
|
||||||
check_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
check_recent_balance(0, &rpc_client, &bob_pubkey); // recipient balance
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -284,11 +285,11 @@ fn test_offline_pay_tx() {
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
let default_offline_signer = Keypair::new();
|
let default_offline_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
config_offline.json_rpc_url =
|
config_offline.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_offline.signers = vec![&default_offline_signer];
|
config_offline.signers = vec![&default_offline_signer];
|
||||||
let mut config_online = CliConfig::default();
|
let mut config_online = CliConfig::recent_for_tests();
|
||||||
config_online.json_rpc_url =
|
config_online.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_online.signers = vec![&default_signer];
|
config_online.signers = vec![&default_signer];
|
||||||
|
@ -314,8 +315,8 @@ fn test_offline_pay_tx() {
|
||||||
&config_offline,
|
&config_offline,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(50, &rpc_client, &config_offline.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config_offline.signers[0].pubkey());
|
||||||
check_balance(50, &rpc_client, &config_online.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config_online.signers[0].pubkey());
|
||||||
|
|
||||||
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
||||||
config_offline.command = CliCommand::Pay(PayCommand {
|
config_offline.command = CliCommand::Pay(PayCommand {
|
||||||
|
@ -328,9 +329,9 @@ fn test_offline_pay_tx() {
|
||||||
config_offline.output_format = OutputFormat::JsonCompact;
|
config_offline.output_format = OutputFormat::JsonCompact;
|
||||||
let sig_response = process_command(&config_offline).unwrap();
|
let sig_response = process_command(&config_offline).unwrap();
|
||||||
|
|
||||||
check_balance(50, &rpc_client, &config_offline.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config_offline.signers[0].pubkey());
|
||||||
check_balance(50, &rpc_client, &config_online.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config_online.signers[0].pubkey());
|
||||||
check_balance(0, &rpc_client, &bob_pubkey);
|
check_recent_balance(0, &rpc_client, &bob_pubkey);
|
||||||
|
|
||||||
let sign_only = parse_sign_only_reply_string(&sig_response);
|
let sign_only = parse_sign_only_reply_string(&sig_response);
|
||||||
assert!(sign_only.has_all_signers());
|
assert!(sign_only.has_all_signers());
|
||||||
|
@ -347,9 +348,9 @@ fn test_offline_pay_tx() {
|
||||||
});
|
});
|
||||||
process_command(&config_online).unwrap();
|
process_command(&config_online).unwrap();
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config_offline.signers[0].pubkey());
|
check_recent_balance(40, &rpc_client, &config_offline.signers[0].pubkey());
|
||||||
check_balance(50, &rpc_client, &online_pubkey);
|
check_recent_balance(50, &rpc_client, &online_pubkey);
|
||||||
check_balance(10, &rpc_client, &bob_pubkey);
|
check_recent_balance(10, &rpc_client, &bob_pubkey);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -373,7 +374,7 @@ fn test_nonced_pay_tx() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -389,7 +390,7 @@ fn test_nonced_pay_tx() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(
|
check_recent_balance(
|
||||||
50 + minimum_nonce_balance,
|
50 + minimum_nonce_balance,
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
&config.signers[0].pubkey(),
|
&config.signers[0].pubkey(),
|
||||||
|
@ -406,11 +407,15 @@ fn test_nonced_pay_tx() {
|
||||||
config.signers.push(&nonce_account);
|
config.signers.push(&nonce_account);
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
check_balance(50, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(50, &rpc_client, &config.signers[0].pubkey());
|
||||||
check_balance(minimum_nonce_balance, &rpc_client, &nonce_account.pubkey());
|
check_recent_balance(minimum_nonce_balance, &rpc_client, &nonce_account.pubkey());
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -429,11 +434,15 @@ fn test_nonced_pay_tx() {
|
||||||
});
|
});
|
||||||
process_command(&config).expect("failed to process pay command");
|
process_command(&config).expect("failed to process pay command");
|
||||||
|
|
||||||
check_balance(40, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(40, &rpc_client, &config.signers[0].pubkey());
|
||||||
check_balance(10, &rpc_client, &bob_pubkey);
|
check_recent_balance(10, &rpc_client, &bob_pubkey);
|
||||||
|
|
||||||
// Verify that nonce has been used
|
// Verify that nonce has been used
|
||||||
let nonce_hash2 = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash2 = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
|
|
@ -2,7 +2,7 @@ use solana_cli::cli::{process_command, CliCommand, CliConfig};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::validator::TestValidator;
|
use solana_core::validator::TestValidator;
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::signature::Keypair;
|
use solana_sdk::{commitment_config::CommitmentConfig, signature::Keypair};
|
||||||
use std::{fs::remove_dir_all, sync::mpsc::channel};
|
use std::{fs::remove_dir_all, sync::mpsc::channel};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -18,7 +18,7 @@ fn test_cli_request_airdrop() {
|
||||||
run_local_faucet(alice, sender, None);
|
run_local_faucet(alice, sender, None);
|
||||||
let faucet_addr = receiver.recv().unwrap();
|
let faucet_addr = receiver.recv().unwrap();
|
||||||
|
|
||||||
let mut bob_config = CliConfig::default();
|
let mut bob_config = CliConfig::recent_for_tests();
|
||||||
bob_config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
bob_config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
bob_config.command = CliCommand::Airdrop {
|
bob_config.command = CliCommand::Airdrop {
|
||||||
faucet_host: None,
|
faucet_host: None,
|
||||||
|
@ -35,8 +35,9 @@ fn test_cli_request_airdrop() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
|
||||||
let balance = rpc_client
|
let balance = rpc_client
|
||||||
.get_balance(&bob_config.signers[0].pubkey())
|
.get_balance_with_commitment(&bob_config.signers[0].pubkey(), CommitmentConfig::recent())
|
||||||
.unwrap();
|
.unwrap()
|
||||||
|
.value;
|
||||||
assert_eq!(balance, 50);
|
assert_eq!(balance, 50);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use solana_cli::test_utils::check_balance;
|
|
||||||
use solana_cli::{
|
use solana_cli::{
|
||||||
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
||||||
cli_output::OutputFormat,
|
cli_output::OutputFormat,
|
||||||
|
@ -8,12 +7,14 @@ use solana_cli::{
|
||||||
parse_sign_only_reply_string,
|
parse_sign_only_reply_string,
|
||||||
},
|
},
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
|
test_utils::{check_ready, check_recent_balance},
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
nonce::State as NonceState,
|
nonce::State as NonceState,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{keypair_from_seed, Keypair, Signer},
|
signature::{keypair_from_seed, Keypair, Signer},
|
||||||
|
@ -40,7 +41,7 @@ fn test_stake_delegation_force() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -136,7 +137,7 @@ fn test_seed_stake_delegation_and_deactivation() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
|
||||||
let validator_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let validator_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
let mut config_validator = CliConfig::default();
|
let mut config_validator = CliConfig::recent_for_tests();
|
||||||
config_validator.json_rpc_url =
|
config_validator.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_validator.signers = vec![&validator_keypair];
|
config_validator.signers = vec![&validator_keypair];
|
||||||
|
@ -149,7 +150,7 @@ fn test_seed_stake_delegation_and_deactivation() {
|
||||||
&config_validator,
|
&config_validator,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
||||||
|
|
||||||
let stake_address = Pubkey::create_with_seed(
|
let stake_address = Pubkey::create_with_seed(
|
||||||
&config_validator.signers[0].pubkey(),
|
&config_validator.signers[0].pubkey(),
|
||||||
|
@ -181,7 +182,7 @@ fn test_seed_stake_delegation_and_deactivation() {
|
||||||
stake_account_pubkey: stake_address,
|
stake_account_pubkey: stake_address,
|
||||||
vote_account_pubkey: vote_pubkey,
|
vote_account_pubkey: vote_pubkey,
|
||||||
stake_authority: 0,
|
stake_authority: 0,
|
||||||
force: false,
|
force: true,
|
||||||
sign_only: false,
|
sign_only: false,
|
||||||
blockhash_query: BlockhashQuery::default(),
|
blockhash_query: BlockhashQuery::default(),
|
||||||
nonce_account: None,
|
nonce_account: None,
|
||||||
|
@ -225,7 +226,7 @@ fn test_stake_delegation_and_deactivation() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
|
|
||||||
let mut config_validator = CliConfig::default();
|
let mut config_validator = CliConfig::recent_for_tests();
|
||||||
config_validator.json_rpc_url =
|
config_validator.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config_validator.signers = vec![&validator_keypair];
|
config_validator.signers = vec![&validator_keypair];
|
||||||
|
@ -240,7 +241,7 @@ fn test_stake_delegation_and_deactivation() {
|
||||||
&config_validator,
|
&config_validator,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
||||||
|
|
||||||
// Create stake account
|
// Create stake account
|
||||||
config_validator.signers.push(&stake_keypair);
|
config_validator.signers.push(&stake_keypair);
|
||||||
|
@ -266,7 +267,7 @@ fn test_stake_delegation_and_deactivation() {
|
||||||
stake_account_pubkey: stake_keypair.pubkey(),
|
stake_account_pubkey: stake_keypair.pubkey(),
|
||||||
vote_account_pubkey: vote_pubkey,
|
vote_account_pubkey: vote_pubkey,
|
||||||
stake_authority: 0,
|
stake_authority: 0,
|
||||||
force: false,
|
force: true,
|
||||||
sign_only: false,
|
sign_only: false,
|
||||||
blockhash_query: BlockhashQuery::default(),
|
blockhash_query: BlockhashQuery::default(),
|
||||||
nonce_account: None,
|
nonce_account: None,
|
||||||
|
@ -309,19 +310,19 @@ fn test_offline_stake_delegation_and_deactivation() {
|
||||||
|
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
|
||||||
let mut config_validator = CliConfig::default();
|
let mut config_validator = CliConfig::recent_for_tests();
|
||||||
config_validator.json_rpc_url =
|
config_validator.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
let validator_keypair = Keypair::new();
|
let validator_keypair = Keypair::new();
|
||||||
config_validator.signers = vec![&validator_keypair];
|
config_validator.signers = vec![&validator_keypair];
|
||||||
|
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.json_rpc_url =
|
config_payer.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
|
|
||||||
let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let stake_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
config_offline.json_rpc_url = String::default();
|
config_offline.json_rpc_url = String::default();
|
||||||
config_offline.command = CliCommand::ClusterVersion;
|
config_offline.command = CliCommand::ClusterVersion;
|
||||||
let offline_keypair = Keypair::new();
|
let offline_keypair = Keypair::new();
|
||||||
|
@ -337,7 +338,7 @@ fn test_offline_stake_delegation_and_deactivation() {
|
||||||
&config_offline,
|
&config_offline,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
check_recent_balance(100_000, &rpc_client, &config_validator.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(
|
request_and_confirm_airdrop(
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
|
@ -347,7 +348,7 @@ fn test_offline_stake_delegation_and_deactivation() {
|
||||||
&config_validator,
|
&config_validator,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &config_offline.signers[0].pubkey());
|
check_recent_balance(100_000, &rpc_client, &config_offline.signers[0].pubkey());
|
||||||
|
|
||||||
// Create stake account
|
// Create stake account
|
||||||
config_validator.signers.push(&stake_keypair);
|
config_validator.signers.push(&stake_keypair);
|
||||||
|
@ -373,7 +374,7 @@ fn test_offline_stake_delegation_and_deactivation() {
|
||||||
stake_account_pubkey: stake_keypair.pubkey(),
|
stake_account_pubkey: stake_keypair.pubkey(),
|
||||||
vote_account_pubkey: vote_pubkey,
|
vote_account_pubkey: vote_pubkey,
|
||||||
stake_authority: 0,
|
stake_authority: 0,
|
||||||
force: false,
|
force: true,
|
||||||
sign_only: true,
|
sign_only: true,
|
||||||
blockhash_query: BlockhashQuery::None(blockhash),
|
blockhash_query: BlockhashQuery::None(blockhash),
|
||||||
nonce_account: None,
|
nonce_account: None,
|
||||||
|
@ -392,7 +393,7 @@ fn test_offline_stake_delegation_and_deactivation() {
|
||||||
stake_account_pubkey: stake_keypair.pubkey(),
|
stake_account_pubkey: stake_keypair.pubkey(),
|
||||||
vote_account_pubkey: vote_pubkey,
|
vote_account_pubkey: vote_pubkey,
|
||||||
stake_authority: 0,
|
stake_authority: 0,
|
||||||
force: false,
|
force: true,
|
||||||
sign_only: false,
|
sign_only: false,
|
||||||
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash),
|
||||||
nonce_account: None,
|
nonce_account: None,
|
||||||
|
@ -453,7 +454,7 @@ fn test_nonced_stake_delegation_and_deactivation() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
|
||||||
let config_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let config_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.signers = vec![&config_keypair];
|
config.signers = vec![&config_keypair];
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
|
|
||||||
|
@ -501,7 +502,11 @@ fn test_nonced_stake_delegation_and_deactivation() {
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -512,7 +517,7 @@ fn test_nonced_stake_delegation_and_deactivation() {
|
||||||
stake_account_pubkey: stake_keypair.pubkey(),
|
stake_account_pubkey: stake_keypair.pubkey(),
|
||||||
vote_account_pubkey: vote_pubkey,
|
vote_account_pubkey: vote_pubkey,
|
||||||
stake_authority: 0,
|
stake_authority: 0,
|
||||||
force: false,
|
force: true,
|
||||||
sign_only: false,
|
sign_only: false,
|
||||||
blockhash_query: BlockhashQuery::FeeCalculator(
|
blockhash_query: BlockhashQuery::FeeCalculator(
|
||||||
blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
|
blockhash_query::Source::NonceAccount(nonce_account.pubkey()),
|
||||||
|
@ -525,7 +530,11 @@ fn test_nonced_stake_delegation_and_deactivation() {
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -567,7 +576,7 @@ fn test_stake_authorize() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -581,7 +590,7 @@ fn test_stake_authorize() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let offline_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let offline_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
config_offline.signers = vec![&offline_keypair];
|
config_offline.signers = vec![&offline_keypair];
|
||||||
config_offline.json_rpc_url = String::default();
|
config_offline.json_rpc_url = String::default();
|
||||||
let offline_authority_pubkey = config_offline.signers[0].pubkey();
|
let offline_authority_pubkey = config_offline.signers[0].pubkey();
|
||||||
|
@ -632,7 +641,11 @@ fn test_stake_authorize() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_authority = match stake_state {
|
let current_authority = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.authorized.staker,
|
StakeState::Initialized(meta) => meta.authorized.staker,
|
||||||
|
@ -659,7 +672,11 @@ fn test_stake_authorize() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let (current_staker, current_withdrawer) = match stake_state {
|
let (current_staker, current_withdrawer) = match stake_state {
|
||||||
StakeState::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer),
|
StakeState::Initialized(meta) => (meta.authorized.staker, meta.authorized.withdrawer),
|
||||||
|
@ -681,7 +698,11 @@ fn test_stake_authorize() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_authority = match stake_state {
|
let current_authority = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.authorized.staker,
|
StakeState::Initialized(meta) => meta.authorized.staker,
|
||||||
|
@ -692,7 +713,10 @@ fn test_stake_authorize() {
|
||||||
// Offline assignment of new nonced stake authority
|
// Offline assignment of new nonced stake authority
|
||||||
let nonced_authority = Keypair::new();
|
let nonced_authority = Keypair::new();
|
||||||
let nonced_authority_pubkey = nonced_authority.pubkey();
|
let nonced_authority_pubkey = nonced_authority.pubkey();
|
||||||
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
let (blockhash, _, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value;
|
||||||
config_offline.command = CliCommand::StakeAuthorize {
|
config_offline.command = CliCommand::StakeAuthorize {
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
new_authorizations: vec![(StakeAuthorize::Staker, nonced_authority_pubkey, 0)],
|
new_authorizations: vec![(StakeAuthorize::Staker, nonced_authority_pubkey, 0)],
|
||||||
|
@ -718,7 +742,11 @@ fn test_stake_authorize() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_authority = match stake_state {
|
let current_authority = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.authorized.staker,
|
StakeState::Initialized(meta) => meta.authorized.staker,
|
||||||
|
@ -741,7 +769,11 @@ fn test_stake_authorize() {
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -779,7 +811,11 @@ fn test_stake_authorize() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_authority = match stake_state {
|
let current_authority = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.authorized.staker,
|
StakeState::Initialized(meta) => meta.authorized.staker,
|
||||||
|
@ -787,7 +823,11 @@ fn test_stake_authorize() {
|
||||||
};
|
};
|
||||||
assert_eq!(current_authority, online_authority_pubkey);
|
assert_eq!(current_authority, online_authority_pubkey);
|
||||||
|
|
||||||
let new_nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let new_nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -821,18 +861,18 @@ fn test_stake_authorize_with_fee_payer() {
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
let default_pubkey = default_signer.pubkey();
|
let default_pubkey = default_signer.pubkey();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
let payer_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
let payer_keypair = keypair_from_seed(&[0u8; 32]).unwrap();
|
||||||
let mut config_payer = CliConfig::default();
|
let mut config_payer = CliConfig::recent_for_tests();
|
||||||
config_payer.signers = vec![&payer_keypair];
|
config_payer.signers = vec![&payer_keypair];
|
||||||
config_payer.json_rpc_url =
|
config_payer.json_rpc_url =
|
||||||
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
let payer_pubkey = config_payer.signers[0].pubkey();
|
let payer_pubkey = config_payer.signers[0].pubkey();
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
let offline_signer = Keypair::new();
|
let offline_signer = Keypair::new();
|
||||||
config_offline.signers = vec![&offline_signer];
|
config_offline.signers = vec![&offline_signer];
|
||||||
config_offline.json_rpc_url = String::new();
|
config_offline.json_rpc_url = String::new();
|
||||||
|
@ -843,15 +883,17 @@ fn test_stake_authorize_with_fee_payer() {
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &default_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &default_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(100_000, &rpc_client, &config.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &payer_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &payer_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &payer_pubkey);
|
check_recent_balance(100_000, &rpc_client, &payer_pubkey);
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &offline_pubkey);
|
check_recent_balance(100_000, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
|
check_ready(&rpc_client);
|
||||||
|
|
||||||
// Create stake account, identity is authority
|
// Create stake account, identity is authority
|
||||||
let stake_keypair = Keypair::new();
|
let stake_keypair = Keypair::new();
|
||||||
|
@ -873,7 +915,7 @@ fn test_stake_authorize_with_fee_payer() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
// `config` balance should be 50,000 - 1 stake account sig - 1 fee sig
|
// `config` balance should be 50,000 - 1 stake account sig - 1 fee sig
|
||||||
check_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
||||||
|
|
||||||
// Assign authority with separate fee payer
|
// Assign authority with separate fee payer
|
||||||
config.signers = vec![&default_signer, &payer_keypair];
|
config.signers = vec![&default_signer, &payer_keypair];
|
||||||
|
@ -888,13 +930,16 @@ fn test_stake_authorize_with_fee_payer() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
// `config` balance has not changed, despite submitting the TX
|
// `config` balance has not changed, despite submitting the TX
|
||||||
check_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
||||||
// `config_payer` however has paid `config`'s authority sig
|
// `config_payer` however has paid `config`'s authority sig
|
||||||
// and `config_payer`'s fee sig
|
// and `config_payer`'s fee sig
|
||||||
check_balance(100_000 - SIG_FEE - SIG_FEE, &rpc_client, &payer_pubkey);
|
check_recent_balance(100_000 - SIG_FEE - SIG_FEE, &rpc_client, &payer_pubkey);
|
||||||
|
|
||||||
// Assign authority with offline fee payer
|
// Assign authority with offline fee payer
|
||||||
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
let (blockhash, _, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value;
|
||||||
config_offline.command = CliCommand::StakeAuthorize {
|
config_offline.command = CliCommand::StakeAuthorize {
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
new_authorizations: vec![(StakeAuthorize::Staker, payer_pubkey, 0)],
|
new_authorizations: vec![(StakeAuthorize::Staker, payer_pubkey, 0)],
|
||||||
|
@ -921,10 +966,10 @@ fn test_stake_authorize_with_fee_payer() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
// `config`'s balance again has not changed
|
// `config`'s balance again has not changed
|
||||||
check_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
check_recent_balance(50_000 - SIG_FEE - SIG_FEE, &rpc_client, &default_pubkey);
|
||||||
// `config_offline` however has paid 1 sig due to being both authority
|
// `config_offline` however has paid 1 sig due to being both authority
|
||||||
// and fee payer
|
// and fee payer
|
||||||
check_balance(100_000 - SIG_FEE, &rpc_client, &offline_pubkey);
|
check_recent_balance(100_000 - SIG_FEE, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -953,11 +998,11 @@ fn test_stake_split() {
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
let offline_signer = Keypair::new();
|
let offline_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
config_offline.json_rpc_url = String::default();
|
config_offline.json_rpc_url = String::default();
|
||||||
config_offline.signers = vec![&offline_signer];
|
config_offline.signers = vec![&offline_signer];
|
||||||
let offline_pubkey = config_offline.signers[0].pubkey();
|
let offline_pubkey = config_offline.signers[0].pubkey();
|
||||||
|
@ -973,11 +1018,11 @@ fn test_stake_split() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(500_000, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(500_000, &rpc_client, &config.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &offline_pubkey);
|
check_recent_balance(100_000, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
// Create stake account, identity is authority
|
// Create stake account, identity is authority
|
||||||
let minimum_stake_balance = rpc_client
|
let minimum_stake_balance = rpc_client
|
||||||
|
@ -1001,7 +1046,7 @@ fn test_stake_split() {
|
||||||
from: 0,
|
from: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(
|
check_recent_balance(
|
||||||
10 * minimum_stake_balance,
|
10 * minimum_stake_balance,
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
|
@ -1020,17 +1065,21 @@ fn test_stake_split() {
|
||||||
amount: SpendAmount::Some(minimum_nonce_balance),
|
amount: SpendAmount::Some(minimum_nonce_balance),
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(minimum_nonce_balance, &rpc_client, &nonce_account.pubkey());
|
check_recent_balance(minimum_nonce_balance, &rpc_client, &nonce_account.pubkey());
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
|
||||||
// Nonced offline split
|
// Nonced offline split
|
||||||
let split_account = keypair_from_seed(&[2u8; 32]).unwrap();
|
let split_account = keypair_from_seed(&[2u8; 32]).unwrap();
|
||||||
check_balance(0, &rpc_client, &split_account.pubkey());
|
check_recent_balance(0, &rpc_client, &split_account.pubkey());
|
||||||
config_offline.signers.push(&split_account);
|
config_offline.signers.push(&split_account);
|
||||||
config_offline.command = CliCommand::SplitStake {
|
config_offline.command = CliCommand::SplitStake {
|
||||||
stake_account_pubkey,
|
stake_account_pubkey,
|
||||||
|
@ -1066,12 +1115,12 @@ fn test_stake_split() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(
|
check_recent_balance(
|
||||||
8 * minimum_stake_balance,
|
8 * minimum_stake_balance,
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
);
|
);
|
||||||
check_balance(
|
check_recent_balance(
|
||||||
2 * minimum_stake_balance,
|
2 * minimum_stake_balance,
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
&split_account.pubkey(),
|
&split_account.pubkey(),
|
||||||
|
@ -1104,11 +1153,11 @@ fn test_stake_set_lockup() {
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
let offline_signer = Keypair::new();
|
let offline_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
config_offline.json_rpc_url = String::default();
|
config_offline.json_rpc_url = String::default();
|
||||||
config_offline.signers = vec![&offline_signer];
|
config_offline.signers = vec![&offline_signer];
|
||||||
let offline_pubkey = config_offline.signers[0].pubkey();
|
let offline_pubkey = config_offline.signers[0].pubkey();
|
||||||
|
@ -1124,11 +1173,11 @@ fn test_stake_set_lockup() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(500_000, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(500_000, &rpc_client, &config.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &offline_pubkey);
|
check_recent_balance(100_000, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
// Create stake account, identity is authority
|
// Create stake account, identity is authority
|
||||||
let minimum_stake_balance = rpc_client
|
let minimum_stake_balance = rpc_client
|
||||||
|
@ -1157,7 +1206,7 @@ fn test_stake_set_lockup() {
|
||||||
from: 0,
|
from: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(
|
check_recent_balance(
|
||||||
10 * minimum_stake_balance,
|
10 * minimum_stake_balance,
|
||||||
&rpc_client,
|
&rpc_client,
|
||||||
&stake_account_pubkey,
|
&stake_account_pubkey,
|
||||||
|
@ -1181,7 +1230,11 @@ fn test_stake_set_lockup() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_lockup = match stake_state {
|
let current_lockup = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.lockup,
|
StakeState::Initialized(meta) => meta.lockup,
|
||||||
|
@ -1232,7 +1285,11 @@ fn test_stake_set_lockup() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_lockup = match stake_state {
|
let current_lockup = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.lockup,
|
StakeState::Initialized(meta) => meta.lockup,
|
||||||
|
@ -1277,10 +1334,14 @@ fn test_stake_set_lockup() {
|
||||||
amount: SpendAmount::Some(minimum_nonce_balance),
|
amount: SpendAmount::Some(minimum_nonce_balance),
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(minimum_nonce_balance, &rpc_client, &nonce_account_pubkey);
|
check_recent_balance(minimum_nonce_balance, &rpc_client, &nonce_account_pubkey);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -1321,7 +1382,11 @@ fn test_stake_set_lockup() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let stake_account = rpc_client.get_account(&stake_account_pubkey).unwrap();
|
let stake_account = rpc_client
|
||||||
|
.get_account_with_commitment(&stake_account_pubkey, CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
|
.unwrap();
|
||||||
let stake_state: StakeState = stake_account.state().unwrap();
|
let stake_state: StakeState = stake_account.state().unwrap();
|
||||||
let current_lockup = match stake_state {
|
let current_lockup = match stake_state {
|
||||||
StakeState::Initialized(meta) => meta.lockup,
|
StakeState::Initialized(meta) => meta.lockup,
|
||||||
|
@ -1355,12 +1420,12 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
|
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
let default_signer = keypair_from_seed(&[1u8; 32]).unwrap();
|
let default_signer = keypair_from_seed(&[1u8; 32]).unwrap();
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
|
|
||||||
let mut config_offline = CliConfig::default();
|
let mut config_offline = CliConfig::recent_for_tests();
|
||||||
let offline_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
let offline_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
||||||
config_offline.signers = vec![&offline_signer];
|
config_offline.signers = vec![&offline_signer];
|
||||||
let offline_pubkey = config_offline.signers[0].pubkey();
|
let offline_pubkey = config_offline.signers[0].pubkey();
|
||||||
|
@ -1377,11 +1442,11 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(200_000, &rpc_client, &config.signers[0].pubkey());
|
check_recent_balance(200_000, &rpc_client, &config.signers[0].pubkey());
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 100_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(100_000, &rpc_client, &offline_pubkey);
|
check_recent_balance(100_000, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
// Create nonce account
|
// Create nonce account
|
||||||
let minimum_nonce_balance = rpc_client
|
let minimum_nonce_balance = rpc_client
|
||||||
|
@ -1399,7 +1464,11 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -1447,10 +1516,14 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
from: 0,
|
from: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(50_000, &rpc_client, &stake_pubkey);
|
check_recent_balance(50_000, &rpc_client, &stake_pubkey);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -1491,10 +1564,14 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(42, &rpc_client, &recipient_pubkey);
|
check_recent_balance(42, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -1541,7 +1618,7 @@ fn test_offline_nonced_create_stake_account_and_withdraw() {
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let seed_address =
|
let seed_address =
|
||||||
Pubkey::create_with_seed(&stake_pubkey, seed, &solana_stake_program::id()).unwrap();
|
Pubkey::create_with_seed(&stake_pubkey, seed, &solana_stake_program::id()).unwrap();
|
||||||
check_balance(50_000, &rpc_client, &seed_address);
|
check_recent_balance(50_000, &rpc_client, &seed_address);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use solana_cli::test_utils::check_balance;
|
|
||||||
use solana_cli::{
|
use solana_cli::{
|
||||||
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
||||||
cli_output::OutputFormat,
|
cli_output::OutputFormat,
|
||||||
|
@ -8,11 +7,13 @@ use solana_cli::{
|
||||||
parse_sign_only_reply_string,
|
parse_sign_only_reply_string,
|
||||||
},
|
},
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
|
test_utils::{check_ready, check_recent_balance},
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
use solana_core::validator::{TestValidator, TestValidatorOptions};
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
nonce::State as NonceState,
|
nonce::State as NonceState,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{keypair_from_seed, Keypair, NullSigner, Signer},
|
signature::{keypair_from_seed, Keypair, NullSigner, Signer},
|
||||||
|
@ -42,7 +43,7 @@ fn test_transfer() {
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
let default_offline_signer = Keypair::new();
|
let default_offline_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -51,8 +52,10 @@ fn test_transfer() {
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &sender_pubkey, 50_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &sender_pubkey, 50_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(50_000, &rpc_client, &sender_pubkey);
|
check_recent_balance(50_000, &rpc_client, &sender_pubkey);
|
||||||
check_balance(0, &rpc_client, &recipient_pubkey);
|
check_recent_balance(0, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
|
check_ready(&rpc_client);
|
||||||
|
|
||||||
// Plain ole transfer
|
// Plain ole transfer
|
||||||
config.command = CliCommand::Transfer {
|
config.command = CliCommand::Transfer {
|
||||||
|
@ -67,8 +70,8 @@ fn test_transfer() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(49_989, &rpc_client, &sender_pubkey);
|
check_recent_balance(49_989, &rpc_client, &sender_pubkey);
|
||||||
check_balance(10, &rpc_client, &recipient_pubkey);
|
check_recent_balance(10, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
// Plain ole transfer, failure due to InsufficientFundsForSpendAndFee
|
// Plain ole transfer, failure due to InsufficientFundsForSpendAndFee
|
||||||
config.command = CliCommand::Transfer {
|
config.command = CliCommand::Transfer {
|
||||||
|
@ -83,10 +86,10 @@ fn test_transfer() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
assert!(process_command(&config).is_err());
|
assert!(process_command(&config).is_err());
|
||||||
check_balance(49_989, &rpc_client, &sender_pubkey);
|
check_recent_balance(49_989, &rpc_client, &sender_pubkey);
|
||||||
check_balance(10, &rpc_client, &recipient_pubkey);
|
check_recent_balance(10, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
let mut offline = CliConfig::default();
|
let mut offline = CliConfig::recent_for_tests();
|
||||||
offline.json_rpc_url = String::default();
|
offline.json_rpc_url = String::default();
|
||||||
offline.signers = vec![&default_offline_signer];
|
offline.signers = vec![&default_offline_signer];
|
||||||
// Verify we cannot contact the cluster
|
// Verify we cannot contact the cluster
|
||||||
|
@ -95,10 +98,13 @@ fn test_transfer() {
|
||||||
|
|
||||||
let offline_pubkey = offline.signers[0].pubkey();
|
let offline_pubkey = offline.signers[0].pubkey();
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 50, &config).unwrap();
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &offline_pubkey, 50, &config).unwrap();
|
||||||
check_balance(50, &rpc_client, &offline_pubkey);
|
check_recent_balance(50, &rpc_client, &offline_pubkey);
|
||||||
|
|
||||||
// Offline transfer
|
// Offline transfer
|
||||||
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
let (blockhash, _, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value;
|
||||||
offline.command = CliCommand::Transfer {
|
offline.command = CliCommand::Transfer {
|
||||||
amount: SpendAmount::Some(10),
|
amount: SpendAmount::Some(10),
|
||||||
to: recipient_pubkey,
|
to: recipient_pubkey,
|
||||||
|
@ -128,8 +134,8 @@ fn test_transfer() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(39, &rpc_client, &offline_pubkey);
|
check_recent_balance(39, &rpc_client, &offline_pubkey);
|
||||||
check_balance(20, &rpc_client, &recipient_pubkey);
|
check_recent_balance(20, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
// Create nonce account
|
// Create nonce account
|
||||||
let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap();
|
let nonce_account = keypair_from_seed(&[3u8; 32]).unwrap();
|
||||||
|
@ -144,10 +150,14 @@ fn test_transfer() {
|
||||||
amount: SpendAmount::Some(minimum_nonce_balance),
|
amount: SpendAmount::Some(minimum_nonce_balance),
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(49_987 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
check_recent_balance(49_987 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -169,9 +179,13 @@ fn test_transfer() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(49_976 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
check_recent_balance(49_976 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
||||||
check_balance(30, &rpc_client, &recipient_pubkey);
|
check_recent_balance(30, &rpc_client, &recipient_pubkey);
|
||||||
let new_nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let new_nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -185,10 +199,14 @@ fn test_transfer() {
|
||||||
new_authority: offline_pubkey,
|
new_authority: offline_pubkey,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(49_975 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
check_recent_balance(49_975 - minimum_nonce_balance, &rpc_client, &sender_pubkey);
|
||||||
|
|
||||||
// Fetch nonce hash
|
// Fetch nonce hash
|
||||||
let nonce_hash = nonce::get_account(&rpc_client, &nonce_account.pubkey())
|
let nonce_hash = nonce::get_account_with_commitment(
|
||||||
|
&rpc_client,
|
||||||
|
&nonce_account.pubkey(),
|
||||||
|
CommitmentConfig::recent(),
|
||||||
|
)
|
||||||
.and_then(|ref a| nonce::data_from_account(a))
|
.and_then(|ref a| nonce::data_from_account(a))
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.blockhash;
|
.blockhash;
|
||||||
|
@ -226,8 +244,8 @@ fn test_transfer() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(28, &rpc_client, &offline_pubkey);
|
check_recent_balance(28, &rpc_client, &offline_pubkey);
|
||||||
check_balance(40, &rpc_client, &recipient_pubkey);
|
check_recent_balance(40, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -255,7 +273,7 @@ fn test_transfer_multisession_signing() {
|
||||||
let offline_from_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
let offline_from_signer = keypair_from_seed(&[2u8; 32]).unwrap();
|
||||||
let offline_fee_payer_signer = keypair_from_seed(&[3u8; 32]).unwrap();
|
let offline_fee_payer_signer = keypair_from_seed(&[3u8; 32]).unwrap();
|
||||||
let from_null_signer = NullSigner::new(&offline_from_signer.pubkey());
|
let from_null_signer = NullSigner::new(&offline_from_signer.pubkey());
|
||||||
let config = CliConfig::default();
|
let config = CliConfig::recent_for_tests();
|
||||||
|
|
||||||
// Setup accounts
|
// Setup accounts
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
|
@ -275,14 +293,19 @@ fn test_transfer_multisession_signing() {
|
||||||
&config,
|
&config,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(43, &rpc_client, &offline_from_signer.pubkey());
|
check_recent_balance(43, &rpc_client, &offline_from_signer.pubkey());
|
||||||
check_balance(3, &rpc_client, &offline_fee_payer_signer.pubkey());
|
check_recent_balance(3, &rpc_client, &offline_fee_payer_signer.pubkey());
|
||||||
check_balance(0, &rpc_client, &to_pubkey);
|
check_recent_balance(0, &rpc_client, &to_pubkey);
|
||||||
|
|
||||||
let (blockhash, _) = rpc_client.get_recent_blockhash().unwrap();
|
check_ready(&rpc_client);
|
||||||
|
|
||||||
|
let (blockhash, _, _) = rpc_client
|
||||||
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value;
|
||||||
|
|
||||||
// Offline fee-payer signs first
|
// Offline fee-payer signs first
|
||||||
let mut fee_payer_config = CliConfig::default();
|
let mut fee_payer_config = CliConfig::recent_for_tests();
|
||||||
fee_payer_config.json_rpc_url = String::default();
|
fee_payer_config.json_rpc_url = String::default();
|
||||||
fee_payer_config.signers = vec![&offline_fee_payer_signer, &from_null_signer];
|
fee_payer_config.signers = vec![&offline_fee_payer_signer, &from_null_signer];
|
||||||
// Verify we cannot contact the cluster
|
// Verify we cannot contact the cluster
|
||||||
|
@ -308,7 +331,7 @@ fn test_transfer_multisession_signing() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Now the offline fund source
|
// Now the offline fund source
|
||||||
let mut from_config = CliConfig::default();
|
let mut from_config = CliConfig::recent_for_tests();
|
||||||
from_config.json_rpc_url = String::default();
|
from_config.json_rpc_url = String::default();
|
||||||
from_config.signers = vec![&fee_payer_presigner, &offline_from_signer];
|
from_config.signers = vec![&fee_payer_presigner, &offline_from_signer];
|
||||||
// Verify we cannot contact the cluster
|
// Verify we cannot contact the cluster
|
||||||
|
@ -334,7 +357,7 @@ fn test_transfer_multisession_signing() {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Finally submit to the cluster
|
// Finally submit to the cluster
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&fee_payer_presigner, &from_presigner];
|
config.signers = vec![&fee_payer_presigner, &from_presigner];
|
||||||
config.command = CliCommand::Transfer {
|
config.command = CliCommand::Transfer {
|
||||||
|
@ -350,9 +373,9 @@ fn test_transfer_multisession_signing() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
|
|
||||||
check_balance(1, &rpc_client, &offline_from_signer.pubkey());
|
check_recent_balance(1, &rpc_client, &offline_from_signer.pubkey());
|
||||||
check_balance(1, &rpc_client, &offline_fee_payer_signer.pubkey());
|
check_recent_balance(1, &rpc_client, &offline_fee_payer_signer.pubkey());
|
||||||
check_balance(42, &rpc_client, &to_pubkey);
|
check_recent_balance(42, &rpc_client, &to_pubkey);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
@ -380,7 +403,7 @@ fn test_transfer_all() {
|
||||||
|
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -389,8 +412,10 @@ fn test_transfer_all() {
|
||||||
|
|
||||||
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &sender_pubkey, 50_000, &config)
|
request_and_confirm_airdrop(&rpc_client, &faucet_addr, &sender_pubkey, 50_000, &config)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
check_balance(50_000, &rpc_client, &sender_pubkey);
|
check_recent_balance(50_000, &rpc_client, &sender_pubkey);
|
||||||
check_balance(0, &rpc_client, &recipient_pubkey);
|
check_recent_balance(0, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
|
check_ready(&rpc_client);
|
||||||
|
|
||||||
// Plain ole transfer
|
// Plain ole transfer
|
||||||
config.command = CliCommand::Transfer {
|
config.command = CliCommand::Transfer {
|
||||||
|
@ -405,8 +430,8 @@ fn test_transfer_all() {
|
||||||
fee_payer: 0,
|
fee_payer: 0,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(0, &rpc_client, &sender_pubkey);
|
check_recent_balance(0, &rpc_client, &sender_pubkey);
|
||||||
check_balance(49_999, &rpc_client, &recipient_pubkey);
|
check_recent_balance(49_999, &rpc_client, &recipient_pubkey);
|
||||||
|
|
||||||
server.close().unwrap();
|
server.close().unwrap();
|
||||||
remove_dir_all(ledger_path).unwrap();
|
remove_dir_all(ledger_path).unwrap();
|
||||||
|
|
|
@ -2,13 +2,14 @@ use solana_cli::{
|
||||||
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
cli::{process_command, request_and_confirm_airdrop, CliCommand, CliConfig},
|
||||||
offline::{blockhash_query::BlockhashQuery, *},
|
offline::{blockhash_query::BlockhashQuery, *},
|
||||||
spend_utils::SpendAmount,
|
spend_utils::SpendAmount,
|
||||||
test_utils::check_balance,
|
test_utils::check_recent_balance,
|
||||||
};
|
};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_core::validator::TestValidator;
|
use solana_core::validator::TestValidator;
|
||||||
use solana_faucet::faucet::run_local_faucet;
|
use solana_faucet::faucet::run_local_faucet;
|
||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
account_utils::StateMut,
|
account_utils::StateMut,
|
||||||
|
commitment_config::CommitmentConfig,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
signature::{Keypair, Signer},
|
signature::{Keypair, Signer},
|
||||||
};
|
};
|
||||||
|
@ -31,7 +32,7 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||||
let default_signer = Keypair::new();
|
let default_signer = Keypair::new();
|
||||||
|
|
||||||
let mut config = CliConfig::default();
|
let mut config = CliConfig::recent_for_tests();
|
||||||
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
config.json_rpc_url = format!("http://{}:{}", leader_data.rpc.ip(), leader_data.rpc.port());
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
|
||||||
|
@ -57,7 +58,9 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let vote_account = rpc_client
|
let vote_account = rpc_client
|
||||||
.get_account(&vote_account_keypair.pubkey())
|
.get_account_with_commitment(&vote_account_keypair.pubkey(), CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
||||||
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
||||||
|
@ -66,7 +69,7 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
.get_minimum_balance_for_rent_exemption(VoteState::size_of())
|
.get_minimum_balance_for_rent_exemption(VoteState::size_of())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.max(1);
|
.max(1);
|
||||||
check_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
check_recent_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
||||||
|
|
||||||
// Transfer in some more SOL
|
// Transfer in some more SOL
|
||||||
config.signers = vec![&default_signer];
|
config.signers = vec![&default_signer];
|
||||||
|
@ -83,7 +86,7 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let expected_balance = expected_balance + 1_000;
|
let expected_balance = expected_balance + 1_000;
|
||||||
check_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
check_recent_balance(expected_balance, &rpc_client, &vote_account_pubkey);
|
||||||
|
|
||||||
// Authorize vote account withdrawal to another signer
|
// Authorize vote account withdrawal to another signer
|
||||||
let withdraw_authority = Keypair::new();
|
let withdraw_authority = Keypair::new();
|
||||||
|
@ -95,7 +98,9 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
let vote_account = rpc_client
|
let vote_account = rpc_client
|
||||||
.get_account(&vote_account_keypair.pubkey())
|
.get_account_with_commitment(&vote_account_keypair.pubkey(), CommitmentConfig::recent())
|
||||||
|
.unwrap()
|
||||||
|
.value
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
let vote_state: VoteStateVersions = vote_account.state().unwrap();
|
||||||
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
let authorized_withdrawer = vote_state.convert_to_current().authorized_withdrawer;
|
||||||
|
@ -111,8 +116,8 @@ fn test_vote_authorize_and_withdraw() {
|
||||||
destination_account_pubkey: destination_account,
|
destination_account_pubkey: destination_account,
|
||||||
};
|
};
|
||||||
process_command(&config).unwrap();
|
process_command(&config).unwrap();
|
||||||
check_balance(expected_balance - 100, &rpc_client, &vote_account_pubkey);
|
check_recent_balance(expected_balance - 100, &rpc_client, &vote_account_pubkey);
|
||||||
check_balance(100, &rpc_client, &destination_account);
|
check_recent_balance(100, &rpc_client, &destination_account);
|
||||||
|
|
||||||
// Re-assign validator identity
|
// Re-assign validator identity
|
||||||
let new_identity_keypair = Keypair::new();
|
let new_identity_keypair = Keypair::new();
|
||||||
|
|
|
@ -17,7 +17,7 @@ use solana_sdk::{
|
||||||
Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
|
Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
|
||||||
MAX_HASH_AGE_IN_SECONDS,
|
MAX_HASH_AGE_IN_SECONDS,
|
||||||
},
|
},
|
||||||
commitment_config::CommitmentConfig,
|
commitment_config::{CommitmentConfig, CommitmentLevel},
|
||||||
epoch_info::EpochInfo,
|
epoch_info::EpochInfo,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||||
|
@ -831,6 +831,19 @@ impl RpcClient {
|
||||||
) -> ClientResult<Signature> {
|
) -> ClientResult<Signature> {
|
||||||
self.send_and_confirm_transaction_with_spinner_and_config(
|
self.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
transaction,
|
transaction,
|
||||||
|
CommitmentConfig::default(),
|
||||||
|
RpcSendTransactionConfig::default(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn send_and_confirm_transaction_with_spinner_and_commitment(
|
||||||
|
&self,
|
||||||
|
transaction: &Transaction,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
|
) -> ClientResult<Signature> {
|
||||||
|
self.send_and_confirm_transaction_with_spinner_and_config(
|
||||||
|
transaction,
|
||||||
|
commitment,
|
||||||
RpcSendTransactionConfig::default(),
|
RpcSendTransactionConfig::default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -838,8 +851,13 @@ impl RpcClient {
|
||||||
pub fn send_and_confirm_transaction_with_spinner_and_config(
|
pub fn send_and_confirm_transaction_with_spinner_and_config(
|
||||||
&self,
|
&self,
|
||||||
transaction: &Transaction,
|
transaction: &Transaction,
|
||||||
|
commitment: CommitmentConfig,
|
||||||
config: RpcSendTransactionConfig,
|
config: RpcSendTransactionConfig,
|
||||||
) -> ClientResult<Signature> {
|
) -> ClientResult<Signature> {
|
||||||
|
let desired_confirmations = match commitment.commitment {
|
||||||
|
CommitmentLevel::Max | CommitmentLevel::Root => MAX_LOCKOUT_HISTORY + 1,
|
||||||
|
_ => 1,
|
||||||
|
};
|
||||||
let mut confirmations = 0;
|
let mut confirmations = 0;
|
||||||
|
|
||||||
let progress_bar = new_spinner_progress_bar();
|
let progress_bar = new_spinner_progress_bar();
|
||||||
|
@ -848,13 +866,11 @@ impl RpcClient {
|
||||||
let signature = loop {
|
let signature = loop {
|
||||||
progress_bar.set_message(&format!(
|
progress_bar.set_message(&format!(
|
||||||
"[{}/{}] Finalizing transaction {}",
|
"[{}/{}] Finalizing transaction {}",
|
||||||
confirmations,
|
confirmations, desired_confirmations, transaction.signatures[0],
|
||||||
MAX_LOCKOUT_HISTORY + 1,
|
|
||||||
transaction.signatures[0],
|
|
||||||
));
|
));
|
||||||
let mut status_retries = 15;
|
let mut status_retries = 15;
|
||||||
let (signature, status) = loop {
|
let (signature, status) = loop {
|
||||||
let signature = self.send_transaction_with_config(transaction, config.clone())?;
|
let signature = self.send_transaction_with_config(transaction, config)?;
|
||||||
|
|
||||||
// Get recent commitment in order to count confirmations for successful transactions
|
// Get recent commitment in order to count confirmations for successful transactions
|
||||||
let status = self
|
let status = self
|
||||||
|
@ -904,17 +920,30 @@ impl RpcClient {
|
||||||
};
|
};
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
loop {
|
loop {
|
||||||
|
match commitment.commitment {
|
||||||
|
CommitmentLevel::Max | CommitmentLevel::Root =>
|
||||||
// Return when default (max) commitment is reached
|
// Return when default (max) commitment is reached
|
||||||
// Failed transactions have already been eliminated, `is_some` check is sufficient
|
// Failed transactions have already been eliminated, `is_some` check is sufficient
|
||||||
|
{
|
||||||
if self.get_signature_status(&signature)?.is_some() {
|
if self.get_signature_status(&signature)?.is_some() {
|
||||||
progress_bar.set_message("Transaction confirmed");
|
progress_bar.set_message("Transaction confirmed");
|
||||||
progress_bar.finish_and_clear();
|
progress_bar.finish_and_clear();
|
||||||
return Ok(signature);
|
return Ok(signature);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
// Return when one confirmation has been reached
|
||||||
|
if confirmations >= desired_confirmations {
|
||||||
|
progress_bar.set_message("Transaction reached commitment");
|
||||||
|
progress_bar.finish_and_clear();
|
||||||
|
return Ok(signature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
progress_bar.set_message(&format!(
|
progress_bar.set_message(&format!(
|
||||||
"[{}/{}] Finalizing transaction {}",
|
"[{}/{}] Finalizing transaction {}",
|
||||||
confirmations + 1,
|
confirmations + 1,
|
||||||
MAX_LOCKOUT_HISTORY + 1,
|
desired_confirmations,
|
||||||
signature,
|
signature,
|
||||||
));
|
));
|
||||||
sleep(Duration::from_millis(500));
|
sleep(Duration::from_millis(500));
|
||||||
|
|
|
@ -6,7 +6,7 @@ pub struct RpcSignatureStatusConfig {
|
||||||
pub search_transaction_history: bool,
|
pub search_transaction_history: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct RpcSendTransactionConfig {
|
pub struct RpcSendTransactionConfig {
|
||||||
pub skip_preflight: bool,
|
pub skip_preflight: bool,
|
||||||
|
|
Loading…
Reference in New Issue