Skip to content

Commit

Permalink
clippy and fix claiming calc
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Sep 1, 2023
1 parent db546f4 commit d92493e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
2 changes: 1 addition & 1 deletion sdk/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl NetworkInfo {
}

pub fn with_tangle_time(mut self, tangle_time: u64) -> Self {
self.tangle_time = Some(tangle_time.into());
self.tangle_time = Some(tangle_time);
self
}
}
2 changes: 1 addition & 1 deletion sdk/src/client/node_api/core/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ClientInner {
/// Returns the information of committee members at the given epoch index. If epoch index is not provided, the
/// current committee members are returned.
/// GET /api/core/v3/committee/?epochIndex
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>>) -> Result<CommitteeResponse> {
pub async fn get_committee(&self, epoch_index: impl Into<Option<EpochIndex>> + Send) -> Result<CommitteeResponse> {
const PATH: &str = "api/core/v3/committee";

let epoch_index = epoch_index.into().map(|i| format!("epochIndex={i}"));
Expand Down
1 change: 0 additions & 1 deletion sdk/src/types/block/address/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ impl Ed25519Address {
Self::from(address)
}

#[allow(dead_code)]
pub(crate) fn null() -> Self {
Self::new([0; Self::LENGTH])
}
Expand Down
17 changes: 16 additions & 1 deletion sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{
};
use crate::types::{
block::{
address::Address,
address::{Address, Ed25519Address},
output::{
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{
Expand Down Expand Up @@ -64,6 +64,14 @@ impl BasicOutputBuilder {
}
}

/// Gets the current amount as a concrete value.
pub fn amount(&self) -> u64 {
match self.amount {
OutputBuilderAmount::Amount(amount) => amount,
OutputBuilderAmount::MinimumStorageDeposit(rent_structure) => self.rent_cost(rent_structure),
}
}

/// Sets the amount to the provided value.
#[inline(always)]
pub fn with_amount(mut self, amount: u64) -> Self {
Expand Down Expand Up @@ -208,6 +216,13 @@ impl BasicOutputBuilder {
})
}

pub fn min_storage_deposit_amount(&self, rent_structure: RentStructure, token_supply: u64) -> Result<u64, Error> {
Ok(self
.clone()
.with_sufficient_storage_deposit(Ed25519Address::null(), rent_structure, token_supply)?
.amount())
}

///
pub fn finish(self) -> Result<BasicOutput, Error> {
let amount = match self.amount {
Expand Down
5 changes: 1 addition & 4 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ pub use self::{
unlock_condition::{UnlockCondition, UnlockConditions},
};
use super::{protocol::ProtocolParameters, slot::SlotIndex, BlockId};
use crate::types::{
block::{address::Address, semantic::ValidationContext, Error},
ValidationParams,
};
use crate::types::block::{address::Address, semantic::ValidationContext, Error};

/// The maximum number of outputs of a transaction.
pub const OUTPUT_COUNT_MAX: u16 = 128;
Expand Down
22 changes: 8 additions & 14 deletions sdk/src/wallet/account/operations/output_claiming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
address::Address,
output::{
unlock_condition::{AddressUnlockCondition, StorageDepositReturnUnlockCondition},
BasicOutputBuilder, NativeTokens, NativeTokensBuilder, NftOutputBuilder, Output, OutputId, RentCost,
BasicOutputBuilder, NativeTokens, NativeTokensBuilder, NftOutputBuilder, Output, OutputId,
},
},
wallet::account::{
Expand Down Expand Up @@ -294,15 +294,10 @@ where
Some(new_native_tokens.clone().finish()?)
};

// 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() {
required_amount_for_nfts
} else {
required_amount_for_nfts
+ BasicOutputBuilder::new_with_amount(Output::AMOUNT_MIN)
.with_native_tokens(option_native_token.into_iter().flatten())
.rent_cost(rent_structure)
};
// Get the required amount using a sufficient storage deposit
let mut required_amount = BasicOutputBuilder::new_with_amount(required_amount_for_nfts)
.with_native_tokens(option_native_token.into_iter().flatten())
.min_storage_deposit_amount(rent_structure, token_supply)?;

let mut additional_inputs = Vec::new();
if available_amount < required_amount {
Expand All @@ -318,10 +313,9 @@ where
};
// Recalculate every time, because new inputs can also add more native tokens, which would increase
// the required storage deposit
required_amount = required_amount_for_nfts
+ BasicOutputBuilder::new_with_amount(Output::AMOUNT_MIN)
.with_native_tokens(option_native_token.into_iter().flatten())
.rent_cost(rent_structure);
required_amount = BasicOutputBuilder::new_with_amount(required_amount_for_nfts)
.with_native_tokens(option_native_token.into_iter().flatten())
.min_storage_deposit_amount(rent_structure, token_supply)?;

if available_amount < required_amount {
if !additional_inputs_used.contains(&output_data.output_id) {
Expand Down

0 comments on commit d92493e

Please sign in to comment.