1#[macro_use]
2extern crate serde_derive;
3
4#[macro_use]
5extern crate lazy_static;
6
7#[macro_use]
8mod macros;
9pub mod constants;
10
11pub use hex;
12pub use indoc::formatdoc;
14pub use indoc::indoc;
15use types::commands::CommandInputsEvaluationResult;
16use types::commands::CommandInstance;
17use types::diagnostics::Diagnostic;
18use types::AddonPostProcessingResult;
19use types::ConstructDid;
20pub use uuid;
21pub extern crate crossbeam_channel as channel;
22pub use futures;
23pub use hmac;
24pub use indexmap;
25pub use libsecp256k1 as secp256k1;
26pub use pbkdf2;
27
28pub use hcl_edit as hcl;
29use std::{collections::HashMap, fmt::Debug};
30use types::{
31 commands::{CommandId, PreCommandSpecification},
32 functions::FunctionSpecification,
33 signers::SignerSpecification,
34};
35
36pub use keccak_hash;
37pub use reqwest;
38pub use serde;
39pub use serde_json;
40pub use sha2;
41
42use crate::types::types::Value;
43
44pub mod crypto;
45pub mod helpers;
46pub mod types;
47
48lazy_static! {
49 pub static ref DEFAULT_ADDON_DOCUMENTATION_TEMPLATE: String =
50 include_str!("doc/default_addon_template.mdx").to_string();
51 pub static ref DEFAULT_ADDON_FUNCTIONS_TEMPLATE: String =
52 include_str!("doc/default_addon_functions_template.mdx").to_string();
53 pub static ref DEFAULT_ADDON_ACTIONS_TEMPLATE: String =
54 include_str!("doc/default_addon_actions_template.mdx").to_string();
55 pub static ref DEFAULT_ADDON_WALLETS_TEMPLATE: String =
56 include_str!("doc/default_addon_signers_template.mdx").to_string();
57 pub static ref DEFAULT_ADDON_OVERVIEW_TEMPLATE: String =
58 include_str!("doc/default_addon_overview_template.mdx").to_string();
59}
60
61pub trait Addon: Debug + Sync + Send {
63 fn get_name(self: &Self) -> &str;
65 fn get_description(self: &Self) -> &str;
67 fn get_namespace(self: &Self) -> &str;
69 fn get_functions(self: &Self) -> Vec<FunctionSpecification> {
71 vec![]
72 }
73 fn get_actions(&self) -> Vec<PreCommandSpecification> {
75 vec![]
76 }
77 fn get_signers(&self) -> Vec<SignerSpecification> {
79 vec![]
80 }
81 fn to_json(&self, _value: &Value) -> Result<Option<serde_json::Value>, Diagnostic> {
82 Ok(None)
83 }
84 fn build_function_lookup(self: &Self) -> HashMap<String, FunctionSpecification> {
86 let mut functions = HashMap::new();
87 for function in self.get_functions().into_iter() {
88 functions.insert(function.name.clone(), function);
89 }
90 functions
91 }
92 fn build_command_lookup(self: &Self) -> HashMap<CommandId, PreCommandSpecification> {
94 let mut commands = HashMap::new();
95
96 for command in self.get_actions().into_iter() {
97 let matcher = match &command {
98 PreCommandSpecification::Atomic(command) => command.matcher.clone(),
99 PreCommandSpecification::Composite(command) => command.matcher.clone(),
100 };
101 commands.insert(CommandId::Action(matcher), command);
102 }
103 commands
104 }
105 fn build_signer_lookup(self: &Self) -> HashMap<String, SignerSpecification> {
107 let mut signer_specs = HashMap::new();
108
109 for signer in self.get_signers().into_iter() {
110 signer_specs.insert(signer.matcher.clone(), signer);
111 }
112
113 signer_specs
114 }
115 fn get_domain_specific_commands_inputs_dependencies<'a>(
117 self: &Self,
118 _commands_instances: &'a Vec<(
119 ConstructDid,
120 &'a CommandInstance,
121 Option<&'a CommandInputsEvaluationResult>,
122 )>,
123 ) -> Result<AddonPostProcessingResult, (Diagnostic, ConstructDid)> {
124 Ok(AddonPostProcessingResult::new())
125 }
126}