Skip to content

Commit

Permalink
feat: building logic for multiple supply of eval input
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Aug 16, 2024
1 parent 5a7da5b commit 9de7bb2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 12 deletions.
14 changes: 7 additions & 7 deletions packages/sidan-csl-rs/src/model/tx_builder_types/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ pub struct InlineDatumSource {
pub tx_index: u32,
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ScriptSourceInfo {
pub tx_hash: String,
pub tx_index: u32,
pub spending_script_hash: Option<String>,
}
// #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
// #[serde(rename_all = "camelCase")]
// pub struct ScriptSourceInfo {
// pub tx_hash: String,
// pub tx_index: u32,
// pub spending_script_hash: Option<String>,
// }
4 changes: 3 additions & 1 deletion packages/whisky/src/builder/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ impl MeshTxBuilder {
self.complete_sync(customized_tx)?;
match &self.evaluator {
Some(evaluator) => {
let inputs_for_evaluation: Vec<_> =
self.inputs_for_evaluation.values().cloned().collect();
let tx_evaluation_result = evaluator
.evaluate_tx(
&self.core.mesh_csl.tx_hex,
&self.inputs_for_evaluation.clone(),
&inputs_for_evaluation,
&self.chained_txs.clone(),
)
.await;
Expand Down
57 changes: 53 additions & 4 deletions packages/whisky/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod tx_in;
mod tx_out;
mod withdrawal;

use std::collections::HashMap;

use cardano_serialization_lib::JsError;
pub use data::*;
use sidan_csl_rs::{core::algo::select_utxos, core::builder::*, model::*};
Expand All @@ -31,7 +33,7 @@ pub struct MeshTxBuilder {
pub extra_inputs: Vec<UTxO>,
pub selection_threshold: u64,
pub chained_txs: Vec<String>,
pub inputs_for_evaluation: Vec<UTxO>,
pub inputs_for_evaluation: HashMap<String, UTxO>,
}

pub struct MeshTxBuilderParam {
Expand Down Expand Up @@ -74,7 +76,7 @@ impl MeshTxBuilder {
extra_inputs: vec![],
selection_threshold: 5_000_000,
chained_txs: vec![],
inputs_for_evaluation: vec![],
inputs_for_evaluation: HashMap::new(),
}
}

Expand Down Expand Up @@ -254,7 +256,54 @@ impl MeshTxBuilder {
///
/// * `Self` - The MeshTxBuilder instance
pub fn input_for_evaluation(&mut self, input: &UTxO) -> &mut Self {
self.inputs_for_evaluation.push(input.clone());
let utxo_id = format!("{}{}", input.input.tx_hash, input.input.output_index);
let current_utxo = self.inputs_for_evaluation.get(&utxo_id);
match current_utxo {
Some(current_utxo) => {
let UtxoOutput {
address,
amount,
data_hash,
plutus_data,
script_ref,
script_hash,
} = input.clone().output;
let UtxoOutput {
data_hash: current_data_hash,
plutus_data: current_plutus_data,
script_ref: current_script_ref,
script_hash: current_script_hash,
..
} = current_utxo.output.clone();
let updated_utxo = UTxO {
output: UtxoOutput {
address,
amount,
data_hash: match data_hash {
Some(_) => data_hash,
None => current_data_hash,
},
plutus_data: match plutus_data {
Some(_) => plutus_data,
None => current_plutus_data,
},
script_ref: match script_ref {
Some(_) => script_ref,
None => current_script_ref,
},
script_hash: match script_hash {
Some(_) => script_hash,
None => current_script_hash,
},
},
..input.clone()
};
self.inputs_for_evaluation.insert(utxo_id, updated_utxo);
}
None => {
self.inputs_for_evaluation.insert(utxo_id, input.clone());
}
}
self
}

Expand Down Expand Up @@ -469,7 +518,7 @@ impl MeshTxBuilder {
.mesh_tx_builder_body
.inputs
.push(pub_key_input.clone());
self.inputs_for_evaluation.push(input);
self.input_for_evaluation(&input);
}
Ok(())
}
Expand Down

0 comments on commit 9de7bb2

Please sign in to comment.