hashmap is the mind killer

This commit is contained in:
Ryan Heywood 2025-02-08 17:14:15 -05:00
parent e4756fd158
commit dcb9c50d29
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
4 changed files with 15 additions and 16 deletions

View File

@ -1,7 +1,7 @@
use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath}; use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use std::collections::{HashMap, HashSet}; use std::collections::{BTreeMap, HashSet};
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum SimulationError { pub enum SimulationError {
@ -38,7 +38,7 @@ pub struct Workflow {
steps: Vec<WorkflowStep>, steps: Vec<WorkflowStep>,
} }
pub type StringMap = HashMap<String, String>; pub type StringMap<T = String> = BTreeMap<String, T>;
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct WorkflowStep { pub struct WorkflowStep {
@ -60,7 +60,7 @@ pub struct WorkflowStep {
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct OperationResult { pub struct OperationResult {
// All values returned from an operation. // All values returned from an operation.
blob: HashMap<String, Value>, blob: StringMap<Value>,
// Any requested accounts from an operation. // Any requested accounts from an operation.
// //
@ -115,10 +115,10 @@ impl Workflow {
pub fn run_workflow<T: InvocableOperation>( pub fn run_workflow<T: InvocableOperation>(
&self, &self,
mut data: HashMap<String, Value>, mut data: StringMap<Value>,
operations: &[T], operations: &[T],
derive_keys: DeriveKeys, derive_keys: DeriveKeys,
) -> Result<HashMap<String, Value>, WorkflowError> { ) -> Result<StringMap<Value>, WorkflowError> {
let mut derived_keys = vec![]; let mut derived_keys = vec![];
let mut derivation_accounts = vec![]; let mut derivation_accounts = vec![];
@ -138,7 +138,7 @@ impl Workflow {
derivation_accounts.clear(); derivation_accounts.clear();
// Prepare all inputs for the operation invocation // Prepare all inputs for the operation invocation
let inputs: HashMap<String, Value> = data let inputs: StringMap<Value> = data
.iter() .iter()
.map(|(k, v)| (k, v.clone())) .map(|(k, v)| (k, v.clone()))
.filter_map(|(k, v)| { .filter_map(|(k, v)| {
@ -192,7 +192,7 @@ pub trait WorkflowHandler {
/// within themselves. /// within themselves.
pub trait InvocableOperation { pub trait InvocableOperation {
/// Invoke the operation with the supplied inputs and derived keys. /// Invoke the operation with the supplied inputs and derived keys.
fn invoke(&self, input: &HashMap<String, Value>, derived_keys: &[Vec<u8>]) -> OperationResult; fn invoke(&self, input: &StringMap<Value>, derived_keys: &[Vec<u8>]) -> OperationResult;
/// The name of the operation. /// The name of the operation.
fn name(&self) -> &String; fn name(&self) -> &String;

View File

@ -39,6 +39,8 @@ fn main() {
workflows.push(workflow); workflows.push(workflow);
} }
workflows.sort_by(|a, b| a.name.cmp(&b.name));
workflows_by_module.insert( workflows_by_module.insert(
module_dir.file_name().to_str().unwrap().to_owned(), module_dir.file_name().to_str().unwrap().to_owned(),
workflows, workflows,

View File

@ -3,7 +3,7 @@ use icepick_module::help::*;
use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath}; use keyfork_derive_util::{request::DerivationAlgorithm, DerivationIndex, DerivationPath};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
collections::HashMap, collections::{HashMap, BTreeMap},
io::{IsTerminal, Write}, io::{IsTerminal, Write},
path::PathBuf, path::PathBuf,
process::{Command, Stdio}, process::{Command, Stdio},
@ -368,7 +368,7 @@ pub fn do_cli_thing() {
} }
}; };
let inputs: HashMap<String, serde_json::Value> = let inputs: BTreeMap<String, serde_json::Value> =
serde_json::from_value(inputs).unwrap(); serde_json::from_value(inputs).unwrap();
let workflow = workflows let workflow = workflows

View File

@ -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_derive_util::{request::DerivationAlgorithm, DerivationPath};
use keyfork_shard::{openpgp::OpenPGP, Format}; use keyfork_shard::{openpgp::OpenPGP, Format};
use miniquorum::{Payload, PayloadVerification}; use miniquorum::{Payload, PayloadVerification};
use serde_json::Value; use serde_json::Value;
use std::{ use std::{
collections::HashMap,
io::Write, io::Write,
process::{Command, Stdio}, process::{Command, Stdio},
}; };
@ -20,8 +19,6 @@ pub enum Purpose {
RunQuorum, RunQuorum,
} }
pub type StringMap = std::collections::HashMap<String, String>;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct CLIOperation { struct CLIOperation {
/// The name of the operation (i.e. `transfer-token`). /// The name of the operation (i.e. `transfer-token`).
@ -41,7 +38,7 @@ struct CLIOperation {
} }
impl InvocableOperation for CLIOperation { impl InvocableOperation for CLIOperation {
fn invoke(&self, input: &HashMap<String, Value>, derived_keys: &[Vec<u8>]) -> OperationResult { fn invoke(&self, input: &StringMap<Value>, derived_keys: &[Vec<u8>]) -> OperationResult {
let (command, args) = get_command(&self.binary); let (command, args) = get_command(&self.binary);
let json = serde_json::json!({ let json = serde_json::json!({
@ -236,7 +233,7 @@ pub fn parse_quorum_with_shardfile(
pub fn handle_payload( pub fn handle_payload(
workflow: &Workflow, workflow: &Workflow,
inputs: HashMap<String, Value>, inputs: StringMap<Value>,
modules: Commands, modules: Commands,
config: &[ModuleConfig], config: &[ModuleConfig],
) { ) {
@ -255,7 +252,7 @@ pub fn handle(
config: &[ModuleConfig], config: &[ModuleConfig],
) { ) {
let inputs = load_inputs(&workflow.inputs, &workflow.optional_inputs, matches); let inputs = load_inputs(&workflow.inputs, &workflow.optional_inputs, matches);
let data: HashMap<String, Value> = inputs let data: StringMap<Value> = inputs
.into_iter() .into_iter()
.map(|(k, v)| (k, Value::String(v))) .map(|(k, v)| (k, Value::String(v)))
.collect(); .collect();