Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make output dtos private #1712

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn verify_unlock_conditions_packable<const VERIFY: bool>(
}

#[cfg(feature = "serde")]
pub(crate) mod dto {
pub mod dto {
DaughterOfMars marked this conversation as resolved.
Show resolved Hide resolved
use alloc::vec::Vec;

use serde::{Deserialize, Serialize};
Expand Down
52 changes: 1 addition & 51 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl OutputWithMetadata {

/// A generic output that can represent different types defining the deposit of funds.
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, From, Packable)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(untagged))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(untagged))]
#[packable(unpack_error = Error)]
#[packable(unpack_visitor = ProtocolParameters)]
#[packable(tag_type = u8, with_error = Error::InvalidOutputKind)]
Expand Down Expand Up @@ -435,53 +435,3 @@ pub trait MinimumOutputAmount: StorageScore {
self.storage_score(params) * params.storage_cost()
}
}

#[cfg(feature = "serde")]
pub mod dto {
use alloc::format;

use serde::Deserialize;
use serde_json::Value;

use super::*;

impl<'de> Deserialize<'de> for Output {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let value = Value::deserialize(d)?;
Ok(
match value
.get("type")
.and_then(Value::as_u64)
.ok_or_else(|| serde::de::Error::custom("invalid output type"))? as u8
{
BasicOutput::KIND => Self::Basic(
BasicOutput::deserialize(value)
.map_err(|e| serde::de::Error::custom(format!("cannot deserialize basic output: {e}")))?,
),
AccountOutput::KIND => Self::Account(
AccountOutput::deserialize(value)
.map_err(|e| serde::de::Error::custom(format!("cannot deserialize account output: {e}")))?,
),
AnchorOutput::KIND => Self::Anchor(
AnchorOutput::deserialize(value)
.map_err(|e| serde::de::Error::custom(format!("cannot deserialize anchor output: {e}")))?,
),
FoundryOutput::KIND => Self::Foundry(
FoundryOutput::deserialize(value)
.map_err(|e| serde::de::Error::custom(format!("cannot deserialize foundry output: {e}")))?,
),
NftOutput::KIND => Self::Nft(
NftOutput::deserialize(value)
.map_err(|e| serde::de::Error::custom(format!("cannot deserialize NFT output: {e}")))?,
),
DelegationOutput::KIND => {
Self::Delegation(DelegationOutput::deserialize(value).map_err(|e| {
serde::de::Error::custom(format!("cannot deserialize delegation output: {e}"))
})?)
}
_ => return Err(serde::de::Error::custom("invalid output type")),
},
)
}
}
}
Loading