From 8b5c2d1ba66f982b971fddc428fcf158ce5e3884 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Tue, 21 Nov 2023 12:24:29 +0100 Subject: [PATCH] Wallet implicit_account_transition method --- sdk/src/types/block/output/account.rs | 28 +-------- .../wallet/operations/transaction/account.rs | 59 +++++++++++++++++++ sdk/src/wallet/operations/transaction/mod.rs | 1 + 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 sdk/src/wallet/operations/transaction/account.rs diff --git a/sdk/src/types/block/output/account.rs b/sdk/src/types/block/output/account.rs index 822df0f2c7..b9b1555725 100644 --- a/sdk/src/types/block/output/account.rs +++ b/sdk/src/types/block/output/account.rs @@ -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, @@ -99,22 +93,6 @@ impl AccountOutputBuilder { } } - pub fn from_implicit_account(output: &BasicOutput, output_id: &OutputId) -> Result { - 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 { diff --git a/sdk/src/wallet/operations/transaction/account.rs b/sdk/src/wallet/operations/transaction/account.rs new file mode 100644 index 0000000000..ab0a9d7055 --- /dev/null +++ b/sdk/src/wallet/operations/transaction/account.rs @@ -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 Wallet +where + crate::wallet::Error: From, + crate::client::Error: From, +{ + async fn implicit_account_transition(&self, output_id: &OutputId) -> Result { + 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 + } +} diff --git a/sdk/src/wallet/operations/transaction/mod.rs b/sdk/src/wallet/operations/transaction/mod.rs index 78cfcdfbf7..64b163b6a2 100644 --- a/sdk/src/wallet/operations/transaction/mod.rs +++ b/sdk/src/wallet/operations/transaction/mod.rs @@ -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;