From 2058b6461cb0de5af90b04eb8fae4225a368251e Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 4 Aug 2022 10:11:13 +0200 Subject: [PATCH] Client: Support sending via nonblocking RpcClient --- client/src/lib.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 5bbf862a..af97bf79 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -535,13 +535,16 @@ impl<'a> RequestBuilder<'a> { } pub fn send(self) -> Result { + 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 { 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 { + 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,