From 437fbd1357d914fd12565e03a498c3cf5ede4879 Mon Sep 17 00:00:00 2001 From: Alex Coats Date: Wed, 28 Feb 2024 12:39:51 -0500 Subject: [PATCH] add undecayed stored mana to balance --- .../inx-chronicle/api/explorer/responses.rs | 4 +++- src/bin/inx-chronicle/api/explorer/routes.rs | 14 ++++++++------ src/db/mongodb/collections/outputs/mod.rs | 19 ++++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/bin/inx-chronicle/api/explorer/responses.rs b/src/bin/inx-chronicle/api/explorer/responses.rs index cd4eeba2d..1a599d8a4 100644 --- a/src/bin/inx-chronicle/api/explorer/responses.rs +++ b/src/bin/inx-chronicle/api/explorer/responses.rs @@ -78,7 +78,9 @@ impl_success_response!(BalanceResponse); pub struct Balance { #[serde(with = "string")] pub amount: u64, - pub mana: DecayedMana, + #[serde(with = "string")] + pub stored_mana: u64, + pub decayed_mana: DecayedMana, } #[derive(Clone, Debug, Serialize, Deserialize)] diff --git a/src/bin/inx-chronicle/api/explorer/routes.rs b/src/bin/inx-chronicle/api/explorer/routes.rs index b8acf5d71..98084018f 100644 --- a/src/bin/inx-chronicle/api/explorer/routes.rs +++ b/src/bin/inx-chronicle/api/explorer/routes.rs @@ -173,16 +173,18 @@ async fn balance(database: State, Path(address): Path) - Ok(BalanceResponse { total_balance: Balance { amount: res.total.amount, - mana: DecayedMana { - stored: res.total.mana.stored, - potential: res.total.mana.potential, + stored_mana: res.total.stored_mana, + decayed_mana: DecayedMana { + stored: res.total.decayed_mana.stored, + potential: res.total.decayed_mana.potential, }, }, available_balance: Balance { amount: res.available.amount, - mana: DecayedMana { - stored: res.available.mana.stored, - potential: res.available.mana.potential, + stored_mana: res.available.stored_mana, + decayed_mana: DecayedMana { + stored: res.available.decayed_mana.stored, + potential: res.available.decayed_mana.potential, }, }, ledger_index: latest_slot.slot_index, diff --git a/src/db/mongodb/collections/outputs/mod.rs b/src/db/mongodb/collections/outputs/mod.rs index 450ca6c61..51cc6389c 100644 --- a/src/db/mongodb/collections/outputs/mod.rs +++ b/src/db/mongodb/collections/outputs/mod.rs @@ -313,12 +313,14 @@ impl BalanceResult { ) -> Result<(), DbError> { self.total.amount += amount; self.available.amount += amount; + self.total.stored_mana += stored_mana; + self.available.stored_mana += stored_mana; let stored = params.mana_with_decay(stored_mana, creation_slot, target_slot)?; let potential = params.generate_mana_with_decay(generation_amount, creation_slot, target_slot)?; - self.total.mana.stored += stored; - self.available.mana.stored += stored; - self.total.mana.potential += potential; - self.available.mana.potential += potential; + self.total.decayed_mana.stored += stored; + self.available.decayed_mana.stored += stored; + self.total.decayed_mana.potential += potential; + self.available.decayed_mana.potential += potential; Ok(()) } } @@ -327,7 +329,8 @@ impl BalanceResult { #[allow(missing_docs)] pub struct Balance { pub amount: u64, - pub mana: DecayedMana, + pub stored_mana: u64, + pub decayed_mana: DecayedMana, } impl Balance { @@ -341,8 +344,10 @@ impl Balance { params: &ProtocolParameters, ) -> Result<(), DbError> { self.amount += amount; - self.mana.stored += params.mana_with_decay(stored_mana, creation_slot, target_slot)?; - self.mana.potential += params.generate_mana_with_decay(generation_amount, creation_slot, target_slot)?; + self.stored_mana += stored_mana; + self.decayed_mana.stored += params.mana_with_decay(stored_mana, creation_slot, target_slot)?; + self.decayed_mana.potential += + params.generate_mana_with_decay(generation_amount, creation_slot, target_slot)?; Ok(()) } }