Skip to content

Commit

Permalink
Add rust client support for getRecentPrioritizationFees (backport #29558
Browse files Browse the repository at this point in the history
) (#29564)

* Add rust client support for getRecentPrioritizationFees (#29558)

(cherry picked from commit e0d2a40)

* Fix conflict

* Fix doctests

Co-authored-by: Tyera <tyera@solana.com>
  • Loading branch information
mergify[bot] and CriesofCarrots authored Jan 7, 2023
1 parent fa7055e commit b8f2a9d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
8 changes: 6 additions & 2 deletions client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use {
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcBlockhash,
RpcConfirmedTransactionStatusWithSignature, RpcContactInfo, RpcFees, RpcIdentity,
RpcInflationGovernor, RpcInflationRate, RpcInflationReward, RpcKeyedAccount,
RpcPerfSample, RpcResponseContext, RpcSimulateTransactionResult, RpcSnapshotSlotInfo,
RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo,
RpcPerfSample, RpcPrioritizationFee, RpcResponseContext, RpcSimulateTransactionResult,
RpcSnapshotSlotInfo, RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountInfo,
RpcVoteAccountStatus, StakeActivationState,
},
rpc_sender::*,
Expand Down Expand Up @@ -418,6 +418,10 @@ impl RpcSender for MockSender {
num_slots: 123,
sample_period_secs: 60,
}])?,
"getRecentPrioritizationFees" => serde_json::to_value(vec![RpcPrioritizationFee {
slot: 123_456_789,
prioritization_fee: 10_000,
}])?,
"getIdentity" => serde_json::to_value(RpcIdentity {
identity: PUBKEY.to_string(),
})?,
Expand Down
45 changes: 45 additions & 0 deletions client/src/nonblocking/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,51 @@ impl RpcClient {
.await
}

/// Returns a list of minimum prioritization fees from recent blocks.
/// Takes an optional vector of addresses; if any addresses are provided, the response will
/// reflect the minimum prioritization fee to land a transaction locking all of the provided
/// accounts as writable.
///
/// Currently, a node's prioritization-fee cache stores data from up to 150 blocks.
///
/// # RPC Reference
///
/// This method corresponds directly to the [`getRecentPrioritizationFees`] RPC method.
///
/// [`getRecentPrioritizationFees`]: https://docs.solana.com/developing/clients/jsonrpc-api#getrecentprioritizationfees
///
/// # Examples
///
/// ```
/// # use solana_client::{
/// # client_error::ClientError,
/// # nonblocking::rpc_client::RpcClient,
/// # };
/// # use solana_sdk::signature::{Keypair, Signer};
/// # futures::executor::block_on(async {
/// # let rpc_client = RpcClient::new_mock("succeeds".to_string());
/// # let alice = Keypair::new();
/// # let bob = Keypair::new();
/// let addresses = vec![alice.pubkey(), bob.pubkey()];
/// let prioritization_fees = rpc_client.get_recent_prioritization_fees(
/// &addresses,
/// ).await?;
/// # Ok::<(), ClientError>(())
/// # })?;
/// # Ok::<(), ClientError>(())
/// ```
pub async fn get_recent_prioritization_fees(
&self,
addresses: &[Pubkey],
) -> ClientResult<Vec<RpcPrioritizationFee>> {
let addresses: Vec<_> = addresses
.iter()
.map(|address| address.to_string())
.collect();
self.send(RpcRequest::GetRecentPrioritizationFees, json!([addresses]))
.await
}

/// Returns the identity pubkey for the current node.
///
/// # RPC Reference
Expand Down
37 changes: 37 additions & 0 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3023,6 +3023,43 @@ impl RpcClient {
self.invoke(self.rpc_client.get_recent_performance_samples(limit))
}

/// Returns a list of minimum prioritization fees from recent blocks.
/// Takes an optional vector of addresses; if any addresses are provided, the response will
/// reflect the minimum prioritization fee to land a transaction locking all of the provided
/// accounts as writable.
///
/// Currently, a node's prioritization-fee cache stores data from up to 150 blocks.
///
/// # RPC Reference
///
/// This method corresponds directly to the [`getRecentPrioritizationFees`] RPC method.
///
/// [`getRecentPrioritizationFees`]: https://docs.solana.com/developing/clients/jsonrpc-api#getrecentprioritizationfees
///
/// # Examples
///
/// ```
/// # use solana_client::{
/// # client_error::ClientError,
/// # rpc_client::RpcClient,
/// # };
/// # use solana_sdk::signature::{Keypair, Signer};
/// # let rpc_client = RpcClient::new_mock("succeeds".to_string());
/// # let alice = Keypair::new();
/// # let bob = Keypair::new();
/// let addresses = vec![alice.pubkey(), bob.pubkey()];
/// let prioritization_fees = rpc_client.get_recent_prioritization_fees(
/// &addresses,
/// )?;
/// # Ok::<(), ClientError>(())
/// ```
pub fn get_recent_prioritization_fees(
&self,
addresses: &[Pubkey],
) -> ClientResult<Vec<RpcPrioritizationFee>> {
self.invoke(self.rpc_client.get_recent_prioritization_fees(addresses))
}

/// Returns the identity pubkey for the current node.
///
/// # RPC Reference
Expand Down
2 changes: 2 additions & 0 deletions client/src/rpc_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub enum RpcRequest {
)]
GetRecentBlockhash,
GetRecentPerformanceSamples,
GetRecentPrioritizationFees,
GetHighestSnapshotSlot,
#[deprecated(
since = "1.9.0",
Expand Down Expand Up @@ -157,6 +158,7 @@ impl fmt::Display for RpcRequest {
RpcRequest::GetProgramAccounts => "getProgramAccounts",
RpcRequest::GetRecentBlockhash => "getRecentBlockhash",
RpcRequest::GetRecentPerformanceSamples => "getRecentPerformanceSamples",
RpcRequest::GetRecentPrioritizationFees => "getRecentPrioritizationFees",
RpcRequest::GetHighestSnapshotSlot => "getHighestSnapshotSlot",
RpcRequest::GetSnapshotSlot => "getSnapshotSlot",
RpcRequest::GetSignaturesForAddress => "getSignaturesForAddress",
Expand Down

0 comments on commit b8f2a9d

Please sign in to comment.