From 93427ffa01854856bb1e23f3fc7bc9fbbb5f9a87 Mon Sep 17 00:00:00 2001 From: niks3089 Date: Mon, 19 Feb 2024 14:28:19 +0530 Subject: [PATCH] das-api: Include mint-extensions in the response --- digital_asset_types/src/dapi/common/asset.rs | 28 ++++++++++++++++++++ digital_asset_types/src/rpc/asset.rs | 3 +++ 2 files changed, 31 insertions(+) diff --git a/digital_asset_types/src/dapi/common/asset.rs b/digital_asset_types/src/dapi/common/asset.rs index 655eefdc4..9fd9a3881 100644 --- a/digital_asset_types/src/dapi/common/asset.rs +++ b/digital_asset_types/src/dapi/common/asset.rs @@ -16,6 +16,7 @@ use log::warn; use mime_guess::Mime; use sea_orm::DbErr; +use serde_json::Map; use serde_json::Value; use std::cmp::Ordering; use std::collections::HashMap; @@ -47,6 +48,30 @@ pub fn file_from_str(str: String) -> File { } } +fn filter_non_null_fields(value: Option<&Value>) -> Option { + match value { + Some(Value::Null) => None, + Some(Value::Object(map)) => { + if map.values().all(|v| matches!(v, Value::Null)) { + None + } else { + let filtered_map: Map = map + .into_iter() + .filter(|(_k, v)| !matches!(v, Value::Null)) + .map(|(k, v)| (k.clone(), v.clone())) + .collect(); + + if filtered_map.is_empty() { + None + } else { + Some(Value::Object(filtered_map)) + } + } + } + _ => value.cloned(), + } +} + pub fn build_asset_response( assets: Vec, limit: u64, @@ -368,6 +393,8 @@ pub fn asset_to_rpc(asset: FullAsset, options: &Options) -> Result Result, pub mutable: bool, pub burnt: bool, + #[serde(skip_serializing_if = "Option::is_none")] + pub mint_extensions: Option, }