Skip to content

Commit

Permalink
feat: add native balances support + few more displayOptions (#29)
Browse files Browse the repository at this point in the history
* feat: add native balances support + few more displayOptions

* fix: make fields of NativeBalance public
  • Loading branch information
xoac committed Apr 23, 2024
1 parent 8b20b0d commit a491783
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/api/das/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ pub struct SearchAssetsParams {
pub royalty_target_type: Option<RoyaltyModel>,
pub compressible: Option<bool>,
pub compressed: Option<bool>,
pub display_options: Option<SearchAssetDisplayOptions>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
#[allow(clippy::struct_excessive_bools)]
pub struct SearchAssetDisplayOptions {
pub show_inscription: bool,
pub show_native_balance: bool,
pub show_zero_balance: bool,
pub show_unverified_collections: bool,
pub require_full_index: bool,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -146,12 +158,15 @@ pub struct GetAssetResponse {
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
#[serde(rename_all = "camelCase")]
pub struct GetAssetResponseList {
pub grand_total: Option<bool>,
pub total: u32,
pub limit: u32,
pub page: u32,
pub items: Vec<GetAssetResponse>,
/// Available when query `search assets` and `display_options.show_native_balance = true`
pub native_balance: Option<NativeBalance>,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
Expand Down Expand Up @@ -305,6 +320,13 @@ impl Default for PriceInfo {
}
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct NativeBalance {
pub lamports: u64,
pub price_per_sol: BigDecimal,
pub total_price: BigDecimal,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, Default)]
#[serde(default)]
pub struct TokenInfo {
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ mod tests {
use crate::api::das::{
DisplayOptions, GetAssetBatchParams, GetAssetParams, GetAssetProofBatchParams, GetAssetProofParams,
GetAssetsByAuthorityParams, GetAssetsByCreatorParams, GetAssetsByGroupParams, GetAssetsByOwnerParams,
GetTokenAccountsParams, Pagination, PriorityLevel, SearchAssetsParams, TokenInfo,
GetTokenAccountsParams, Pagination, PriorityLevel, SearchAssetDisplayOptions, SearchAssetsParams, TokenInfo,
};
use crate::api::types::enhanced::ParseTransactionsRequest;
use crate::api::types::{AccountWebhookEncoding, TokenType, TransactionType, TxnStatus};
Expand Down Expand Up @@ -429,10 +429,12 @@ mod tests {
owner_address: Some(rando.clone()),
token_type: Some(t),
pagination: Pagination { limit: Some(100), ..Default::default() },
display_options: Some(SearchAssetDisplayOptions { show_native_balance: true, ..Default::default() }),
..Default::default()
})
.await?;
assert!(!r.items.is_empty());
assert!(r.native_balance.is_some());
}
Ok(())
}
Expand Down

0 comments on commit a491783

Please sign in to comment.