Amount::{zero, is_positive, is_negative}
This commit is contained in:
parent
fa50d551c8
commit
0ea4408d46
|
@ -79,7 +79,7 @@ impl SaplingOutput {
|
||||||
Some(g_d) => g_d,
|
Some(g_d) => g_d,
|
||||||
None => return Err(Error(ErrorKind::InvalidAddress)),
|
None => return Err(Error(ErrorKind::InvalidAddress)),
|
||||||
};
|
};
|
||||||
if value.0 < 0 {
|
if value.is_negative() {
|
||||||
return Err(Error(ErrorKind::InvalidAmount));
|
return Err(Error(ErrorKind::InvalidAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ impl<R: RngCore + CryptoRng> Builder<R> {
|
||||||
to: &TransparentAddress,
|
to: &TransparentAddress,
|
||||||
value: Amount,
|
value: Amount,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
if value.0 < 0 {
|
if value.is_negative() {
|
||||||
return Err(Error(ErrorKind::InvalidAmount));
|
return Err(Error(ErrorKind::InvalidAmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,11 @@ const MAX_MONEY: i64 = 21_000_000 * COIN;
|
||||||
pub struct Amount(pub i64);
|
pub struct Amount(pub i64);
|
||||||
|
|
||||||
impl Amount {
|
impl Amount {
|
||||||
|
/// Returns a zero-valued Amount.
|
||||||
|
pub const fn zero() -> Self {
|
||||||
|
Amount(0)
|
||||||
|
}
|
||||||
|
|
||||||
// Read an Amount from a signed 64-bit little-endian integer.
|
// Read an Amount from a signed 64-bit little-endian integer.
|
||||||
pub fn read_i64<R: Read>(mut reader: R, allow_negative: bool) -> io::Result<Self> {
|
pub fn read_i64<R: Read>(mut reader: R, allow_negative: bool) -> io::Result<Self> {
|
||||||
let amount = reader.read_i64::<LittleEndian>()?;
|
let amount = reader.read_i64::<LittleEndian>()?;
|
||||||
|
@ -39,6 +44,18 @@ impl Amount {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive and `false` if the number is zero or
|
||||||
|
/// negative.
|
||||||
|
pub const fn is_positive(self) -> bool {
|
||||||
|
self.0.is_positive()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is negative and `false` if the number is zero or
|
||||||
|
/// positive.
|
||||||
|
pub const fn is_negative(self) -> bool {
|
||||||
|
self.0.is_negative()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -112,7 +112,7 @@ impl TransactionData {
|
||||||
vout: vec![],
|
vout: vec![],
|
||||||
lock_time: 0,
|
lock_time: 0,
|
||||||
expiry_height: 0,
|
expiry_height: 0,
|
||||||
value_balance: Amount(0),
|
value_balance: Amount::zero(),
|
||||||
shielded_spends: vec![],
|
shielded_spends: vec![],
|
||||||
shielded_outputs: vec![],
|
shielded_outputs: vec![],
|
||||||
joinsplits: vec![],
|
joinsplits: vec![],
|
||||||
|
@ -190,7 +190,7 @@ impl Transaction {
|
||||||
let so = Vector::read(&mut reader, OutputDescription::read)?;
|
let so = Vector::read(&mut reader, OutputDescription::read)?;
|
||||||
(vb, ss, so)
|
(vb, ss, so)
|
||||||
} else {
|
} else {
|
||||||
(Amount(0), vec![], vec![])
|
(Amount::zero(), vec![], vec![])
|
||||||
};
|
};
|
||||||
|
|
||||||
let (joinsplits, joinsplit_pubkey, joinsplit_sig) = if version >= 2 {
|
let (joinsplits, joinsplit_pubkey, joinsplit_sig) = if version >= 2 {
|
||||||
|
|
Loading…
Reference in New Issue