Browse Source

client: Add send w/ spinner and options (#1926)

Sammy 3 years ago
parent
commit
b993854767
2 changed files with 33 additions and 2 deletions
  1. 1 0
      CHANGELOG.md
  2. 32 2
      client/src/lib.rs

+ 1 - 0
CHANGELOG.md

@@ -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
 

+ 32 - 2
client/src/lib.rs

@@ -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};
@@ -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)]