-
Notifications
You must be signed in to change notification settings - Fork 119
Open
Labels
good first issueGood for newcomersGood for newcomersrustIssues that affect or pull requests that update Rust codeIssues that affect or pull requests that update Rust codestandardsRelated to standard note scripts or account componentsRelated to standard note scripts or account components
Description
We should add a dedicated type that represents a valid amount in a FungibleAsset. This could be called FungibleAssetAmount or AssetAmount. The former is a bit clearer to which type it belongs while the latter is more concise. I think I'd go with the former.
It should probably have at least these parts:
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct FungibleAssetAmount(u64);
impl FungibleAssetAmount {
// Replaces from FungibleAsset::MAX_AMOUNT
pub const MAX: Self = Self(2u64.pow(63) - 2u64.pow(31));
/// Returns an error if amount exceeds Self::MAX.
pub fn new(amount: u64) -> Result<Self, _> { ... }
}
impl From<u8> for FungibleAssetAmount { ... }
impl From<u16> for FungibleAssetAmount { ... }
impl From<u32> for FungibleAssetAmount { ... }
impl TryFrom<u64> for FungibleAssetAmount { ... }
impl core::fmt::Display for FungibleAssetAmount { ... }We should definitely avoid constructors that take an arbitrary u64 and round it down to % FungibleAssetAmount::MAX.
The need for this came up in a few places:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersrustIssues that affect or pull requests that update Rust codeIssues that affect or pull requests that update Rust codestandardsRelated to standard note scripts or account componentsRelated to standard note scripts or account components