Function cardano_serialization_lib::utils::hash_script_data
source · pub fn hash_script_data(
redeemers: &Redeemers,
cost_models: &Costmdls,
datums: Option<PlutusList>
) -> ScriptDataHash
Examples found in repository?
src/tx_builder.rs (lines 1724-1728)
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731
pub fn calc_script_data_hash(&mut self, cost_models: &Costmdls) -> Result<(), JsError> {
let mut used_langs = BTreeSet::new();
let mut retained_cost_models = Costmdls::new();
let mut plutus_witnesses = PlutusWitnesses::new();
if let Some(mut inputs_plutus) = self.inputs.get_plutus_input_scripts() {
used_langs.append(&mut self.inputs.get_used_plutus_lang_versions());
plutus_witnesses.0.append(&mut inputs_plutus.0)
}
if let Some(mut collateral_plutus) = self.collateral.get_plutus_input_scripts() {
used_langs.append(&mut self.collateral.get_used_plutus_lang_versions());
plutus_witnesses.0.append(&mut collateral_plutus.0)
}
if let Some(mint_builder) = &self.mint {
used_langs.append(&mut mint_builder.get_used_plutus_lang_versions());
plutus_witnesses.0.append(&mut mint_builder.get_plutus_witnesses().0)
}
if plutus_witnesses.len() > 0 {
let (_scripts, datums, redeemers) = plutus_witnesses.collect();
for lang in used_langs {
match cost_models.get(&lang) {
Some(cost) => {
retained_cost_models.insert(&lang, &cost);
}
_ => {
return Err(JsError::from_str(&format!(
"Missing cost model for language version: {:?}",
lang
)))
}
}
}
self.script_data_hash = Some(hash_script_data(
&redeemers,
&retained_cost_models,
datums,
));
}
Ok(())
}