Skip to content

Commit

Permalink
Start Adding get_priority_fee_estimate Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed May 1, 2024
1 parent 8bb7090 commit a30e4ac
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ use crate::error::Result;
use crate::request_handler::RequestHandler;
use crate::types::types::{RpcRequest, RpcResponse};
use crate::types::{
Asset, AssetList, AssetProof, EditionsList, GetAsset, GetAssetBatch, GetAssetProof, GetAssetProofBatch,
GetAssetSignatures, GetAssetsByAuthority, GetAssetsByCreator, GetAssetsByGroup, GetAssetsByOwner, GetNftEditions,
GetTokenAccounts, SearchAssets, TokenAccountsList, TransactionSignatureList,
Asset, AssetList, AssetProof, EditionsList, GetAsset, GetAssetBatch, GetAssetProof, GetAssetProofBatch, GetAssetSignatures, GetAssetsByAuthority, GetAssetsByCreator, GetAssetsByGroup, GetAssetsByOwner, GetNftEditions, GetPriorityFeeEstimateRequest, GetTokenAccounts, SearchAssets, TokenAccountsList, TransactionSignatureList
};

use reqwest::{Client, Method, Url};
Expand Down Expand Up @@ -228,4 +226,15 @@ impl RpcClient {
pub async fn get_nft_editions(&self, request: GetNftEditions) -> Result<EditionsList> {
self.post_rpc_request("getNftEditions", request).await
}

/// Gets an estimate of the priority fees required for a transaction to be processed more quicklGetPriorityFeeEstimateRequest
///
/// This method calculates varying levels of transaction fees that can influence the priority of a transaction, based on current network conditions
///
/// # Arguments
/// * `request` - A struct that includes the following:
/// `transaction` - Optionally, the serialized transaction for which the fee estimate is requested
pub async fn get_priority_fee_estimate(&self, request: GetPriorityFeeEstimateRequest) -> Result<GetPriorityFeeEstimateResponse> {
self.post_rpc_request("getPriorityFeeEstimate", request).await
}
}
20 changes: 20 additions & 0 deletions src/types/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,23 @@ impl MintApiAuthority {
}
}
}

#[derive(Serialize, Deserialize, Debug)]
pub enum PriorityLevel {
None,
Low,
Medium,
High,
VeryHigh,
UnsafeMax,
Default,
}

#[derive(Serialize, Deserialize, Debug)]
pub enum UiTransactionEncoding {
Binary,
Base64,
Base58,
Json,
JsonParsed,
}
38 changes: 37 additions & 1 deletion src/types/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
enums::{AssetSortBy, AssetSortDirection, Context, Interface, OwnershipModel, RoyaltyModel, Scope, UseMethod},
SearchAssetsOptions, SearchConditionType, TokenType,
SearchAssetsOptions, SearchConditionType, TokenType, PriorityLevel, UiTransactionEncoding
};
use crate::types::{DisplayOptions, GetAssetOptions};
// use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -768,3 +768,39 @@ pub struct MintResponse {
#[serde(rename = "assetId")]
pub asset_id: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetPriorityFeeEstimateOptions {
priority_level: Option<PriorityLevel>,
include_all_priority_fee_levels: Option<bool>,
transaction_encoding: Option<UiTransactionEncoding>,
lookback_slots: Option<u8>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetPriorityFeeEstimateRequest {
transaction: Option<String>,
#[serde(rename = "accountKeys")]
account_keys: Option<Vec<String>>,
options: Option<GetPriorityFeeEstimateOptions>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct MicroLamportPriorityFeeLevels {
none: f64,
low: f64,
medium: f64,
high: f64,
#[serde(rename = "veryHigh")]
very_high: f64,
#[serde(rename = "unsafeMax")]
unsafe_max: f64,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct GetPriorityFeeResponse {
priority_fee_estimate: Option<f64>,
priority_fee_levels: Option<MicroLamportPriorityFeeLevels>,
}

0 comments on commit a30e4ac

Please sign in to comment.