From 68e8f8a5d96a2079e2771ee47c02209691127a4c Mon Sep 17 00:00:00 2001 From: jouzo <15011228+Jouzo@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:16:52 +0100 Subject: [PATCH] Use skip_serializing_none --- lib/ain-macros/src/lib.rs | 5 ++++- lib/ain-ocean/src/api/address.rs | 2 ++ lib/ain-ocean/src/api/governance.rs | 2 ++ lib/ain-ocean/src/api/loan.rs | 6 ++++++ lib/ain-ocean/src/api/prices.rs | 2 ++ lib/ain-ocean/src/api/tokens.rs | 3 ++- lib/ain-ocean/src/api/transactions.rs | 3 +++ lib/ain-ocean/src/model/governance.rs | 2 +- 8 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/ain-macros/src/lib.rs b/lib/ain-macros/src/lib.rs index 958c3a28c1..8e603d77d9 100644 --- a/lib/ain-macros/src/lib.rs +++ b/lib/ain-macros/src/lib.rs @@ -2,7 +2,10 @@ extern crate proc_macro; use proc_macro::TokenStream; use quote::quote; -use syn::{parse_macro_input, Data, DeriveInput, Fields, ItemFn, ReturnType, Type}; +use syn::{ + parse_macro_input, Data, DeriveInput, Fields, ItemFn, + ReturnType, Type, +}; #[proc_macro_attribute] pub fn ffi_fallible(_attr: TokenStream, item: TokenStream) -> TokenStream { diff --git a/lib/ain-ocean/src/api/address.rs b/lib/ain-ocean/src/api/address.rs index d80bd5dd6f..6e98e80c46 100644 --- a/lib/ain-ocean/src/api/address.rs +++ b/lib/ain-ocean/src/api/address.rs @@ -41,6 +41,7 @@ struct History { txno: u32, } +#[skip_serializing_none] #[derive(Debug, Serialize)] struct AddressHistory { owner: String, @@ -426,6 +427,7 @@ pub struct ScriptUnspentScriptResponse { pub hex: String, } +#[skip_serializing_none] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct ScriptUnspentVoutResponse { diff --git a/lib/ain-ocean/src/api/governance.rs b/lib/ain-ocean/src/api/governance.rs index 0529b69c8f..071866ad38 100644 --- a/lib/ain-ocean/src/api/governance.rs +++ b/lib/ain-ocean/src/api/governance.rs @@ -5,6 +5,7 @@ use axum::{routing::get, Extension, Router}; use bitcoin::Txid; use defichain_rpc::{json::governance::*, GovernanceRPC}; use serde::Deserialize; +use serde_with::skip_serializing_none; use super::{ path::Path, @@ -14,6 +15,7 @@ use super::{ }; use crate::{error::ApiError, model::ApiProposalInfo, Result}; +#[skip_serializing_none] #[derive(Deserialize, Default)] pub struct GovernanceQuery { #[serde(flatten)] diff --git a/lib/ain-ocean/src/api/loan.rs b/lib/ain-ocean/src/api/loan.rs index e58281bac7..6acdb898ee 100644 --- a/lib/ain-ocean/src/api/loan.rs +++ b/lib/ain-ocean/src/api/loan.rs @@ -18,6 +18,7 @@ use defichain_rpc::{ use futures::future::try_join_all; use log::trace; use serde::{Serialize, Serializer}; +use serde_with::skip_serializing_none; use snafu::OptionExt; use super::{ @@ -95,6 +96,7 @@ async fn get_scheme( Ok(Response::new(scheme.into())) } +#[skip_serializing_none] #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct CollateralToken { @@ -219,6 +221,7 @@ async fn get_collateral_token( ))) } +#[skip_serializing_none] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct LoanToken { @@ -571,6 +574,7 @@ pub struct VaultLiquidatedResponse { pub batches: Vec, } +#[skip_serializing_none] #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct HighestBidResponse { @@ -578,6 +582,7 @@ pub struct HighestBidResponse { pub amount: Option, } +#[skip_serializing_none] #[derive(Serialize, Debug)] #[serde(rename_all = "camelCase")] pub struct VaultLiquidatedBatchResponse { @@ -588,6 +593,7 @@ pub struct VaultLiquidatedBatchResponse { froms: Vec, } +#[skip_serializing_none] #[derive(Serialize, Debug, Clone)] #[serde(rename_all = "camelCase")] pub struct VaultTokenAmountResponse { diff --git a/lib/ain-ocean/src/api/prices.rs b/lib/ain-ocean/src/api/prices.rs index 43340419af..8b17022992 100644 --- a/lib/ain-ocean/src/api/prices.rs +++ b/lib/ain-ocean/src/api/prices.rs @@ -11,6 +11,7 @@ use bitcoin::{hashes::Hash, Txid}; use indexmap::IndexSet; use rust_decimal::{prelude::ToPrimitive, Decimal}; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; use snafu::OptionExt; use super::{ @@ -352,6 +353,7 @@ async fn get_feed_with_interval( })) } +#[skip_serializing_none] #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PriceOracleResponse { diff --git a/lib/ain-ocean/src/api/tokens.rs b/lib/ain-ocean/src/api/tokens.rs index 2237888b19..b0bc76162d 100644 --- a/lib/ain-ocean/src/api/tokens.rs +++ b/lib/ain-ocean/src/api/tokens.rs @@ -8,7 +8,7 @@ use defichain_rpc::{ }; use serde::Serialize; use serde_json::json; -use serde_with::{serde_as, DisplayFromStr}; +use serde_with::{serde_as, skip_serializing_none, DisplayFromStr}; use super::{ common::parse_display_symbol, @@ -28,6 +28,7 @@ pub struct TxHeight { height: i64, } +#[skip_serializing_none] #[serde_as] #[derive(Serialize, Debug, Clone, Default)] #[serde(rename_all = "camelCase")] diff --git a/lib/ain-ocean/src/api/transactions.rs b/lib/ain-ocean/src/api/transactions.rs index 5538327a27..26b65738bc 100644 --- a/lib/ain-ocean/src/api/transactions.rs +++ b/lib/ain-ocean/src/api/transactions.rs @@ -4,6 +4,7 @@ use ain_macros::ocean_endpoint; use axum::{extract::Query, routing::get, Extension, Router}; use bitcoin::Txid; use serde::{Deserialize, Serialize}; +use serde_with::skip_serializing_none; use super::{path::Path, query::PaginationQuery, response::ApiPagedResponse, AppContext}; use crate::{ @@ -33,6 +34,7 @@ async fn get_transaction( Ok(Response::new(transactions)) } +#[skip_serializing_none] #[derive(Debug, Serialize)] struct TransactionVinResponse { pub id: String, @@ -96,6 +98,7 @@ async fn get_vins( })) } +#[skip_serializing_none] #[derive(Debug, Serialize)] struct TransactionVoutResponse { pub id: String, diff --git a/lib/ain-ocean/src/model/governance.rs b/lib/ain-ocean/src/model/governance.rs index 03a2d70b7f..5192e3081f 100644 --- a/lib/ain-ocean/src/model/governance.rs +++ b/lib/ain-ocean/src/model/governance.rs @@ -25,11 +25,11 @@ pub struct ApiProposalInfo { pub vote_info: ApiProposalVoteInfo, } +#[skip_serializing_none] #[derive(Debug, Serialize)] #[serde(rename_all = "camelCase")] pub struct ApiProposalConfidenceVote { pub amount: Option, - #[serde(skip_serializing_if = "Option::is_none")] pub payout_address: Option, }