-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ManaAllotments to InputSelection * Add fulfill_mana_requirement * Add allotments to requirement * Already fulfilled check * Select inputs for mana * Cleanup allotments * Remove ManaAllotment * Pass mana allotments to ISA * Build tw with mana allotments * Add allot_mana and prepare_allot_mana * Add allot_mana_command to CLI * Add CLI log * Fix deadlock * Temporarily disable mana semantic check * fallback to implicit accounts * ManaAllotment camelCase * Tmp mana burn * Move mana burn cap to a single place * Some clippy * Nits * Copyright date * Add TODO * Cleanup TODO * Add mana_allotments to ISA output count check * Nit * Remove check * Fix no_std * move dto.outputs * Nit --------- Co-authored-by: /alex/ <[email protected]>
- Loading branch information
1 parent
656f20f
commit 679b8fa
Showing
20 changed files
with
337 additions
and
222 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
31 changes: 31 additions & 0 deletions
31
sdk/src/client/api/block_builder/input_selection/requirement/mana.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,31 @@ | ||
// Copyright 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use super::{Error, InputSelection}; | ||
use crate::client::secret::types::InputSigningData; | ||
|
||
impl InputSelection { | ||
pub(crate) fn fulfill_mana_requirement(&mut self, allotments: u64) -> Result<Vec<InputSigningData>, Error> { | ||
let required_mana = self.outputs.iter().map(|o| o.mana()).sum::<u64>() + allotments; | ||
let mut selected_mana = self.selected_inputs.iter().map(|o| o.output.mana()).sum::<u64>(); | ||
|
||
if selected_mana >= required_mana { | ||
log::debug!("Mana requirement already fulfilled"); | ||
Ok(Vec::new()) | ||
} else { | ||
let mut inputs = Vec::new(); | ||
|
||
// TODO we should do as for the amount and have preferences on which inputs to pick. | ||
while let Some(input) = self.available_inputs.pop() { | ||
selected_mana += input.output.mana(); | ||
inputs.push(input); | ||
|
||
if selected_mana >= required_mana { | ||
break; | ||
} | ||
} | ||
|
||
Ok(inputs) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.