Skip to content

Commit

Permalink
Use skip_serializing_none
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo committed Oct 2, 2024
1 parent 50a50e8 commit 68e8f8a
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/ain-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions lib/ain-ocean/src/api/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct History {
txno: u32,
}

#[skip_serializing_none]
#[derive(Debug, Serialize)]
struct AddressHistory {
owner: String,
Expand Down Expand Up @@ -426,6 +427,7 @@ pub struct ScriptUnspentScriptResponse {
pub hex: String,
}

#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptUnspentVoutResponse {
Expand Down
2 changes: 2 additions & 0 deletions lib/ain-ocean/src/api/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +15,7 @@ use super::{
};
use crate::{error::ApiError, model::ApiProposalInfo, Result};

#[skip_serializing_none]
#[derive(Deserialize, Default)]
pub struct GovernanceQuery {
#[serde(flatten)]
Expand Down
6 changes: 6 additions & 0 deletions lib/ain-ocean/src/api/loan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -219,6 +221,7 @@ async fn get_collateral_token(
)))
}

#[skip_serializing_none]
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct LoanToken {
Expand Down Expand Up @@ -571,13 +574,15 @@ pub struct VaultLiquidatedResponse {
pub batches: Vec<VaultLiquidatedBatchResponse>,
}

#[skip_serializing_none]
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct HighestBidResponse {
pub owner: String,
pub amount: Option<VaultTokenAmountResponse>,
}

#[skip_serializing_none]
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct VaultLiquidatedBatchResponse {
Expand All @@ -588,6 +593,7 @@ pub struct VaultLiquidatedBatchResponse {
froms: Vec<String>,
}

#[skip_serializing_none]
#[derive(Serialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct VaultTokenAmountResponse {
Expand Down
2 changes: 2 additions & 0 deletions lib/ain-ocean/src/api/prices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -352,6 +353,7 @@ async fn get_feed_with_interval(
}))
}

#[skip_serializing_none]
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PriceOracleResponse {
Expand Down
3 changes: 2 additions & 1 deletion lib/ain-ocean/src/api/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,6 +28,7 @@ pub struct TxHeight {
height: i64,
}

#[skip_serializing_none]
#[serde_as]
#[derive(Serialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
Expand Down
3 changes: 3 additions & 0 deletions lib/ain-ocean/src/api/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -33,6 +34,7 @@ async fn get_transaction(
Ok(Response::new(transactions))
}

#[skip_serializing_none]
#[derive(Debug, Serialize)]
struct TransactionVinResponse {
pub id: String,
Expand Down Expand Up @@ -96,6 +98,7 @@ async fn get_vins(
}))
}

#[skip_serializing_none]
#[derive(Debug, Serialize)]
struct TransactionVoutResponse {
pub id: String,
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/model/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payout_address: Option<String>,
}

Expand Down

0 comments on commit 68e8f8a

Please sign in to comment.