diff --git a/Cargo.lock b/Cargo.lock index d02070e0610..f0f629d4d4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3029,6 +3029,7 @@ dependencies = [ "num_enum 0.7.0", "serde", "serde_json", + "serde_with", "tempfile", "thiserror", ] diff --git a/massa-client/src/cmds.rs b/massa-client/src/cmds.rs index d2891dc1398..89e7aa5b8f0 100644 --- a/massa-client/src/cmds.rs +++ b/massa-client/src/cmds.rs @@ -1127,7 +1127,7 @@ impl Command { } } Command::read_only_execute_smart_contract => { - if parameters.len() < 2 || parameters.len() > 4 { + if parameters.len() < 2 || parameters.len() > 5 { bail!("wrong number of parameters"); } @@ -1165,7 +1165,7 @@ impl Command { } } Command::read_only_call => { - if parameters.len() < 4 || parameters.len() > 6 { + if parameters.len() < 4 || parameters.len() > 8 { bail!("wrong number of parameters"); } diff --git a/massa-ledger-exports/Cargo.toml b/massa-ledger-exports/Cargo.toml index 2713b45dd6c..874b516aff2 100644 --- a/massa-ledger-exports/Cargo.toml +++ b/massa-ledger-exports/Cargo.toml @@ -11,6 +11,7 @@ test-exports = ["tempfile", "massa_models/test-exports"] displaydoc = {workspace = true} serde = {workspace = true, "features" = ["derive"]} serde_json = {workspace = true} # BOM UPGRADE Revert to "1.0" if problem +serde_with = { workspace = true } tempfile = {workspace = true, "optional" = true} # BOM UPGRADE Revert to {"version": "3.3", "optional": true} if problem thiserror = {workspace = true} nom = {workspace = true} @@ -21,4 +22,4 @@ massa_serialization = {workspace = true} massa_db_exports = {workspace = true} [dev-dependencies] -massa_hash = {workspace = true} \ No newline at end of file +massa_hash = {workspace = true} diff --git a/massa-ledger-exports/src/ledger_changes.rs b/massa-ledger-exports/src/ledger_changes.rs index 3764cf429f2..02551f0b096 100644 --- a/massa-ledger-exports/src/ledger_changes.rs +++ b/massa-ledger-exports/src/ledger_changes.rs @@ -20,11 +20,13 @@ use nom::error::{context, ContextError, ParseError}; use nom::multi::length_count; use nom::sequence::tuple; use nom::{IResult, Parser}; -use serde::{ser::SerializeSeq, Deserialize, Serialize}; +use serde::{Deserialize, Serialize}; +use serde_with::serde_as; use std::collections::{hash_map, BTreeMap}; use std::ops::Bound::Included; /// represents an update to one or more fields of a `LedgerEntry` +#[serde_as] #[derive(Default, Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub struct LedgerEntryUpdate { /// change the balance @@ -32,26 +34,10 @@ pub struct LedgerEntryUpdate { /// change the executable bytecode pub bytecode: SetOrKeep, /// change datastore entries - #[serde(serialize_with = "as_array")] + #[serde_as(as = "Vec<(_, _)>")] pub datastore: BTreeMap, SetOrDelete>>, } -// Serializer for `datastore` field of `LedgerEntryUpdate` -fn as_array( - datastore: &BTreeMap, SetOrDelete>>, - serializer: S, -) -> Result -where - S: serde::Serializer, -{ - let mut seq = serializer.serialize_seq(Some(datastore.len()))?; - for (key, value) in datastore { - seq.serialize_element(&(&key, &value))?; - } - - seq.end() -} - /// Serializer for `datastore` field of `LedgerEntryUpdate` pub struct DatastoreUpdateSerializer { u64_serializer: U64VarIntSerializer,