Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 10, 2024
1 parent 7df277e commit dc616eb
Showing 1 changed file with 48 additions and 5 deletions.
53 changes: 48 additions & 5 deletions crates/chia-sdk-driver/src/primitives/vault/vault_primitive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
use chia_protocol::{Bytes32, Coin};
use chia_puzzles::singleton::SingletonArgs;
use chia_sdk_types::Mod;
use clvm_utils::TreeHash;
use clvmr::NodePtr;

use super::{Member, PuzzleWithRestrictions};
use crate::{DriverError, SpendContext};

use super::{KnownPuzzles, Member, PuzzleWithRestrictions, VaultLayer};

#[derive(Debug, Clone)]
pub struct Vault {
Expand All @@ -19,11 +25,33 @@ impl Vault {
}
}

impl VaultLayer for Vault {
fn puzzle_hash(&self) -> TreeHash {
SingletonArgs::new(self.launcher_id, self.custody.puzzle_hash()).curry_tree_hash()
}

fn puzzle(&self, ctx: &mut SpendContext) -> Result<NodePtr, DriverError> {
let puzzle = self.custody.puzzle(ctx)?;
ctx.curry(SingletonArgs::new(self.launcher_id, puzzle))
}

fn replace(self, known_puzzles: &KnownPuzzles) -> Self {
Self {
coin: self.coin,
launcher_id: self.launcher_id,
custody: self.custody.replace(known_puzzles),
}
}
}

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use chia_sdk_test::Simulator;
use chia_sdk_types::BlsMember;

use crate::{Launcher, SpendContext, StandardLayer};
use crate::{Launcher, MemberKind, SpendContext, StandardLayer};

use super::*;

Expand All @@ -35,12 +63,27 @@ mod tests {
let (sk, pk, _puzzle_hash, coin) = sim.new_p2(1)?;
let p2 = StandardLayer::new(pk);

let custody = PuzzleWithRestrictions::top_level(0, Vec::new(), Member::bls(pk));
let (mint_vault, _vault) = Launcher::new(coin.coin_id(), 1).mint_vault(ctx, custody, ())?;
p2.spend(ctx, coin, mint_vault)?;
let hidden_member = BlsMember::new(pk);

let custody = PuzzleWithRestrictions::top_level(
0,
Vec::new(),
Member::unknown(hidden_member.curry_tree_hash()),
);
let (mint_vault, vault) = Launcher::new(coin.coin_id(), 1).mint_vault(ctx, custody, ())?;
p2.spend(ctx, coin, mint_vault)?;
sim.spend_coins(ctx.take(), &[sk])?;

let mut known_members = HashMap::new();
known_members.insert(
hidden_member.curry_tree_hash(),
MemberKind::Bls(hidden_member),
);
let _vault = vault.replace(&KnownPuzzles {
members: known_members,
..Default::default()
});

Ok(())
}
}

0 comments on commit dc616eb

Please sign in to comment.