server: documentation part 1

This commit is contained in:
nym21
2025-10-06 22:53:50 +02:00
parent db344749b6
commit 7ff79c3164
23 changed files with 670 additions and 183 deletions

View File

@@ -1342,7 +1342,7 @@ impl Vecs {
.height_to_supply
.into_iter()
.unwrap_get_inner(prev_height);
state.supply.utxos = *self
state.supply.utxo_count = *self
.height_to_utxo_count
.into_iter()
.unwrap_get_inner(prev_height);
@@ -1579,7 +1579,7 @@ impl Vecs {
self.height_to_utxo_count.forced_push_at(
height,
StoredU64::from(state.supply.utxos),
StoredU64::from(state.supply.utxo_count),
exit,
)?;

View File

@@ -1899,7 +1899,7 @@ impl AddressTypeToVec<(TypeIndex, Sats)> {
let addressdata = addressdata_withsource.deref_mut();
let prev_amount = addressdata.amount();
let prev_amount = addressdata.balance();
let amount = prev_amount + value;
@@ -2000,11 +2000,11 @@ impl HeightToAddressTypeToVec<(TypeIndex, Sats)> {
let addressdata = addressdata_withsource.deref_mut();
let prev_amount = addressdata.amount();
let prev_amount = addressdata.balance();
let amount = prev_amount.checked_sub(value).unwrap();
let will_be_empty = addressdata.utxos - 1 == 0;
let will_be_empty = addressdata.utxo_count - 1 == 0;
if will_be_empty
|| vecs.amount_range.get_mut(amount).0.clone()

View File

@@ -44,19 +44,22 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| addressdata.realized_price());
let prev_supply_state = SupplyState {
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
utxo_count: addressdata.utxo_count as u64,
value: addressdata.balance(),
};
addressdata.send(value, prev_price)?;
let supply_state = SupplyState {
utxos: addressdata.utxos as u64,
value: addressdata.amount(),
utxo_count: addressdata.utxo_count as u64,
value: addressdata.balance(),
};
self.inner.send_(
&SupplyState { utxos: 1, value },
&SupplyState {
utxo_count: 1,
value,
},
current_price,
prev_price,
blocks_old,
@@ -79,19 +82,22 @@ impl AddressCohortState {
let prev_realized_price = compute_price.then(|| address_data.realized_price());
let prev_supply_state = SupplyState {
utxos: address_data.utxos as u64,
value: address_data.amount(),
utxo_count: address_data.utxo_count as u64,
value: address_data.balance(),
};
address_data.receive(value, price);
let supply_state = SupplyState {
utxos: address_data.utxos as u64,
value: address_data.amount(),
utxo_count: address_data.utxo_count as u64,
value: address_data.balance(),
};
self.inner.receive_(
&SupplyState { utxos: 1, value },
&SupplyState {
utxo_count: 1,
value,
},
price,
compute_price.then(|| (address_data.realized_price(), &supply_state)),
prev_realized_price.map(|prev_price| (prev_price, &prev_supply_state)),

View File

@@ -204,7 +204,7 @@ impl CohortState {
price_to_amount_increment: Option<(Dollars, &SupplyState)>,
price_to_amount_decrement: Option<(Dollars, &SupplyState)>,
) {
if supply_state.utxos == 0 {
if supply_state.utxo_count == 0 {
return;
}

View File

@@ -6,7 +6,7 @@ use zerocopy_derive::{FromBytes, Immutable, IntoBytes, KnownLayout};
#[derive(Debug, Default, Clone, FromBytes, Immutable, IntoBytes, KnownLayout, Serialize)]
pub struct SupplyState {
pub utxos: u64,
pub utxo_count: u64,
pub value: Sats,
}
@@ -14,7 +14,7 @@ impl Add<SupplyState> for SupplyState {
type Output = Self;
fn add(self, rhs: SupplyState) -> Self::Output {
Self {
utxos: self.utxos + rhs.utxos,
utxo_count: self.utxo_count + rhs.utxo_count,
value: self.value + rhs.value,
}
}
@@ -28,14 +28,14 @@ impl AddAssign<SupplyState> for SupplyState {
impl AddAssign<&SupplyState> for SupplyState {
fn add_assign(&mut self, rhs: &Self) {
self.utxos += rhs.utxos;
self.utxo_count += rhs.utxo_count;
self.value += rhs.value;
}
}
impl SubAssign<&SupplyState> for SupplyState {
fn sub_assign(&mut self, rhs: &Self) {
self.utxos = self.utxos.checked_sub(rhs.utxos).unwrap();
self.utxo_count = self.utxo_count.checked_sub(rhs.utxo_count).unwrap();
self.value = self.value.checked_sub(rhs.value).unwrap();
}
}
@@ -43,14 +43,14 @@ impl SubAssign<&SupplyState> for SupplyState {
impl From<&LoadedAddressData> for SupplyState {
fn from(value: &LoadedAddressData) -> Self {
Self {
utxos: value.utxos as u64,
value: value.amount(),
utxo_count: value.utxo_count as u64,
value: value.balance(),
}
}
}
impl std::fmt::Display for SupplyState {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "utxos: {}, value: {}", self.utxos, self.value)
write!(f, "utxos: {}, value: {}", self.utxo_count, self.value)
}
}

View File

@@ -14,7 +14,10 @@ pub struct Transacted {
impl Transacted {
#[allow(clippy::inconsistent_digit_grouping)]
pub fn iterate(&mut self, value: Sats, _type: OutputType) {
let supply = SupplyState { utxos: 1, value };
let supply = SupplyState {
utxo_count: 1,
value,
};
*self.by_type.get_mut(_type) += &supply;