-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathstandard_puzzle.rs
34 lines (29 loc) · 1 KB
/
standard_puzzle.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
use chia_bls::PublicKey;
use clvm_utils::{curry_tree_hash, tree_hash_atom, FromClvm, LazyNode, ToClvm};
use clvmr::{allocator::NodePtr, Allocator};
use crate::puzzles::STANDARD_PUZZLE_HASH;
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(curried_args)]
pub struct StandardArgs {
pub synthetic_key: PublicKey,
}
#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)]
#[clvm(proper_list)]
pub struct StandardSolution {
pub original_public_key: Option<PublicKey>,
pub delegated_puzzle: LazyNode,
pub solution: LazyNode,
}
impl StandardSolution {
pub fn with_conditions(a: &mut Allocator, conditions: NodePtr) -> Self {
Self {
original_public_key: None,
delegated_puzzle: LazyNode(conditions),
solution: LazyNode(a.null()),
}
}
}
pub fn standard_puzzle_hash(synthetic_key: &PublicKey) -> [u8; 32] {
let synthetic_key = tree_hash_atom(&synthetic_key.to_bytes());
curry_tree_hash(&STANDARD_PUZZLE_HASH, &[&synthetic_key])
}