Skip to content

Commit

Permalink
Remove delegation and implicit accounts amounts from available balance (
Browse files Browse the repository at this point in the history
#2181)

* Remove delegation and implicit accounts amounts from available balance

* Merge delegation_implicit_accounts_amount with locked_amount

* Merge delegation_implicit_accounts_amount with locked_amount

* Use is_implicit_account_creation()

* Remove unused import

---------

Co-authored-by: Thibault Martinez <thibault@iota.org>
Co-authored-by: DaughterOfMars <alexandcoats@gmail.com>
  • Loading branch information
3 people authored Mar 20, 2024
1 parent 8c36dcf commit b4fca53
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl<S: 'static + SecretManage> Wallet<S> {

let mut balance = Balance::default();
let mut total_storage_cost = 0;
let mut locked_amount = 0;
let mut total_native_tokens = NativeTokensBuilder::default();

#[cfg(feature = "participation")]
Expand Down Expand Up @@ -110,6 +111,7 @@ impl<S: 'static + SecretManage> Wallet<S> {
Output::Delegation(delegation) => {
// Add amount
balance.base_coin.total += delegation.amount();
locked_amount += delegation.amount();
// Add mana rewards
reward_outputs.insert(*output_id);
// Add storage deposit
Expand All @@ -124,7 +126,7 @@ impl<S: 'static + SecretManage> Wallet<S> {
_ => {
// If there is only an [AddressUnlockCondition], then we can spend the output at any time
// without restrictions
if let [UnlockCondition::Address(_)] = output.unlock_conditions().as_ref() {
if let [UnlockCondition::Address(address_unlock_cond)] = output.unlock_conditions().as_ref() {
// add nft_id for nft outputs
if let Output::Nft(nft) = &output {
let nft_id = nft.nft_id_non_null(output_id);
Expand All @@ -133,6 +135,9 @@ impl<S: 'static + SecretManage> Wallet<S> {

// Add amount
balance.base_coin.total += output.amount();
if address_unlock_cond.address().is_implicit_account_creation() {
locked_amount += output.amount();
}
// Add decayed mana
balance.mana.total += output.decayed_mana(
&protocol_parameters,
Expand Down Expand Up @@ -253,7 +258,6 @@ impl<S: 'static + SecretManage> Wallet<S> {
// for `available` get locked_outputs, sum outputs amount and subtract from total_amount
log::debug!("[BALANCE] locked outputs: {:#?}", wallet_ledger.locked_outputs);

let mut locked_amount = 0;
let mut locked_mana = DecayedMana::default();
let mut locked_native_tokens = NativeTokensBuilder::default();

Expand Down

0 comments on commit b4fca53

Please sign in to comment.