Skip to content

Commit

Permalink
add getTokenLargestAccounts rpc method to rust client (#26840)
Browse files Browse the repository at this point in the history
* add get token largest accounts rpc call to client

* split to include with commitment
  • Loading branch information
anthontaylor authored Aug 16, 2022
1 parent 3b87aa9 commit 9fb7ec7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5016,6 +5016,31 @@ impl RpcClient {
.await
}

pub async fn get_token_largest_accounts(
&self,
mint: &Pubkey,
) -> ClientResult<Vec<RpcTokenAccountBalance>> {
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<Vec<RpcTokenAccountBalance>> {
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<UiTokenAmount> {
Ok(self
.get_token_supply_with_commitment(mint, self.commitment())
Expand Down
18 changes: 18 additions & 0 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,6 +3901,24 @@ impl RpcClient {
)
}

pub fn get_token_largest_accounts(
&self,
mint: &Pubkey,
) -> ClientResult<Vec<RpcTokenAccountBalance>> {
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<Vec<RpcTokenAccountBalance>> {
self.invoke(
(self.rpc_client.as_ref())
.get_token_largest_accounts_with_commitment(mint, commitment_config),
)
}

pub fn get_token_supply(&self, mint: &Pubkey) -> ClientResult<UiTokenAmount> {
self.invoke((self.rpc_client.as_ref()).get_token_supply(mint))
}
Expand Down
6 changes: 6 additions & 0 deletions client/src/rpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub enum RpcRequest {
GetTokenAccountBalance,
GetTokenAccountsByDelegate,
GetTokenAccountsByOwner,
GetTokenLargestAccounts,
GetTokenSupply,
GetTransaction,
GetTransactionCount,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 9fb7ec7

Please sign in to comment.