From df2fb8f5b3ad0e3d90abc0dd171cd60f989467b6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 8 Apr 2020 23:49:40 -0700 Subject: [PATCH] Add --no-wait arg to transfer (#9388) (#9390) automerge --- cli/src/cli.rs | 48 ++++++++++++++++++++++++++++++++++++++++++- cli/tests/nonce.rs | 2 ++ cli/tests/transfer.rs | 9 ++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/cli/src/cli.rs b/cli/src/cli.rs index 9ddffa1d85..5f2e6e8f95 100644 --- a/cli/src/cli.rs +++ b/cli/src/cli.rs @@ -405,6 +405,7 @@ pub enum CliCommand { to: Pubkey, from: SignerIndex, sign_only: bool, + no_wait: bool, blockhash_query: BlockhashQuery, nonce_account: Option, nonce_authority: SignerIndex, @@ -902,6 +903,7 @@ pub fn parse_command( let lamports = lamports_of_sol(matches, "amount").unwrap(); let to = pubkey_of_signer(matches, "to", wallet_manager)?.unwrap(); let sign_only = matches.is_present(SIGN_ONLY_ARG.name); + let no_wait = matches.is_present("no_wait"); let blockhash_query = BlockhashQuery::new_from_matches(matches); let nonce_account = pubkey_of_signer(matches, NONCE_ARG.name, wallet_manager)?; let (nonce_authority, nonce_authority_pubkey) = @@ -927,6 +929,7 @@ pub fn parse_command( lamports, to, sign_only, + no_wait, blockhash_query, nonce_account, nonce_authority: signer_info.index_of(nonce_authority_pubkey).unwrap(), @@ -1488,6 +1491,7 @@ fn process_transfer( to: &Pubkey, from: SignerIndex, sign_only: bool, + no_wait: bool, blockhash_query: &BlockhashQuery, nonce_account: Option<&Pubkey>, nonce_authority: SignerIndex, @@ -1534,7 +1538,11 @@ fn process_transfer( &fee_calculator, &tx.message, )?; - let result = rpc_client.send_and_confirm_transaction_with_spinner(&mut tx, &config.signers); + let result = if no_wait { + rpc_client.send_transaction(&tx) + } else { + rpc_client.send_and_confirm_transaction_with_spinner(&mut tx, &config.signers) + }; log_instruction_custom_error::(result) } } @@ -2080,6 +2088,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { to, from, sign_only, + no_wait, ref blockhash_query, ref nonce_account, nonce_authority, @@ -2091,6 +2100,7 @@ pub fn process_command(config: &CliConfig) -> ProcessResult { to, *from, *sign_only, + *no_wait, blockhash_query, nonce_account.as_ref(), *nonce_authority, @@ -2497,6 +2507,12 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, ' .validator(is_valid_signer) .help("Source account of funds (if different from client local account)"), ) + .arg( + Arg::with_name("no_wait") + .long("no-wait") + .takes_value(false) + .help("Return signature immediately after submitting the transaction, instead of waiting for confirmations"), + ) .offline_args() .arg(nonce_arg()) .arg(nonce_authority_arg()) @@ -3557,6 +3573,33 @@ mod tests { to: to_pubkey, from: 0, sign_only: false, + no_wait: false, + blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster), + nonce_account: None, + nonce_authority: 0, + fee_payer: 0, + }, + signers: vec![read_keypair_file(&default_keypair_file).unwrap().into()], + } + ); + + // Test Transfer no-wait + let test_transfer = test_commands.clone().get_matches_from(vec![ + "test", + "transfer", + "--no-wait", + &to_string, + "42", + ]); + assert_eq!( + parse_command(&test_transfer, &default_keypair_file, None).unwrap(), + CliCommandInfo { + command: CliCommand::Transfer { + lamports: 42_000_000_000, + to: to_pubkey, + from: 0, + sign_only: false, + no_wait: true, blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster), nonce_account: None, nonce_authority: 0, @@ -3586,6 +3629,7 @@ mod tests { to: to_pubkey, from: 0, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(blockhash), nonce_account: None, nonce_authority: 0, @@ -3620,6 +3664,7 @@ mod tests { to: to_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator( blockhash_query::Source::Cluster, blockhash @@ -3658,6 +3703,7 @@ mod tests { to: to_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator( blockhash_query::Source::NonceAccount(nonce_address), blockhash diff --git a/cli/tests/nonce.rs b/cli/tests/nonce.rs index 75dc090ba7..8c06cd17c7 100644 --- a/cli/tests/nonce.rs +++ b/cli/tests/nonce.rs @@ -338,6 +338,7 @@ fn test_create_account_with_seed() { to: to_address, from: 0, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(nonce_hash), nonce_account: Some(nonce_address), nonce_authority: 0, @@ -358,6 +359,7 @@ fn test_create_account_with_seed() { to: to_address, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator( blockhash_query::Source::NonceAccount(nonce_address), sign_only.blockhash, diff --git a/cli/tests/transfer.rs b/cli/tests/transfer.rs index 03d323352d..4cdf0d7b46 100644 --- a/cli/tests/transfer.rs +++ b/cli/tests/transfer.rs @@ -68,6 +68,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::All(blockhash_query::Source::Cluster), nonce_account: None, nonce_authority: 0, @@ -95,6 +96,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(blockhash), nonce_account: None, nonce_authority: 0, @@ -110,6 +112,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash), nonce_account: None, nonce_authority: 0, @@ -147,6 +150,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator( blockhash_query::Source::NonceAccount(nonce_account.pubkey()), nonce_hash, @@ -187,6 +191,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(nonce_hash), nonce_account: Some(nonce_account.pubkey()), nonce_authority: 0, @@ -202,6 +207,7 @@ fn test_transfer() { to: recipient_pubkey, from: 0, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator( blockhash_query::Source::NonceAccount(nonce_account.pubkey()), sign_only.blockhash, @@ -269,6 +275,7 @@ fn test_transfer_multisession_signing() { to: to_pubkey, from: 1, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(blockhash), nonce_account: None, nonce_authority: 0, @@ -293,6 +300,7 @@ fn test_transfer_multisession_signing() { to: to_pubkey, from: 1, sign_only: true, + no_wait: false, blockhash_query: BlockhashQuery::None(blockhash), nonce_account: None, nonce_authority: 0, @@ -314,6 +322,7 @@ fn test_transfer_multisession_signing() { to: to_pubkey, from: 1, sign_only: false, + no_wait: false, blockhash_query: BlockhashQuery::FeeCalculator(blockhash_query::Source::Cluster, blockhash), nonce_account: None, nonce_authority: 0,