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