Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve Amount usage in api #4688

Open
modship opened this issue May 7, 2024 · 3 comments · May be fixed by #4699
Open

Improve Amount usage in api #4688

modship opened this issue May 7, 2024 · 3 comments · May be fixed by #4699
Assignees
Labels
api Issues related to the API

Comments

@modship
Copy link
Member

modship commented May 7, 2024

First

And then we should also :

  • Update massa Amount serializer/deserializer str to accept string in nMAS and u64 nMAS (check if is decimal or no)
  • update the openrpc api spec and create Amount wrapper which is oneOf [ string, number]
@modship
Copy link
Member Author

modship commented May 29, 2024

Some modifications should be done, we can't safely accept Massa and nanoMassa in from str.

So, now the number provided is in nanoMassa not in Massa and we return errors when a decimal is provided

@AurelienFT can u validate if this test verify all case

#[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);
}

@AurelienFT
Copy link
Contributor

@modship sorry for the late reply the test seems very effective.

@modship
Copy link
Member Author

modship commented Jun 3, 2024

impact in config files :

  • config.toml
    • minimal_fees should be update from 0.01 to 10000000
  • initial_ledger.json
    • balance should be update from ex "1000" string massa to 1000000000000 nanoMassa (has u64)

Also interface_impl.rs :

  • native_amount_from_str_wasmv1
  • native_amount_to_string_wasmv1

massa-client :

  • read_only_execute_smart_contract
    • fee is now nanoMassa instead of Massa
  • read_only_call
    • coins && fee in nanoMassa instead of Massa
  • wallet_info
    • display balance in nanoMassa
    • deferred_credits in nanoMassa

Api :

  • JSONRpc
    • get_status minimal_fee in nanoMassa
    • get_addresses
      • final_balance , candidate_balance, deferred_credits → nanoMassa

@modship modship linked a pull request Jun 3, 2024 that will close this issue
8 tasks
@modship modship added the api Issues related to the API label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants