From d310a347dd0f721c4fcc3843b64bec392736428e Mon Sep 17 00:00:00 2001 From: AJ Taylor Date: Thu, 28 Jul 2022 23:31:17 -0600 Subject: [PATCH 1/2] add get token largest accounts rpc call to client --- client/src/nonblocking/rpc_client.rs | 15 +++++++++++++++ client/src/rpc_client.rs | 11 +++++++++++ client/src/rpc_request.rs | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/client/src/nonblocking/rpc_client.rs b/client/src/nonblocking/rpc_client.rs index c6f0098d71eb64..f68cd2627f9f3a 100644 --- a/client/src/nonblocking/rpc_client.rs +++ b/client/src/nonblocking/rpc_client.rs @@ -5016,6 +5016,21 @@ impl RpcClient { .await } + pub async fn get_token_largest_accounts( + &self, + mint: &Pubkey, + commitment_config: CommitmentConfig, + ) -> RpcResult> { + self.send( + RpcRequest::GetTokenLargestAccounts, + json!([ + mint.to_string(), + self.maybe_map_commitment(commitment_config).await? + ]), + ) + .await + } + pub async fn get_token_supply(&self, mint: &Pubkey) -> ClientResult { Ok(self .get_token_supply_with_commitment(mint, self.commitment()) diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 1aba5a0c53f047..e3188c4acc0732 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -3956,6 +3956,17 @@ impl RpcClient { )) } + pub fn get_token_largest_accounts( + &self, + mint: &Pubkey, + commitment_config: CommitmentConfig, + ) -> RpcResult> { + self.invoke( + self.rpc_client + .get_token_largest_accounts(mint, commitment_config), + ) + } + pub fn get_token_supply(&self, mint: &Pubkey) -> ClientResult { self.invoke(self.rpc_client.get_token_supply(mint)) } diff --git a/client/src/rpc_request.rs b/client/src/rpc_request.rs index d3f0ceb1c0ad54..32f8c45183762d 100644 --- a/client/src/rpc_request.rs +++ b/client/src/rpc_request.rs @@ -100,6 +100,7 @@ pub enum RpcRequest { GetTokenAccountBalance, GetTokenAccountsByDelegate, GetTokenAccountsByOwner, + GetTokenLargestAccounts, GetTokenSupply, GetTransaction, GetTransactionCount, @@ -175,6 +176,7 @@ impl fmt::Display for RpcRequest { RpcRequest::GetTokenAccountsByDelegate => "getTokenAccountsByDelegate", RpcRequest::GetTokenAccountsByOwner => "getTokenAccountsByOwner", RpcRequest::GetTokenSupply => "getTokenSupply", + RpcRequest::GetTokenLargestAccounts => "getTokenLargestAccounts", RpcRequest::GetTransaction => "getTransaction", RpcRequest::GetTransactionCount => "getTransactionCount", RpcRequest::GetVersion => "getVersion", @@ -322,6 +324,10 @@ mod tests { let test_request = RpcRequest::SendTransaction; let request = test_request.build_request_json(1, Value::Null); assert_eq!(request["method"], "sendTransaction"); + + let test_request = RpcRequest::GetTokenLargestAccounts; + let request = test_request.build_request_json(1, Value::Null); + assert_eq!(request["method"], "getTokenLargestAccounts"); } #[test] From 312272883b6678eb902e1a6b802e653983aabac4 Mon Sep 17 00:00:00 2001 From: AJ Taylor Date: Mon, 15 Aug 2022 20:00:16 -0600 Subject: [PATCH 2/2] split to include with commitment --- client/src/nonblocking/rpc_client.rs | 10 ++++++++++ client/src/rpc_client.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/client/src/nonblocking/rpc_client.rs b/client/src/nonblocking/rpc_client.rs index f68cd2627f9f3a..ead129fa26ac60 100644 --- a/client/src/nonblocking/rpc_client.rs +++ b/client/src/nonblocking/rpc_client.rs @@ -5019,6 +5019,16 @@ impl RpcClient { pub async fn get_token_largest_accounts( &self, mint: &Pubkey, + ) -> ClientResult> { + Ok(self + .get_token_largest_accounts_with_commitment(mint, self.commitment()) + .await? + .value) + } + + pub async fn get_token_largest_accounts_with_commitment( + &self, + mint: &Pubkey, commitment_config: CommitmentConfig, ) -> RpcResult> { self.send( diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index fba04128c5d7d5..b89b906e57ade4 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -3904,11 +3904,18 @@ impl RpcClient { pub fn get_token_largest_accounts( &self, mint: &Pubkey, + ) -> ClientResult> { + self.invoke((self.rpc_client.as_ref()).get_token_largest_accounts(mint)) + } + + pub fn get_token_largest_accounts_with_commitment( + &self, + mint: &Pubkey, commitment_config: CommitmentConfig, ) -> RpcResult> { self.invoke( - self.rpc_client - .get_token_largest_accounts(mint, commitment_config), + (self.rpc_client.as_ref()) + .get_token_largest_accounts_with_commitment(mint, commitment_config), ) }