Skip to content

Commit

Permalink
Wallet implicit_account_transition method
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez committed Nov 21, 2023
1 parent e6e6bbc commit 8b5c2d1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
28 changes: 3 additions & 25 deletions sdk/src/types/block/output/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ use packable::{
use crate::types::block::{
address::{AccountAddress, Address},
output::{
feature::{
verify_allowed_features, BlockIssuerFeature, BlockIssuerKey, BlockIssuerKeys, Ed25519BlockIssuerKey,
Feature, FeatureFlags, Features,
},
unlock_condition::{
verify_allowed_unlock_conditions, AddressUnlockCondition, UnlockCondition, UnlockConditionFlags,
UnlockConditions,
},
BasicOutput, ChainId, MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, StateTransitionError,
feature::{verify_allowed_features, Feature, FeatureFlags, Features},
unlock_condition::{verify_allowed_unlock_conditions, UnlockCondition, UnlockConditionFlags, UnlockConditions},
ChainId, MinimumOutputAmount, Output, OutputBuilderAmount, OutputId, StateTransitionError,
StateTransitionVerifier, StorageScore, StorageScoreParameters,
},
payload::signed_transaction::TransactionCapabilityFlag,
Expand Down Expand Up @@ -99,22 +93,6 @@ impl AccountOutputBuilder {
}
}

pub fn from_implicit_account(output: &BasicOutput, output_id: &OutputId) -> Result<Self, Error> {
if !output.is_implicit_account() {
panic!()
}

Ok(Self::new_with_amount(output.amount(), AccountId::from(output_id))
.with_mana(output.mana())
.with_unlock_conditions([AddressUnlockCondition::from(output.address().clone())])
.with_features([BlockIssuerFeature::new(
0,
BlockIssuerKeys::from_vec([BlockIssuerKey::from(Ed25519BlockIssuerKey::from(
output.address().as_implicit_account_creation(),
))])?,
)]))
}

/// Sets the amount to the provided value.
#[inline(always)]
pub fn with_amount(mut self, amount: u64) -> Self {
Expand Down
59 changes: 59 additions & 0 deletions sdk/src/wallet/operations/transaction/account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crate::{
client::secret::SecretManage,
types::block::output::{
feature::{BlockIssuerFeature, BlockIssuerKey, BlockIssuerKeys, Ed25519BlockIssuerKey},
unlock_condition::{AddressUnlockCondition, UnlockCondition},
AccountId, AccountOutput, BasicOutput, FoundryId, MinimumOutputAmount, NativeTokensBuilder, Output, OutputId,
},
wallet::{
operations::transaction::{TransactionOptions, TransactionWithMetadata},
Result, Wallet,
},
};

impl<S: 'static + SecretManage> Wallet<S>
where
crate::wallet::Error: From<S::Error>,
crate::client::Error: From<S::Error>,
{
async fn implicit_account_transition(&self, output_id: &OutputId) -> Result<TransactionWithMetadata> {
let implicit_account_data = self.data().await.unspent_outputs.get(output_id).cloned();

let implicit_account = if let Some(implicit_account_data) = &implicit_account_data {
if implicit_account_data.output.is_implicit_account() {
implicit_account_data.output.as_basic()
} else {
todo!()
}
} else {
todo!()
};

// [BlockIssuerFeature::new(
// 0,
// BlockIssuerKeys::from_vec([BlockIssuerKey::from(Ed25519BlockIssuerKey::from(
// implicit_account.address().as_implicit_account_creation(),
// ))]

let account = AccountOutput::build_with_amount(implicit_account.amount(), AccountId::from(output_id))
.with_mana(implicit_account.mana())
.with_unlock_conditions([AddressUnlockCondition::from(implicit_account.address().clone())])
.finish_output()?;
// .with_features()?,

let transaction_options = TransactionOptions {
custom_inputs: Some(vec![*output_id]),
..Default::default()
};

let prepared_transaction = self
.prepare_transaction(vec![account], transaction_options.clone())
.await?;

self.sign_and_submit_transaction(prepared_transaction, transaction_options)
.await
}
}
1 change: 1 addition & 0 deletions sdk/src/wallet/operations/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

pub(crate) mod account;
mod build_transaction;
pub(crate) mod high_level;
mod input_selection;
Expand Down

0 comments on commit 8b5c2d1

Please sign in to comment.