Skip to content

Commit

Permalink
available_mana
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Jan 16, 2024
1 parent 5b5d199 commit 2159225
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl InputSelection {
let mut input_mana = 0;

for input in &self.selected_inputs {
input_mana += input.output.all_mana(
input_mana += input.output.available_mana(
&self.protocol_parameters,
input.output_id().transaction_id().slot_index(),
self.slot_index,
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl Output {
}

/// Returns all the mana held by the output, which is potential + stored, all decayed.
pub fn all_mana(
pub fn available_mana(
&self,
protocol_parameters: &ProtocolParameters,
creation_index: SlotIndex,
Expand Down
19 changes: 7 additions & 12 deletions sdk/src/types/block/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,13 @@ impl<'a> SemanticValidationContext<'a> {
pub fn validate(mut self) -> Result<Option<TransactionFailureReason>, Error> {
// Validation of inputs.
for (index, (output_id, consumed_output)) in self.inputs.iter().enumerate() {
let (amount, mana, consumed_native_token, unlock_conditions) = match consumed_output {
Output::Basic(output) => (
output.amount(),
output.mana(),
output.native_token(),
output.unlock_conditions(),
),
Output::Account(output) => (output.amount(), output.mana(), None, output.unlock_conditions()),
let (amount, consumed_native_token, unlock_conditions) = match consumed_output {
Output::Basic(output) => (output.amount(), output.native_token(), output.unlock_conditions()),
Output::Account(output) => (output.amount(), None, output.unlock_conditions()),
Output::Anchor(_) => return Err(Error::UnsupportedOutputKind(AnchorOutput::KIND)),
Output::Foundry(output) => (output.amount(), 0, output.native_token(), output.unlock_conditions()),
Output::Nft(output) => (output.amount(), output.mana(), None, output.unlock_conditions()),
Output::Delegation(output) => (output.amount(), 0, None, output.unlock_conditions()),
Output::Foundry(output) => (output.amount(), output.native_token(), output.unlock_conditions()),
Output::Nft(output) => (output.amount(), None, output.unlock_conditions()),
Output::Delegation(output) => (output.amount(), None, output.unlock_conditions()),
};

let commitment_slot_index = self
Expand Down Expand Up @@ -162,7 +157,7 @@ impl<'a> SemanticValidationContext<'a> {

self.input_mana = self
.input_mana
.checked_add(consumed_output.all_mana(
.checked_add(consumed_output.available_mana(
&self.protocol_parameters,
output_id.transaction_id().slot_index(),
self.transaction.creation_slot(),
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/wallet/operations/transaction/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ where

let account_id = AccountId::from(output_id);
let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id)
.with_mana(implicit_account_data.output.all_mana(
.with_mana(implicit_account_data.output.available_mana(
&self.client().get_protocol_parameters().await?,
implicit_account_data.output_id.transaction_id().slot_index(),
self.client().get_slot_index().await?,
Expand Down

0 comments on commit 2159225

Please sign in to comment.