Skip to content

Commit

Permalink
Remove the allow_allotting_from_account_mana flag (#2087)
Browse files Browse the repository at this point in the history
* Remove the stupid flag

* fmt

---------

Co-authored-by: Thoralf Müller <[email protected]>
  • Loading branch information
DaughterOfMars and Thoralf-M authored Feb 28, 2024
1 parent 7046f54 commit 59a68ab
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 94 deletions.
5 changes: 0 additions & 5 deletions bindings/nodejs/lib/types/wallet/transaction-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ export interface TransactionOptions {
allowMicroAmount?: boolean;
/** Whether to allow the selection of additional inputs for this transaction. */
allowAdditionalInputSelection?: boolean;
/**
* Whether to allow allotting automatically calculated mana from the issuer account.
* If this flag is disabled, additional inputs will be selected to cover the amount.
*/
allowAllottingFromAccountMana?: boolean;
/** Transaction capabilities. */
capabilities?: HexEncodedString;
/** Mana allotments for the transaction. */
Expand Down
3 changes: 0 additions & 3 deletions bindings/python/iota_sdk/types/transaction_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class TransactionOptions:
note: A string attached to the transaction.
allow_micro_amount: Whether to allow sending a micro amount.
allow_additional_input_selection: Whether to allow the selection of additional inputs for this transaction.
allow_allotting_from_account_mana: Whether to allow allotting automatically calculated mana from the issuer account.
If this flag is disabled, additional inputs will be selected to cover the amount.
capabilities: Transaction capabilities.
mana_allotments: Mana allotments for the transaction.
issuer_id: Optional block issuer to which the transaction will have required mana allotted.
Expand All @@ -70,7 +68,6 @@ class TransactionOptions:
note: Optional[str] = None
allow_micro_amount: Optional[bool] = None
allow_additional_input_selection: Optional[bool] = None
allow_allotting_from_account_mana: Optional[bool] = None
capabilities: Optional[HexStr] = None
mana_allotments: Optional[dict[HexStr, int]] = None
issuer_id: Optional[HexStr] = None
64 changes: 8 additions & 56 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ pub enum WalletCommand {
fixed_cost: u64,
/// The staking period (in epochs). Will default to the staking unbonding period.
staking_period: Option<u32>,
/// Whether to allot mana from the account output.
#[arg(long, default_value_t = true)]
allot_from_account: bool,
},
/// Burn an amount of native token.
BurnNativeToken {
Expand Down Expand Up @@ -167,9 +164,6 @@ pub enum WalletCommand {
EndStaking {
/// The Account ID of the staking account.
account_id: AccountId,
/// Whether to allot mana from the account output.
#[arg(long, default_value_t = true)]
allot_from_account: bool,
},
/// Exit the CLI wallet.
Exit,
Expand All @@ -179,9 +173,6 @@ pub enum WalletCommand {
account_id: AccountId,
/// The number of additional epochs to add to the staking period.
additional_epochs: u32,
/// Whether to allot mana from the account output.
#[arg(long, default_value_t = true)]
allot_from_account: bool,
},
/// Request funds from the faucet.
Faucet {
Expand Down Expand Up @@ -491,7 +482,6 @@ pub async fn begin_staking_command(
staked_amount: u64,
fixed_cost: u64,
staking_period: Option<u32>,
allot_from_account: bool,
) -> Result<(), Error> {
println_log_info!("Begin staking for {account_id}.");

Expand All @@ -503,10 +493,7 @@ pub async fn begin_staking_command(
fixed_cost,
staking_period,
},
TransactionOptions {
allow_allotting_from_account_mana: allot_from_account,
..Default::default()
},
None,
)
.await?;

Expand Down Expand Up @@ -816,22 +803,10 @@ pub async fn destroy_foundry_command(wallet: &Wallet, foundry_id: FoundryId) ->
}

// `end-staking` command
pub async fn end_staking_command(
wallet: &Wallet,
account_id: AccountId,
allot_from_account: bool,
) -> Result<(), Error> {
pub async fn end_staking_command(wallet: &Wallet, account_id: AccountId) -> Result<(), Error> {
println_log_info!("Ending staking for {account_id}.");

let transaction = wallet
.end_staking(
account_id,
TransactionOptions {
allow_allotting_from_account_mana: allot_from_account,
..Default::default()
},
)
.await?;
let transaction = wallet.end_staking(account_id, None).await?;

println_log_info!(
"End staking transaction sent:\n{:?}\n{:?}",
Expand All @@ -847,20 +822,10 @@ pub async fn extend_staking_command(
wallet: &Wallet,
account_id: AccountId,
additional_epochs: u32,
allot_from_account: bool,
) -> Result<(), Error> {
println_log_info!("Extending staking for {account_id} by {additional_epochs} epochs.");

let transaction = wallet
.extend_staking(
account_id,
additional_epochs,
TransactionOptions {
allow_allotting_from_account_mana: allot_from_account,
..Default::default()
},
)
.await?;
let transaction = wallet.extend_staking(account_id, additional_epochs, None).await?;

println_log_info!(
"Extend staking transaction sent:\n{:?}\n{:?}",
Expand Down Expand Up @@ -1472,18 +1437,9 @@ pub async fn prompt_internal(
staked_amount,
fixed_cost,
staking_period,
allot_from_account,
} => {
ensure_password(wallet).await?;
begin_staking_command(
wallet,
account_id,
staked_amount,
fixed_cost,
staking_period,
allot_from_account,
)
.await
begin_staking_command(wallet, account_id, staked_amount, fixed_cost, staking_period).await
}
WalletCommand::BurnNativeToken { token_id, amount } => {
ensure_password(wallet).await?;
Expand Down Expand Up @@ -1555,23 +1511,19 @@ pub async fn prompt_internal(
ensure_password(wallet).await?;
destroy_foundry_command(wallet, foundry_id).await
}
WalletCommand::EndStaking {
account_id,
allot_from_account,
} => {
WalletCommand::EndStaking { account_id } => {
ensure_password(wallet).await?;
end_staking_command(wallet, account_id, allot_from_account).await
end_staking_command(wallet, account_id).await
}
WalletCommand::Exit => {
return Ok(PromptResponse::Done);
}
WalletCommand::ExtendStaking {
account_id,
additional_epochs,
allot_from_account,
} => {
ensure_password(wallet).await?;
extend_staking_command(wallet, account_id, additional_epochs, allot_from_account).await
extend_staking_command(wallet, account_id, additional_epochs).await
}
WalletCommand::Faucet { address, url } => faucet_command(wallet, address, url).await,
WalletCommand::ImplicitAccountCreationAddress => {
Expand Down
9 changes: 1 addition & 8 deletions sdk/src/client/api/block_builder/input_selection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ pub struct InputSelection {
#[derive(Copy, Clone, Debug)]
pub(crate) struct MinManaAllotment {
issuer_id: AccountId,
allow_allotting_from_account_mana: bool,
reference_mana_cost: u64,
allotment_debt: u64,
}
Expand Down Expand Up @@ -418,15 +417,9 @@ impl InputSelection {
}

/// Specifies an account to which the minimum required mana allotment will be added.
pub fn with_min_mana_allotment(
mut self,
account_id: AccountId,
reference_mana_cost: u64,
allow_allotting_from_account_mana: bool,
) -> Self {
pub fn with_min_mana_allotment(mut self, account_id: AccountId, reference_mana_cost: u64) -> Self {
self.min_mana_allotment.replace(MinManaAllotment {
issuer_id: account_id,
allow_allotting_from_account_mana,
reference_mana_cost,
allotment_debt: 0,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ impl InputSelection {
let MinManaAllotment {
issuer_id,
allotment_debt,
allow_allotting_from_account_mana,
..
} = self
.min_mana_allotment
Expand All @@ -102,9 +101,7 @@ impl InputSelection {
*allotment_debt = self.mana_allotments[issuer_id];
}

if *allow_allotting_from_account_mana {
self.reduce_account_output()?;
}
self.reduce_account_output()?;
} else if !self.requirements.contains(&Requirement::Mana) {
self.requirements.push(Requirement::Mana);
}
Expand Down
6 changes: 1 addition & 5 deletions sdk/src/wallet/operations/transaction/input_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,7 @@ where
.with_burn(options.burn);

if let (Some(account_id), Some(reference_mana_cost)) = (options.issuer_id, reference_mana_cost) {
input_selection = input_selection.with_min_mana_allotment(
account_id,
reference_mana_cost,
options.allow_allotting_from_account_mana,
);
input_selection = input_selection.with_min_mana_allotment(account_id, reference_mana_cost);
}

if !options.allow_additional_input_selection {
Expand Down
4 changes: 0 additions & 4 deletions sdk/src/wallet/operations/transaction/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ pub struct TransactionOptions {
pub allow_micro_amount: bool,
/// Whether to allow the selection of additional inputs for this transaction.
pub allow_additional_input_selection: bool,
/// Whether to allow allotting automatically calculated mana from the issuer account.
/// If this flag is disabled, additional inputs will be selected to cover the amount.
pub allow_allotting_from_account_mana: bool,
/// Transaction capabilities.
pub capabilities: Option<TransactionCapabilities>,
/// Mana allotments for the transaction.
Expand All @@ -58,7 +55,6 @@ impl Default for TransactionOptions {
note: Default::default(),
allow_micro_amount: false,
allow_additional_input_selection: true,
allow_allotting_from_account_mana: false,
capabilities: Default::default(),
mana_allotments: Default::default(),
issuer_id: Default::default(),
Expand Down
14 changes: 7 additions & 7 deletions sdk/tests/client/input_selection/account_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@ fn min_allot_account_mana() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.select()
.unwrap();

Expand Down Expand Up @@ -1793,7 +1793,7 @@ fn min_allot_account_mana_additional() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.with_mana_allotments(Some((account_id_1, provided_allotment)))
.select()
.unwrap();
Expand Down Expand Up @@ -1859,7 +1859,7 @@ fn min_allot_account_mana_cannot_select_additional() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.with_mana_allotments(Some((account_id_2, provided_allotment)))
.with_required_inputs([*inputs[0].output_id()])
.disable_additional_input_selection()
Expand Down Expand Up @@ -1912,7 +1912,7 @@ fn min_allot_account_mana_requirement_twice() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.with_required_inputs([*inputs[1].output_id()])
.select()
.unwrap();
Expand Down Expand Up @@ -1993,7 +1993,7 @@ fn min_allot_account_mana_requirement_covered() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.with_mana_allotments(Some((account_id_1, provided_allotment)))
.select()
.unwrap();
Expand Down Expand Up @@ -2068,7 +2068,7 @@ fn min_allot_account_mana_requirement_covered_2() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.with_mana_allotments(Some((account_id_1, provided_allotment)))
.select()
.unwrap();
Expand Down Expand Up @@ -2127,7 +2127,7 @@ fn implicit_account_transition() {
protocol_parameters,
)
.with_required_inputs(vec![input_output_id])
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.select()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/input_selection/basic_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ fn automatic_allotment_provided_in_and_output() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 2, true)
.with_min_mana_allotment(account_id_1, 2)
.select()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion sdk/tests/client/input_selection/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ fn consolidate_with_min_allotment() {
SLOT_COMMITMENT_ID,
protocol_parameters,
)
.with_min_mana_allotment(account_id_1, 10, true)
.with_min_mana_allotment(account_id_1, 10)
.with_required_inputs(inputs.iter().map(|i| *i.output_id()))
.select()
.unwrap();
Expand Down

0 comments on commit 59a68ab

Please sign in to comment.