diff --git a/src/types/enhanced_transaction_types.rs b/src/types/enhanced_transaction_types.rs index 98d4dc7..e3caa92 100644 --- a/src/types/enhanced_transaction_types.rs +++ b/src/types/enhanced_transaction_types.rs @@ -163,6 +163,15 @@ pub struct NativeBalanceChange { pub amount: Number, } +#[derive(Serialize, Deserialize, Debug)] +pub struct NativeBalance { + // helius does not return this field if account don't exist on chain + #[serde(default)] + pub lamports: u64, + pub price_per_sol: Option, + pub total_price: Option, +} + #[derive(Serialize, Deserialize, Debug)] pub struct ProgramInfo { pub source: Source, diff --git a/src/types/types.rs b/src/types/types.rs index 062ef13..d64df88 100644 --- a/src/types/types.rs +++ b/src/types/types.rs @@ -1,7 +1,7 @@ use super::{ enums::{AssetSortBy, AssetSortDirection, Context, Interface, OwnershipModel, RoyaltyModel, Scope, UseMethod}, - AccountWebhookEncoding, CollectionIdentifier, PriorityLevel, SearchAssetsOptions, SearchConditionType, TokenType, - TransactionStatus, TransactionType, UiTransactionEncoding, WebhookType, + AccountWebhookEncoding, CollectionIdentifier, NativeBalance, PriorityLevel, SearchAssetsOptions, + SearchConditionType, TokenType, TransactionStatus, TransactionType, UiTransactionEncoding, WebhookType, }; use crate::types::{DisplayOptions, GetAssetOptions}; // use chrono::{DateTime, Utc}; @@ -288,6 +288,8 @@ pub struct AssetList { pub items: Vec, #[serde(skip_serializing_if = "Option::is_none")] pub errors: Option>, + #[serde(skip_serializing_if = "Option::is_none", rename = "nativeBalance")] + pub native_balance: Option, } #[derive(Serialize, Deserialize, Debug, Default)] diff --git a/tests/rpc/test_get_assets_by_authority.rs b/tests/rpc/test_get_assets_by_authority.rs index b4854fb..1439f62 100644 --- a/tests/rpc/test_get_assets_by_authority.rs +++ b/tests/rpc/test_get_assets_by_authority.rs @@ -204,6 +204,7 @@ async fn test_get_assets_by_authority_success() { }, ], errors: None, + native_balance: None, }, id: "1".to_string(), }; diff --git a/tests/rpc/test_get_assets_by_creator.rs b/tests/rpc/test_get_assets_by_creator.rs index f54023a..9ddb5cb 100644 --- a/tests/rpc/test_get_assets_by_creator.rs +++ b/tests/rpc/test_get_assets_by_creator.rs @@ -204,6 +204,7 @@ async fn test_get_assets_by_creator_success() { }, ], errors: None, + native_balance: None, }, id: "1".to_string(), }; diff --git a/tests/rpc/test_get_assets_by_group.rs b/tests/rpc/test_get_assets_by_group.rs index e2ce4ee..6d06f7f 100644 --- a/tests/rpc/test_get_assets_by_group.rs +++ b/tests/rpc/test_get_assets_by_group.rs @@ -119,6 +119,7 @@ async fn test_get_assets_by_group_success() { }, ], errors: None, + native_balance: None, }, id: "1".to_string(), }; diff --git a/tests/rpc/test_get_assets_by_owner.rs b/tests/rpc/test_get_assets_by_owner.rs index 1d3ee52..97ff97d 100644 --- a/tests/rpc/test_get_assets_by_owner.rs +++ b/tests/rpc/test_get_assets_by_owner.rs @@ -134,6 +134,7 @@ async fn test_get_assets_by_owner_success() { mpl_core_info: None, }], errors: None, + native_balance: None, }, id: "1".to_string(), }; diff --git a/tests/rpc/test_search_assets.rs b/tests/rpc/test_search_assets.rs index 812641d..522eb34 100644 --- a/tests/rpc/test_search_assets.rs +++ b/tests/rpc/test_search_assets.rs @@ -134,6 +134,7 @@ async fn test_search_assets_success() { mpl_core_info: None, }], errors: None, + native_balance: None, }, id: "1".to_string(), }; diff --git a/tests/tests.rs b/tests/tests.rs index fba8dbc..a8fbf6f 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -4,6 +4,10 @@ mod utils { mod test_make_keypairs; } +mod types { + mod test_deserialize_asset_list; +} + mod rpc { mod test_get_asset; mod test_get_asset_batch; diff --git a/tests/types/asset_list_with_native_balance.json b/tests/types/asset_list_with_native_balance.json new file mode 100644 index 0000000..9b3315e --- /dev/null +++ b/tests/types/asset_list_with_native_balance.json @@ -0,0 +1,108 @@ +{ + "total": 1, + "limit": 1000, + "cursor": "eeHNoMJoFxNE9sGgyb3ZU4yJs65ekMX4mRUXWkVB3KV", + "items": [ + { + "interface": "V1_NFT", + "id": "JDPM1gUHdke4pHuABnNv51sVGw2ZeuDbyPhKMFnxgGxn", + "content": { + "$schema": "https://schema.metaplex.com/nft1.0.json", + "json_uri": "https://www.hi-hi.vip/json/wifdrop6.json", + "files": [ + { + "uri": "https://img.hi-hi.vip/json/img/wif.gif", + "cdn_uri": "https://cdn.helius-rpc.com/cdn-cgi/image//https://img.hi-hi.vip/json/img/wif.gif", + "mime": "image/gif" + } + ], + "metadata": { + "attributes": [ + { + "value": "https://wifdrop.com", + "trait_type": "Website" + }, + { + "value": "True", + "trait_type": "Verified" + }, + { + "value": "3,000+ WIF", + "trait_type": "Amount" + }, + { + "value": "35 minutes!", + "trait_type": "Time Left" + } + ], + "description": "Random Drop event! https://WIFDROP.com", + "name": "3000$ WIF Lucky Drop WIFDROP.com", + "symbol": "WFD", + "token_standard": "NonFungible" + }, + "links": { + "external_url": "https://Wifdrop.com", + "image": "https://img.hi-hi.vip/json/img/wif.gif" + } + }, + "authorities": [ + { + "address": "G1GmNbuEwkmxvawJb2tRa1DAxScGPeXydmCVF2roaDEw", + "scopes": [ + "full" + ] + } + ], + "compression": { + "eligible": false, + "compressed": true, + "data_hash": "38H9vrizmkU7s7eRr4nXWxJuTc2GivGSa8e5yw5fyQy8", + "creator_hash": "H6fmhtvYtsLtsXNtNBsniiSZXkV1J4yP35zgZVzcBb3b", + "asset_hash": "HEmRb8ED5EuyXTitH1bJcWgL6HDLHY95c728Am5A1JT5", + "tree": "3Grymv861hLiCa8cefye5UP5fkAirbtodvkjoe9dH2iV", + "seq": 20911, + "leaf_id": 20908 + }, + "grouping": [ + { + "group_key": "collection", + "group_value": "HPc65ZxbkxdaWZrQBGKYhctCShJoSLWd7Dtkh2eicRwC" + } + ], + "royalty": { + "royalty_model": "creators", + "target": null, + "percent": 0.0, + "basis_points": 0, + "primary_sale_happened": false, + "locked": false + }, + "creators": [ + { + "address": "H17XJzC1N5o15pwB9gMZ8RRHhmNVMbt4PXiHj53epf1n", + "share": 100, + "verified": true + } + ], + "ownership": { + "frozen": false, + "delegated": true, + "delegate": "H17XJzC1N5o15pwB9gMZ8RRHhmNVMbt4PXiHj53epf1n", + "ownership_model": "single", + "owner": "HmBek5ZndbgLsWLUqRjXBauXjTupfxZrAGnuL9FJhsBP" + }, + "supply": { + "print_max_supply": 0, + "print_current_supply": 0, + "edition_nonce": 0 + }, + "mutable": true, + "burnt": false + } + ], + "nativeBalance": { + "lamports": 47770720, + "price_per_sol": 150.3314666748047, + "total_price": 7.1814424017114264 + } +} \ No newline at end of file diff --git a/tests/types/test_deserialize_asset_list.rs b/tests/types/test_deserialize_asset_list.rs new file mode 100644 index 0000000..1370322 --- /dev/null +++ b/tests/types/test_deserialize_asset_list.rs @@ -0,0 +1,12 @@ +use helius::types::AssetList; + +#[test] +fn des_asset_list_with_native_balance() { + let raw_json = include_str!("./asset_list_with_native_balance.json"); + let deserialized: AssetList = serde_json::from_str(raw_json).unwrap(); + + let native_balance = deserialized.native_balance.unwrap(); + assert_eq!(native_balance.lamports, 47770720); + assert_eq!(native_balance.price_per_sol, Some(150.3314666748047_f64)); + assert_eq!(native_balance.total_price, Some(7.1814424017114264_f64)); +}