pub struct Amount { /* private fields */ }Expand description
A quantity of a Hive asset, held as an integer count of its smallest unit.
Implementations§
Source§impl Amount
impl Amount
Sourcepub fn from_units(units: i64, symbol: &str, chain: Chain) -> Result<Self>
pub fn from_units(units: i64, symbol: &str, chain: Chain) -> Result<Self>
Build from a raw unit count and a symbol on the given chain.
Sourcepub fn parse(s: &str, chain: Chain) -> Result<Self>
pub fn parse(s: &str, chain: Chain) -> Result<Self>
Parse Hive’s textual amount form, "1.234 HIVE".
The decimal string is converted to an integer directly. A value with more decimal places than the asset allows is an error, not a silent truncation: quietly dropping a digit from a monetary amount transfers a different sum than the caller asked for.
Sourcepub fn wire_symbol(&self) -> &'static str
pub fn wire_symbol(&self) -> &'static str
The symbol used in the legacy binary encoding, e.g. STEEM.
Sourcepub fn checked_add(&self, other: &Amount) -> Result<Amount>
pub fn checked_add(&self, other: &Amount) -> Result<Amount>
Add two amounts of the same asset. Refuses a mismatch rather than coercing.
Sourcepub fn checked_sub(&self, other: &Amount) -> Result<Amount>
pub fn checked_sub(&self, other: &Amount) -> Result<Amount>
Subtract two amounts of the same asset.
Sourcepub fn to_nai_json(&self, chain: Chain) -> Result<Value>
pub fn to_nai_json(&self, chain: Chain) -> Result<Value>
The NAI-style JSON form used by database_api:
{"amount": "1234", "precision": 3, "nai": "@@000000021"}.
Trait Implementations§
impl Copy for Amount
Source§impl<'de> Deserialize<'de> for Amount
Amounts arrive from the API in two different shapes, and both are accepted.
impl<'de> Deserialize<'de> for Amount
Amounts arrive from the API in two different shapes, and both are accepted.
condenser_api and the legacy forms send the textual "1.234 HIVE". database_api
and account_history_api in appbase mode send the NAI object
{"amount": "1234", "precision": 3, "nai": "@@000000021"}. beem handled both too,
but by branching on isinstance inside Amount.__init__ across four cases.
Deserialization resolves symbols against Hive mainnet. For a testnet, decode
the raw JSON and use Amount::from_units with the right chain.
Source§fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(d: D) -> Result<Self, D::Error>
impl Eq for Amount
Source§impl GrapheneDeserialize for Amount
impl GrapheneDeserialize for Amount
Source§fn read_from(r: &mut Reader<'_>) -> Result<Self>
fn read_from(r: &mut Reader<'_>) -> Result<Self>
Read the 16-byte legacy asset: int64 units, uint8 precision, 7-byte
NUL-padded symbol.
The symbol is resolved against the reader’s chain and cross-checked: an asset whose declared precision disagrees with the chain’s is refused rather than silently reinterpreted, because that mismatch means the bytes are not the asset they claim to be.
Source§impl GrapheneSerialize for Amount
impl GrapheneSerialize for Amount
Source§impl Ord for Amount
impl Ord for Amount
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Amount
impl PartialOrd for Amount
Source§impl Serialize for Amount
Amounts render in Hive’s textual form, "1.234 HIVE", which is what
condenser_api and network_broadcast_api accept.
impl Serialize for Amount
Amounts render in Hive’s textual form, "1.234 HIVE", which is what
condenser_api and network_broadcast_api accept.
impl StructuralPartialEq for Amount
Auto Trait Implementations§
impl Freeze for Amount
impl RefUnwindSafe for Amount
impl Send for Amount
impl Sync for Amount
impl Unpin for Amount
impl UnsafeUnpin for Amount
impl UnwindSafe for Amount
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.