Client: Support sending via nonblocking RpcClient

This commit is contained in:
Christian Kamm 2022-08-04 10:11:13 +02:00
parent 442c00634e
commit 2058b6461c
1 changed files with 30 additions and 2 deletions

View File

@ -535,13 +535,16 @@ impl<'a> RequestBuilder<'a> {
}
pub fn send(self) -> Result<Signature, ClientError> {
let rpc_client = RpcClient::new_with_commitment(self.cluster.clone(), self.options);
self.send_rpc(&rpc_client)
}
pub fn send_rpc(self, rpc_client: &RpcClient) -> 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(
@ -557,6 +560,31 @@ impl<'a> RequestBuilder<'a> {
.map_err(Into::into)
}
pub async fn send_rpc_async(
self,
rpc_client: &solana_client::nonblocking::rpc_client::RpcClient,
) -> Result<Signature, ClientError> {
let instructions = self.instructions()?;
let mut signers = self.signers;
signers.push(&*self.payer);
let tx = {
let latest_hash = rpc_client.get_latest_blockhash().await?;
Transaction::new_signed_with_payer(
&instructions,
Some(&self.payer.pubkey()),
&signers,
latest_hash,
)
};
rpc_client
.send_and_confirm_transaction(&tx)
.await
.map_err(Into::into)
}
pub fn send_with_spinner_and_config(
self,
config: RpcSendTransactionConfig,