txtx_addon_kit/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#[macro_use]
extern crate serde_derive;

#[macro_use]
extern crate lazy_static;

#[macro_use]
mod macros;
pub mod constants;

pub use hex;
// pub use hiro_system_kit;
pub use indoc::formatdoc;
pub use indoc::indoc;
use types::commands::CommandInputsEvaluationResult;
use types::commands::CommandInstance;
use types::diagnostics::Diagnostic;
use types::AddonPostProcessingResult;
use types::ConstructDid;
pub use uuid;
pub extern crate crossbeam_channel as channel;
pub use futures;
pub use hmac;
pub use indexmap;
pub use libsecp256k1 as secp256k1;
pub use pbkdf2;
pub use tiny_hderive;

pub use dotenvy_macro::dotenv;
pub use hcl_edit as hcl;
use std::{collections::HashMap, fmt::Debug};
use types::{
    commands::{CommandId, PreCommandSpecification},
    functions::FunctionSpecification,
    signers::SignerSpecification,
};

pub use keccak_hash;
pub use reqwest;
pub use serde;
pub use serde_json;
pub use sha2;

pub mod crypto;
pub mod helpers;
pub mod types;

lazy_static! {
    pub static ref DEFAULT_ADDON_DOCUMENTATION_TEMPLATE: String =
        include_str!("doc/default_addon_template.mdx").to_string();
    pub static ref DEFAULT_ADDON_FUNCTIONS_TEMPLATE: String =
        include_str!("doc/default_addon_functions_template.mdx").to_string();
    pub static ref DEFAULT_ADDON_ACTIONS_TEMPLATE: String =
        include_str!("doc/default_addon_actions_template.mdx").to_string();
    pub static ref DEFAULT_ADDON_WALLETS_TEMPLATE: String =
        include_str!("doc/default_addon_signers_template.mdx").to_string();
    pub static ref DEFAULT_ADDON_OVERVIEW_TEMPLATE: String =
        include_str!("doc/default_addon_overview_template.mdx").to_string();
}

///
pub trait Addon: Debug + Sync + Send {
    ///
    fn get_name(self: &Self) -> &str;
    ///
    fn get_description(self: &Self) -> &str;
    ///
    fn get_namespace(self: &Self) -> &str;
    ///
    fn get_functions(self: &Self) -> Vec<FunctionSpecification> {
        vec![]
    }
    ///
    fn get_actions(&self) -> Vec<PreCommandSpecification> {
        vec![]
    }
    ///
    fn get_signers(&self) -> Vec<SignerSpecification> {
        vec![]
    }
    ///
    fn build_function_lookup(self: &Self) -> HashMap<String, FunctionSpecification> {
        let mut functions = HashMap::new();
        for function in self.get_functions().into_iter() {
            functions.insert(function.name.clone(), function);
        }
        functions
    }
    ///
    fn build_command_lookup(self: &Self) -> HashMap<CommandId, PreCommandSpecification> {
        let mut commands = HashMap::new();

        for command in self.get_actions().into_iter() {
            let matcher = match &command {
                PreCommandSpecification::Atomic(command) => command.matcher.clone(),
                PreCommandSpecification::Composite(command) => command.matcher.clone(),
            };
            commands.insert(CommandId::Action(matcher), command);
        }
        commands
    }
    ///
    fn build_signer_lookup(self: &Self) -> HashMap<String, SignerSpecification> {
        let mut signer_specs = HashMap::new();

        for signer in self.get_signers().into_iter() {
            signer_specs.insert(signer.matcher.clone(), signer);
        }

        signer_specs
    }
    ///
    fn get_domain_specific_commands_inputs_dependencies<'a>(
        self: &Self,
        _commands_instances: &'a Vec<(
            ConstructDid,
            &'a CommandInstance,
            Option<&'a CommandInputsEvaluationResult>,
        )>,
    ) -> Result<AddonPostProcessingResult, (Diagnostic, ConstructDid)> {
        Ok(AddonPostProcessingResult::new())
    }
}