-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable modifying Block Issuer Keys in CLI Wallet (#2235)
* Enable adding block issuer keys in cli wallet * Add Modify Block Issuer Keys in AccountChange Co-authored-by: Thoralf-M <[email protected]> * Add remove block issuer key command * Fix incorrect info message * Add missing comment on enum variant * Add missing "for" in doc comment * Rename `account` -> `account_id` * Refactor account transition requirement Co-authored-by: Thoralf-M <[email protected]> * Update sdk/src/wallet/operations/transaction/high_level/account_block_issuer_keys.rs Co-authored-by: Thoralf-M <[email protected]> * Avoid clone of account_id * Remove required_inputs from begin staking as it's handled by the transition --------- Co-authored-by: Thoralf-M <[email protected]> Co-authored-by: Thoralf Müller <[email protected]>
- Loading branch information
1 parent
e046ae5
commit e5e80d3
Showing
8 changed files
with
190 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
sdk/src/wallet/operations/transaction/high_level/account_block_issuer_keys.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{ | ||
client::{ | ||
api::{ | ||
transaction_builder::{transition::AccountChange, Transitions}, | ||
PreparedTransactionData, | ||
}, | ||
secret::SecretManage, | ||
ClientError, | ||
}, | ||
types::block::output::{feature::BlockIssuerKey, AccountId}, | ||
wallet::{operations::transaction::TransactionOptions, types::TransactionWithMetadata, Wallet, WalletError}, | ||
}; | ||
|
||
/// Params for `modify_account_output_block_issuer_keys()` | ||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ModifyAccountBlockIssuerKey { | ||
pub account_id: AccountId, | ||
/// The keys that will be added. | ||
pub keys_to_add: Vec<BlockIssuerKey>, | ||
/// The keys that will be removed. | ||
pub keys_to_remove: Vec<BlockIssuerKey>, | ||
} | ||
|
||
impl<S: 'static + SecretManage> Wallet<S> | ||
where | ||
WalletError: From<S::Error>, | ||
ClientError: From<S::Error>, | ||
{ | ||
pub async fn modify_account_output_block_issuer_keys( | ||
&self, | ||
params: ModifyAccountBlockIssuerKey, | ||
options: impl Into<Option<TransactionOptions>> + Send, | ||
) -> Result<TransactionWithMetadata, WalletError> { | ||
let options = options.into(); | ||
let prepared_transaction = self | ||
.prepare_modify_account_output_block_issuer_keys(params, options.clone()) | ||
.await?; | ||
|
||
self.sign_and_submit_transaction(prepared_transaction, options).await | ||
} | ||
|
||
/// Prepares the transaction for [Wallet::create_account_output()]. | ||
pub async fn prepare_modify_account_output_block_issuer_keys( | ||
&self, | ||
params: ModifyAccountBlockIssuerKey, | ||
options: impl Into<Option<TransactionOptions>> + Send, | ||
) -> Result<PreparedTransactionData, WalletError> { | ||
log::debug!("[TRANSACTION] prepare_modify_account_output_block_issuer_keys"); | ||
|
||
let change = AccountChange::ModifyBlockIssuerKeys { | ||
keys_to_add: params.keys_to_add, | ||
keys_to_remove: params.keys_to_remove, | ||
}; | ||
|
||
let account_id = params.account_id; | ||
|
||
let mut options = options.into(); | ||
if let Some(options) = options.as_mut() { | ||
if let Some(transitions) = options.transitions.take() { | ||
options.transitions = Some(transitions.add_account(account_id, change)); | ||
} | ||
} else { | ||
options.replace(TransactionOptions { | ||
transitions: Some(Transitions::new().add_account(account_id, change)), | ||
..Default::default() | ||
}); | ||
} | ||
|
||
self.prepare_send_outputs(None, options).await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters