From 54080262ef27957594fb9a27c460179ea65eed62 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 31 May 2024 15:51:57 +0200 Subject: [PATCH 1/9] using nanomassa in Amount::from_str --- massa-models/src/amount.rs | 71 +++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 24 deletions(-) diff --git a/massa-models/src/amount.rs b/massa-models/src/amount.rs index afd347f020e..b0553698c1f 100644 --- a/massa-models/src/amount.rs +++ b/massa-models/src/amount.rs @@ -35,14 +35,6 @@ impl Amount { Self(0) } - /// Convert to decimal - fn to_decimal(self) -> Decimal { - Decimal::from_u64(self.0) - .unwrap() // will never panic - .checked_div(AMOUNT_DECIMAL_FACTOR.into()) // will never panic - .unwrap() // will never panic - } - /// Create an Amount from a Decimal fn from_decimal(dec: Decimal) -> Result { let res = dec @@ -74,7 +66,7 @@ impl Amount { /// ``` /// # use massa_models::amount::Amount; /// # use std::str::FromStr; - /// let amount_1: Amount = Amount::from_str("0.042").unwrap(); + /// let amount_1: Amount = Amount::from_str("42000000").unwrap(); /// let amount_2: Amount = Amount::const_init(42, 3); /// assert_eq!(amount_1, amount_2); /// let amount_1: Amount = Amount::from_str("1000").unwrap(); @@ -99,7 +91,7 @@ impl Amount { /// # use massa_models::amount::Amount; /// # use massa_models::amount::AMOUNT_DECIMAL_SCALE; /// # use std::str::FromStr; - /// let amount = Amount::from_str("0.123456789").unwrap(); + /// let amount = Amount::from_str("123456789").unwrap(); /// let (mantissa, scale) = amount.to_mantissa_scale(); /// assert_eq!(mantissa, 123456789); /// assert_eq!(scale, AMOUNT_DECIMAL_SCALE); @@ -113,7 +105,7 @@ impl Amount { /// # use massa_models::amount::Amount; /// # use std::str::FromStr; /// let a = Amount::from_mantissa_scale(123, 2).unwrap(); - /// assert_eq!(a.to_string(), "1.23"); + /// assert_eq!(a.to_string(), "123"); /// let a = Amount::from_mantissa_scale(123, 100); /// assert!(a.is_err()); /// ``` @@ -133,7 +125,7 @@ impl Amount { /// constructs an `Amount` from the underlying raw `u64` representation /// Warning: do not use this unless you know what you are doing /// because the raw value does not take the `AMOUNT_DECIMAL_FACTOR` into account - /// In most cases, you should be using `Amount::from_str("11.23")` + /// In most cases, you should be using `Amount::from_str("11230000000")` pub const fn from_raw(raw: u64) -> Self { Self(raw) } @@ -267,7 +259,7 @@ impl Amount { /// ``` impl fmt::Display for Amount { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.to_decimal()) + write!(f, "{}", self.to_raw()) } } @@ -295,9 +287,13 @@ impl FromStr for Amount { type Err = ModelsError; fn from_str(str_amount: &str) -> Result { - let res = Decimal::from_str_exact(str_amount) - .map_err(|err| ModelsError::AmountParseError(err.to_string()))?; - Amount::from_decimal(res) + // let res = Decimal::from_str_exact(str_amount) + // .map_err(|err| ModelsError::AmountParseError(err.to_string()))?; + + let amount = str_amount + .parse::() + .map_err(|_| ModelsError::AmountParseError("invalid integer".to_string()))?; + Ok(Amount(amount)) } } @@ -396,12 +392,41 @@ impl Deserializer for AmountDeserializer { } } +// impl<'de> serde::Deserialize<'de> for Amount { +// fn deserialize(deserializer: D) -> Result +// where +// D: serde::de::Deserializer<'de>, +// { +// deserializer.deserialize_str(AmountVisitor) +// } +// } + +// struct AmountVisitor; + +// impl<'de> serde::de::Visitor<'de> for AmountVisitor { +// type Value = Amount; + +// fn visit_str(self, value: &str) -> Result +// where +// E: serde::de::Error, +// { +// Amount::from_str(value).map_err(|_| E::invalid_value(Unexpected::Str(value), &self)) +// } + +// fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { +// write!( +// formatter, +// "an Amount type representing a fixed-point currency amount" +// ) +// } +// } + impl<'de> serde::Deserialize<'de> for Amount { fn deserialize(deserializer: D) -> Result where D: serde::de::Deserializer<'de>, { - deserializer.deserialize_str(AmountVisitor) + deserializer.deserialize_u64(AmountVisitor) } } @@ -410,18 +435,15 @@ struct AmountVisitor; impl<'de> serde::de::Visitor<'de> for AmountVisitor { type Value = Amount; - fn visit_str(self, value: &str) -> Result + fn visit_u64(self, value: u64) -> Result where E: serde::de::Error, { - Amount::from_str(value).map_err(|_| E::invalid_value(Unexpected::Str(value), &self)) + Ok(Amount::from_raw(value)) } fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { - write!( - formatter, - "an Amount type representing a fixed-point currency amount" - ) + write!(formatter, "a u64 representing an Amount in nanoMassa") } } @@ -430,6 +452,7 @@ impl serde::Serialize for Amount { where S: serde::Serializer, { - serializer.serialize_str(&self.to_string()) + // let a = format!("{}", self.to_raw()); + serializer.serialize_u64(self.to_raw()) } } From 5df5d994a28f8cca58bf692203b9305fea9c17a3 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 31 May 2024 17:26:06 +0200 Subject: [PATCH 2/9] replace lot of amount::from_str by amount::from_raw --- massa-api-exports/src/operation.rs | 2 +- massa-api/src/tests/public.rs | 40 +++++++++++++++++-- massa-async-pool/src/message.rs | 16 ++++---- massa-async-pool/src/pool.rs | 4 +- .../src/tests/scenarios_mandatories.rs | 16 ++++---- .../src/tests/block_scenarios.rs | 2 +- massa-final-state/src/test_exports/mock.rs | 2 +- massa-grpc/src/tests/stream.rs | 2 +- massa-models/src/amount.rs | 20 +++++----- massa-models/src/operation.rs | 10 ++--- massa-pos-exports/src/deferred_credits.rs | 2 +- massa-pos-exports/src/pos_changes.rs | 2 +- massa-pos-exports/src/pos_final_state.rs | 6 +-- 13 files changed, 77 insertions(+), 47 deletions(-) diff --git a/massa-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs index b4caadf85e3..0d8ad740cf7 100644 --- a/massa-api-exports/src/operation.rs +++ b/massa-api-exports/src/operation.rs @@ -78,7 +78,7 @@ mod tests { fn test_execute_sc_with_datastore() { let expected_op = OperationType::ExecuteSC { max_gas: 123, - max_coins: Amount::from_str("5000000").unwrap(), + max_coins: Amount::from_raw(5000000), data: vec![23u8, 123u8, 44u8], datastore: BTreeMap::from([ (vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]), diff --git a/massa-api/src/tests/public.rs b/massa-api/src/tests/public.rs index e711e04fed7..61ee813775b 100644 --- a/massa-api/src/tests/public.rs +++ b/massa-api/src/tests/public.rs @@ -454,8 +454,8 @@ async fn send_operations_low_fee() { let addr: SocketAddr = "[::]:5049".parse().unwrap(); let (mut api_public, mut config) = start_public_api(addr); - config.minimal_fees = Amount::from_str("0.01").unwrap(); - api_public.0.api_settings.minimal_fees = Amount::from_str("0.01").unwrap(); + config.minimal_fees = Amount::from_str("10000000").unwrap(); + api_public.0.api_settings.minimal_fees = Amount::from_str("10000000").unwrap(); let mut pool_ctrl = MockPoolController::new(); pool_ctrl.expect_clone_box().returning(|| { @@ -559,6 +559,7 @@ async fn send_operations() { serialized_content: operation.serialized_data, }; + dbg!(serde_json::to_string(&input).unwrap()); let response: Vec = client .request("send_operations", rpc_params![vec![input]]) .await @@ -762,6 +763,39 @@ async fn execute_read_only_bytecode() { assert!(response.is_err()); api_public_handle.stop().await; } +#[test] +fn test_amount() { + // decimal now return error + assert!(Amount::from_str("15463.123").is_err()); + assert!(Amount::from_str("100.0").is_err()); + + // from str now uses nanoMassa + let amount = Amount::from_str("100").unwrap(); // nanoMassa + + // print no longer display massa unit as decimal + // print display nanoMassa + println!("{}", amount); // Should print 100 (nanoMassa) + + // to_raw return nanoMassa as u64 like before + assert_eq!(amount.to_raw(), 000000000100); + // to_string return nanoMassa as string + assert_eq!(amount.to_string(), "100".to_string()); + + let serialized_serde = serde_json::to_string(&amount).unwrap(); + assert_eq!(serialized_serde, "100".to_string()); + + // serde from_str + let deserialized_serde: Amount = serde_json::from_str(&serialized_serde).unwrap(); + // amount from_str + let deserialized_amount: Amount = Amount::from_str(&serialized_serde).unwrap(); + + assert_eq!(deserialized_serde.to_string(), "100"); + assert_eq!(deserialized_serde.to_raw(), 000000000100); + + assert_eq!(deserialized_amount.to_string(), "100"); + assert_eq!(deserialized_amount.to_raw(), 000000000100); + assert_eq!(deserialized_serde, deserialized_amount); +} #[tokio::test] async fn execute_read_only_call() { @@ -821,7 +855,7 @@ async fn execute_read_only_call() { target_function: "hello".to_string(), parameter: vec![], caller_address: None, - fee: None, + fee: Some(Amount::from_str("10000000").unwrap()), coins: None, }]]; let response: Vec = client diff --git a/massa-async-pool/src/message.rs b/massa-async-pool/src/message.rs index 9b5379426ea..503816f6ace 100644 --- a/massa-async-pool/src/message.rs +++ b/massa-async-pool/src/message.rs @@ -1039,8 +1039,8 @@ mod tests { .unwrap(), function: String::from(""), max_gas: 0, - fee: Amount::from_str("0").unwrap(), - coins: Amount::from_str("0").unwrap(), + fee: Amount::zero(), + coins: Amount::zero(), validity_start: Slot::new(0, 0), validity_end: Slot::new(0, 0), function_params: vec![], @@ -1082,8 +1082,8 @@ mod tests { .unwrap(), function: String::from(""), max_gas: 0, - fee: Amount::from_str("0").unwrap(), - coins: Amount::from_str("0").unwrap(), + fee: Amount::zero(), + coins: Amount::zero(), validity_start: Slot::new(0, 0), validity_end: Slot::new(0, 0), function_params: vec![], @@ -1162,8 +1162,8 @@ mod tests { .unwrap(), function: String::from(""), max_gas: 0, - fee: Amount::from_str("0").unwrap(), - coins: Amount::from_str("0").unwrap(), + fee: Amount::zero(), + coins: Amount::zero(), validity_start: Slot::new(0, 0), validity_end: Slot::new(0, 0), function_params: vec![], @@ -1315,8 +1315,8 @@ mod tests { .unwrap(), function: String::from(""), max_gas: 0, - fee: Amount::from_str("0").unwrap(), - coins: Amount::from_str("0").unwrap(), + fee: Amount::zero(), + coins: Amount::zero(), validity_start: Slot::new(0, 0), validity_end: Slot::new(0, 0), function_params: vec![], diff --git a/massa-async-pool/src/pool.rs b/massa-async-pool/src/pool.rs index 33e2f5592bc..6f9e22daa65 100644 --- a/massa-async-pool/src/pool.rs +++ b/massa-async-pool/src/pool.rs @@ -1074,8 +1074,8 @@ mod tests { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index c394fac4589..16fb4cd6519 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -413,8 +413,8 @@ fn test_nested_call_gas_usage() { let operation = ExecutionTestUniverse::create_call_sc_operation( &KeyPair::from_str(TEST_SK_2).unwrap(), 10000000, - Amount::from_str("0").unwrap(), - Amount::from_str("0").unwrap(), + Amount::zero(), + Amount::zero(), Address::from_str(&address).unwrap(), String::from("test"), address.as_bytes().to_vec(), @@ -516,7 +516,7 @@ fn test_get_call_coins() { let operation = ExecutionTestUniverse::create_call_sc_operation( &KeyPair::from_str(TEST_SK_2).unwrap(), 10000000, - Amount::from_str("0").unwrap(), + Amount::zero(), coins_sent, Address::from_str(&address).unwrap(), String::from("test"), @@ -681,7 +681,7 @@ fn send_and_receive_async_message() { SetUpdateOrDelete::Update(change_sc_update) => { assert_eq!( change_sc_update.balance, - SetOrKeep::Set(Amount::from_str("100.0000001").unwrap()) + SetOrKeep::Set(Amount::from_raw(100000000100)) ); } _ => panic!("wrong change type"), @@ -816,9 +816,7 @@ fn cancel_async_message() { assert_eq!( changes.ledger_changes.0.get(&sender_addr).unwrap(), &SetUpdateOrDelete::Update(LedgerEntryUpdate { - balance: massa_ledger_exports::SetOrKeep::Set( - Amount::from_str("100.670399899").unwrap() - ), + balance: massa_ledger_exports::SetOrKeep::Set(Amount::from_raw(100670399899)), bytecode: massa_ledger_exports::SetOrKeep::Keep, datastore: BTreeMap::new() }) @@ -841,7 +839,7 @@ fn cancel_async_message() { SetUpdateOrDelete::Update(change_sender_update) => { assert_eq!( change_sender_update.balance, - SetOrKeep::Set(Amount::from_str("100.0000001").unwrap()) + SetOrKeep::Set(Amount::from_raw(100000000100)) ); } _ => panic!("wrong change type"), @@ -993,7 +991,7 @@ fn local_execution() { ); assert_eq!(events[2].data, "one local execution completed"); let amount = Amount::from_raw(events[5].data.parse().unwrap()); - assert_eq!(Amount::from_str("89.6713").unwrap(), amount); + assert_eq!(Amount::from_raw(89671300000), amount); assert_eq!(events[5].context.call_stack.len(), 1); assert_eq!( events[1].context.call_stack.back().unwrap(), diff --git a/massa-factory-worker/src/tests/block_scenarios.rs b/massa-factory-worker/src/tests/block_scenarios.rs index d6fedf2a7ab..5863a4e525b 100644 --- a/massa-factory-worker/src/tests/block_scenarios.rs +++ b/massa-factory-worker/src/tests/block_scenarios.rs @@ -131,7 +131,7 @@ fn basic_creation_with_operation() { .returning(move |slot| { assert_eq!(*slot, Slot::new(1, 0)); let content = Operation { - fee: Amount::from_str("0.01").unwrap(), + fee: Amount::from_str("10000000").unwrap(), expire_period: 2, op: OperationType::RollBuy { roll_count: 1 }, }; diff --git a/massa-final-state/src/test_exports/mock.rs b/massa-final-state/src/test_exports/mock.rs index 74c3fb1b061..796903cdfad 100644 --- a/massa-final-state/src/test_exports/mock.rs +++ b/massa-final-state/src/test_exports/mock.rs @@ -155,7 +155,7 @@ pub fn get_initials() -> (NamedTempFile, HashMap) { ledger.insert( addr, LedgerEntry { - balance: Amount::from_str("300_000").unwrap(), + balance: Amount::from_raw(300000000000000), ..Default::default() }, ); diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 97935bbf2c5..b30b069d6b0 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -1235,7 +1235,7 @@ async fn new_slot_execution_outputs() { async fn send_operations_low_fee() { let addr: SocketAddr = "[::]:4000".parse().unwrap(); let mut public_server = grpc_public_service(&addr); - public_server.grpc_config.minimal_fees = Amount::from_str("0.01").unwrap(); + public_server.grpc_config.minimal_fees = Amount::from_raw(10000000); let mut pool_ctrl = Box::new(MockPoolController::new()); pool_ctrl.expect_clone_box().returning(|| { diff --git a/massa-models/src/amount.rs b/massa-models/src/amount.rs index b0553698c1f..e3a80a4dc33 100644 --- a/massa-models/src/amount.rs +++ b/massa-models/src/amount.rs @@ -254,8 +254,8 @@ impl Amount { /// ``` /// # use massa_models::amount::Amount; /// # use std::str::FromStr; -/// let value = Amount::from_str("11.111").unwrap(); -/// assert_eq!(format!("{}", value), "11.111") +/// let value = Amount::from_raw(11111); +/// assert_eq!(format!("{}", value), "11111") /// ``` impl fmt::Display for Amount { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -277,7 +277,8 @@ impl fmt::Debug for Amount { /// ``` /// # use massa_models::amount::Amount; /// # use std::str::FromStr; -/// assert!(Amount::from_str("11.1").is_ok()); +/// assert!(Amount::from_str("11").is_ok()); +/// assert!(Amount::from_str("11.1").is_err()); /// assert!(Amount::from_str("11.1111111111111111111111").is_err()); /// assert!(Amount::from_str("1111111111111111111111").is_err()); /// assert!(Amount::from_str("-11.1").is_err()); @@ -287,12 +288,9 @@ impl FromStr for Amount { type Err = ModelsError; fn from_str(str_amount: &str) -> Result { - // let res = Decimal::from_str_exact(str_amount) - // .map_err(|err| ModelsError::AmountParseError(err.to_string()))?; - - let amount = str_amount - .parse::() - .map_err(|_| ModelsError::AmountParseError("invalid integer".to_string()))?; + let amount = str_amount.parse::().map_err(|_| { + ModelsError::AmountParseError(format!("invalid integer : {}", str_amount)) + })?; Ok(Amount(amount)) } } @@ -326,7 +324,7 @@ impl Serializer for AmountSerializer { /// use std::str::FromStr; /// use std::ops::Bound::Included; /// - /// let amount = Amount::from_str("11.111").unwrap(); + /// let amount = Amount::from_str("11111").unwrap(); /// let serializer = AmountSerializer::new(); /// let mut serialized = vec![]; /// serializer.serialize(&amount, &mut serialized).unwrap(); @@ -371,7 +369,7 @@ impl Deserializer for AmountDeserializer { /// use std::str::FromStr; /// use std::ops::Bound::Included; /// - /// let amount = Amount::from_str("11.111").unwrap(); + /// let amount = Amount::from_raw(11111); /// let serializer = AmountSerializer::new(); /// let deserializer = AmountDeserializer::new(Included(Amount::MIN), Included(Amount::MAX)); /// let mut serialized = vec![]; diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index eaea9e9c2db..8296372d28c 100644 --- a/massa-models/src/operation.rs +++ b/massa-models/src/operation.rs @@ -1638,7 +1638,7 @@ mod tests { let op = OperationType::ExecuteSC { max_gas: 123, - max_coins: Amount::from_str("1.0").unwrap(), + max_coins: Amount::from_raw(1000000000), data: vec![23u8, 123u8, 44u8], datastore: BTreeMap::from([ (vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]), @@ -1720,7 +1720,7 @@ mod tests { let op = OperationType::CallSC { max_gas: 123, target_addr, - coins: Amount::from_str("456.789").unwrap(), + coins: Amount::from_raw(456789000000), target_func: "target function".to_string(), param: b"parameter".to_vec(), }; @@ -1832,7 +1832,7 @@ mod tests { fn test_executesc_serde() { let op = OperationType::ExecuteSC { max_gas: 123, - max_coins: Amount::from_str("1.0").unwrap(), + max_coins: Amount::from_raw(1000000000), data: vec![23u8, 123u8, 44u8], datastore: BTreeMap::from([ (vec![1, 2, 3], vec![4, 5, 6, 7, 8, 9]), @@ -1877,7 +1877,7 @@ mod tests { let op = OperationType::CallSC { max_gas: 123, target_addr, - coins: Amount::from_str("456.789").unwrap(), + coins: Amount::from_raw(456789000000), target_func: "target function".to_string(), param: b"parameter".to_vec(), }; @@ -1898,7 +1898,7 @@ mod tests { assert_eq!(res_type, op); let orig_operation = Operation { - fee: Amount::from_str("20").unwrap(), + fee: Amount::from_raw(20000000000), op, expire_period: 50, }; diff --git a/massa-pos-exports/src/deferred_credits.rs b/massa-pos-exports/src/deferred_credits.rs index 877c8faa240..edf2b2fdaba 100644 --- a/massa-pos-exports/src/deferred_credits.rs +++ b/massa-pos-exports/src/deferred_credits.rs @@ -340,7 +340,7 @@ mod test { Address::from_str("AU12nfJdBNotWffSEDDCS9mMXAxDbHbAVM9GW7pvVJoLxdCeeroX8").unwrap(); let mut def_credits = DeferredCredits::default(); - def_credits.insert(Slot::new(1, 0), addr1, Amount::from_str("0.0").unwrap()); + def_credits.insert(Slot::new(1, 0), addr1, Amount::zero()); def_credits.insert(Slot::new(1, 3), addr2, Amount::from_raw(u64::MAX)); let mut buf = Vec::new(); diff --git a/massa-pos-exports/src/pos_changes.rs b/massa-pos-exports/src/pos_changes.rs index 191fc87ad78..44e2442e4b5 100644 --- a/massa-pos-exports/src/pos_changes.rs +++ b/massa-pos-exports/src/pos_changes.rs @@ -232,7 +232,7 @@ mod test { }, ); let mut def_credits = DeferredCredits::default(); - def_credits.insert(Slot::new(1, 0), addr1, Amount::from_str("300.0").unwrap()); + def_credits.insert(Slot::new(1, 0), addr1, Amount::from_raw(300000000000)); let pos_changes = PoSChanges { roll_changes, diff --git a/massa-pos-exports/src/pos_final_state.rs b/massa-pos-exports/src/pos_final_state.rs index 7416159bb73..77c86c64df7 100644 --- a/massa-pos-exports/src/pos_final_state.rs +++ b/massa-pos-exports/src/pos_final_state.rs @@ -1723,10 +1723,10 @@ mod tests { let addr1 = Address::from_str("AU12pAcVUzsgUBJHaYSAtDKVTYnUT9NorBDjoDovMfAFTLFa16MNa").unwrap(); - let a_a1_s3 = Amount::from_str("5.01").unwrap(); + let a_a1_s3 = Amount::from_raw(5010000000); let addr2 = Address::from_str("AU1wN8rn4SkwYSTDF3dHFY4U28KtsqKL1NnEjDZhHnHEy6cEQm53").unwrap(); - let a_a2_s3 = Amount::from_str("2.01").unwrap(); + let a_a2_s3 = Amount::from_raw(2010000000); let expected_credits = vec![ ( Slot::new(3, 0), @@ -1736,7 +1736,7 @@ mod tests { ), ( Slot::new(4, 1), - vec![(addr1, Amount::from_str("6.0").unwrap())] + vec![(addr1, Amount::from_raw(6000000000))] .into_iter() .collect(), ), From 34d93e1a4334fc7564c15b176813ef4763c61970 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 31 May 2024 17:29:55 +0200 Subject: [PATCH 3/9] delete import --- massa-models/src/amount.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/massa-models/src/amount.rs b/massa-models/src/amount.rs index e3a80a4dc33..d8e40e173be 100644 --- a/massa-models/src/amount.rs +++ b/massa-models/src/amount.rs @@ -6,7 +6,6 @@ use massa_serialization::{U64VarIntDeserializer, U64VarIntSerializer}; use nom::error::{context, ContextError, ParseError}; use nom::{IResult, Parser}; use rust_decimal::prelude::*; -use serde::de::Unexpected; use std::fmt; use std::ops::Bound; use std::str::FromStr; From 3803c0c1a0dfc4e34eb8ccefc6881747980df6e2 Mon Sep 17 00:00:00 2001 From: modship Date: Fri, 31 May 2024 17:43:43 +0200 Subject: [PATCH 4/9] clippy --- massa-api-exports/src/operation.rs | 1 - massa-grpc/src/tests/stream.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/massa-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs index 0d8ad740cf7..3a2e71e50bc 100644 --- a/massa-api-exports/src/operation.rs +++ b/massa-api-exports/src/operation.rs @@ -71,7 +71,6 @@ mod tests { use massa_models::{amount::Amount, operation::OperationType}; use serial_test::serial; use std::collections::BTreeMap; - use std::str::FromStr; #[test] #[serial] diff --git a/massa-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index b30b069d6b0..06dd41a2b5a 100644 --- a/massa-grpc/src/tests/stream.rs +++ b/massa-grpc/src/tests/stream.rs @@ -27,7 +27,7 @@ use massa_protocol_exports::{ use massa_serialization::Serializer; use massa_signature::KeyPair; use massa_time::MassaTime; -use std::{net::SocketAddr, ops::Add, str::FromStr, time::Duration}; +use std::{net::SocketAddr, ops::Add, time::Duration}; use tokio_stream::StreamExt; #[tokio::test] From 87f5004f56cf5e326cad8b64ff5159580fbd6b25 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 3 Jun 2024 16:07:15 +0200 Subject: [PATCH 5/9] Amount from_str to from_raw (part2) --- massa-api/src/tests/public.rs | 12 +++++------ massa-async-pool/src/changes.rs | 6 +++--- massa-async-pool/src/message.rs | 20 +++++++++---------- .../src/test_exports/bootstrap.rs | 3 +-- .../src/tests/scenarios_mandatories.rs | 4 ++-- massa-execution-worker/src/tests/universe.rs | 2 +- .../src/tests/block_scenarios.rs | 2 +- massa-final-state/src/final_state.rs | 6 +++--- massa-final-state/src/state_changes.rs | 12 +++++------ massa-final-state/src/tests/scenarios.rs | 6 +++--- massa-ledger-exports/src/ledger_changes.rs | 8 ++++---- massa-ledger-exports/src/ledger_entry.rs | 4 ++-- massa-ledger-worker/src/ledger_db.rs | 6 +++--- massa-models/src/amount.rs | 5 +---- massa-models/src/operation.rs | 2 +- 15 files changed, 47 insertions(+), 51 deletions(-) diff --git a/massa-api/src/tests/public.rs b/massa-api/src/tests/public.rs index 61ee813775b..d0b53356a4e 100644 --- a/massa-api/src/tests/public.rs +++ b/massa-api/src/tests/public.rs @@ -454,8 +454,8 @@ async fn send_operations_low_fee() { let addr: SocketAddr = "[::]:5049".parse().unwrap(); let (mut api_public, mut config) = start_public_api(addr); - config.minimal_fees = Amount::from_str("10000000").unwrap(); - api_public.0.api_settings.minimal_fees = Amount::from_str("10000000").unwrap(); + config.minimal_fees = Amount::from_raw(10000000); + api_public.0.api_settings.minimal_fees = Amount::from_raw(10000000); let mut pool_ctrl = MockPoolController::new(); pool_ctrl.expect_clone_box().returning(|| { @@ -774,7 +774,7 @@ fn test_amount() { // print no longer display massa unit as decimal // print display nanoMassa - println!("{}", amount); // Should print 100 (nanoMassa) + // println!("{}", amount); // Should print 100 (nanoMassa) // to_raw return nanoMassa as u64 like before assert_eq!(amount.to_raw(), 000000000100); @@ -855,7 +855,7 @@ async fn execute_read_only_call() { target_function: "hello".to_string(), parameter: vec![], caller_address: None, - fee: Some(Amount::from_str("10000000").unwrap()), + fee: Some(Amount::from_raw(10000000)), coins: None, }]]; let response: Vec = client @@ -876,8 +876,8 @@ async fn get_addresses() { exec_ctrl.expect_get_addresses_infos().returning(|a| { a.iter() .map(|_addr| ExecutionAddressInfo { - candidate_balance: Amount::from_str("100000").unwrap(), - final_balance: Amount::from_str("80000").unwrap(), + candidate_balance: Amount::from_raw(10000000), + final_balance: Amount::from_raw(80000), final_roll_count: 55, final_datastore_keys: std::collections::BTreeSet::new(), candidate_roll_count: 12, diff --git a/massa-async-pool/src/changes.rs b/massa-async-pool/src/changes.rs index 22756446237..4d7119ed764 100644 --- a/massa-async-pool/src/changes.rs +++ b/massa-async-pool/src/changes.rs @@ -277,11 +277,11 @@ mod tests { ); let mut message2 = message.clone(); - message2.fee = Amount::from_str("2").unwrap(); + message2.fee = Amount::from_raw(2000000000); assert_ne!(message.compute_id(), message2.compute_id()); let mut message3 = message.clone(); - message3.fee = Amount::from_str("3").unwrap(); + message3.fee = Amount::from_raw(3000000000); assert_ne!(message.compute_id(), message3.compute_id()); changes @@ -289,7 +289,7 @@ mod tests { .insert(message2.compute_id(), SetUpdateOrDelete::Delete); let update3 = AsyncMessageUpdate { - coins: SetOrKeep::Set(Amount::from_str("3").unwrap()), + coins: SetOrKeep::Set(Amount::from_raw(3000000000)), ..Default::default() }; diff --git a/massa-async-pool/src/message.rs b/massa-async-pool/src/message.rs index 503816f6ace..c20de506d8f 100644 --- a/massa-async-pool/src/message.rs +++ b/massa-async-pool/src/message.rs @@ -68,8 +68,8 @@ impl Serializer for AsyncMessageIdSerializer { /// Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), /// String::from("test"), /// 10000000, - /// Amount::from_str("1").unwrap(), - /// Amount::from_str("1").unwrap(), + /// Amount::from_raw(1000000000), + /// Amount::from_raw(1000000000), /// Slot::new(2, 0), /// Slot::new(3, 0), /// vec![1, 2, 3, 4], @@ -138,8 +138,8 @@ impl Deserializer for AsyncMessageIdDeserializer { /// Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), /// String::from("test"), /// 10000000, - /// Amount::from_str("1").unwrap(), - /// Amount::from_str("1").unwrap(), + /// Amount::from_raw(1000000000), + /// Amount::from_raw(1000000000), /// Slot::new(2, 0), /// Slot::new(3, 0), /// vec![1, 2, 3, 4], @@ -429,8 +429,8 @@ impl Serializer for AsyncMessageSerializer { /// Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), /// String::from("test"), /// 10000000, - /// Amount::from_str("1").unwrap(), - /// Amount::from_str("1").unwrap(), + /// Amount::from_raw(1000000000), + /// Amount::from_raw(1000000000), /// Slot::new(2, 0), /// Slot::new(3, 0), /// vec![1, 2, 3, 4], @@ -546,8 +546,8 @@ impl Deserializer for AsyncMessageDeserializer { /// Address::from_str("AS12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), /// String::from("test"), /// 10000000, - /// Amount::from_str("1").unwrap(), - /// Amount::from_str("1").unwrap(), + /// Amount::from_raw(1000000000), + /// Amount::from_raw(1000000000), /// Slot::new(2, 0), /// Slot::new(3, 0), /// vec![1, 2, 3, 4], @@ -1479,8 +1479,8 @@ mod tests { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], diff --git a/massa-async-pool/src/test_exports/bootstrap.rs b/massa-async-pool/src/test_exports/bootstrap.rs index bafd44393f9..aec000d579e 100644 --- a/massa-async-pool/src/test_exports/bootstrap.rs +++ b/massa-async-pool/src/test_exports/bootstrap.rs @@ -4,7 +4,6 @@ use crate::AsyncMessage; use massa_models::{address::Address, amount::Amount, slot::Slot}; use massa_signature::KeyPair; use rand::Rng; -use std::str::FromStr; /// This file defines tools to test the asynchronous pool bootstrap @@ -23,7 +22,7 @@ pub fn get_random_message(fee: Option, thread_count: u8) -> AsyncMessage String::from("test"), 10_000, fee.unwrap_or_default(), - Amount::from_str("100").unwrap(), + Amount::from_raw(100000000000), Slot::new(2, 0), Slot::new(4, 0), vec![1, 2, 3], diff --git a/massa-execution-worker/src/tests/scenarios_mandatories.rs b/massa-execution-worker/src/tests/scenarios_mandatories.rs index 16fb4cd6519..c5f90350385 100644 --- a/massa-execution-worker/src/tests/scenarios_mandatories.rs +++ b/massa-execution-worker/src/tests/scenarios_mandatories.rs @@ -110,7 +110,7 @@ fn final_state_boilerplate( ledger_controller.set_expectations(|ledger_controller| { ledger_controller .expect_get_balance() - .returning(move |_| Some(Amount::from_str("100").unwrap())); + .returning(move |_| Some(Amount::from_raw(100000000000))); if let Some(saved_bytecode) = saved_bytecode { ledger_controller .expect_get_bytecode() @@ -254,7 +254,7 @@ fn test_readonly_execution() { .set_expectations(|ledger_controller| { ledger_controller .expect_get_balance() - .returning(move |_| Some(Amount::from_str("100").unwrap())); + .returning(move |_| Some(Amount::from_raw(100000000000))); ledger_controller .expect_entry_exists() .times(1) diff --git a/massa-execution-worker/src/tests/universe.rs b/massa-execution-worker/src/tests/universe.rs index beadb9798bb..3e5eed9afda 100644 --- a/massa-execution-worker/src/tests/universe.rs +++ b/massa-execution-worker/src/tests/universe.rs @@ -164,7 +164,7 @@ impl ExecutionTestUniverse { // here we use 1.5B as most of the tests perform a SC creation: // 314_000_000 (SP COMPIL) + 745_000_000 (CL COMPIL) + margin max_gas: 1_500_000_000, - max_coins: Amount::from_str("5000000").unwrap(), + max_coins: Amount::from_raw(5000000000000), datastore, }; let op = Operation::new_verifiable( diff --git a/massa-factory-worker/src/tests/block_scenarios.rs b/massa-factory-worker/src/tests/block_scenarios.rs index 5863a4e525b..76089af8fdf 100644 --- a/massa-factory-worker/src/tests/block_scenarios.rs +++ b/massa-factory-worker/src/tests/block_scenarios.rs @@ -131,7 +131,7 @@ fn basic_creation_with_operation() { .returning(move |slot| { assert_eq!(*slot, Slot::new(1, 0)); let content = Operation { - fee: Amount::from_str("10000000").unwrap(), + fee: Amount::from_raw(10000000000000000), expire_period: 2, op: OperationType::RollBuy { roll_count: 1 }, }; diff --git a/massa-final-state/src/final_state.rs b/massa-final-state/src/final_state.rs index f8bb4ecae6b..39f97224427 100644 --- a/massa-final-state/src/final_state.rs +++ b/massa-final-state/src/final_state.rs @@ -1063,8 +1063,8 @@ mod test { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], @@ -1077,7 +1077,7 @@ mod test { .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); state_changes.async_pool_changes = async_pool_changes; - let amount = Amount::from_str("1").unwrap(); + let amount = Amount::from_raw(1000000000); let bytecode = Bytecode(vec![1, 2, 3]); let ledger_entry = LedgerEntryUpdate { balance: SetOrKeep::Set(amount), diff --git a/massa-final-state/src/state_changes.rs b/massa-final-state/src/state_changes.rs index 85dd5b9b3df..92086708ac5 100644 --- a/massa-final-state/src/state_changes.rs +++ b/massa-final-state/src/state_changes.rs @@ -270,8 +270,8 @@ mod test { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], @@ -284,7 +284,7 @@ mod test { .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); state_changes.async_pool_changes = async_pool_changes; - let amount = Amount::from_str("1").unwrap(); + let amount = Amount::from_raw(1000000000); let bytecode = Bytecode(vec![1, 2, 3]); let ledger_entry = LedgerEntryUpdate { balance: SetOrKeep::Set(amount), @@ -334,8 +334,8 @@ mod test { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], @@ -348,7 +348,7 @@ mod test { .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); state_changes.async_pool_changes = async_pool_changes; - let amount = Amount::from_str("1").unwrap(); + let amount = Amount::from_raw(1000000000); let bytecode = Bytecode(vec![1, 2, 3]); let mut datastore = BTreeMap::new(); datastore.insert( diff --git a/massa-final-state/src/tests/scenarios.rs b/massa-final-state/src/tests/scenarios.rs index 7ac021e6608..d8cf4f47815 100644 --- a/massa-final-state/src/tests/scenarios.rs +++ b/massa-final-state/src/tests/scenarios.rs @@ -180,8 +180,8 @@ fn test_final_state() { Address::from_str("AU12htxRWiEm8jDJpJptr6cwEhWNcCSFWstN1MLSa96DDkVM9Y42G").unwrap(), String::from("test"), 10000000, - Amount::from_str("1").unwrap(), - Amount::from_str("1").unwrap(), + Amount::from_raw(1000000000), + Amount::from_raw(1000000000), Slot::new(2, 0), Slot::new(3, 0), vec![1, 2, 3, 4], @@ -194,7 +194,7 @@ fn test_final_state() { .insert(message.compute_id(), SetUpdateOrDelete::Set(message)); state_changes.async_pool_changes = async_pool_changes; - let amount = Amount::from_str("1").unwrap(); + let amount = Amount::from_raw(1000000000); let bytecode = Bytecode(vec![1, 2, 3]); let ledger_entry = LedgerEntryUpdate { balance: SetOrKeep::Set(amount), diff --git a/massa-ledger-exports/src/ledger_changes.rs b/massa-ledger-exports/src/ledger_changes.rs index 02551f0b096..2412d4a9495 100644 --- a/massa-ledger-exports/src/ledger_changes.rs +++ b/massa-ledger-exports/src/ledger_changes.rs @@ -208,7 +208,7 @@ impl Serializer for LedgerEntryUpdateSerializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::default(); /// datastore.insert(key, SetOrDelete::Set(vec![1, 2, 3])); - /// let amount = Amount::from_str("1").unwrap(); + /// let amount = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntryUpdate { /// balance: SetOrKeep::Keep, @@ -276,7 +276,7 @@ impl Deserializer for LedgerEntryUpdateDeserializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::default(); /// datastore.insert(key, SetOrDelete::Set(vec![1, 2, 3])); - /// let amount = Amount::from_str("1").unwrap(); + /// let amount = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntryUpdate { /// balance: SetOrKeep::Keep, @@ -377,7 +377,7 @@ impl Serializer for LedgerChangesSerializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::new(); /// datastore.insert(key, vec![1, 2, 3]); - /// let balance = Amount::from_str("1").unwrap(); + /// let balance = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntry { /// balance, @@ -459,7 +459,7 @@ impl Deserializer for LedgerChangesDeserializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::new(); /// datastore.insert(key, vec![1, 2, 3]); - /// let balance = Amount::from_str("1").unwrap(); + /// let balance = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntry { /// balance, diff --git a/massa-ledger-exports/src/ledger_entry.rs b/massa-ledger-exports/src/ledger_entry.rs index abac9332072..60ec2dec282 100644 --- a/massa-ledger-exports/src/ledger_entry.rs +++ b/massa-ledger-exports/src/ledger_entry.rs @@ -66,7 +66,7 @@ impl Serializer for LedgerEntrySerializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::new(); /// datastore.insert(key, vec![1, 2, 3]); - /// let balance = Amount::from_str("1").unwrap(); + /// let balance = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntry { /// balance, @@ -128,7 +128,7 @@ impl Deserializer for LedgerEntryDeserializer { /// let key = "hello world".as_bytes().to_vec(); /// let mut datastore = BTreeMap::new(); /// datastore.insert(key, vec![1, 2, 3]); - /// let balance = Amount::from_str("1").unwrap(); + /// let balance = Amount::from_raw(1000000000); /// let bytecode = Bytecode(vec![1, 2, 3]); /// let ledger_entry = LedgerEntry { /// balance, diff --git a/massa-ledger-worker/src/ledger_db.rs b/massa-ledger-worker/src/ledger_db.rs index 8bf446e154f..dca3c2d986c 100644 --- a/massa-ledger-worker/src/ledger_db.rs +++ b/massa-ledger-worker/src/ledger_db.rs @@ -582,12 +582,12 @@ mod tests { data.insert(b"2".to_vec(), b"b".to_vec()); data.insert(b"3".to_vec(), b"c".to_vec()); let entry = LedgerEntry { - balance: Amount::from_str("42").unwrap(), + balance: Amount::from_raw(42000000000), datastore: data.clone(), ..Default::default() }; let entry_update = LedgerEntryUpdate { - balance: SetOrKeep::Set(Amount::from_str("21").unwrap()), + balance: SetOrKeep::Set(Amount::from_raw(21000000000)), bytecode: SetOrKeep::Keep, ..Default::default() }; @@ -646,7 +646,7 @@ mod tests { ) .unwrap() .1, - Amount::from_str("21").unwrap() + Amount::from_raw(21000000000) ); assert_eq!(data, ledger_db.get_entire_datastore(&addr)); diff --git a/massa-models/src/amount.rs b/massa-models/src/amount.rs index d8e40e173be..e3b805d423d 100644 --- a/massa-models/src/amount.rs +++ b/massa-models/src/amount.rs @@ -269,10 +269,8 @@ impl fmt::Debug for Amount { } } -/// build an Amount from decimal string form (like "10.33") +/// build an Amount from nanoMassa string (like "11230000000") /// note that this will fail if the string format is invalid -/// or if the conversion would cause an overflow, underflow or precision loss -/// /// ``` /// # use massa_models::amount::Amount; /// # use std::str::FromStr; @@ -449,7 +447,6 @@ impl serde::Serialize for Amount { where S: serde::Serializer, { - // let a = format!("{}", self.to_raw()); serializer.serialize_u64(self.to_raw()) } } diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index 8296372d28c..0bfb9371fb3 100644 --- a/massa-models/src/operation.rs +++ b/massa-models/src/operation.rs @@ -724,7 +724,7 @@ impl Serializer for OperationTypeSerializer { /// let op = OperationType::ExecuteSC { /// data: vec![0x01, 0x02, 0x03], /// max_gas: 100, - /// max_coins: Amount::from_str("5000000").unwrap(), + /// max_coins: Amount::from_raw(5000000000000000), /// datastore: BTreeMap::default(), /// }; /// let mut buffer = Vec::new(); From 3516f3b55b164aead34a3d2eceea2525ce5c451c Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 3 Jun 2024 16:15:58 +0200 Subject: [PATCH 6/9] clippy --- massa-api/src/tests/public.rs | 6 +++--- massa-execution-worker/src/tests/universe.rs | 1 - massa-factory-worker/src/tests/block_scenarios.rs | 2 +- massa-ledger-worker/src/ledger_db.rs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/massa-api/src/tests/public.rs b/massa-api/src/tests/public.rs index d0b53356a4e..fa725171042 100644 --- a/massa-api/src/tests/public.rs +++ b/massa-api/src/tests/public.rs @@ -777,7 +777,7 @@ fn test_amount() { // println!("{}", amount); // Should print 100 (nanoMassa) // to_raw return nanoMassa as u64 like before - assert_eq!(amount.to_raw(), 000000000100); + assert_eq!(amount.to_raw(), 100); // to_string return nanoMassa as string assert_eq!(amount.to_string(), "100".to_string()); @@ -790,10 +790,10 @@ fn test_amount() { let deserialized_amount: Amount = Amount::from_str(&serialized_serde).unwrap(); assert_eq!(deserialized_serde.to_string(), "100"); - assert_eq!(deserialized_serde.to_raw(), 000000000100); + assert_eq!(deserialized_serde.to_raw(), 100); assert_eq!(deserialized_amount.to_string(), "100"); - assert_eq!(deserialized_amount.to_raw(), 000000000100); + assert_eq!(deserialized_amount.to_raw(), 100); assert_eq!(deserialized_serde, deserialized_amount); } diff --git a/massa-execution-worker/src/tests/universe.rs b/massa-execution-worker/src/tests/universe.rs index 3e5eed9afda..f81e2888966 100644 --- a/massa-execution-worker/src/tests/universe.rs +++ b/massa-execution-worker/src/tests/universe.rs @@ -1,6 +1,5 @@ use std::{ collections::{BTreeMap, HashMap}, - str::FromStr, sync::Arc, }; diff --git a/massa-factory-worker/src/tests/block_scenarios.rs b/massa-factory-worker/src/tests/block_scenarios.rs index 76089af8fdf..d15d861180e 100644 --- a/massa-factory-worker/src/tests/block_scenarios.rs +++ b/massa-factory-worker/src/tests/block_scenarios.rs @@ -1,4 +1,4 @@ -use std::{str::FromStr, sync::Arc}; +use std::sync::Arc; use super::BlockTestFactory; use massa_consensus_exports::MockConsensusController; diff --git a/massa-ledger-worker/src/ledger_db.rs b/massa-ledger-worker/src/ledger_db.rs index dca3c2d986c..b5f66dc97c6 100644 --- a/massa-ledger-worker/src/ledger_db.rs +++ b/massa-ledger-worker/src/ledger_db.rs @@ -570,7 +570,6 @@ mod tests { use parking_lot::RwLock; use std::collections::BTreeMap; use std::ops::Bound::Included; - use std::str::FromStr; use std::sync::Arc; use tempfile::TempDir; From a125ce1d021db5d44844b63eace47e6a802c994e Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 3 Jun 2024 16:56:53 +0200 Subject: [PATCH 7/9] update public openrpc spec --- massa-node/base_config/openrpc.json | 697 +++++++++++++++++++--------- 1 file changed, 467 insertions(+), 230 deletions(-) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 4671a33b21e..89731ca5ad1 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -2,7 +2,7 @@ "openrpc": "1.2.4", "info": { "title": "Massa OpenRPC Specification", - "version": "DEVN.28.3", + "version": "MAIN.2.1", "description": "Massa OpenRPC Specification document. Find more information on https://docs.massa.net/docs/build/api/jsonrpc", "termsOfService": "https://open-rpc.org", "contact": { @@ -54,7 +54,7 @@ "$ref": "#/components/schemas/ExecuteReadOnlyResponse" } }, - "name": "ExecuteReadOnlyResponse(s)" + "name": "ExecuteReadOnlyResponses" }, "name": "execute_read_only_bytecode", "summary": "Execute a smart contract in a read only context", @@ -85,7 +85,7 @@ "$ref": "#/components/schemas/ExecuteReadOnlyResponse" } }, - "name": "ExecuteReadOnlyResponse(s)" + "name": "ExecuteReadOnlyResponses" }, "name": "execute_read_only_call", "summary": "Call a function of a contract in a read only context", @@ -112,13 +112,13 @@ } ], "result": { + "name": "AddressInfo", "schema": { "type": "array", "items": { "$ref": "#/components/schemas/AddressInfo" } - }, - "name": "AddressInfo(s)" + } }, "name": "get_addresses", "summary": "To check when your address is selected to stake.", @@ -133,7 +133,7 @@ ], "params": [ { - "name": "address filter", + "name": "addressFilter", "description": "Need to provide at least one valid address filter", "schema": { "type": "array", @@ -148,7 +148,8 @@ "schema": { "type": "array", "items": { - "type": "integer" + "type": "string", + "format": "byte" } }, "name": "Addresses bytecode array" @@ -180,13 +181,16 @@ ], "result": { "schema": { - "$ref": "#/components/schemas/BlockInfo" + "type": "array", + "items": { + "$ref": "#/components/schemas/BlockInfo" + } }, "name": "BlockInfo" }, "name": "get_blocks", - "summary": "Get block(s)", - "description": "Get block(s)." + "summary": "Get blocks", + "description": "Get blocks." }, { "tags": [ @@ -231,7 +235,7 @@ "$ref": "#/components/schemas/Clique" } }, - "name": "Clique(s)" + "name": "Cliques" }, "name": "get_cliques", "summary": "Get cliques", @@ -246,7 +250,7 @@ ], "params": [ { - "name": "DatastoreEntryInput(s)", + "name": "DatastoreEntryInputs", "description": "Datastore entry input", "schema": { "type": "array", @@ -263,46 +267,12 @@ "$ref": "#/components/schemas/DataStoreEntryOutput" } }, - "name": "DataStoreEntryOutput(s)" + "name": "DataStoreEntryOutputs" }, "name": "get_datastore_entries", "summary": "Get a data entry both at the latest final and active executed slots for the given addresses.", "description": "Get a data entry both at the latest final and active executed slots for the given addresses.\n\nIf an existing final entry (final_value) is found in the active history, it will return its final value in active_value field. If it was deleted in the active history, it will return null in active_value field." }, - { - "tags": [ - { - "name": "public", - "description": "Massa public api" - } - ], - "params": [ - { - "name": "key", - "schema": { - "type": "string" - }, - "required": true - }, - { - "name": "address", - "schema": { - "$ref": "#/components/schemas/Address" - }, - "required": true - } - ], - "result": { - "schema": { - "$ref": "#/components/schemas/DataStoreEntry" - }, - "name": "DataStoreEntry" - }, - "deprecated": true, - "name": "get_datastore_entry", - "summary": "Get datastore entry", - "description": "Get datastore entry." - }, { "tags": [ { @@ -366,7 +336,7 @@ "$ref": "#/components/schemas/EndorsementInfo" } }, - "name": "EndorsementInfo(s)" + "name": "EndorsementInfos" }, "name": "get_endorsements", "summary": "Get endorsements", @@ -394,7 +364,7 @@ "$ref": "#/components/schemas/SCOutputEvent" } }, - "name": "SCOutputEvent(s)" + "name": "SCOutputEvents" }, "name": "get_filtered_sc_output_event", "summary": "Returns events optionally filtered", @@ -409,23 +379,27 @@ ], "params": [ { - "name": "end", - "schema": { - "type": "number" - }, - "required": false - }, - { - "name": "start", + "name": "TimeInterval", "schema": { - "type": "number" - }, - "required": false + "type": "object", + "properties": { + "start": { + "type": "number" + }, + "end": { + "type": "number" + } + }, + "additionalProperties": false + } } ], "result": { "schema": { - "$ref": "#/components/schemas/GraphInterval" + "type": "array", + "items": { + "$ref": "#/components/schemas/GraphInterval" + } }, "name": "GraphInterval" }, @@ -460,7 +434,7 @@ "$ref": "#/components/schemas/OperationInfo" } }, - "name": "OperationInfo(s)" + "name": "OperationInfos" }, "name": "get_operations", "summary": "Get operations", @@ -559,7 +533,7 @@ } }, "description": "The strings are addresses.", - "name": "Address(es)" + "name": "Addresses" }, "name": "get_staking_addresses", "summary": "Return hashset of staking addresses", @@ -575,7 +549,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -592,8 +566,8 @@ "schema": false }, "name": "node_add_to_bootstrap_blacklist", - "summary": "Add to bootstrap blacklist given IP address(es)", - "description": "Add to bootstrap blacklist given IP address(es)." + "summary": "Add to bootstrap blacklist given IP addresses", + "description": "Add to bootstrap blacklist given IP addresses." }, { "tags": [ @@ -605,7 +579,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -622,8 +596,8 @@ "schema": false }, "name": "node_add_to_bootstrap_whitelist", - "summary": "Add to bootstrap whitelist given IP address(es)", - "description": "Add to bootstrap whitelist given IP address(es)." + "summary": "Add to bootstrap whitelist given IP addresses", + "description": "Add to bootstrap whitelist given IP addresses." }, { "tags": [ @@ -635,7 +609,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -652,8 +626,8 @@ "schema": false }, "name": "node_add_to_peers_whitelist", - "summary": "Add to peers whitelist given IP address(es)", - "description": "Add to peers whitelist given IP address(es)." + "summary": "Add to peers whitelist given IP addresses", + "description": "Add to peers whitelist given IP addresses." }, { "tags": [ @@ -681,8 +655,8 @@ "schema": false }, "name": "node_ban_by_id", - "summary": "Ban given id(s)", - "description": "Ban given id(s)." + "summary": "Ban given ids", + "description": "Ban given ids." }, { "tags": [ @@ -710,8 +684,8 @@ "schema": false }, "name": "node_ban_by_ip", - "summary": "Ban given IP address(es)", - "description": "Ban given IP address(es)." + "summary": "Ban given IP addresses", + "description": "Ban given IP addresses." }, { "tags": [ @@ -723,7 +697,7 @@ "params": [], "result": { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -733,8 +707,8 @@ } }, "name": "node_bootstrap_blacklist", - "summary": "Returns bootstrap blacklist IP address(es)", - "description": "Returns bootstrap blacklist IP address(es)." + "summary": "Returns bootstrap blacklist IP addresses", + "description": "Returns bootstrap blacklist IP addresses." }, { "tags": [ @@ -746,7 +720,7 @@ "params": [], "result": { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -756,8 +730,8 @@ } }, "name": "node_bootstrap_whitelist", - "summary": "Returns bootstrap whitelist IP address(es)", - "description": "Returns bootstrap whitelist IP address(es)." + "summary": "Returns bootstrap whitelist IP addresses", + "description": "Returns bootstrap whitelist IP addresses." }, { "tags": [ @@ -786,7 +760,7 @@ "params": [], "result": { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -796,8 +770,8 @@ } }, "name": "node_peers_whitelist", - "summary": "Returns peers whitelist IP address(es)", - "description": "Returns peers whitelist IP address(es)." + "summary": "Returns peers whitelist IP addresses", + "description": "Returns peers whitelist IP addresses." }, { "tags": [ @@ -809,7 +783,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -826,8 +800,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_blacklist", - "summary": "Remove from bootstrap blacklist given IP address(es)", - "description": "Remove from bootstrap blacklist given IP address(es)." + "summary": "Remove from bootstrap blacklist given IP addresses", + "description": "Remove from bootstrap blacklist given IP addresses." }, { "tags": [ @@ -839,7 +813,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -856,8 +830,8 @@ "schema": false }, "name": "node_remove_from_bootstrap_whitelist", - "summary": "Remove from bootstrap whitelist given IP address(es)", - "description": "Remove from bootstrap whitelist given IP address(es)." + "summary": "Remove from bootstrap whitelist given IP addresses", + "description": "Remove from bootstrap whitelist given IP addresses." }, { "tags": [ @@ -869,7 +843,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -886,8 +860,8 @@ "schema": false }, "name": "node_remove_from_peers_whitelist", - "summary": "Remove from peers whitelist given IP address(es)", - "description": "Remove from peers whitelist given IP address(es)." + "summary": "Remove from peers whitelist given IP addresses", + "description": "Remove from peers whitelist given IP addresses." }, { "tags": [ @@ -899,7 +873,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -916,8 +890,8 @@ "schema": false }, "name": "node_remove_from_whitelist", - "summary": "Remove from whitelist given IP address(es)", - "description": "Remove from whitelist given IP address(es)." + "summary": "Remove from whitelist given IP addresses", + "description": "Remove from whitelist given IP addresses." }, { "tags": [ @@ -1021,8 +995,8 @@ "schema": false }, "name": "node_unban_by_id", - "summary": "Unban given id(s)", - "description": "Unban given id(s)." + "summary": "Unban given ids", + "description": "Unban given ids." }, { "tags": [ @@ -1051,8 +1025,8 @@ "schema": false }, "name": "node_unban_by_ip", - "summary": "Unban given IP address(es)", - "description": "Unban given IP address(es)." + "summary": "Unban given IP addresses", + "description": "Unban given IP addresses." }, { "tags": [ @@ -1064,7 +1038,7 @@ "params": [ { "name": "ip", - "description": "The strings must be IP address(es)", + "description": "The strings must be IP addresses", "schema": { "type": "array", "items": { @@ -1081,8 +1055,8 @@ "schema": false }, "name": "node_whitelist", - "summary": "Whitelist given IP address(es)", - "description": "Whitelist given IP address(es)." + "summary": "Whitelist given IP addresses", + "description": "Whitelist given IP addresses." }, { "tags": [ @@ -1099,7 +1073,8 @@ "items": { "$ref": "#/components/schemas/OperationInput" } - } + }, + "required": true } ], "result": { @@ -1109,7 +1084,7 @@ "$ref": "#/components/schemas/OperationId" } }, - "name": "Operation(s)" + "name": "Operations" }, "name": "send_operations", "summary": "Adds operations to pool", @@ -1445,10 +1420,12 @@ "components": { "schemas": { "Address": { + "title": "Address", "description": "Address", "type": "string" }, "AddressFilter": { + "title": "AddressFilter", "description": "Address filter", "type": "object", "properties": { @@ -1460,7 +1437,8 @@ "type": "boolean", "description": "true means final, false means candidate" } - } + }, + "additionalProperties": false }, "AddressInfo": { "title": "AddressInfo", @@ -1493,7 +1471,7 @@ }, "final_balance": { "description": "The final balance", - "type": "number" + "type": "string" }, "final_roll_count": { "description": "The final roll count", @@ -1511,7 +1489,7 @@ }, "candidate_balance": { "description": "The candidate balance", - "type": "number" + "type": "string" }, "candidate_roll_count": { "description": "The candidate roll count", @@ -1538,10 +1516,11 @@ "type": "object" }, "amount": { - "type": "number" + "type": "string" } } - } + }, + "minItems": 0 }, "next_block_draws": { "description": "The next block draws", @@ -1569,15 +1548,30 @@ }, "created_blocks": { "description": "BlockIds of created blocks", - "type": "string" + "type": "array", + "items": { + "$ref": "#/components/schemas/BlockId", + "type": "string" + }, + "minItems": 0 }, "created_operations": { "description": "OperationIds of created operations", - "type": "string" + "type": "array", + "items": { + "$ref": "#/components/schemas/OperationId", + "type": "string" + }, + "minItems": 0 }, "created_endorsements": { "description": "EndorsementIds of created endorsements", - "type": "string" + "type": "array", + "items": { + "$ref": "#/components/schemas/EndorsementId", + "type": "string" + }, + "minItems": 0 }, "cycle_infos": { "description": "Cycle infos", @@ -1591,6 +1585,7 @@ "additionalProperties": false }, "ApiRequest": { + "title": "ApiRequest", "description": "ApiRequest for apiV2", "type": "object", "properties": { @@ -1598,7 +1593,8 @@ "$ref": "#/components/schemas/PageRequest", "description": "Optional page request" } - } + }, + "additionalProperties": false }, "Balance": { "title": "Balance", @@ -1647,6 +1643,7 @@ "additionalProperties": false }, "BlockId": { + "title": "BlockId", "description": "Block identifier", "type": "string" }, @@ -1672,7 +1669,7 @@ "block", "is_final", "is_in_blockclique", - "is_stale" + "is_candidate" ], "type": "object", "properties": { @@ -1680,8 +1677,12 @@ "description": "true if final", "type": "boolean" }, - "is_stale": { - "description": "true if incompatible with a final block", + "is_candidate": { + "description": "true if candidate", + "type": "boolean" + }, + "is_discarded": { + "description": "true if discarded", "type": "boolean" }, "is_in_blockclique": { @@ -1750,6 +1751,7 @@ "additionalProperties": false }, "Clique": { + "title": "Clique", "description": "Clique", "required": [ "block_ids", @@ -1773,7 +1775,8 @@ "description": "True if it is the clique of higher fitness", "type": "boolean" } - } + }, + "additionalProperties": false }, "CompactConfig": { "title": "Config", @@ -1784,11 +1787,10 @@ "genesis_timestamp", "operation_validity_periods", "periods_per_cycle", - "pos_lock_cycles", - "pos_lookback_cycles", "roll_price", "t0", - "thread_count" + "thread_count", + "execution_stats" ], "type": "object", "properties": { @@ -1802,7 +1804,14 @@ }, "end_timestamp": { "description": "(Only in tesnets)\nTime in milliseconds when the blockclique started.", - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] }, "genesis_timestamp": { "description": "Time in milliseconds when the blockclique started.", @@ -1820,14 +1829,6 @@ "description": "cycle duration in periods", "type": "number" }, - "pos_lock_cycles": { - "description": "PoS look back cycles: when drawing for cycle N, we use the rolls from cycle N - `pos_look` `back_cycles` - 1", - "type": "number" - }, - "pos_lookback_cycles": { - "description": "PoS lock cycles: when some rolls are released, we only credit the coins back to their owner after waiting `pos_lock_cycles`", - "type": "number" - }, "roll_price": { "description": "Represent an Amount in coins", "type": "string" @@ -1870,8 +1871,6 @@ "clique_count", "end_timespan", "final_block_count", - "final_operation_count", - "staker_count", "stale_block_count", "start_timespan" ], @@ -1887,18 +1886,12 @@ "final_block_count": { "type": "number" }, - "final_operation_count": { - "type": "number" - }, - "staker_count": { - "type": "number" - }, "stale_block_count": { "type": "number" }, "start_timespan": { "description": "Stats time interval, millis since 1970-01-01", - "type": "string" + "type": "number" } }, "additionalProperties": false @@ -1941,6 +1934,7 @@ ] }, "DataStoreEntry": { + "title": "DatastoreEntry", "description": "Datastore entry", "type": "object", "properties": { @@ -1952,9 +1946,11 @@ "description": "", "type": "string" } - } + }, + "additionalProperties": false }, "DatastoreEntryInput": { + "title": "DatastoreEntryInput", "description": "", "required": [ "address", @@ -1963,29 +1959,103 @@ "type": "object", "properties": { "address": { - "description": "", - "type": "string" + "$ref": "#/components/schemas/Address" }, "key": { "description": "", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } } - } + }, + "additionalProperties": false }, "DataStoreEntryOutput": { + "title": "DatastoreEntryOutput", "description": "Datastore entry", "type": "object", "properties": { "candidate_value": { "description": "", - "type": "string" + "oneOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] }, "final_value": { "description": "", + "oneOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + "Denunciation": { + "oneOf": [ + { + "$ref": "#/components/schemas/EndorsementDenunciation" + }, + { + "$ref": "#/components/schemas/BlockHeaderDenunciation" + } + ] + }, + "EndorsementDenunciation": { + "type": "object", + "properties": { + "public_key": { + "type": "string" + }, + "slot": { + "type": "integer" + }, + "index": { + "type": "integer" + }, + "hash_1": { + "type": "string" + }, + "hash_2": { + "type": "string" + }, + "signature_1": { + "type": "string" + }, + "signature_2": { + "type": "string" + } + } + }, + "BlockHeaderDenunciation": { + "type": "object", + "properties": { + "public_key": { + "type": "string" + }, + "slot": { + "type": "integer" + }, + "hash_1": { + "type": "string" + }, + "hash_2": { + "type": "string" + }, + "signature_1": { + "type": "string" + }, + "signature_2": { "type": "string" } } @@ -1995,7 +2065,7 @@ "description": "Endorsement", "required": [ "content", - "creator_public_key", + "content_creator_pub_key", "signature" ], "type": "object", @@ -2003,18 +2073,14 @@ "content": { "$ref": "#/components/schemas/EndorsementContent" }, - "creator_public_key": { - "$ref": "#/components/schemas/PublicKey", - "description": "the content creator public key" - }, - "creator_address": { - "type": "string" + "content_creator_pub_key": { + "$ref": "#/components/schemas/PublicKey" }, - "thread": { - "type": "number" + "content_creator_address": { + "$ref": "#/components/schemas/Address" }, "id": { - "type": "string" + "$ref": "#/components/schemas/EndorsementId" }, "signature": { "type": "string" @@ -2022,20 +2088,56 @@ }, "additionalProperties": false }, + "ExecutionStats": { + "title": "ExecutionStats", + "description": "Execution stats", + "required": [ + "time_window_start", + "time_window_end", + "final_block_count", + "final_executed_operations_count", + "active_cursor", + "final_cursor" + ], + "type": "object", + "properties": { + "time_window_start": { + "description": "Time window start", + "type": "number" + }, + "time_window_end": { + "description": "Time window end", + "type": "number" + }, + "final_block_count": { + "description": "number of final blocks in the time window", + "type": "number" + }, + "final_executed_operations_count": { + "description": "number of final executed operations in the time window", + "type": "number" + }, + "active_cursor": { + "descritpion": "active execution cursor slot", + "$ref": "#/components/schemas/Slot" + }, + "final_cursor": { + "description": "final execution cursor slot", + "$ref": "#/components/schemas/Slot" + } + }, + "additionalProperties": false + }, "EndorsementContent": { - "title": "Content", + "title": "EndorsementContent", "description": "Endorsement content", "required": [ "endorsed_block", "index", - "sender_public_key", "slot" ], "type": "object", "properties": { - "sender_public_key": { - "type": "string" - }, "slot": { "$ref": "#/components/schemas/Slot" }, @@ -2043,7 +2145,7 @@ "type": "number" }, "endorsed_block": { - "type": "string" + "$ref": "#/components/schemas/BlockId" } }, "additionalProperties": false @@ -2065,6 +2167,11 @@ }, "additionalProperties": false }, + "EndorsementId": { + "title": "EndorsementId", + "description": "Endorsement id", + "type": "string" + }, "EndorsementInfo": { "title": "EndorsementInfo", "description": "Endorsement info", @@ -2078,7 +2185,7 @@ "type": "object", "properties": { "id": { - "type": "string" + "$ref": "#/components/schemas/EndorsementId" }, "in_pool": { "type": "boolean" @@ -2087,7 +2194,7 @@ "description": "Block Id", "type": "array", "items": { - "type": "string" + "$ref": "#/components/schemas/BlockId" } }, "is_final": { @@ -2095,13 +2202,13 @@ }, "endorsement": { "$ref": "#/components/schemas/Endorsement", - "description": "Endorsement Id" + "description": "Endorsement" } }, "additionalProperties": false }, "ExecutedAt": { - "title": "Slot", + "title": "ExecuteAt", "required": [ "period", "thread" @@ -2201,9 +2308,17 @@ "type": "number" }, "active_rolls": { - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] } - } + }, + "additionalProperties": false }, "EventFilter": { "title": "EventFilter", @@ -2311,6 +2426,7 @@ "additionalProperties": false }, "IpAddress": { + "title": "IpAddress", "description": "Ipv4 or Ipv6 address", "type": "string" }, @@ -2427,15 +2543,26 @@ "Header": { "title": "Header", "required": [ - "creator", "operation_merkle_root", "parents", "slot" ], "type": "object", "properties": { - "creator": { - "type": "string" + "current_version": { + "description": "Current version", + "type": "number" + }, + "announced_version": { + "description": "Announced version", + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] }, "operation_merkle_root": { "type": "string" @@ -2448,6 +2575,38 @@ }, "slot": { "$ref": "#/components/schemas/Slot" + }, + "endorsements": { + "description": "Endorsements", + "type": "array", + "items": { + "type": "object", + "properties": { + "content": { + "$ref": "#/components/schemas/EndorsementContent" + }, + "signature": { + "type": "string" + }, + "content_creator_pub_key": { + "$ref": "#/components/schemas/PublicKey" + }, + "content_creator_address": { + "$ref": "#/components/schemas/Address" + }, + "id": { + "$ref": "#/components/schemas/EndorsementId" + } + } + } + }, + "denunciations": { + "description": "Denunciations", + "type": "array", + "items": { + "$ref": "#/components/schemas/Denunciation" + }, + "minItems": 0 } }, "additionalProperties": false @@ -2530,7 +2689,9 @@ "next_slot", "node_id", "pool_stats", - "version" + "version", + "execution_stats", + "chain_id" ], "type": "object", "properties": { @@ -2580,7 +2741,14 @@ }, "node_ip": { "description": "Optional node ip if provided", - "type": "string" + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] }, "pool_stats": { "$ref": "#/components/schemas/PoolStats", @@ -2589,6 +2757,14 @@ "version": { "$ref": "#/components/schemas/Version", "description": "Node Version" + }, + "execution_stats": { + "$ref": "#/components/schemas/ExecutionStats", + "description": "Execution stats" + }, + "chain_id": { + "description": "Chain id", + "type": "number" } }, "additionalProperties": false @@ -2619,6 +2795,7 @@ "additionalProperties": false }, "OperationId": { + "title": "OperationId", "description": "Operation id", "type": "string" }, @@ -2629,7 +2806,7 @@ "id", "in_blocks", "in_pool", - "is_final", + "is_operation_final", "thread", "operation" ], @@ -2643,16 +2820,23 @@ "description": "Block ids\nThe operation appears in `in_blocks`\nIf it appears in multiple blocks, these blocks are in different cliques", "type": "array", "items": { - "type": "string" + "$ref": "#/components/schemas/BlockId" } }, "in_pool": { "description": "True if operation is still in pool", "type": "boolean" }, - "is_final": { + "is_operation_final": { "description": "True if the operation is final (for example in a final block)", - "type": "boolean" + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + } + ] }, "thread": { "description": "Thread in which the operation can be included", @@ -2664,12 +2848,20 @@ }, "op_exec_status": { "description": "true if the operation execution succeeded, false if failed, None means unknown", - "type": "boolean" + "oneOf": [ + { + "type": "null" + }, + { + "type": "boolean" + } + ] } }, "additionalProperties": false }, "OperationInput": { + "title": "OperationInput", "description": "Operation input", "required": [ "creator_public_key", @@ -2687,17 +2879,16 @@ "description": "The signature of the operation" }, "serialized_content": { - "description": "The serialized version of the content `base58` encoded", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } } }, "additionalProperties": false }, "OperationType": { + "title": "OperationType", "description": "Type specific operation content.", "type": "object", "properties": { @@ -2721,10 +2912,11 @@ "$ref": "#/components/schemas/RollSell", "description": "the sender sells `roll_count` rolls. Roll price is defined in configuration" } - } + }, + "additionalProperties": false }, "PageRequest": { - "title": "PageRequest", + "title": "Pagination", "description": "An PageRequest object, which contains limit (max elements par page) and a page offset.", "type": "object", "required": [ @@ -2738,9 +2930,11 @@ "offset": { "type": "number" } - } + }, + "additionalProperties": false }, "PagedVecStaker": { + "title": "PagedVecStaker", "description": "PagedVec of stakers for apiV2", "type": "object", "properties": { @@ -2753,27 +2947,19 @@ "total_count": { "type": "number" } - } + }, + "additionalProperties": false }, "PoolStats": { "title": "PoolStats", "description": "Pool stats", - "required": [ - "endorsement_count", - "operation_count" - ], - "type": "object", - "properties": { - "endorsement_count": { - "type": "number" - }, - "operation_count": { - "type": "number" - } - }, - "additionalProperties": false + "type": "array", + "items": { + "type": "number" + } }, "PrivateKey": { + "title": "PrivateKey", "description": "`PrivateKey` is used for signature and decryption", "type": "string" }, @@ -2803,10 +2989,12 @@ "additionalProperties": false }, "PublicKey": { + "title": "PublicKey", "description": "Public key used to check if a message was encoded by the corresponding `PublicKey`.\nGenerated from the `KeyPair` using `SignatureEngine`", "type": "string" }, "PubkeySig": { + "title": "PubkeySig", "description": "Public key and a signature it has produced used for serialization/deserialization purpose", "required": [ "public_key", @@ -2822,7 +3010,8 @@ "description": "signature", "type": "string" } - } + }, + "additionalProperties": false }, "ReadOnlyBytecodeExecution": { "title": "ReadOnlyBytecodeExecution", @@ -2841,8 +3030,7 @@ "description": "Bytecode to execute", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } }, "address": { @@ -2853,8 +3041,7 @@ "description": "An operation datastore", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } }, "is_final": { @@ -2877,9 +3064,9 @@ "description": "Read only call", "required": [ "max_gas", - "parameter", "target_address", - "target_function" + "target_function", + "parameter" ], "type": "object", "properties": { @@ -2897,19 +3084,43 @@ }, "parameter": { "description": "Function parameter", - "type": "string" + "type": "array", + "items": { + "type": "integer" + } }, "caller_address": { "description": "Caller's address, optional", - "type": "string" + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] }, "coins": { "description": "Amount in coins, optional", - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] }, "fee": { "description": "Fee, optional", - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] } }, "additionalProperties": false @@ -2923,15 +3134,15 @@ "description": "Included in case of success. The result of the execution", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "number" } }, "Error": { "description": "Included in case of error. The error message", "type": "string" } - } + }, + "additionalProperties": false }, "Roll": { "title": "Roll", @@ -2948,6 +3159,7 @@ "additionalProperties": false }, "RollBuy": { + "title": "RollBuy", "description": "the sender buys `roll_count` rolls. Roll price is defined in configuration", "required": [ "roll_count" @@ -2958,10 +3170,11 @@ "description": "roll count", "type": "number" } - } + }, + "additionalProperties": false }, "RollsInfo": { - "title": "Rolls", + "title": "RollsInfo", "required": [ "active_rolls", "candidate_rolls", @@ -2982,6 +3195,7 @@ "additionalProperties": false }, "RollSell": { + "title": "RollSell", "description": "the sender sells `roll_count` rolls. Roll price is defined in configuration", "required": [ "roll_count" @@ -2992,7 +3206,8 @@ "description": "roll count", "type": "number" } - } + }, + "additionalProperties": false }, "SCOEContext": { "title": "SCOEContext", @@ -3052,11 +3267,12 @@ "additionalProperties": false }, "Signature": { + "title": "Signature", "description": "Signature generated from a message and a `KeyPair`.", "type": "string" }, "Slot": { - "title": "TSlot", + "title": "Slot", "description": "Slot", "required": [ "period", @@ -3099,7 +3315,9 @@ "async_pool_changes", "executed_ops_changes", "ledger_changes", - "pos_changes" + "pos_changes", + "executed_denunciations_changes", + "execution_trail_hash_change" ], "type": "object", "properties": { @@ -3121,6 +3339,14 @@ "executed_ops_changes": { "description": "executed operations changes", "type": "object" + }, + "executed_denunciations_changes": { + "description": "executed denunciation changes", + "type": "object" + }, + "execution_trail_hash_change": { + "description": "execution trail hash change", + "type": "string" } }, "additionalProperties": false @@ -3191,19 +3417,22 @@ "description": "ID of the block in which the operation is included", "type": "string" } - } + }, + "additionalProperties": false }, "Version": { + "title": "Version", "description": "Application version, checked during handshakes", "type": "string" }, "WrappedHeader": { + "title": "WrappedHeader", "description": "signed operation", "required": [ "content", "signature", - "creator_public_key", - "creator_address" + "content_creator_pub_key", + "content_creator_address" ], "type": "object", "properties": { @@ -3215,17 +3444,22 @@ "$ref": "#/components/schemas/Signature", "description": "signature" }, - "creator_public_key": { + "content_creator_pub_key": { "$ref": "#/components/schemas/PublicKey", "description": "the content creator public key" }, - "creator_address": { + "content_creator_address": { "$ref": "#/components/schemas/Address", "description": "the content creator address" + }, + "id": { + "$ref": "#/components/schemas/BlockId" } - } + }, + "additionalProperties": false }, "WrappedOperation": { + "title": "WrappedOperation", "description": "signed operation", "required": [ "content", @@ -3236,22 +3470,25 @@ "type": "object", "properties": { "content": { - "$ref": "#/components/schemas/OperationType", - "description": "operation type" + "$ref": "#/components/schemas/Operation" }, "signature": { "$ref": "#/components/schemas/Signature", "description": "signature" }, - "creator_public_key": { + "content_creator_pub_key": { "$ref": "#/components/schemas/PublicKey", "description": "the content creator public key" }, - "creator_address": { + "content_creator_address": { "$ref": "#/components/schemas/Address", "description": "the content creator address" + }, + "id": { + "$ref": "#/components/schemas/OperationId" } - } + }, + "additionalProperties": false } }, "contentDescriptors": { From 461e894264fe00b6b7c3f43f94680b3add8ada92 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 3 Jun 2024 17:27:22 +0200 Subject: [PATCH 8/9] amount wrapper --- massa-node/base_config/openrpc.json | 31 ++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 89731ca5ad1..09691f2b77f 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -148,8 +148,7 @@ "schema": { "type": "array", "items": { - "type": "string", - "format": "byte" + "type": "number" } }, "name": "Addresses bytecode array" @@ -1516,7 +1515,7 @@ "type": "object" }, "amount": { - "type": "string" + "$ref": "#/components/schemas/Amount" } } }, @@ -1584,6 +1583,11 @@ }, "additionalProperties": false }, + "Amount": { + "title": "Amount", + "description": "Amount in nanoMassa", + "type": "integer" + }, "ApiRequest": { "title": "ApiRequest", "description": "ApiRequest for apiV2", @@ -1607,15 +1611,15 @@ "properties": { "candidate_balance": { "description": "Represent an Amount in coins", - "type": "string" + "$ref": "#/components/schemas/Amount" }, "final_balance": { "description": "Represent an Amount in coins", - "type": "string" + "$ref": "#/components/schemas/Amount" }, "locked_balance": { "description": "Represent an Amount in coins", - "type": "string" + "$ref": "#/components/schemas/Amount" } }, "additionalProperties": false @@ -3107,7 +3111,8 @@ "type": "null" }, { - "type": "number" + "$ref": "#/components/schemas/Amount", + "description": "Amount in nanoMassa" } ] }, @@ -3395,11 +3400,11 @@ }, "amount": { "description": "Amount transferred", - "type": "integer" + "$ref": "#/components/schemas/Amount" }, "effective_amount_received": { "description": "Amount received by the receiver", - "type": "integer" + "$ref": "#/components/schemas/Amount" }, "context": { "description": "Context of the transfer : operation or asyncronous execution", @@ -3516,6 +3521,14 @@ "$ref": "#/components/schemas/AddressInfo" } }, + "Amount": { + "name": "Amount", + "summary": "Amount", + "description": "A Amount value in nanoMassa", + "schema": { + "$ref": "#/components/schemas/Amount" + } + }, "BlockId": { "name": "BlockId", "summary": "BlockId", From 27f952ebfbf79bdcdfd438f466969377a0ac1562 Mon Sep 17 00:00:00 2001 From: modship Date: Mon, 3 Jun 2024 17:39:29 +0200 Subject: [PATCH 9/9] remove `LedgerInfo` which is not used --- massa-api-exports/src/ledger.rs | 30 ---------------------------- massa-api-exports/src/lib.rs | 2 -- massa-node/base_config/openrpc.json | 31 ----------------------------- 3 files changed, 63 deletions(-) delete mode 100644 massa-api-exports/src/ledger.rs diff --git a/massa-api-exports/src/ledger.rs b/massa-api-exports/src/ledger.rs deleted file mode 100644 index b9e83094976..00000000000 --- a/massa-api-exports/src/ledger.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2022 MASSA LABS - -use massa_models::amount::Amount; -use massa_models::ledger::LedgerData; - -use serde::{Deserialize, Serialize}; - -/// Current balance ledger info -#[derive(Debug, Deserialize, Serialize, Clone, Copy)] -pub struct LedgerInfo { - /// final data - pub final_ledger_info: LedgerData, - /// latest data - pub candidate_ledger_info: LedgerData, - /// locked balance, for example balance due to a roll sell - pub locked_balance: Amount, -} - -impl std::fmt::Display for LedgerInfo { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - writeln!(f, "\tFinal balance: {}", self.final_ledger_info.balance)?; - writeln!( - f, - "\tCandidate balance: {}", - self.candidate_ledger_info.balance - )?; - writeln!(f, "\tLocked balance: {}", self.locked_balance)?; - Ok(()) - } -} diff --git a/massa-api-exports/src/lib.rs b/massa-api-exports/src/lib.rs index a723e3ad15f..3307877e135 100644 --- a/massa-api-exports/src/lib.rs +++ b/massa-api-exports/src/lib.rs @@ -23,8 +23,6 @@ pub mod endorsement; pub mod error; /// execution pub mod execution; -/// ledger structures -pub mod ledger; /// node related structure pub mod node; /// operations diff --git a/massa-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 09691f2b77f..dbd091a51af 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -1584,8 +1584,6 @@ "additionalProperties": false }, "Amount": { - "title": "Amount", - "description": "Amount in nanoMassa", "type": "integer" }, "ApiRequest": { @@ -2615,34 +2613,6 @@ }, "additionalProperties": false }, - "LedgerInfo": { - "title": "SceLedgerInfo", - "required": [ - "balance", - "datastore" - ], - "type": "object", - "properties": { - "balance": { - "description": "Represent an amount", - "type": "string" - }, - "module": { - "description": "Stored bytecode", - "type": "array", - "items": { - "type": "integer" - } - }, - "datastore": { - "type": "array", - "items": { - "$ref": "#/components/schemas/DataStore" - } - } - }, - "additionalProperties": false - }, "NetworkStats": { "title": "NetworkStats", "description": "Network stats", @@ -3523,7 +3493,6 @@ }, "Amount": { "name": "Amount", - "summary": "Amount", "description": "A Amount value in nanoMassa", "schema": { "$ref": "#/components/schemas/Amount"