Skip to content

Commit

Permalink
return result from utxo selection
Browse files Browse the repository at this point in the history
  • Loading branch information
twwu123 committed Apr 23, 2024
1 parent 9ea5492 commit 12a2bfd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rust/src/builder/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ impl IMeshTxBuilderCore for MeshTxBuilder {
required_assets.negate_asset(mint_amount);
}

let selected_inputs = select_utxos(extra_inputs, required_assets, threshold.to_string());
let selected_inputs = select_utxos(extra_inputs, required_assets, threshold.to_string()).unwrap();

for input in selected_inputs {
self.mesh_csl.add_tx_in(PubKeyTxIn {
Expand Down
8 changes: 4 additions & 4 deletions rust/src/core/algo/utxo_selection.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::model::*;
use std::collections::HashSet;

pub fn select_utxos(inputs: Vec<UTxO>, required_assets: Value, threshold: String) -> Vec<UTxO> {
pub fn select_utxos(inputs: Vec<UTxO>, required_assets: Value, threshold: String) -> Result<Vec<UTxO>, String> {
let mut total_required_assets = required_assets.clone();
total_required_assets.add_asset(Asset::new("lovelace".to_string(), threshold));

Expand Down Expand Up @@ -80,7 +80,7 @@ pub fn select_utxos(inputs: Vec<UTxO>, required_assets: Value, threshold: String
for unit in required_units.clone() {
if total_required_assets.get(&unit) > 0 {
println!("Total required assets: {:?}", total_required_assets);
panic!("Selection failed");
return Err("Selection failed".to_string());
}
}

Expand All @@ -89,7 +89,7 @@ pub fn select_utxos(inputs: Vec<UTxO>, required_assets: Value, threshold: String
selected_utxos.push(inputs[*index].clone());
}

selected_utxos
Ok(selected_utxos)
}

#[test]
Expand All @@ -114,6 +114,6 @@ fn test_basic_selection() {

let mut required_assets: Value = Value::new();
required_assets.add_asset(Asset::new_from_str("lovelace", "5000000"));
let selected_list = select_utxos(utxo_list.clone(), required_assets, "5000000".to_string());
let selected_list = select_utxos(utxo_list.clone(), required_assets, "5000000".to_string()).unwrap();
assert_eq!(utxo_list, selected_list);
}

0 comments on commit 12a2bfd

Please sign in to comment.