Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

token-client: Make confirmation of ProgramRpcClientSendTransaction optional #7596

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion single-pool/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Config {
// and program client
let program_client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

// resolve default signer
Expand Down
2 changes: 1 addition & 1 deletion single-pool/cli/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn setup(initialize: bool) -> Env {
let rpc_client = Arc::new(validator.get_async_rpc_client());
let program_client: PClient = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

// write the payer to disk
Expand Down
8 changes: 4 additions & 4 deletions token-upgrade/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async fn process_create_escrow_account(

let program_client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
let token = Token::new(
program_client.clone(),
Expand Down Expand Up @@ -545,7 +545,7 @@ mod test {
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

let mint_authority = Keypair::new();
Expand Down Expand Up @@ -614,7 +614,7 @@ mod test {
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

let mint_authority = Keypair::new();
Expand Down Expand Up @@ -721,7 +721,7 @@ mod test {
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

let mint_authority = Keypair::new();
Expand Down
4 changes: 2 additions & 2 deletions token/cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ impl<'a> Config<'a> {
.unwrap_or_default();
Arc::new(ProgramOfflineClient::new(
blockhash,
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new(),
))
} else {
Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new(),
))
};
Self::new_with_clients_and_ws_url(
Expand Down
42 changes: 26 additions & 16 deletions token/cli/tests/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ fn test_config_with_default_signer<'a>(
) -> Config<'a> {
let websocket_url = test_validator.rpc_pubsub_url();
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramRpcClient::new(rpc_client.clone(), ProgramRpcClientSendTransaction),
);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
Config {
rpc_client,
program_client,
Expand All @@ -219,9 +221,11 @@ fn test_config_without_default_signer<'a>(
) -> Config<'a> {
let websocket_url = test_validator.rpc_pubsub_url();
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramRpcClient::new(rpc_client.clone(), ProgramRpcClientSendTransaction),
);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
Config {
rpc_client,
program_client,
Expand Down Expand Up @@ -3132,7 +3136,7 @@ async fn do_offline_multisig_transfer(
let offline_program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramOfflineClient::new(
blockhash,
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
let mut args = vec![
"spl-token".to_string(),
Expand Down Expand Up @@ -3192,9 +3196,11 @@ async fn do_offline_multisig_transfer(
assert!(!absent_signers.contains(&token.to_string()));

// now send the transaction
let rpc_program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramRpcClient::new(config.rpc_client.clone(), ProgramRpcClientSendTransaction),
);
let rpc_program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramRpcClient::new(
config.rpc_client.clone(),
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
config.program_client = rpc_program_client;
let mut args = vec![
"spl-token".to_string(),
Expand Down Expand Up @@ -3849,9 +3855,11 @@ async fn transfer_hook(test_validator: &TestValidator, payer: &Keypair) {
// Make sure that parsing transfer hook accounts works
let real_program_client = config.program_client;
let blockhash = Hash::default();
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramOfflineClient::new(blockhash, ProgramRpcClientSendTransaction),
);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramOfflineClient::new(
blockhash,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
config.program_client = program_client;
let _result = exec_test_cmd(
&config,
Expand Down Expand Up @@ -3965,9 +3973,11 @@ async fn transfer_hook_with_transfer_fee(test_validator: &TestValidator, payer:

// Make sure that parsing transfer hook accounts and expected-fee works
let blockhash = Hash::default();
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> = Arc::new(
ProgramOfflineClient::new(blockhash, ProgramRpcClientSendTransaction),
);
let program_client: Arc<dyn ProgramClient<ProgramRpcClientSendTransaction>> =
Arc::new(ProgramOfflineClient::new(
blockhash,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));
config.program_client = program_client;

let _result = exec_test_cmd(
Expand Down
31 changes: 25 additions & 6 deletions token/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,23 @@ pub trait SimulateTransactionRpc: SimulateTransaction {
}

#[derive(Debug, Clone, Copy, Default)]
pub struct ProgramRpcClientSendTransaction;
pub struct ProgramRpcClientSendTransaction {
/// Confirm the transaction after sending it
confirm: bool,
}

impl ProgramRpcClientSendTransaction {
/// Create an instance that sends the transaction **without** waiting for
/// confirmation.
pub fn new() -> Self {
Self::default()
}

/// Create an instance that sends and confirms the transaction.
pub fn new_with_confirmation() -> Self {
Self { confirm: true }
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RpcClientResponse {
Expand All @@ -139,16 +155,19 @@ impl SendTransactionRpc for ProgramRpcClientSendTransaction {
client: &'a RpcClient,
transaction: &'a Transaction,
) -> BoxFuture<'a, ProgramClientResult<Self::Output>> {
let confirm = self.confirm;
Box::pin(async move {
if !transaction.is_signed() {
return Err("Cannot send transaction: not fully signed".into());
}

client
.send_and_confirm_transaction(transaction)
.await
.map(RpcClientResponse::Signature)
.map_err(Into::into)
if confirm {
client.send_and_confirm_transaction(transaction).await
} else {
client.send_transaction(transaction).await
}
.map(RpcClientResponse::Signature)
.map_err(Into::into)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion token/transfer-hook/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ mod test {
let rpc_client = Arc::new(test_validator.get_async_rpc_client());
let client = Arc::new(ProgramRpcClient::new(
rpc_client.clone(),
ProgramRpcClientSendTransaction,
ProgramRpcClientSendTransaction::new_with_confirmation(),
));

let token = Token::new(
Expand Down
Loading