Skip to content

Commit

Permalink
Review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Dec 6, 2023
1 parent 7dc8db1 commit 29136d5
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> {
// Output might be associated with the address, but can't be unlocked by it, so we check that here.
let required_address = &output_data
.output
.required_address(slot_index, protocol_parameters.committable_age())?;
.required_address(slot_index, protocol_parameters.committable_age_range())?;

if required_address
.as_ref()
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/client/api/block_builder/input_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl InputSelection {
fn required_account_nft_addresses(&self, input: &InputSigningData) -> Result<Option<Requirement>, Error> {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())?
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())?
.expect("expiration unlockable outputs already filtered out");

let required_address = if let Address::Restricted(restricted) = &required_address {
Expand Down Expand Up @@ -235,7 +235,7 @@ impl InputSelection {
let required_address = input
.output
// Account transition is irrelevant here as we keep accounts anyway.
.required_address(self.slot_index, self.protocol_parameters.committable_age())
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())
// PANIC: safe to unwrap as non basic/account/foundry/nft outputs are already filtered out.
.unwrap();

Expand All @@ -259,7 +259,7 @@ impl InputSelection {
.addresses
.contains(&Address::from(*implicit_account_creation.ed25519_address()))
}
_ => self.addresses.contains(&required_address),
_ => self.addresses.contains(required_address),
}
})
}
Expand Down Expand Up @@ -412,7 +412,7 @@ impl InputSelection {
inputs: Self::sort_input_signing_data(
self.selected_inputs,
self.slot_index,
self.protocol_parameters.committable_age(),
self.protocol_parameters.committable_age_range(),
)?,
outputs: self.outputs,
remainder,
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/client/api/block_builder/input_selection/remainder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl InputSelection {
for input in self.available_inputs.iter().chain(self.selected_inputs.iter()) {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())?
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())?
.expect("expiration unlockable outputs already filtered out");

if &required_address == remainder_address {
Expand All @@ -39,7 +39,7 @@ impl InputSelection {
for input in &self.selected_inputs {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())?
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())?
.expect("expiration unlockable outputs already filtered out");

if required_address.is_ed25519() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl InputSelection {
.locked_address(
output.address(),
self.slot_index,
self.protocol_parameters.committable_age(),
self.protocol_parameters.committable_age_range(),
)
.expect("expiration unlockable outputs already filtered out")
.is_ed25519()
Expand All @@ -370,7 +370,7 @@ impl InputSelection {
.locked_address(
output.address(),
self.slot_index,
self.protocol_parameters.committable_age(),
self.protocol_parameters.committable_age_range(),
)
.expect("expiration unlockable outputs already filtered out")
.is_ed25519()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl InputSelection {
fn selected_unlocks_ed25519_address(&self, input: &InputSigningData, address: &Address) -> bool {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())
// PANIC: safe to unwrap as outputs with no address have been filtered out already.
.unwrap()
.expect("expiration unlockable outputs already filtered out");
Expand All @@ -22,7 +22,7 @@ impl InputSelection {
fn available_has_ed25519_address(&self, input: &InputSigningData, address: &Address) -> bool {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())
// PANIC: safe to unwrap as outputs with no address have been filtered out already.
.unwrap()
.expect("expiration unlockable outputs already filtered out");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl InputSelection {
for input in self.selected_inputs.iter() {
let required_address = input
.output
.required_address(self.slot_index, self.protocol_parameters.committable_age())?
.required_address(self.slot_index, self.protocol_parameters.committable_age_range())?
.expect("expiration unlockable outputs already filtered out");

if &required_address == weight_address.address() {
Expand Down
8 changes: 2 additions & 6 deletions sdk/src/client/secret/ledger_nano.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,9 @@ fn merge_unlocks(
// Get the address that is required to unlock the input
let required_address = input
.output
.required_address(slot_index, protocol_parameters.committable_age())?;

let required_address = match required_address {
Some(address) => address,
.required_address(slot_index, protocol_parameters.committable_age_range())?
// Time in which no address can unlock the output because of an expiration unlock condition
None => return Err(Error::ExpirationDeadzone),
};
.ok_or(Error::ExpirationDeadzone)?;

// Check if we already added an [Unlock] for this address
match block_indexes.get(&required_address) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/client/secret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ where
// Get the address that is required to unlock the input
let required_address = input
.output
.required_address(slot_index, protocol_parameters.committable_age())?
.required_address(slot_index, protocol_parameters.committable_age_range())?
.ok_or(crate::client::Error::ExpirationDeadzone)?;

// Check if we already added an [Unlock] for this address
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ impl AccountOutput {
.locked_address(
self.address(),
context.transaction.creation_slot(),
context.protocol_parameters.committable_age(),
context.protocol_parameters.committable_age_range(),
)
// Safe to unwrap, AccountOutput can't have an expiration unlock condition.
.unwrap()
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl BasicOutput {
self.address(),
// Safe to unwrap, we return an error before if its required but None
slot_index.unwrap_or(SlotIndex(0)),
context.protocol_parameters.committable_age(),
context.protocol_parameters.committable_age_range(),
)
// because of expiration the input can't be unlocked at this time
.ok_or(TransactionFailureReason::SemanticValidationFailed)?
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl DelegationOutput {
.locked_address(
self.address(),
context.transaction.creation_slot(),
context.protocol_parameters.committable_age(),
context.protocol_parameters.committable_age_range(),
)
// Safe to unwrap, DelegationOutput can't have an expiration unlock condition.
.unwrap()
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/output/nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,15 +425,15 @@ impl NftOutput {
&& (self.unlock_conditions().timelock().is_some() || self.unlock_conditions().expiration().is_some())
{
// Missing CommitmentContextInput
return Err(TransactionFailureReason::SemanticValidationFailed);
return Err(TransactionFailureReason::InvalidCommitmentContextInput);
}

self.unlock_conditions()
.locked_address(
self.address(),
// Safe to unwrap, we return an error before if its required but None
slot_index.unwrap_or(SlotIndex(0)),
context.protocol_parameters.committable_age(),
context.protocol_parameters.committable_age_range(),
)
// because of expiration the input can't be unlocked at this time
.ok_or(TransactionFailureReason::SemanticValidationFailed)?
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl ProtocolParameters {
}

/// Returns the [`CommittableAgeRange`].
pub fn committable_age(&self) -> CommittableAgeRange {
pub fn committable_age_range(&self) -> CommittableAgeRange {
CommittableAgeRange {
min: self.min_committable_age(),
max: self.max_committable_age(),
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/types/block/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ impl<'a> SemanticValidationContext<'a> {

if let Some(expiration) = unlock_conditions.expiration() {
if let Some(commitment_slot_index) = commitment_slot_index {
if expiration.is_expired(commitment_slot_index, self.protocol_parameters.committable_age())
if expiration.is_expired(commitment_slot_index, self.protocol_parameters.committable_age_range())
== Some(false)
{
if let Some(storage_deposit_return) = unlock_conditions.storage_deposit_return() {
Expand All @@ -318,7 +318,7 @@ impl<'a> SemanticValidationContext<'a> {
}
} else {
// Missing CommitmentContextInput
return Ok(Some(TransactionFailureReason::SemanticValidationFailed));
return Ok(Some(TransactionFailureReason::InvalidCommitmentContextInput));
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ where
wallet_data.address.inner(),
output,
slot_index,
protocol_parameters.committable_age(),
protocol_parameters.committable_age_range(),
);

if output_can_be_unlocked_now_and_in_future {
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/wallet/operations/output_claiming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ impl WalletData {
self.address.inner(),
output_data,
slot_index,
protocol_parameters.committable_age(),
protocol_parameters.committable_age_range(),
)?
{
match outputs_to_claim {
OutputsToClaim::MicroTransactions => {
if let Some(sdr) = unlock_conditions.storage_deposit_return() {
// If expired, it's not a micro transaction anymore
match unlock_conditions
.is_expired(slot_index, protocol_parameters.committable_age())
.is_expired(slot_index, protocol_parameters.committable_age_range())
{
Some(false) => {
// Only micro transaction if not the same amount needs to be returned
Expand All @@ -104,7 +104,7 @@ impl WalletData {
}
OutputsToClaim::Amount => {
let mut claimable_amount = output_data.output.amount();
if unlock_conditions.is_expired(slot_index, protocol_parameters.committable_age())
if unlock_conditions.is_expired(slot_index, protocol_parameters.committable_age_range())
== Some(false)
{
claimable_amount -= unlock_conditions
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/wallet/operations/output_consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where
}

let has_storage_deposit_return = unlock_conditions.storage_deposit_return().is_some();
let is_expired = unlock_conditions.is_expired(slot_index, protocol_parameters.committable_age());
let is_expired = unlock_conditions.is_expired(slot_index, protocol_parameters.committable_age_range());
if is_expired.is_none() {
// If the output is in a deadzone because of expiration, then it cannot be consolidated.
return Ok(false);
Expand All @@ -101,7 +101,7 @@ where
wallet_address,
output_data,
slot_index,
protocol_parameters.committable_age(),
protocol_parameters.committable_age_range(),
)?
} else {
false
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/transaction/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ where
&wallet_data,
wallet_data.unspent_outputs.values(),
slot_index,
protocol_parameters.committable_age(),
protocol_parameters.committable_age_range(),
custom_inputs.as_ref(),
mandatory_inputs.as_ref(),
)?;
Expand Down

0 comments on commit 29136d5

Please sign in to comment.