Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using account mana for allotments, fix semantic validation #1986

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
address::Address,
input::{Input, UtxoInput},
mana::ManaAllotment,
output::Output,
output::{AccountOutputBuilder, Output},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
signature::Ed25519Signature,
unlock::{AccountUnlock, NftUnlock, ReferenceUnlock, SignatureUnlock, Unlock, Unlocks},
Expand Down Expand Up @@ -71,6 +71,24 @@ impl InputSelection {
if self.mana_allotments[&issuer_id] < required_allotment_mana {
log::debug!("Allotting at least {required_allotment_mana} to account ID {issuer_id}");
self.mana_allotments.insert(issuer_id, required_allotment_mana);

if let Some(output) = self
.outputs
.iter_mut()
.filter(|o| o.is_account())
.find(|o| *o.as_account().account_id() == issuer_id && o.mana() >= required_allotment_mana)
{
log::debug!(
"Reducing account mana of {} by {required_allotment_mana} for allotment",
output.as_account().account_id()
);
let new_mana = output.mana() - required_allotment_mana;
*output = match output {
Output::Account(a) => AccountOutputBuilder::from(&*a).with_mana(new_mana).finish_output()?,
_ => unreachable!(),
};
}

log::debug!("Checking mana requirement again with added allotment");
let additional_inputs = self.fulfill_mana_requirement()?;
// If we needed more inputs to cover the additional allotment mana
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl InputSelection {
.with_features(features);

if input.is_block_issuer() {
// TODO https://github.com/iotaledger/iota-sdk/issues/1918
builder = builder.with_mana(Output::from(input.clone()).available_mana(
&self.protocol_parameters,
output_id.transaction_id().slot_index(),
Expand Down
16 changes: 8 additions & 8 deletions sdk/src/types/block/semantic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ impl<'a> SemanticValidationContext<'a> {
}
}

// Add allotted mana
for mana_allotment in self.transaction.allotments() {
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
self.output_mana = self
.output_mana
.checked_add(mana_allotment.mana())
.ok_or(Error::CreatedManaOverflow)?;
}

// Validation of outputs.
for created_output in self.transaction.outputs() {
let (amount, mana, created_native_token, features) = match created_output {
Expand Down Expand Up @@ -261,14 +269,6 @@ impl<'a> SemanticValidationContext<'a> {
// Add stored mana
self.output_mana = self.output_mana.checked_add(mana).ok_or(Error::CreatedManaOverflow)?;

// Add allotted mana
for mana_allotment in self.transaction.allotments() {
self.output_mana = self
.output_mana
.checked_add(mana_allotment.mana())
.ok_or(Error::CreatedManaOverflow)?;
}

if let Some(created_native_token) = created_native_token {
let native_token_amount = self
.output_native_tokens
Expand Down