mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-22 08:28:10 -07:00
global: fmt
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
use std::path::Path;
|
||||
|
||||
use brk_error::Result;
|
||||
use brk_types::{Age, Cents, CentsCompact, CentsSats, CentsSquaredSats, CostBasisSnapshot, Height, Sats, SupplyState};
|
||||
use brk_types::{
|
||||
Age, Cents, CentsCompact, CentsSats, CentsSquaredSats, CostBasisSnapshot, Height, Sats,
|
||||
SupplyState,
|
||||
};
|
||||
|
||||
use super::super::{cost_basis::{Accumulate, CostBasisData, CostBasisOps, RealizedOps, UnrealizedState}, pending::PendingDelta};
|
||||
use super::super::{
|
||||
cost_basis::{Accumulate, CostBasisData, CostBasisOps, RealizedOps, UnrealizedState},
|
||||
pending::PendingDelta,
|
||||
};
|
||||
|
||||
pub struct SendPrecomputed {
|
||||
pub sats: Sats,
|
||||
@@ -193,11 +199,7 @@ impl<R: RealizedOps, C: CostBasisOps> CohortState<R, C> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn send_utxo_precomputed(
|
||||
&mut self,
|
||||
supply: &SupplyState,
|
||||
pre: &SendPrecomputed,
|
||||
) {
|
||||
pub(crate) fn send_utxo_precomputed(&mut self, supply: &SupplyState, pre: &SendPrecomputed) {
|
||||
self.supply -= supply;
|
||||
self.sent += pre.sats;
|
||||
self.spent_utxo_count += supply.utxo_count;
|
||||
@@ -205,8 +207,13 @@ impl<R: RealizedOps, C: CostBasisOps> CohortState<R, C> {
|
||||
self.satdays_destroyed += pre.age.satdays_destroyed(pre.sats);
|
||||
}
|
||||
|
||||
self.realized
|
||||
.send(pre.sats, pre.current_ps, pre.prev_ps, pre.ath_ps, pre.prev_investor_cap);
|
||||
self.realized.send(
|
||||
pre.sats,
|
||||
pre.current_ps,
|
||||
pre.prev_ps,
|
||||
pre.ath_ps,
|
||||
pre.prev_investor_cap,
|
||||
);
|
||||
|
||||
self.cost_basis
|
||||
.decrement(pre.prev_price, pre.sats, pre.prev_ps, pre.prev_investor_cap);
|
||||
|
||||
@@ -370,7 +370,11 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
let (base, rest) = CostBasisDistribution::deserialize_with_rest(&data)?;
|
||||
self.map = Some(base);
|
||||
self.raw.state = Some(RawState::deserialize(rest)?);
|
||||
debug_assert!(rest.len() >= 32, "CostBasisData state too short: {} bytes", rest.len());
|
||||
debug_assert!(
|
||||
rest.len() >= 32,
|
||||
"CostBasisData state too short: {} bytes",
|
||||
rest.len()
|
||||
);
|
||||
self.investor_cap_raw = CentsSquaredSats::from_bytes(&rest[16..32])?;
|
||||
self.pending.clear();
|
||||
self.raw.pending_cap = PendingCapDelta::default();
|
||||
@@ -435,7 +439,9 @@ impl<S: Accumulate> CostBasisOps for CostBasisData<S> {
|
||||
Path: {:?}\n\
|
||||
Current (after increments): {:?}\n\
|
||||
Trying to decrement by: {:?}",
|
||||
self.raw.pathbuf, self.investor_cap_raw, self.pending_investor_cap.dec
|
||||
self.raw.pathbuf,
|
||||
self.investor_cap_raw,
|
||||
self.pending_investor_cap.dec
|
||||
);
|
||||
self.investor_cap_raw -= self.pending_investor_cap.dec;
|
||||
self.pending_investor_cap = PendingInvestorCapDelta::default();
|
||||
|
||||
@@ -6,7 +6,7 @@ pub use data::*;
|
||||
pub use realized::*;
|
||||
pub use unrealized::UnrealizedState;
|
||||
|
||||
pub(crate) use unrealized::{Accumulate, WithoutCapital, WithCapital};
|
||||
pub(crate) use unrealized::{Accumulate, WithCapital, WithoutCapital};
|
||||
|
||||
// Internal use only
|
||||
pub(super) use unrealized::CachedUnrealizedState;
|
||||
|
||||
@@ -58,10 +58,18 @@ pub trait Accumulate: Default + Clone + Send + Sync + 'static {
|
||||
fn core(&self) -> &WithoutCapital;
|
||||
fn core_mut(&mut self) -> &mut WithoutCapital;
|
||||
|
||||
fn supply_in_profit(&self) -> Sats { self.core().supply_in_profit }
|
||||
fn supply_in_loss(&self) -> Sats { self.core().supply_in_loss }
|
||||
fn unrealized_profit(&mut self) -> &mut u128 { &mut self.core_mut().unrealized_profit }
|
||||
fn unrealized_loss(&mut self) -> &mut u128 { &mut self.core_mut().unrealized_loss }
|
||||
fn supply_in_profit(&self) -> Sats {
|
||||
self.core().supply_in_profit
|
||||
}
|
||||
fn supply_in_loss(&self) -> Sats {
|
||||
self.core().supply_in_loss
|
||||
}
|
||||
fn unrealized_profit(&mut self) -> &mut u128 {
|
||||
&mut self.core_mut().unrealized_profit
|
||||
}
|
||||
fn unrealized_loss(&mut self) -> &mut u128 {
|
||||
&mut self.core_mut().unrealized_loss
|
||||
}
|
||||
|
||||
fn accumulate_profit(&mut self, price_u128: u128, sats: Sats);
|
||||
fn accumulate_loss(&mut self, price_u128: u128, sats: Sats);
|
||||
@@ -80,8 +88,12 @@ impl Accumulate for WithoutCapital {
|
||||
}
|
||||
}
|
||||
|
||||
fn core(&self) -> &WithoutCapital { self }
|
||||
fn core_mut(&mut self) -> &mut WithoutCapital { self }
|
||||
fn core(&self) -> &WithoutCapital {
|
||||
self
|
||||
}
|
||||
fn core_mut(&mut self) -> &mut WithoutCapital {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn accumulate_profit(&mut self, _price_u128: u128, sats: Sats) {
|
||||
@@ -110,8 +122,12 @@ impl Accumulate for WithCapital {
|
||||
}
|
||||
}
|
||||
|
||||
fn core(&self) -> &WithoutCapital { &self.core }
|
||||
fn core_mut(&mut self) -> &mut WithoutCapital { &mut self.core }
|
||||
fn core(&self) -> &WithoutCapital {
|
||||
&self.core
|
||||
}
|
||||
fn core_mut(&mut self) -> &mut WithoutCapital {
|
||||
&mut self.core
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn accumulate_profit(&mut self, price_u128: u128, sats: Sats) {
|
||||
|
||||
Reference in New Issue
Block a user