Skip to content

Commit

Permalink
Adjust claim_outputs() to work even if an input has less amount than …
Browse files Browse the repository at this point in the history
…min storage deposit
  • Loading branch information
Thoralf-M committed Oct 4, 2023
1 parent 4a1bff8 commit 44241e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Update protocol params and addresses with correct bech32 HRP in `Wallet::set_client_options()`;
- `Account::claim_outputs()` if an input have less amount than min storage deposit;

## 1.1.0 - 2023-09-29

Expand Down
13 changes: 11 additions & 2 deletions sdk/src/wallet/account/operations/output_claiming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ where
let mut available_amount = 0;
let mut required_amount_for_nfts = 0;
let mut new_native_tokens = NativeTokensBuilder::new();

// There can be outputs with less amount than min required storage deposit, so we have to check that we
// have enough amount to create a new basic output
let enough_amount_for_basic_output = possible_additional_inputs
.iter()
.map(|i| i.output.amount())
.sum::<u64>()
>= MinimumStorageDepositBasicOutput::new(rent_structure, token_supply).finish()?;

// check native tokens
for output_data in &outputs_to_claim {
if let Some(native_tokens) = output_data.output.native_tokens() {
Expand All @@ -266,7 +275,7 @@ where
// build new output with same amount, nft_id, immutable/feature blocks and native tokens, just
// updated address unlock conditions

let nft_output = if possible_additional_inputs.is_empty() {
let nft_output = if !enough_amount_for_basic_output {
// Only update address and nft id if we have no additional inputs which can provide the storage
// deposit for the remaining amount and possible NTs
NftOutputBuilder::from(nft_output)
Expand Down Expand Up @@ -296,7 +305,7 @@ where
};

// Check if the new amount is enough for the storage deposit, otherwise increase it to this
let mut required_amount = if possible_additional_inputs.is_empty() {
let mut required_amount = if !enough_amount_for_basic_output {
required_amount_for_nfts
} else {
required_amount_for_nfts
Expand Down

0 comments on commit 44241e3

Please sign in to comment.