1use hdk::prelude::holo_hash::DnaHash;
2use hdk::prelude::*;
3
4#[derive(Debug, Serialize, Deserialize, SerializedBytes, Clone, PartialEq)]
5pub struct HashString(String);
6
7#[derive(Hash, Eq, Debug, Serialize, Deserialize, SerializedBytes, Clone, PartialEq)]
8#[serde(try_from = "HashString")]
9#[serde(into = "HashString")]
10pub struct WrappedAgentPubKey(pub AgentPubKey);
11
12#[derive(Hash, Eq, Debug, Serialize, Deserialize, SerializedBytes, Clone, PartialEq)]
13#[serde(try_from = "HashString")]
14#[serde(into = "HashString")]
15pub struct WrappedActionHash(pub ActionHash);
16
17#[derive(Hash, Eq, Debug, Serialize, Deserialize, SerializedBytes, Clone, PartialEq)]
18#[serde(try_from = "HashString")]
19#[serde(into = "HashString")]
20pub struct WrappedEntryHash(pub EntryHash);
21
22#[derive(Hash, Eq, Debug, Serialize, Deserialize, SerializedBytes, Clone, PartialEq)]
23#[serde(try_from = "HashString")]
24#[serde(into = "HashString")]
25pub struct WrappedDnaHash(pub DnaHash);
26
27impl TryFrom<HashString> for WrappedAgentPubKey {
28 type Error = String;
29 fn try_from(ui_string_hash: HashString) -> Result<Self, Self::Error> {
30 match AgentPubKey::try_from(ui_string_hash.0) {
31 Ok(address) => Ok(Self(address)),
32 Err(e) => Err(format!("{:?}", e)),
33 }
34 }
35}
36
37impl From<WrappedAgentPubKey> for AgentPubKey {
38 fn from(ui_string_hash: WrappedAgentPubKey) -> Self {
39 return ui_string_hash.0;
40 }
41}
42
43impl From<WrappedAgentPubKey> for HashString {
44 fn from(wrapped_agent_pub_key: WrappedAgentPubKey) -> Self {
45 Self(wrapped_agent_pub_key.0.to_string())
46 }
47}
48
49impl TryFrom<HashString> for WrappedActionHash {
50 type Error = String;
51 fn try_from(ui_string_hash: HashString) -> Result<Self, Self::Error> {
52 match ActionHash::try_from(ui_string_hash.0) {
53 Ok(address) => Ok(Self(address)),
54 Err(e) => Err(format!("what is this error {:?}", e)),
55 }
56 }
57}
58impl From<WrappedActionHash> for HashString {
59 fn from(wrapped_action_hash: WrappedActionHash) -> Self {
60 Self(wrapped_action_hash.0.to_string())
61 }
62}
63
64impl TryFrom<HashString> for WrappedEntryHash {
65 type Error = String;
66 fn try_from(ui_string_hash: HashString) -> Result<Self, Self::Error> {
67 match EntryHash::try_from(ui_string_hash.0) {
68 Ok(address) => Ok(Self(address)),
69 Err(e) => Err(format!("{:?}", e)),
70 }
71 }
72}
73impl From<WrappedEntryHash> for HashString {
74 fn from(wrapped_entry_hash: WrappedEntryHash) -> Self {
75 Self(wrapped_entry_hash.0.to_string())
76 }
77}
78
79impl TryFrom<HashString> for WrappedDnaHash {
80 type Error = String;
81 fn try_from(ui_string_hash: HashString) -> Result<Self, Self::Error> {
82 match DnaHash::try_from(ui_string_hash.0) {
83 Ok(address) => Ok(Self(address)),
84 Err(e) => Err(format!("{:?}", e)),
85 }
86 }
87}
88impl From<WrappedDnaHash> for HashString {
89 fn from(wrapped_entry_hash: WrappedDnaHash) -> Self {
90 Self(wrapped_entry_hash.0.to_string())
91 }
92}