-
Notifications
You must be signed in to change notification settings - Fork 9
/
script.rs
49 lines (43 loc) · 1.55 KB
/
script.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use naumachia::scripts::{
plutus_validator::PlutusValidator,
raw_script::BlueprintFile,
ScriptError,
ScriptResult,
};
const BLUEPRINT: &str = include_str!("../../always_succeeds/plutus.json");
const VALIDATOR_NAME: &str = "always_true.spend";
pub fn get_script() -> ScriptResult<PlutusValidator<(), ()>> {
let script_file: BlueprintFile = serde_json::from_str(BLUEPRINT)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
let validator_blueprint = script_file.get_validator(VALIDATOR_NAME).ok_or(
ScriptError::FailedToConstruct(format!(
"Validator not listed in Blueprint: {:?}",
VALIDATOR_NAME
)),
)?;
let raw_script_validator = PlutusValidator::from_blueprint(validator_blueprint)
.map_err(|e| ScriptError::FailedToConstruct(e.to_string()))?;
Ok(raw_script_validator)
}
#[cfg(test)]
mod tests {
use super::*;
use naumachia::{
scripts::{
context::{
pub_key_hash_from_address_if_available,
ContextBuilder,
},
Validator,
},
Address,
};
#[test]
fn test() {
let script = get_script().unwrap();
let owner = Address::from_bech32("addr_test1qpmtp5t0t5y6cqkaz7rfsyrx7mld77kpvksgkwm0p7en7qum7a589n30e80tclzrrnj8qr4qvzj6al0vpgtnmrkkksnqd8upj0").unwrap();
let owner_pkh = pub_key_hash_from_address_if_available(&owner).unwrap();
let ctx = ContextBuilder::new(owner_pkh).build_spend(&vec![], 0);
script.execute((), (), ctx).unwrap();
}
}