Add amount conversion for Orchard values.
This commit is contained in:
parent
2ae55b4145
commit
4bcad97ba1
|
@ -2,6 +2,8 @@ use std::convert::TryFrom;
|
|||
use std::iter::Sum;
|
||||
use std::ops::{Add, AddAssign, Neg, Sub, SubAssign};
|
||||
|
||||
use orchard::value as orchard;
|
||||
|
||||
pub const COIN: i64 = 1_0000_0000;
|
||||
pub const MAX_MONEY: i64 = 21_000_000 * COIN;
|
||||
|
||||
|
@ -180,6 +182,14 @@ impl Neg for Amount {
|
|||
}
|
||||
}
|
||||
|
||||
impl TryFrom<orchard::ValueSum> for Amount {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(v: orchard::ValueSum) -> Result<Amount, Self::Error> {
|
||||
i64::try_from(v).map_err(|_| ()).and_then(Amount::try_from)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(test, feature = "test-dependencies"))]
|
||||
pub mod testing {
|
||||
use proptest::prelude::prop_compose;
|
||||
|
|
Loading…
Reference in New Issue