Skip to content

Commit

Permalink
fixed amount param serializing
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarajm22 committed Jul 4, 2024
1 parent dc4d4a5 commit efed74b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/ain-ocean/src/api/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn list_gov_proposals(
r#type: query.r#type,
cycle: query.cycle,
};
let mut proposals = ctx.client.list_gov_proposals(Some(opts)).await?;
let proposals = ctx.client.list_gov_proposals(Some(opts)).await?;
let mut proposals_with_string_amount: Vec<ApiProposalInfo> =
proposals.into_iter().map(ApiProposalInfo::from).collect();
// proposals.sort_by(|a, b| a.creation_height.cmp(&b.creation_height));
Expand Down
21 changes: 18 additions & 3 deletions lib/ain-ocean/src/model/governance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use bitcoin::Txid;
use defichain_rpc::json::governance::{ProposalInfo, ProposalStatus, ProposalType};
use rust_decimal::Decimal;
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Serialize, Serializer};
use serde_with::skip_serializing_none;

#[skip_serializing_none]
Expand All @@ -14,6 +12,10 @@ pub struct ApiProposalInfo {
pub context_hash: String,
pub r#type: ProposalType,
pub status: ProposalStatus,
#[serde(
serialize_with = "serialize_amount",
skip_serializing_if = "should_skip"
)]
pub amount: Option<String>,
pub current_cycle: u64,
pub total_cycles: u64,
Expand Down Expand Up @@ -72,3 +74,16 @@ impl From<ProposalInfo> for ApiProposalInfo {
}
}
}
fn serialize_amount<S>(amount: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
match amount {
Some(value) => serializer.serialize_some(value),
None => serializer.serialize_some(&serde_json::Value::String("undefined".to_string())),
}
}

fn should_skip<T>(_option: &Option<T>) -> bool {
false
}

0 comments on commit efed74b

Please sign in to comment.