diff --git a/src/request_handler.rs b/src/request_handler.rs index 78b3a17..4ba92c4 100644 --- a/src/request_handler.rs +++ b/src/request_handler.rs @@ -34,7 +34,7 @@ impl RequestHandler { let response: Response = self.send_request(request_builder).await?; - print!("{:?}", response); + print!("RESPONSE {:?}", response); self.handle_response(response).await } diff --git a/src/rpc_client.rs b/src/rpc_client.rs index af16225..8f4688d 100644 --- a/src/rpc_client.rs +++ b/src/rpc_client.rs @@ -5,7 +5,7 @@ use crate::config::Config; use crate::error::Result; use crate::request_handler::RequestHandler; use crate::types::types::{ApiResponse, RpcRequest, RpcResponse}; -use crate::types::{AssetsByAuthorityRequest, AssetsByOwnerRequest, GetAssetRequest}; +use crate::types::{AssetsByAuthorityRequest, AssetsByOwnerRequest, GetAssetRequest, GetAssetResponseForAsset}; use reqwest::{Client, Method, Url}; use serde::de::DeserializeOwned; @@ -37,17 +37,15 @@ impl RpcClient { print!("{}", url); let rpc_request: RpcRequest = RpcRequest::new(method, request); - - - print!("{:?}", rpc_request); + println!("Serialized Request: {:?}", serde_json::to_string(&rpc_request)); let rpc_response: RpcResponse = self.handler.send(Method::POST, url, Some(&rpc_request)).await?; - print!("{:?}", rpc_response); + print!("RPCRESPONSE {:?}", rpc_response.result); Ok(rpc_response.result) } /// Gets an asset by its ID - pub async fn get_asset(&self, request: GetAssetRequest) -> Result { + pub async fn get_asset(&self, request: GetAssetRequest) -> Result> { self.post_rpc_request("getAsset".to_string(), request).await } diff --git a/src/types/enums.rs b/src/types/enums.rs index fde75d4..4cfc02e 100644 --- a/src/types/enums.rs +++ b/src/types/enums.rs @@ -1,9 +1,10 @@ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)] pub enum Interface { #[serde(rename = "V1_NFT")] V1NFT, + #[default] #[serde(rename = "Custom")] Custom, #[serde(rename = "V1_PRINT")] @@ -24,8 +25,9 @@ pub enum Interface { FungibleToken, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] pub enum OwnershipModel { + #[default] #[serde(rename = "single")] Single, #[serde(rename = "token")] diff --git a/src/types/types.rs b/src/types/types.rs index 1b20e27..346808e 100644 --- a/src/types/types.rs +++ b/src/types/types.rs @@ -38,6 +38,7 @@ pub struct RpcRequest { pub jsonrpc: String, pub id: String, pub method: String, + #[serde(rename ="params")] pub parameters: T, } @@ -95,27 +96,23 @@ pub struct AssetsByAuthorityRequest { #[derive(Serialize, Deserialize, Debug)] pub struct GetAssetRequest { pub id: String, - #[serde(flatten)] + #[serde(flatten, rename = "displayOptions")] pub display_options: Option, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct DisplayOptions { - #[serde(rename = "showUnverifiedCollections")] pub show_unverified_collections: bool, - #[serde(rename = "showCollectionMetadata")] pub show_collection_metadata: bool, - #[serde(rename = "showFungible")] pub show_fungible: bool, - #[serde(rename = "showInscription")] pub show_inscription: bool, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct AssetSortingRequest { - #[serde(rename = "sortBy")] pub sort_by: AssetSortBy, - #[serde(rename = "sortDirection")] pub sort_direction: AssetSortDirection, } @@ -141,7 +138,6 @@ pub struct GetAssetResponseList { pub total: Option, pub limit: Option, pub page: Option, - #[serde(rename = "items")] pub items: Option>, } @@ -162,7 +158,7 @@ pub struct GetAssetResponse { pub burnt: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] pub struct GetAssetResponseForAsset { pub interface: Interface, pub id: String, @@ -182,70 +178,53 @@ pub struct GetAssetResponseForAsset { } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct MintExtensions { - #[serde(rename = "confidentialTransferMint")] pub confidential_transfer_mint: Option, - #[serde(rename = "confidentialTransferFeeConfig")] pub confidential_transfer_fee_config: Option, - #[serde(rename = "transferFeeConfig")] pub transfer_fee_config: Option, - #[serde(rename = "metadataPointer")] pub metadata_pointer: MetadataPointer, - #[serde(rename = "mintCloseAuthority")] pub mint_close_authority: MintCloseAuthority, - #[serde(rename = "permanentDelegate")] pub permanent_delegate: PermanentDelegate, - #[serde(rename = "transferHook")] pub transfer_hook: TransferHook, - #[serde(rename = "interestBearingConfig")] pub interest_bearing_config: InterestBearingConfig, - #[serde(rename = "defaultAccountState")] pub default_account_state: DefaultAccountState, - #[serde(rename = "confidentialTransferAccount")] pub confidential_transfer_account: ConfidentialTransferAccount, pub metadata: MintExtensionMetadata, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct ConfidentialTransferMint { pub authority: String, - #[serde(rename = "autoApproveNewAccounts")] pub auto_approve_new_accounts: bool, - #[serde(rename = "auditorElgamalPubkey")] pub auditor_elgamal_pubkey: String, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct ConfidentialTransferFeeConfig { pub authority: String, - #[serde(rename = "withdrawWithheldAuthorityElgamalPubkey")] pub withdraw_withheld_authority_elgamal_pubkey: String, - #[serde(rename = "harvestToMintEnabled")] pub harvest_to_mint_enabled: bool, - #[serde(rename = "withheldAmount")] pub withheld_amount: String, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct TransferFeeConfig { - #[serde(rename = "transferFeeConfigAuthority")] pub transfer_fee_config_authority: String, - #[serde(rename = "withdrawWithheldAuthority")] pub withdraw_withheld_authority: String, - #[serde(rename = "withheldAmount")] pub withheld_amount: i32, - #[serde(rename = "olderTransferFee")] pub older_transfer_fee: OlderTransferFee, - #[serde(rename = "newTransferFee")] pub new_trasfer_fee: NewTransferFee, } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct OlderTransferFee { pub epoch: String, - #[serde(rename = "maximumFee")] pub maximum_fee: String, - #[serde(rename = "transferFeeBasisPoints")] pub transfer_fee_basis_points: String, } @@ -262,8 +241,8 @@ pub struct MetadataPointer { } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct MintCloseAuthority { - #[serde(rename = "closeAuthority")] pub close_authority: String, } @@ -280,16 +259,12 @@ pub struct TransferHook { } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct InterestBearingConfig { - #[serde(rename = "rateAuthority")] pub rate_authority: String, - #[serde(rename = "initializationTimestamp")] pub initialization_timestamp: i32, - #[serde(rename = "preUpdateAverageRate")] pub pre_update_average_rate: i32, - #[serde(rename = "lastUpdateTimestamp")] pub last_update_timestamp: i32, - #[serde(rename = "currentRate")] pub current_rate: i32, } @@ -299,29 +274,19 @@ pub struct DefaultAccountState { } #[derive(Serialize, Deserialize, Debug)] +#[serde(rename_all = "camelCase")] pub struct ConfidentialTransferAccount { pub approved: bool, - #[serde(rename = "elgamalPubkey")] pub elgamal_pubkey: String, - #[serde(rename = "pendingBalanceLo")] pub pending_balance_lo: String, - #[serde(rename = "pendingBalanceHi")] pub pending_balance_hi: String, - #[serde(rename = "availableBalance")] pub available_balance: String, - #[serde(rename = "decryptableAvailableBalance")] pub decryptable_available_balance: String, - #[serde(rename = "allowConfidentialCredits")] pub allow_confidential_credits: bool, - #[serde(rename = "allowNonConfidentialCredits")] pub allow_non_confidential_credits: bool, - #[serde(rename = "pendingBalanceCreditCounter")] pub pending_balance_credit_counter: i32, - #[serde(rename = "maximumPendingBalanceCreditCounter")] pub maximum_pending_balance_credit_counter: i32, - #[serde(rename = "expectedPendingBalanceCreditCounter")] pub expected_pending_balance_credit_counter: i32, - #[serde(rename = "actualPendingBalanceCreditCounter")] pub actual_pending_balance_credit_counter: i32, } @@ -477,7 +442,7 @@ pub struct Royalty { pub locked: bool, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] pub struct Ownership { pub frozen: bool, pub delegated: bool, @@ -493,16 +458,13 @@ pub struct Uses { pub total: u32, } -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] +#[serde(rename_all = "camelCase")] pub struct Supply { - #[serde(rename = "printMaxSupply")] + #[serde(default)] pub print_max_supply: u32, - #[serde(rename = "printCurrentSupply")] pub print_current_supply: u32, - #[serde(rename = "editionNonce")] pub edition_nonce: Option, - #[serde(rename = "editionNumber")] pub edition_number: Option, - #[serde(rename = "masterEditionMint")] pub master_edition_mint: Option, }