chia_sdk_driver/primitives/did/
did_launcher.rs

1use chia_protocol::Bytes32;
2use chia_puzzle_types::{EveProof, Proof};
3use chia_sdk_types::Conditions;
4use clvm_utils::ToTreeHash;
5
6use crate::{DriverError, HashedPtr, Launcher, SingletonInfo, SpendContext, SpendWithConditions};
7
8use super::{Did, DidInfo};
9
10impl Launcher {
11    pub fn create_eve_did(
12        self,
13        ctx: &mut SpendContext,
14        p2_puzzle_hash: Bytes32,
15        recovery_list_hash: Option<Bytes32>,
16        num_verifications_required: u64,
17        metadata: HashedPtr,
18    ) -> Result<(Conditions, Did), DriverError> {
19        let launcher_coin = self.coin();
20
21        let did_info = DidInfo::new(
22            launcher_coin.coin_id(),
23            recovery_list_hash,
24            num_verifications_required,
25            metadata,
26            p2_puzzle_hash,
27        );
28
29        let inner_puzzle_hash = did_info.inner_puzzle_hash();
30        let (launch_singleton, eve_coin) = self.spend(ctx, inner_puzzle_hash.into(), ())?;
31
32        let proof = Proof::Eve(EveProof {
33            parent_parent_coin_info: launcher_coin.parent_coin_info,
34            parent_amount: launcher_coin.amount,
35        });
36
37        Ok((launch_singleton, Did::new(eve_coin, proof, did_info)))
38    }
39
40    pub fn create_did<I>(
41        self,
42        ctx: &mut SpendContext,
43        recovery_list_hash: Option<Bytes32>,
44        num_verifications_required: u64,
45        metadata: HashedPtr,
46        inner: &I,
47    ) -> Result<(Conditions, Did), DriverError>
48    where
49        I: SpendWithConditions + ToTreeHash,
50    {
51        let (create_eve, eve) = self.create_eve_did(
52            ctx,
53            inner.tree_hash().into(),
54            recovery_list_hash,
55            num_verifications_required,
56            metadata,
57        )?;
58
59        let did = eve.update(ctx, inner, Conditions::new())?;
60
61        Ok((create_eve, did))
62    }
63
64    pub fn create_simple_did<I>(
65        self,
66        ctx: &mut SpendContext,
67        inner: &I,
68    ) -> Result<(Conditions, Did), DriverError>
69    where
70        I: SpendWithConditions + ToTreeHash,
71        Self: Sized,
72    {
73        self.create_did(ctx, None, 1, HashedPtr::NIL, inner)
74    }
75}