Skip to content

Commit

Permalink
Set implicit account transition context inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Dec 4, 2023
1 parent 708edc7 commit 9486270
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sdk/src/types/block/context_input/block_issuance_credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct BlockIssuanceCreditContextInput(AccountId);

impl BlockIssuanceCreditContextInput {
/// The context input kind of a [`BlockIssuanceCreditContextInput`].
pub const KIND: u8 = 1;
pub const KIND: u8 = 2;

/// Creates a new [`BlockIssuanceCreditContextInput`].
pub fn new(account_id: AccountId) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/context_input/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct CommitmentContextInput(SlotCommitmentId);

impl CommitmentContextInput {
/// The context input kind of a [`CommitmentContextInput`].
pub const KIND: u8 = 0;
pub const KIND: u8 = 1;

/// Creates a new [`CommitmentContextInput`].
pub fn new(commitment_id: SlotCommitmentId) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/types/block/context_input/reward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct RewardContextInput(#[packable(unpack_error_with = Error::InvalidRewar

impl RewardContextInput {
/// The context input kind of a [`RewardContextInput`].
pub const KIND: u8 = 2;
pub const KIND: u8 = 3;

/// Creates a new [`RewardContextInput`].
pub fn new(index: u16) -> Result<Self, Error> {
Expand Down
10 changes: 9 additions & 1 deletion sdk/src/wallet/operations/transaction/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
client::{api::PreparedTransactionData, secret::SecretManage},
types::block::{
address::Address,
context_input::{BlockIssuanceCreditContextInput, CommitmentContextInput},
output::{
feature::{BlockIssuerFeature, BlockIssuerKey, BlockIssuerKeys, Ed25519BlockIssuerKey},
unlock_condition::AddressUnlockCondition,
Expand Down Expand Up @@ -83,7 +84,8 @@ where
}
};

let account = AccountOutput::build_with_amount(implicit_account.amount(), AccountId::from(output_id))
let account_id = AccountId::from(output_id);
let account = AccountOutput::build_with_amount(implicit_account.amount(), account_id)
.with_mana(implicit_account.mana())
.with_unlock_conditions([AddressUnlockCondition::from(Address::from(
*implicit_account
Expand All @@ -97,7 +99,13 @@ where
)?])
.finish_output()?;

let issuance = self.client().get_issuance().await?;

let transaction_options = TransactionOptions {
context_inputs: Some(vec![
CommitmentContextInput::new(*issuance.latest_commitment.previous_commitment_id()).into(),
BlockIssuanceCreditContextInput::new(account_id).into(),
]),
custom_inputs: Some(vec![*output_id]),
..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 @@ -49,6 +49,10 @@ where
// Optional add a tagged payload
if let Some(options) = options.into() {
builder = builder.with_payload(options.tagged_data_payload);

if let Some(context_inputs) = options.context_inputs {
builder = builder.with_context_inputs(context_inputs);
}
}

let transaction = builder.finish_with_params(&protocol_parameters)?;
Expand Down
6 changes: 5 additions & 1 deletion sdk/src/wallet/operations/transaction/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use serde::{Deserialize, Serialize};

use crate::{
client::api::input_selection::Burn,
types::block::{address::Address, output::OutputId, payload::tagged_data::TaggedDataPayload},
types::block::{
address::Address, context_input::ContextInput, output::OutputId, payload::tagged_data::TaggedDataPayload,
},
};

/// Options for transactions
Expand All @@ -16,6 +18,8 @@ pub struct TransactionOptions {
pub remainder_value_strategy: RemainderValueStrategy,
#[serde(default)]
pub tagged_data_payload: Option<TaggedDataPayload>,
#[serde(default)]
pub context_inputs: Option<Vec<ContextInput>>,
// If custom inputs are provided only they are used. If also other additional inputs should be used,
// `mandatory_inputs` should be used instead.
#[serde(default)]
Expand Down

0 comments on commit 9486270

Please sign in to comment.