diff --git a/sdk/src/types/block/output/feature/native_token.rs b/sdk/src/types/block/output/feature/native_token.rs index 5a79299d43..fe00abd786 100644 --- a/sdk/src/types/block/output/feature/native_token.rs +++ b/sdk/src/types/block/output/feature/native_token.rs @@ -6,7 +6,6 @@ use derive_more::{Deref, From}; use crate::types::block::output::{NativeToken, StorageScore}; #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deref, From, packable::Packable)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct NativeTokenFeature(NativeToken); impl NativeTokenFeature { @@ -25,3 +24,40 @@ impl NativeTokenFeature { } impl StorageScore for NativeTokenFeature {} + +#[cfg(feature = "serde")] +mod dto { + use primitive_types::U256; + use serde::{Deserialize, Serialize}; + + use super::*; + use crate::types::block::{output::TokenId, Error}; + + #[derive(Serialize, Deserialize)] + struct NativeTokenFeatureDto { + #[serde(rename = "type")] + kind: u8, + token_id: TokenId, + amount: U256, + } + + impl From<&NativeTokenFeature> for NativeTokenFeatureDto { + fn from(value: &NativeTokenFeature) -> Self { + Self { + kind: NativeTokenFeature::KIND, + token_id: value.token_id().clone(), + amount: value.amount(), + } + } + } + + impl TryFrom for NativeTokenFeature { + type Error = Error; + + fn try_from(value: NativeTokenFeatureDto) -> Result { + Ok(Self::new(NativeToken::new(value.token_id, value.amount)?)) + } + } + + crate::impl_serde_typed_dto!(NativeTokenFeature, NativeTokenFeatureDto, "native token feature"); +}