mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-15 04:58:12 -07:00
global: snapshot
This commit is contained in:
@@ -2,11 +2,11 @@ mod addressbytes;
|
||||
mod addressindex;
|
||||
mod addresstype;
|
||||
mod addresstypeindex;
|
||||
mod amount;
|
||||
mod blockhash;
|
||||
mod compressed;
|
||||
mod height;
|
||||
mod locktime;
|
||||
mod sats;
|
||||
mod timestamp;
|
||||
mod txid;
|
||||
mod txindex;
|
||||
@@ -21,11 +21,11 @@ pub use addressbytes::*;
|
||||
pub use addressindex::*;
|
||||
pub use addresstype::*;
|
||||
pub use addresstypeindex::*;
|
||||
pub use amount::*;
|
||||
pub use blockhash::*;
|
||||
pub use compressed::*;
|
||||
pub use height::*;
|
||||
pub use locktime::*;
|
||||
pub use sats::*;
|
||||
pub use timestamp::*;
|
||||
pub use txid::*;
|
||||
pub use txindex::*;
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::{
|
||||
};
|
||||
|
||||
use derive_deref::{Deref, DerefMut};
|
||||
use iterator::bitcoin;
|
||||
use iterator::bitcoin::Amount;
|
||||
use serde::Serialize;
|
||||
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
|
||||
|
||||
@@ -27,85 +27,83 @@ use super::Height;
|
||||
KnownLayout,
|
||||
Serialize,
|
||||
)]
|
||||
pub struct Amount(u64);
|
||||
pub struct Sats(u64);
|
||||
|
||||
impl Amount {
|
||||
impl Sats {
|
||||
pub const ZERO: Self = Self(0);
|
||||
pub const ONE_BTC_F32: f32 = 100_000_000.0;
|
||||
pub const ONE_BTC_F64: f64 = 100_000_000.0;
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
*self == Self::ZERO
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Amount {
|
||||
type Output = Amount;
|
||||
fn add(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self + *rhs)
|
||||
impl Add for Sats {
|
||||
type Output = Sats;
|
||||
fn add(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self + *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl AddAssign for Amount {
|
||||
impl AddAssign for Sats {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
*self = *self + rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for Amount {
|
||||
type Output = Amount;
|
||||
fn sub(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self - *rhs)
|
||||
impl Sub for Sats {
|
||||
type Output = Sats;
|
||||
fn sub(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self - *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl SubAssign for Amount {
|
||||
impl SubAssign for Sats {
|
||||
fn sub_assign(&mut self, rhs: Self) {
|
||||
*self = *self - rhs;
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Amount> for Amount {
|
||||
type Output = Amount;
|
||||
fn mul(self, rhs: Amount) -> Self::Output {
|
||||
Amount::from(*self * *rhs)
|
||||
impl Mul<Sats> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: Sats) -> Self::Output {
|
||||
Sats::from(*self * *rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<u64> for Amount {
|
||||
type Output = Amount;
|
||||
impl Mul<u64> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: u64) -> Self::Output {
|
||||
Amount::from(*self * rhs)
|
||||
Sats::from(*self * rhs)
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<Height> for Amount {
|
||||
type Output = Amount;
|
||||
impl Mul<Height> for Sats {
|
||||
type Output = Sats;
|
||||
fn mul(self, rhs: Height) -> Self::Output {
|
||||
Amount::from(*self * *rhs as u64)
|
||||
Sats::from(*self * *rhs as u64)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sum for Amount {
|
||||
impl Sum for Sats {
|
||||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
|
||||
let sats: u64 = iter.map(|amt| *amt).sum();
|
||||
Amount::from(sats)
|
||||
let sats: u64 = iter.map(|sats| *sats).sum();
|
||||
Sats::from(sats)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<u64> for Amount {
|
||||
impl From<u64> for Sats {
|
||||
fn from(value: u64) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bitcoin::Amount> for Amount {
|
||||
fn from(value: bitcoin::Amount) -> Self {
|
||||
impl From<Amount> for Sats {
|
||||
fn from(value: Amount) -> Self {
|
||||
Self(value.to_sat())
|
||||
}
|
||||
}
|
||||
impl From<Amount> for bitcoin::Amount {
|
||||
fn from(value: Amount) -> Self {
|
||||
impl From<Sats> for Amount {
|
||||
fn from(value: Sats) -> Self {
|
||||
Self::from_sat(value.0)
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ use derive_deref::Deref;
|
||||
pub struct Vout(u32);
|
||||
|
||||
impl Vout {
|
||||
const ZERO: Self = Vout(0_u32);
|
||||
const ZERO: Self = Vout(0);
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
*self == Self::ZERO
|
||||
|
||||
Reference in New Issue
Block a user