From 7bffac25c5466958b4959ce324c65d0313468606 Mon Sep 17 00:00:00 2001 From: DaughterOfMars Date: Tue, 6 Feb 2024 15:10:44 -0500 Subject: [PATCH] Add rewards to mana balance (#1951) * add rewards to mana balance * simplify rewards sum * only account/delegation --------- Co-authored-by: Thibault Martinez --- sdk/src/wallet/operations/balance.rs | 8 ++++++++ sdk/src/wallet/types/balance.rs | 2 ++ 2 files changed, 10 insertions(+) diff --git a/sdk/src/wallet/operations/balance.rs b/sdk/src/wallet/operations/balance.rs index 56a8d28a80..e9efdbfd80 100644 --- a/sdk/src/wallet/operations/balance.rs +++ b/sdk/src/wallet/operations/balance.rs @@ -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; @@ -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) { diff --git a/sdk/src/wallet/types/balance.rs b/sdk/src/wallet/types/balance.rs index 2454f2dc04..facdc4e150 100644 --- a/sdk/src/wallet/types/balance.rs +++ b/sdk/src/wallet/types/balance.rs @@ -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)]