Skip to content

Commit

Permalink
Replace creation slot with commitment slot in more places (#2056)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Feb 23, 2024
1 parent b4daa53 commit 8abaebf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion sdk/src/client/api/block_builder/input_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl InputSelection {

let inputs_data = Self::sort_input_signing_data(
self.selected_inputs,
self.creation_slot,
self.latest_slot_commitment_id.slot_index(),
self.protocol_parameters.committable_age_range(),
)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ impl InputSelection {
for selected_input in &self.selected_inputs {
inputs_sum += selected_input.output.amount();

if let Some(sdruc) = sdruc_not_expired(&selected_input.output, self.creation_slot) {
if let Some(sdruc) = sdruc_not_expired(&selected_input.output, self.latest_slot_commitment_id.slot_index())
{
*inputs_sdr.entry(sdruc.return_address().clone()).or_default() += sdruc.amount();
}
}
Expand Down Expand Up @@ -139,7 +140,9 @@ impl AmountSelection {
continue;
}

if let Some(sdruc) = sdruc_not_expired(&input.output, input_selection.creation_slot) {
if let Some(sdruc) =
sdruc_not_expired(&input.output, input_selection.latest_slot_commitment_id.slot_index())
{
// Skip if no additional amount is made available
if input.output.amount() == sdruc.amount() {
continue;
Expand Down Expand Up @@ -201,9 +204,11 @@ impl InputSelection {
base_inputs: impl Iterator<Item = &'a InputSigningData> + Clone,
amount_selection: &mut AmountSelection,
) -> Result<bool, Error> {
let slot_index = self.latest_slot_commitment_id.slot_index();

// No native token, expired SDRUC.
let inputs = base_inputs.clone().filter(|input| {
input.output.native_token().is_none() && sdruc_not_expired(&input.output, self.creation_slot).is_none()
input.output.native_token().is_none() && sdruc_not_expired(&input.output, slot_index).is_none()
});

if amount_selection.fulfil(self, inputs)? {
Expand All @@ -212,7 +217,7 @@ impl InputSelection {

// No native token, unexpired SDRUC.
let inputs = base_inputs.clone().filter(|input| {
input.output.native_token().is_none() && sdruc_not_expired(&input.output, self.creation_slot).is_some()
input.output.native_token().is_none() && sdruc_not_expired(&input.output, slot_index).is_some()
});

if amount_selection.fulfil(self, inputs)? {
Expand All @@ -221,7 +226,7 @@ impl InputSelection {

// Native token, expired SDRUC.
let inputs = base_inputs.clone().filter(|input| {
input.output.native_token().is_some() && sdruc_not_expired(&input.output, self.creation_slot).is_none()
input.output.native_token().is_some() && sdruc_not_expired(&input.output, slot_index).is_none()
});

if amount_selection.fulfil(self, inputs)? {
Expand All @@ -230,7 +235,7 @@ impl InputSelection {

// Native token, unexpired SDRUC.
let inputs = base_inputs.clone().filter(|input| {
input.output.native_token().is_some() && sdruc_not_expired(&input.output, self.creation_slot).is_some()
input.output.native_token().is_some() && sdruc_not_expired(&input.output, slot_index).is_some()
});

if amount_selection.fulfil(self, inputs)? {
Expand Down Expand Up @@ -364,13 +369,15 @@ impl InputSelection {
&mut self,
amount_selection: &mut AmountSelection,
) -> Result<Option<Vec<InputSigningData>>, Error> {
let slot_index = self.latest_slot_commitment_id.slot_index();

let basic_ed25519_inputs = self.available_inputs.iter().filter(|input| {
if let Output::Basic(output) = &input.output {
output
.unlock_conditions()
.locked_address(
output.address(),
self.creation_slot,
slot_index,
self.protocol_parameters.committable_age_range(),
)
.expect("slot index was provided")
Expand All @@ -391,7 +398,7 @@ impl InputSelection {
.unlock_conditions()
.locked_address(
output.address(),
self.creation_slot,
slot_index,
self.protocol_parameters.committable_age_range(),
)
.expect("slot index was provided")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl InputSelection {
if !self.selected_inputs.is_empty() && self.all_outputs().next().is_some() {
self.selected_inputs = Self::sort_input_signing_data(
std::mem::take(&mut self.selected_inputs),
self.creation_slot,
self.latest_slot_commitment_id.slot_index(),
self.protocol_parameters.committable_age_range(),
)?;

Expand Down
4 changes: 2 additions & 2 deletions sdk/src/wallet/operations/transaction/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ where
&self.address().await,
self.bip_path().await,
wallet_ledger.unspent_outputs.values(),
creation_slot,
slot_commitment_id.slot_index(),
protocol_parameters.committable_age_range(),
&options.required_inputs,
)?;
Expand Down Expand Up @@ -125,7 +125,7 @@ where
mana_rewards.insert(
*output_id,
self.client()
.get_output_mana_rewards(output_id, creation_slot)
.get_output_mana_rewards(output_id, slot_commitment_id.slot_index())
.await?
.rewards,
);
Expand Down

0 comments on commit 8abaebf

Please sign in to comment.