Skip to content

Commit

Permalink
Add rewards to mana balance (#1951)
Browse files Browse the repository at this point in the history
* add rewards to mana balance

* simplify rewards sum

* only account/delegation

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
DaughterOfMars and thibault-martinez authored Feb 6, 2024
1 parent a19fc19 commit 7bffac2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ where
output_id.transaction_id().slot_index(),
slot_index,
)?;
// Add mana rewards
if let Ok(response) = self.client().get_output_mana_rewards(output_id, slot_index).await {
balance.mana.rewards += response.rewards;
}

// Add storage deposit
balance.required_storage_deposit.account += storage_cost;
Expand Down Expand Up @@ -98,6 +102,10 @@ where
Output::Delegation(delegation) => {
// Add amount
balance.base_coin.total += delegation.amount();
// Add mana rewards
if let Ok(response) = self.client().get_output_mana_rewards(output_id, slot_index).await {
balance.mana.rewards += response.rewards;
}
// Add storage deposit
balance.required_storage_deposit.delegation += storage_cost;
if !wallet_data.locked_outputs.contains(output_id) {
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/wallet/types/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ pub struct ManaBalance {
pub(crate) total: DecayedMana,
/// Available mana.
pub(crate) available: DecayedMana,
/// Mana rewards.
pub(crate) rewards: u64,
}

#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize, CopyGetters, derive_more::AddAssign)]
Expand Down

0 comments on commit 7bffac2

Please sign in to comment.