diff --git a/sdk/src/types/block/mana/allotment.rs b/sdk/src/types/block/mana/allotment.rs index 20a771148b..5d14393a2c 100644 --- a/sdk/src/types/block/mana/allotment.rs +++ b/sdk/src/types/block/mana/allotment.rs @@ -18,16 +18,17 @@ use crate::types::block::{ /// in the form of Block Issuance Credits to the account. #[derive(Copy, Clone, Debug, Eq, PartialEq, Packable)] #[packable(unpack_error = Error)] -#[packable(unpack_visitor = ProtocolParameters)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ManaAllotment { pub(crate) account_id: AccountId, #[packable(verify_with = verify_mana)] + #[serde(with = "crate::utils::serde::string")] pub(crate) mana: u64, } impl ManaAllotment { - pub fn new(account_id: AccountId, mana: u64, protocol_params: &ProtocolParameters) -> Result { - verify_mana::(&mana, protocol_params)?; + pub fn new(account_id: AccountId, mana: u64) -> Result { + verify_mana::(&mana)?; Ok(Self { account_id, mana }) } @@ -59,8 +60,8 @@ impl WorkScore for ManaAllotment { } } -fn verify_mana(mana: &u64, params: &ProtocolParameters) -> Result<(), Error> { - if VERIFY && *mana > params.mana_parameters().max_mana() { +fn verify_mana(mana: &u64) -> Result<(), Error> { + if VERIFY && *mana == 0 { return Err(Error::InvalidManaValue(*mana)); } @@ -187,46 +188,3 @@ impl IntoIterator for ManaAllotments { Vec::from(Into::>::into(self.0)).into_iter() } } - -#[cfg(feature = "serde")] -pub(super) mod dto { - use serde::{Deserialize, Serialize}; - - use super::*; - use crate::{types::TryFromDto, utils::serde::string}; - - #[derive(Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] - #[serde(rename_all = "camelCase")] - pub struct ManaAllotmentDto { - pub account_id: AccountId, - #[serde(with = "string")] - pub mana: u64, - } - - impl From<&ManaAllotment> for ManaAllotmentDto { - fn from(value: &ManaAllotment) -> Self { - Self { - account_id: value.account_id, - mana: value.mana, - } - } - } - - impl TryFromDto for ManaAllotment { - type Error = Error; - - fn try_from_dto_with_params_inner( - dto: ManaAllotmentDto, - params: Option<&ProtocolParameters>, - ) -> Result { - Ok(if let Some(params) = params { - Self::new(dto.account_id, dto.mana, params)? - } else { - Self { - account_id: dto.account_id, - mana: dto.mana, - } - }) - } - } -} diff --git a/sdk/src/types/block/mana/mod.rs b/sdk/src/types/block/mana/mod.rs index ffda2603a9..a4f22ba61a 100644 --- a/sdk/src/types/block/mana/mod.rs +++ b/sdk/src/types/block/mana/mod.rs @@ -5,7 +5,7 @@ mod allotment; mod parameters; mod rewards; -pub(crate) use self::allotment::{dto::ManaAllotmentDto, verify_mana_allotments_sum, ManaAllotmentCount}; +pub(crate) use self::allotment::{verify_mana_allotments_sum, ManaAllotmentCount}; pub use self::{ allotment::{ManaAllotment, ManaAllotments}, parameters::ManaParameters, diff --git a/sdk/src/types/block/payload/signed_transaction/transaction.rs b/sdk/src/types/block/payload/signed_transaction/transaction.rs index a6116b09bc..e7ed802126 100644 --- a/sdk/src/types/block/payload/signed_transaction/transaction.rs +++ b/sdk/src/types/block/payload/signed_transaction/transaction.rs @@ -542,7 +542,7 @@ pub(crate) mod dto { use super::*; use crate::types::{ - block::{mana::ManaAllotmentDto, payload::dto::PayloadDto, Error}, + block::{payload::dto::PayloadDto, Error}, TryFromDto, }; @@ -555,7 +555,7 @@ pub(crate) mod dto { pub context_inputs: Vec, pub inputs: Vec, #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub allotments: Vec, + pub allotments: Vec, #[serde(default, skip_serializing_if = "TransactionCapabilities::is_none")] pub capabilities: TransactionCapabilities, #[serde(default, skip_serializing_if = "Option::is_none")] @@ -570,7 +570,7 @@ pub(crate) mod dto { creation_slot: value.creation_slot(), context_inputs: value.context_inputs().to_vec(), inputs: value.inputs().to_vec(), - allotments: value.allotments().iter().map(Into::into).collect(), + allotments: value.allotments().to_vec(), capabilities: value.capabilities().clone(), payload: match value.payload() { Some(p @ Payload::TaggedData(_)) => Some(p.into()), @@ -593,18 +593,13 @@ pub(crate) mod dto { .network_id .parse::() .map_err(|_| Error::InvalidField("network_id"))?; - let mana_allotments = dto - .allotments - .into_iter() - .map(|o| ManaAllotment::try_from_dto_with_params_inner(o, params)) - .collect::, Error>>()?; let outputs = dto.outputs; let mut builder = Self::builder(network_id) .with_creation_slot(dto.creation_slot) .with_context_inputs(dto.context_inputs) .with_inputs(dto.inputs) - .with_mana_allotments(mana_allotments) + .with_mana_allotments(dto.allotments) .with_capabilities(dto.capabilities) .with_outputs(outputs); diff --git a/sdk/src/types/block/rand/mana.rs b/sdk/src/types/block/rand/mana.rs index c8c32df3a5..2476a75cdf 100644 --- a/sdk/src/types/block/rand/mana.rs +++ b/sdk/src/types/block/rand/mana.rs @@ -12,7 +12,6 @@ pub fn rand_mana_allotment(params: &ProtocolParameters) -> ManaAllotment { ManaAllotment::new( rand_account_id(), rand_number_range(0..params.mana_parameters().max_mana()), - params, ) .unwrap() }