Skip to content

Commit

Permalink
client: Add send w/ spinner and options (#1926)
Browse files Browse the repository at this point in the history
  • Loading branch information
stegaBOB authored May 29, 2022
1 parent f9c42f1 commit b993854
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ com/project-serum/anchor/pull/1841)).
* cli: Add `b` and `t` aliases for `build` and `test` respectively ([#1823](https://github.com/project-serum/anchor/pull/1823)).
* spl: Add `sync_native` token program CPI wrapper function ([#1833](https://github.com/project-serum/anchor/pull/1833)).
* ts: Implement a coder for system program ([#1920](https://github.com/project-serum/anchor/pull/1920)).
* client: Add send_with_spinner_and_config function to RequestBuilder ([#1926](https://github.com/project-serum/anchor/pull/1926))

### Fixes

Expand Down
34 changes: 32 additions & 2 deletions client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use solana_client::client_error::ClientError as SolanaClientError;
use solana_client::pubsub_client::{PubsubClient, PubsubClientError, PubsubClientSubscription};
use solana_client::rpc_client::RpcClient;
use solana_client::rpc_config::{
RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcTransactionLogsConfig,
RpcTransactionLogsFilter,
RpcAccountInfoConfig, RpcProgramAccountsConfig, RpcSendTransactionConfig,
RpcTransactionLogsConfig, RpcTransactionLogsFilter,
};
use solana_client::rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType};
use solana_client::rpc_response::{Response as RpcResponse, RpcLogsResponse};
Expand Down Expand Up @@ -556,6 +556,36 @@ impl<'a> RequestBuilder<'a> {
.send_and_confirm_transaction(&tx)
.map_err(Into::into)
}

pub fn send_with_spinner_and_config(
self,
config: RpcSendTransactionConfig,
) -> Result<Signature, ClientError> {
let instructions = self.instructions()?;

let mut signers = self.signers;
signers.push(&*self.payer);

let rpc_client = RpcClient::new_with_commitment(self.cluster, self.options);

let tx = {
let latest_hash = rpc_client.get_latest_blockhash()?;
Transaction::new_signed_with_payer(
&instructions,
Some(&self.payer.pubkey()),
&signers,
latest_hash,
)
};

rpc_client
.send_and_confirm_transaction_with_spinner_and_config(
&tx,
rpc_client.commitment(),
config,
)
.map_err(Into::into)
}
}

#[cfg(test)]
Expand Down

0 comments on commit b993854

Please sign in to comment.