Skip to content

Commit

Permalink
feat: building get v2 script hash
Browse files Browse the repository at this point in the history
  • Loading branch information
HinsonSIDAN committed Jan 21, 2024
1 parent b1bb537 commit 6aa718b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sidan-csl-rs"
version = "0.1.6"
version = "0.1.7"
edition = "2021"
license = "MIT"
description = "Wrapper around the cardano-serialization-lib for easier transaction building, heavily inspired by cardano-cli APIs"
Expand Down
10 changes: 10 additions & 0 deletions src/utils/csl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,13 @@ pub fn serialize_bech32_address(bech32_addr: String) -> SerializedAddress {
}
}
}

pub fn get_v2_script_hash(script: &str) -> String {
csl::plutus::PlutusScript::from_hex_with_version(
script,
&csl::plutus::Language::new_plutus_v2(),
)
.unwrap()
.hash()
.to_hex()
}
9 changes: 8 additions & 1 deletion tests/unit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod tests {
core::MeshTxBuilderCore,
models::{Asset, Budget, Redeemer, SerializedAddress},
},
utils::csl::serialize_bech32_address,
utils::csl::{get_v2_script_hash, serialize_bech32_address},
};

#[test]
Expand Down Expand Up @@ -305,4 +305,11 @@ mod tests {
}
)
}

#[test]
fn test_get_v2_script_hash() {
let correct_hash = "cc1bff3c00536918d99a78bd7548e864ffad95c8b6de562f709f0114";
let compiled_code = "584501000032323232323222533300432323253330073370e900018041baa0011324a2600c0022c60120026012002600600229309b2b118021baa0015734aae7555cf2ba157441";
assert_eq!(get_v2_script_hash(compiled_code), correct_hash);
}
}

0 comments on commit 6aa718b

Please sign in to comment.