diff --git a/crates/icepick-workflow/src/lib.rs b/crates/icepick-workflow/src/lib.rs index 4a2bf20..42df6f3 100644 --- a/crates/icepick-workflow/src/lib.rs +++ b/crates/icepick-workflow/src/lib.rs @@ -1,7 +1,7 @@ use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath}; use serde::{Deserialize, Serialize}; use serde_json::Value; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeMap, HashSet}; #[derive(thiserror::Error, Debug)] pub enum SimulationError { @@ -38,7 +38,7 @@ pub struct Workflow { steps: Vec, } -pub type StringMap = HashMap; +pub type StringMap = BTreeMap; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct WorkflowStep { @@ -60,7 +60,7 @@ pub struct WorkflowStep { #[derive(Serialize, Deserialize)] pub struct OperationResult { // All values returned from an operation. - blob: HashMap, + blob: StringMap, // Any requested accounts from an operation. // @@ -115,10 +115,10 @@ impl Workflow { pub fn run_workflow( &self, - mut data: HashMap, + mut data: StringMap, operations: &[T], derive_keys: DeriveKeys, - ) -> Result, WorkflowError> { + ) -> Result, WorkflowError> { let mut derived_keys = vec![]; let mut derivation_accounts = vec![]; @@ -138,7 +138,7 @@ impl Workflow { derivation_accounts.clear(); // Prepare all inputs for the operation invocation - let inputs: HashMap = data + let inputs: StringMap = data .iter() .map(|(k, v)| (k, v.clone())) .filter_map(|(k, v)| { @@ -192,7 +192,7 @@ pub trait WorkflowHandler { /// within themselves. pub trait InvocableOperation { /// Invoke the operation with the supplied inputs and derived keys. - fn invoke(&self, input: &HashMap, derived_keys: &[Vec]) -> OperationResult; + fn invoke(&self, input: &StringMap, derived_keys: &[Vec]) -> OperationResult; /// The name of the operation. fn name(&self) -> &String; diff --git a/crates/icepick/build.rs b/crates/icepick/build.rs index 10c2450..4b38224 100644 --- a/crates/icepick/build.rs +++ b/crates/icepick/build.rs @@ -39,6 +39,8 @@ fn main() { workflows.push(workflow); } + workflows.sort_by(|a, b| a.name.cmp(&b.name)); + workflows_by_module.insert( module_dir.file_name().to_str().unwrap().to_owned(), workflows, diff --git a/crates/icepick/src/cli/mod.rs b/crates/icepick/src/cli/mod.rs index f029535..5469e70 100644 --- a/crates/icepick/src/cli/mod.rs +++ b/crates/icepick/src/cli/mod.rs @@ -3,7 +3,7 @@ use icepick_module::help::*; use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath}; use serde::{Deserialize, Serialize}; use std::{ - collections::HashMap, + collections::{HashMap, BTreeMap}, io::{IsTerminal, Write}, path::PathBuf, process::{Command, Stdio}, @@ -368,7 +368,7 @@ pub fn do_cli_thing() { } }; - let inputs: HashMap = + let inputs: BTreeMap = serde_json::from_value(inputs).unwrap(); let workflow = workflows diff --git a/crates/icepick/src/cli/workflow.rs b/crates/icepick/src/cli/workflow.rs index e66f196..1402f60 100644 --- a/crates/icepick/src/cli/workflow.rs +++ b/crates/icepick/src/cli/workflow.rs @@ -1,10 +1,9 @@ -use icepick_workflow::{InvocableOperation, OperationResult, Workflow}; +use icepick_workflow::{InvocableOperation, OperationResult, Workflow, StringMap}; use keyfork_derive_util::{request::DerivationAlgorithm, DerivationPath}; use keyfork_shard::{openpgp::OpenPGP, Format}; use miniquorum::{Payload, PayloadVerification}; use serde_json::Value; use std::{ - collections::HashMap, io::Write, process::{Command, Stdio}, }; @@ -20,8 +19,6 @@ pub enum Purpose { RunQuorum, } -pub type StringMap = std::collections::HashMap; - #[derive(Clone, Debug)] struct CLIOperation { /// The name of the operation (i.e. `transfer-token`). @@ -41,7 +38,7 @@ struct CLIOperation { } impl InvocableOperation for CLIOperation { - fn invoke(&self, input: &HashMap, derived_keys: &[Vec]) -> OperationResult { + fn invoke(&self, input: &StringMap, derived_keys: &[Vec]) -> OperationResult { let (command, args) = get_command(&self.binary); let json = serde_json::json!({ @@ -236,7 +233,7 @@ pub fn parse_quorum_with_shardfile( pub fn handle_payload( workflow: &Workflow, - inputs: HashMap, + inputs: StringMap, modules: Commands, config: &[ModuleConfig], ) { @@ -255,7 +252,7 @@ pub fn handle( config: &[ModuleConfig], ) { let inputs = load_inputs(&workflow.inputs, &workflow.optional_inputs, matches); - let data: HashMap = inputs + let data: StringMap = inputs .into_iter() .map(|(k, v)| (k, Value::String(v))) .collect();