whisky_pallas/utils/
script.rs1use whisky_common::{LanguageVersion, WError};
2
3use crate::wrapper::witness_set::{native_script::NativeScript, plutus_script::PlutusScript};
4
5pub fn get_native_script_hash(script: &str) -> Result<String, WError> {
6 NativeScript::decode_bytes(&hex::decode(script).map_err(|e| {
7 WError::new(
8 "WhiskyPallas - Decoding native script:",
9 &format!("Hex decode error: {}", e.to_string()),
10 )
11 })?)
12 .map(|ns| ns.hash())
13}
14
15pub fn get_script_hash(script: &str, version: LanguageVersion) -> Result<String, WError> {
16 match version {
17 LanguageVersion::V1 => Ok(
18 PlutusScript::<1>::decode_bytes(&hex::decode(script).map_err(|e| {
19 WError::new(
20 "WhiskyPallas - Decoding Plutus script:",
21 &format!("Hex decode error: {}", e.to_string()),
22 )
23 })?)?
24 .hash(),
25 ),
26 LanguageVersion::V2 => Ok(
27 PlutusScript::<2>::decode_bytes(&hex::decode(script).map_err(|e| {
28 WError::new(
29 "WhiskyPallas - Decoding Plutus script:",
30 &format!("Hex decode error: {}", e.to_string()),
31 )
32 })?)?
33 .hash(),
34 ),
35 LanguageVersion::V3 => Ok(
36 PlutusScript::<3>::decode_bytes(&hex::decode(script).map_err(|e| {
37 WError::new(
38 "WhiskyPallas - Decoding Plutus script:",
39 &format!("Hex decode error: {}", e.to_string()),
40 )
41 })?)?
42 .hash(),
43 ),
44 }
45}