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-api-exports/src/operation.rs b/massa-api-exports/src/operation.rs index b4caadf85e3..3a2e71e50bc 100644 --- a/massa-api-exports/src/operation.rs +++ b/massa-api-exports/src/operation.rs @@ -71,14 +71,13 @@ mod tests { use massa_models::{amount::Amount, operation::OperationType}; use serial_test::serial; use std::collections::BTreeMap; - use std::str::FromStr; #[test] #[serial] 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 293ea753b2d..3d1653f3509 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_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(|| { @@ -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(), 100); + // 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(), 100); + + assert_eq!(deserialized_amount.to_string(), "100"); + assert_eq!(deserialized_amount.to_raw(), 100); + 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_raw(10000000)), coins: None, }]]; let response: Vec = client @@ -842,8 +876,8 @@ async fn get_addresses() { exec_ctrl.expect_get_addresses_infos().returning(|a, _s| { 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 9b5379426ea..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], @@ -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![], @@ -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/pool.rs b/massa-async-pool/src/pool.rs index 403787e3388..9ab3028471b 100644 --- a/massa-async-pool/src/pool.rs +++ b/massa-async-pool/src/pool.rs @@ -1075,8 +1075,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 9bd529984e7..32f9be5c29f 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) @@ -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-execution-worker/src/tests/universe.rs b/massa-execution-worker/src/tests/universe.rs index 5537484aa89..ba90d11bcd6 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, }; @@ -165,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 d6fedf2a7ab..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; @@ -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_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 cb7f2cda116..d893070c317 100644 --- a/massa-final-state/src/final_state.rs +++ b/massa-final-state/src/final_state.rs @@ -1065,8 +1065,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], @@ -1079,7 +1079,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/test_exports/mock.rs b/massa-final-state/src/test_exports/mock.rs index 741a2f27589..4b93b35a92b 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-final-state/src/tests/scenarios.rs b/massa-final-state/src/tests/scenarios.rs index 0d862e30dd9..23798696d82 100644 --- a/massa-final-state/src/tests/scenarios.rs +++ b/massa-final-state/src/tests/scenarios.rs @@ -182,8 +182,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], @@ -196,7 +196,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-grpc/src/tests/stream.rs b/massa-grpc/src/tests/stream.rs index 97935bbf2c5..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] @@ -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-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 56886211cb3..eddcab1ad9d 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; @@ -582,12 +581,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() }; @@ -647,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 afd347f020e..e3b805d423d 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; @@ -35,14 +34,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 +65,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 +90,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 +104,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 +124,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) } @@ -262,12 +253,12 @@ 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 { - write!(f, "{}", self.to_decimal()) + write!(f, "{}", self.to_raw()) } } @@ -278,14 +269,13 @@ 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; -/// 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()); @@ -295,9 +285,10 @@ 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 amount = str_amount.parse::().map_err(|_| { + ModelsError::AmountParseError(format!("invalid integer : {}", str_amount)) + })?; + Ok(Amount(amount)) } } @@ -330,7 +321,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(); @@ -375,7 +366,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![]; @@ -396,12 +387,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 +430,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 +447,6 @@ impl serde::Serialize for Amount { where S: serde::Serializer, { - serializer.serialize_str(&self.to_string()) + serializer.serialize_u64(self.to_raw()) } } diff --git a/massa-models/src/operation.rs b/massa-models/src/operation.rs index eaea9e9c2db..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(); @@ -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-node/base_config/openrpc.json b/massa-node/base_config/openrpc.json index 3cae8316422..534ed001299 100644 --- a/massa-node/base_config/openrpc.json +++ b/massa-node/base_config/openrpc.json @@ -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,7 @@ "schema": { "type": "array", "items": { - "type": "integer" + "type": "number" } }, "name": "Addresses bytecode array" @@ -180,13 +180,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 +234,7 @@ "$ref": "#/components/schemas/Clique" } }, - "name": "Clique(s)" + "name": "Cliques" }, "name": "get_cliques", "summary": "Get cliques", @@ -246,7 +249,7 @@ ], "params": [ { - "name": "DatastoreEntryInput(s)", + "name": "DatastoreEntryInputs", "description": "Datastore entry input", "schema": { "type": "array", @@ -263,46 +266,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 +335,7 @@ "$ref": "#/components/schemas/EndorsementInfo" } }, - "name": "EndorsementInfo(s)" + "name": "EndorsementInfos" }, "name": "get_endorsements", "summary": "Get endorsements", @@ -394,7 +363,7 @@ "$ref": "#/components/schemas/SCOutputEvent" } }, - "name": "SCOutputEvent(s)" + "name": "SCOutputEvents" }, "name": "get_filtered_sc_output_event", "summary": "Returns events optionally filtered", @@ -409,23 +378,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 +433,7 @@ "$ref": "#/components/schemas/OperationInfo" } }, - "name": "OperationInfo(s)" + "name": "OperationInfos" }, "name": "get_operations", "summary": "Get operations", @@ -559,7 +532,7 @@ } }, "description": "The strings are addresses.", - "name": "Address(es)" + "name": "Addresses" }, "name": "get_staking_addresses", "summary": "Return hashset of staking addresses", @@ -575,7 +548,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 +565,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 +578,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 +595,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 +608,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 +625,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 +654,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 +683,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 +696,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 +706,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 +719,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 +729,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 +759,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 +769,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 +782,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 +799,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 +812,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 +829,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 +842,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 +859,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 +872,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 +889,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 +994,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 +1024,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 +1037,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 +1054,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 +1072,8 @@ "items": { "$ref": "#/components/schemas/OperationInput" } - } + }, + "required": true } ], "result": { @@ -1109,7 +1083,7 @@ "$ref": "#/components/schemas/OperationId" } }, - "name": "Operation(s)" + "name": "Operations" }, "name": "send_operations", "summary": "Adds operations to pool", @@ -1445,10 +1419,12 @@ "components": { "schemas": { "Address": { + "title": "Address", "description": "Address", "type": "string" }, "AddressFilter": { + "title": "AddressFilter", "description": "Address filter", "type": "object", "properties": { @@ -1460,7 +1436,8 @@ "type": "boolean", "description": "true means final, false means candidate" } - } + }, + "additionalProperties": false }, "AddressInfo": { "title": "AddressInfo", @@ -1493,7 +1470,7 @@ }, "final_balance": { "description": "The final balance", - "type": "number" + "type": "string" }, "final_roll_count": { "description": "The final roll count", @@ -1511,7 +1488,7 @@ }, "candidate_balance": { "description": "The candidate balance", - "type": "number" + "type": "string" }, "candidate_roll_count": { "description": "The candidate roll count", @@ -1538,10 +1515,11 @@ "type": "object" }, "amount": { - "type": "number" + "$ref": "#/components/schemas/Amount" } } - } + }, + "minItems": 0 }, "next_block_draws": { "description": "The next block draws", @@ -1569,15 +1547,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", @@ -1590,7 +1583,11 @@ }, "additionalProperties": false }, + "Amount": { + "type": "integer" + }, "ApiRequest": { + "title": "ApiRequest", "description": "ApiRequest for apiV2", "type": "object", "properties": { @@ -1598,7 +1595,8 @@ "$ref": "#/components/schemas/PageRequest", "description": "Optional page request" } - } + }, + "additionalProperties": false }, "Balance": { "title": "Balance", @@ -1611,15 +1609,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 @@ -1647,6 +1645,7 @@ "additionalProperties": false }, "BlockId": { + "title": "BlockId", "description": "Block identifier", "type": "string" }, @@ -1672,7 +1671,7 @@ "block", "is_final", "is_in_blockclique", - "is_stale" + "is_candidate" ], "type": "object", "properties": { @@ -1680,8 +1679,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 +1753,7 @@ "additionalProperties": false }, "Clique": { + "title": "Clique", "description": "Clique", "required": [ "block_ids", @@ -1773,7 +1777,8 @@ "description": "True if it is the clique of higher fitness", "type": "boolean" } - } + }, + "additionalProperties": false }, "CompactConfig": { "title": "Config", @@ -1784,11 +1789,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 +1806,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 +1831,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 +1873,6 @@ "clique_count", "end_timespan", "final_block_count", - "final_operation_count", - "staker_count", "stale_block_count", "start_timespan" ], @@ -1887,18 +1888,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 +1936,7 @@ ] }, "DataStoreEntry": { + "title": "DatastoreEntry", "description": "Datastore entry", "type": "object", "properties": { @@ -1952,9 +1948,11 @@ "description": "", "type": "string" } - } + }, + "additionalProperties": false }, "DatastoreEntryInput": { + "title": "DatastoreEntryInput", "description": "", "required": [ "address", @@ -1963,29 +1961,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 +2067,7 @@ "description": "Endorsement", "required": [ "content", - "creator_public_key", + "content_creator_pub_key", "signature" ], "type": "object", @@ -2003,18 +2075,14 @@ "content": { "$ref": "#/components/schemas/EndorsementContent" }, - "creator_public_key": { - "$ref": "#/components/schemas/PublicKey", - "description": "the content creator public key" + "content_creator_pub_key": { + "$ref": "#/components/schemas/PublicKey" }, - "creator_address": { - "type": "string" - }, - "thread": { - "type": "number" + "content_creator_address": { + "$ref": "#/components/schemas/Address" }, "id": { - "type": "string" + "$ref": "#/components/schemas/EndorsementId" }, "signature": { "type": "string" @@ -2022,20 +2090,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 +2147,7 @@ "type": "number" }, "endorsed_block": { - "type": "string" + "$ref": "#/components/schemas/BlockId" } }, "additionalProperties": false @@ -2065,6 +2169,11 @@ }, "additionalProperties": false }, + "EndorsementId": { + "title": "EndorsementId", + "description": "Endorsement id", + "type": "string" + }, "EndorsementInfo": { "title": "EndorsementInfo", "description": "Endorsement info", @@ -2078,7 +2187,7 @@ "type": "object", "properties": { "id": { - "type": "string" + "$ref": "#/components/schemas/EndorsementId" }, "in_pool": { "type": "boolean" @@ -2087,7 +2196,7 @@ "description": "Block Id", "type": "array", "items": { - "type": "string" + "$ref": "#/components/schemas/BlockId" } }, "is_final": { @@ -2095,13 +2204,13 @@ }, "endorsement": { "$ref": "#/components/schemas/Endorsement", - "description": "Endorsement Id" + "description": "Endorsement" } }, "additionalProperties": false }, "ExecutedAt": { - "title": "Slot", + "title": "ExecuteAt", "required": [ "period", "thread" @@ -2201,9 +2310,17 @@ "type": "number" }, "active_rolls": { - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] } - } + }, + "additionalProperties": false }, "EventFilter": { "title": "EventFilter", @@ -2311,6 +2428,7 @@ "additionalProperties": false }, "IpAddress": { + "title": "IpAddress", "description": "Ipv4 or Ipv6 address", "type": "string" }, @@ -2427,15 +2545,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,34 +2577,38 @@ }, "slot": { "$ref": "#/components/schemas/Slot" - } - }, - "additionalProperties": false - }, - "LedgerInfo": { - "title": "SceLedgerInfo", - "required": [ - "balance", - "datastore" - ], - "type": "object", - "properties": { - "balance": { - "description": "Represent an amount", - "type": "string" }, - "module": { - "description": "Stored bytecode", + "endorsements": { + "description": "Endorsements", "type": "array", "items": { - "type": "integer" + "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" + } + } } }, - "datastore": { + "denunciations": { + "description": "Denunciations", "type": "array", "items": { - "$ref": "#/components/schemas/DataStore" - } + "$ref": "#/components/schemas/Denunciation" + }, + "minItems": 0 } }, "additionalProperties": false @@ -2530,7 +2663,9 @@ "next_slot", "node_id", "pool_stats", - "version" + "version", + "execution_stats", + "chain_id" ], "type": "object", "properties": { @@ -2580,7 +2715,14 @@ }, "node_ip": { "description": "Optional node ip if provided", - "type": "string" + "oneOf": [ + { + "type": "null" + }, + { + "type": "string" + } + ] }, "pool_stats": { "$ref": "#/components/schemas/PoolStats", @@ -2589,6 +2731,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 +2769,7 @@ "additionalProperties": false }, "OperationId": { + "title": "OperationId", "description": "Operation id", "type": "string" }, @@ -2629,7 +2780,7 @@ "id", "in_blocks", "in_pool", - "is_final", + "is_operation_final", "thread", "operation" ], @@ -2643,16 +2794,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 +2822,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 +2853,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 +2886,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 +2904,11 @@ "offset": { "type": "number" } - } + }, + "additionalProperties": false }, "PagedVecStaker": { + "title": "PagedVecStaker", "description": "PagedVec of stakers for apiV2", "type": "object", "properties": { @@ -2753,27 +2921,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 +2963,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 +2984,8 @@ "description": "signature", "type": "string" } - } + }, + "additionalProperties": false }, "ReadOnlyBytecodeExecution": { "title": "ReadOnlyBytecodeExecution", @@ -2841,8 +3004,7 @@ "description": "Bytecode to execute", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } }, "address": { @@ -2853,8 +3015,7 @@ "description": "An operation datastore", "type": "array", "items": { - "format": "byte", - "type": "string" + "type": "integer" } }, "is_final": { @@ -2877,9 +3038,9 @@ "description": "Read only call", "required": [ "max_gas", - "parameter", "target_address", - "target_function" + "target_function", + "parameter" ], "type": "object", "properties": { @@ -2897,19 +3058,44 @@ }, "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" + }, + { + "$ref": "#/components/schemas/Amount", + "description": "Amount in nanoMassa" + } + ] }, "fee": { "description": "Fee, optional", - "type": "number" + "oneOf": [ + { + "type": "null" + }, + { + "type": "number" + } + ] } }, "additionalProperties": false @@ -2923,15 +3109,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 +3134,7 @@ "additionalProperties": false }, "RollBuy": { + "title": "RollBuy", "description": "the sender buys `roll_count` rolls. Roll price is defined in configuration", "required": [ "roll_count" @@ -2958,10 +3145,11 @@ "description": "roll count", "type": "number" } - } + }, + "additionalProperties": false }, "RollsInfo": { - "title": "Rolls", + "title": "RollsInfo", "required": [ "active_rolls", "candidate_rolls", @@ -2982,6 +3170,7 @@ "additionalProperties": false }, "RollSell": { + "title": "RollSell", "description": "the sender sells `roll_count` rolls. Roll price is defined in configuration", "required": [ "roll_count" @@ -2992,7 +3181,8 @@ "description": "roll count", "type": "number" } - } + }, + "additionalProperties": false }, "SCOEContext": { "title": "SCOEContext", @@ -3052,11 +3242,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 +3290,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 +3314,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 @@ -3169,11 +3370,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", @@ -3191,19 +3392,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 +3419,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 +3445,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": { @@ -3279,6 +3491,13 @@ "$ref": "#/components/schemas/AddressInfo" } }, + "Amount": { + "name": "Amount", + "description": "A Amount value in nanoMassa", + "schema": { + "$ref": "#/components/schemas/Amount" + } + }, "BlockId": { "name": "BlockId", "summary": "BlockId", 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 4c86f3ce5e8..c19f7bb1f08 100644 --- a/massa-pos-exports/src/pos_final_state.rs +++ b/massa-pos-exports/src/pos_final_state.rs @@ -1663,10 +1663,10 @@ mod tests { let deferred_credits = pos_state.get_deferred_credits().credits; 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), @@ -1676,7 +1676,7 @@ mod tests { ), ( Slot::new(4, 1), - vec![(addr1, Amount::from_str("6.0").unwrap())] + vec![(addr1, Amount::from_raw(6000000000))] .into_iter() .collect(), ),