Skip to content

Commit

Permalink
add undecayed stored mana to balance
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Feb 28, 2024
1 parent 20ec8f0 commit 437fbd1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/bin/inx-chronicle/api/explorer/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
14 changes: 8 additions & 6 deletions src/bin/inx-chronicle/api/explorer/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,18 @@ async fn balance(database: State<MongoDb>, Path(address): Path<Bech32Address>) -
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,
Expand Down
19 changes: 12 additions & 7 deletions src/db/mongodb/collections/outputs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand All @@ -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 {
Expand All @@ -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(())
}
}
Expand Down

0 comments on commit 437fbd1

Please sign in to comment.