Skip to content

Commit

Permalink
Add capabilities to TransactionOptions (#1742)
Browse files Browse the repository at this point in the history
* Add capabilities to TransactionOptions

* TODO
  • Loading branch information
thibault-martinez authored Dec 5, 2023
1 parent 677c2f5 commit 6d3e4c9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions sdk/src/types/block/payload/signed_transaction/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ impl TransactionBuilder {
self
}

pub fn add_capabilities(mut self, capabilities: impl IntoIterator<Item = TransactionCapabilityFlag>) -> Self {
self.capabilities.add_capabilities(capabilities);
self
}

/// Sets the payload of a [`TransactionBuilder`].
pub fn with_payload(mut self, payload: impl Into<OptionalPayload>) -> Self {
self.payload = payload.into();
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/wallet/operations/transaction/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
unlock_condition::AddressUnlockCondition,
AccountId, AccountOutput, OutputId,
},
payload::signed_transaction::{TransactionCapabilities, TransactionCapabilityFlag},
},
wallet::{
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Expand Down Expand Up @@ -102,12 +103,17 @@ where
// TODO https://github.com/iotaledger/iota-sdk/issues/1740
let issuance = self.client().get_issuance().await?;

// TODO remove when https://github.com/iotaledger/iota-sdk/issues/1744 is done
let mut capabilities = TransactionCapabilities::default();
capabilities.add_capability(TransactionCapabilityFlag::BurnMana);

let transaction_options = TransactionOptions {
context_inputs: Some(vec![
CommitmentContextInput::new(issuance.latest_commitment.id()).into(),
BlockIssuanceCreditContextInput::new(account_id).into(),
]),
custom_inputs: Some(vec![*output_id]),
capabilities: Some(capabilities),
..Default::default()
};

Expand Down
4 changes: 4 additions & 0 deletions sdk/src/wallet/operations/transaction/build_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ where
if let Some(context_inputs) = options.context_inputs {
builder = builder.with_context_inputs(context_inputs);
}

if let Some(capabilities) = options.capabilities {
builder = builder.add_capabilities(capabilities.capabilities_iter());
}
}

let transaction = builder.finish_with_params(&protocol_parameters)?;
Expand Down
7 changes: 6 additions & 1 deletion sdk/src/wallet/operations/transaction/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use serde::{Deserialize, Serialize};
use crate::{
client::api::input_selection::Burn,
types::block::{
address::Address, context_input::ContextInput, output::OutputId, payload::tagged_data::TaggedDataPayload,
address::Address,
context_input::ContextInput,
output::OutputId,
payload::{signed_transaction::TransactionCapabilities, tagged_data::TaggedDataPayload},
},
};

Expand All @@ -30,6 +33,8 @@ pub struct TransactionOptions {
pub note: Option<String>,
#[serde(default)]
pub allow_micro_amount: bool,
#[serde(default)]
pub capabilities: Option<TransactionCapabilities>,
}

#[allow(clippy::enum_variant_names)]
Expand Down

0 comments on commit 6d3e4c9

Please sign in to comment.