hashmap is the mind killer
This commit is contained in:
parent
e4756fd158
commit
dcb9c50d29
|
@ -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<WorkflowStep>,
|
||||
}
|
||||
|
||||
pub type StringMap = HashMap<String, String>;
|
||||
pub type StringMap<T = String> = BTreeMap<String, T>;
|
||||
|
||||
#[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<String, Value>,
|
||||
blob: StringMap<Value>,
|
||||
|
||||
// Any requested accounts from an operation.
|
||||
//
|
||||
|
@ -115,10 +115,10 @@ impl Workflow {
|
|||
|
||||
pub fn run_workflow<T: InvocableOperation>(
|
||||
&self,
|
||||
mut data: HashMap<String, Value>,
|
||||
mut data: StringMap<Value>,
|
||||
operations: &[T],
|
||||
derive_keys: DeriveKeys,
|
||||
) -> Result<HashMap<String, Value>, WorkflowError> {
|
||||
) -> Result<StringMap<Value>, 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<String, Value> = data
|
||||
let inputs: StringMap<Value> = 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<String, Value>, derived_keys: &[Vec<u8>]) -> OperationResult;
|
||||
fn invoke(&self, input: &StringMap<Value>, derived_keys: &[Vec<u8>]) -> OperationResult;
|
||||
|
||||
/// The name of the operation.
|
||||
fn name(&self) -> &String;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<String, serde_json::Value> =
|
||||
let inputs: BTreeMap<String, serde_json::Value> =
|
||||
serde_json::from_value(inputs).unwrap();
|
||||
|
||||
let workflow = workflows
|
||||
|
|
|
@ -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<String, String>;
|
||||
|
||||
#[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<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 json = serde_json::json!({
|
||||
|
@ -236,7 +233,7 @@ pub fn parse_quorum_with_shardfile(
|
|||
|
||||
pub fn handle_payload(
|
||||
workflow: &Workflow,
|
||||
inputs: HashMap<String, Value>,
|
||||
inputs: StringMap<Value>,
|
||||
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<String, Value> = inputs
|
||||
let data: StringMap<Value> = inputs
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, Value::String(v)))
|
||||
.collect();
|
||||
|
|
Loading…
Reference in New Issue