Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parsed_transaction_history): add transaction pagination #14

Merged
merged 6 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions examples/get_parsed_transaction_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ async fn main() -> Result<(), HeliusError> {

let helius: Helius = Helius::new(api_key, cluster).unwrap();

let response: Result<Vec<EnhancedTransaction>, HeliusError> = helius
.parsed_transaction_history("2k5AXX4guW9XwRQ1AKCpAuUqgWDpQpwFfpVFh3hnm2Ha")
.await;
let request: ParsedTransactionHistoryRequest = ParsedTransactionHistoryRequest {
address: "2k5AXX4guW9XwRQ1AKCpAuUqgWDpQpwFfpVFh3hnm2Ha".to_string(),
before: None,
};

let response: Result<Vec<EnhancedTransaction>, HeliusError> = helius.parsed_transaction_history(request).await;

println!("Assets: {:?}", response);

Ok(())
Expand Down
23 changes: 17 additions & 6 deletions src/enhanced_transactions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::Result;
use crate::types::{EnhancedTransaction, ParseTransactionsRequest};
use crate::types::{EnhancedTransaction, ParseTransactionsRequest, ParsedTransactionHistoryRequest};
use crate::Helius;

use reqwest::{Method, Url};
Expand All @@ -8,7 +8,8 @@ impl Helius {
/// Parses transactions given an array of transaction IDs
///
/// # Arguments
/// * `transactions` - A vector of transaction IDs to be parsed
/// * `ParseTransactionsRequest` - A parse transaction request, which includes:
/// - A vector of transaction IDs to be parsed
///
/// # Returns
/// A `Result` wrapping a vector of `EnhancedTransaction`s
Expand All @@ -30,15 +31,25 @@ impl Helius {
/// Retrieves a parsed transaction history for a specific address
///
/// # Arguments
/// * `address` - An address for which a given parsed transaction history will be retrieved
/// * `ParsedTransactionHistoryRequest` - A parsed transaction history request, which includes:
/// - An address for which a given parsed transaction history will be retrieved
/// - An optional `before` parameter that, when provided, fetches the parsed transaction history before the given signature. This is useful for pagination
///
/// # Returns
/// A `Result` wrapping a vector of `EnhancedTransaction`s
pub async fn parsed_transaction_history(&self, address: &str) -> Result<Vec<EnhancedTransaction>> {
let url: String = format!(
pub async fn parsed_transaction_history(
&self,
request: ParsedTransactionHistoryRequest,
) -> Result<Vec<EnhancedTransaction>> {
let mut url: String = format!(
"{}v0/addresses/{}/transactions?api-key={}",
self.config.endpoints.api, address, self.config.api_key
self.config.endpoints.api, request.address, self.config.api_key
);

if let Some(before) = request.before {
url = format!("{}&before={}", url, before);
}

let parsed_url: Url = Url::parse(&url).expect("Failed to parse URL");

self.rpc_client.handler.send(Method::GET, parsed_url, None::<&()>).await
Expand Down
6 changes: 6 additions & 0 deletions src/types/enhanced_transaction_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ pub struct ParseTransactionsRequest {
pub transactions: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ParsedTransactionHistoryRequest {
pub address: String,
pub before: Option<String>,
}

/// We have a limit of 100 transactions per call, so this helps split the signatures into different chunks
impl ParseTransactionsRequest {
pub fn from_slice(signatures: &[String]) -> Vec<Self> {
Expand Down
Loading