1pub use dnahub_types;
2pub use devhub_sdk;
3pub use devhub_sdk::*;
4
5use hdk::prelude::*;
6use serde_bytes::*;
7use dnahub_types::{
8 DnaEntry,
9 DnaToken,
10 DnaManifestV1,
11};
12
13
14pub type IntegritiesTokenInput = Vec<(String, ByteBuf)>;
15pub type CoordinatorsTokenInput = Vec<(String, ByteBuf)>;
16
17
18#[derive(Serialize, Deserialize, Clone, Debug)]
19pub struct DnaTokenInput {
20 pub integrity_hash: ByteBuf,
21 pub integrities_token_hash: ByteBuf,
22 pub coordinators_token_hash: ByteBuf,
23}
24
25impl From<DnaTokenInput> for DnaToken {
26 fn from(dna_token_input: DnaTokenInput) -> Self {
27 Self {
28 integrity_hash: dna_token_input.integrity_hash.to_vec(),
29 integrities_token_hash: dna_token_input.integrities_token_hash.to_vec(),
30 coordinators_token_hash: dna_token_input.coordinators_token_hash.to_vec(),
31 }
32 }
33}
34
35
36#[derive(Serialize, Deserialize, Clone, Debug)]
37pub struct DnaEntryInput {
38 pub manifest: DnaManifestV1,
39 pub dna_token: DnaTokenInput,
40 pub integrities_token: IntegritiesTokenInput,
41 pub coordinators_token: CoordinatorsTokenInput,
42}
43
44impl From<DnaEntryInput> for DnaEntry {
45 fn from(dna_entry_input: DnaEntryInput) -> Self {
46 Self {
47 manifest: dna_entry_input.manifest,
48 dna_token: dna_entry_input.dna_token.into(),
49 integrities_token: dna_entry_input.integrities_token.into_iter()
50 .map( |(zome_name, bytes_input)| (zome_name, bytes_input.to_vec()) )
51 .collect(),
52 coordinators_token: dna_entry_input.coordinators_token.into_iter()
53 .map( |(zome_name, bytes_input)| (zome_name, bytes_input.to_vec()) )
54 .collect(),
55 }
56 }
57}
58
59
60#[derive(Clone, Debug, Serialize, Deserialize)]
61pub struct CreateDnaInput {
62 pub manifest: DnaManifestV1,
63}
64
65impl TryFrom<CreateDnaInput> for DnaEntry {
66 type Error = WasmError;
67
68 fn try_from(create_dna_input: CreateDnaInput) -> ExternResult<Self> {
69 Self::try_from( create_dna_input.manifest )
70 }
71}