Compare commits
2 Commits
6a3ab8a64b
...
3d8aec844d
Author | SHA1 | Date |
---|---|---|
|
3d8aec844d | |
|
a2fc02f65a |
|
@ -49,13 +49,25 @@ pub fn derive_keys(
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct ModuleConfig {
|
struct ModuleConfig {
|
||||||
|
/// The name of the module.
|
||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
|
/// The name of the command used to invoke the module. If not given, the default would be
|
||||||
|
/// `format!("icepick-{name}")`, using the name of the module.
|
||||||
command_name: Option<String>,
|
command_name: Option<String>,
|
||||||
algorithm: keyfork_derive_util::request::DerivationAlgorithm,
|
|
||||||
|
|
||||||
|
/// The bip32 derivation algorithm. This is currently used for deriving keys from Keyfork, but
|
||||||
|
/// may be passed to modules within the workflow to provide additional context, such as the
|
||||||
|
/// algorithm for a generic signer.
|
||||||
|
algorithm: Option<DerivationAlgorithm>,
|
||||||
|
|
||||||
|
/// The bip44 derivation prefix. This is currently used for deriving keys from Keyfork directly
|
||||||
|
/// within Icepick, but may be passed to modules within the workflow to provide additional
|
||||||
|
/// context, such as a module for deriving keys.
|
||||||
#[serde(with = "serde_derivation")]
|
#[serde(with = "serde_derivation")]
|
||||||
derivation_prefix: keyfork_derive_util::DerivationPath,
|
derivation_prefix: Option<DerivationPath>,
|
||||||
|
|
||||||
|
/// All workflows for a module.
|
||||||
#[serde(rename = "workflow", default)]
|
#[serde(rename = "workflow", default)]
|
||||||
workflows: Vec<workflow::Workflow>,
|
workflows: Vec<workflow::Workflow>,
|
||||||
}
|
}
|
||||||
|
@ -65,21 +77,28 @@ mod serde_derivation {
|
||||||
use serde::{Deserialize, Deserializer, Serializer};
|
use serde::{Deserialize, Deserializer, Serializer};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
pub fn serialize<S>(p: &DerivationPath, serializer: S) -> Result<S::Ok, S::Error>
|
pub fn serialize<S>(p: &Option<DerivationPath>, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
S: Serializer,
|
S: Serializer,
|
||||||
{
|
{
|
||||||
let path = p.to_string();
|
if let Some(p) = p {
|
||||||
serializer.serialize_str(&path)
|
let path = p.to_string();
|
||||||
|
serializer.serialize_str(&path)
|
||||||
|
} else {
|
||||||
|
serializer.serialize_none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deserialize<'de, D>(deserializer: D) -> Result<DerivationPath, D::Error>
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<DerivationPath>, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use serde::de::Error;
|
use serde::de::Error;
|
||||||
String::deserialize(deserializer)
|
|
||||||
.and_then(|string| DerivationPath::from_str(&string).map_err(Error::custom))
|
let opt_string = Option::<String>::deserialize(deserializer)?;
|
||||||
|
opt_string
|
||||||
|
.map(|string| DerivationPath::from_str(&string).map_err(Error::custom))
|
||||||
|
.transpose()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +268,11 @@ pub fn do_cli_thing() {
|
||||||
let accounts: Vec<keyfork_derive_util::DerivationIndex> =
|
let accounts: Vec<keyfork_derive_util::DerivationIndex> =
|
||||||
serde_json::from_value(accounts.clone())
|
serde_json::from_value(accounts.clone())
|
||||||
.expect("valid derivation_accounts");
|
.expect("valid derivation_accounts");
|
||||||
derived_keys.extend(derive_keys(&algo, &path, &accounts));
|
derived_keys.extend(derive_keys(
|
||||||
|
&algo.expect("a module requested keys but didn't provide algorithm"),
|
||||||
|
&path.expect("a module requested keys but didn't provide prefix"),
|
||||||
|
&accounts,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let json = serde_json::json!({
|
let json = serde_json::json!({
|
||||||
|
|
|
@ -198,7 +198,14 @@ impl Workflow {
|
||||||
.expect("could not find module config");
|
.expect("could not find module config");
|
||||||
let algo = &config.algorithm;
|
let algo = &config.algorithm;
|
||||||
let path_prefix = &config.derivation_prefix;
|
let path_prefix = &config.derivation_prefix;
|
||||||
derived_keys.extend(derive_keys(algo, path_prefix, &derivation_accounts));
|
derived_keys.extend(derive_keys(
|
||||||
|
algo.as_ref()
|
||||||
|
.expect("a module requested keys but didn't provide algorithm"),
|
||||||
|
path_prefix
|
||||||
|
.as_ref()
|
||||||
|
.expect("a module requested keys but didn't provide prefix"),
|
||||||
|
&derivation_accounts,
|
||||||
|
));
|
||||||
derivation_accounts.clear();
|
derivation_accounts.clear();
|
||||||
|
|
||||||
// Prepare all inputs for the operation invocation
|
// Prepare all inputs for the operation invocation
|
||||||
|
|
11
icepick.toml
11
icepick.toml
|
@ -13,7 +13,7 @@ name = "transfer-token"
|
||||||
# be serialized by serde_json::Value.
|
# be serialized by serde_json::Value.
|
||||||
# These values can also be loaded using "internal-load-file", using some form
|
# These values can also be loaded using "internal-load-file", using some form
|
||||||
# of later-defined signature validation.
|
# of later-defined signature validation.
|
||||||
inputs = ["from_address", "to_address", "token_name", "token_amount"]
|
inputs = ["from_address", "to_address", "token_name", "token_amount", "cluster"]
|
||||||
|
|
||||||
## Load the Blockhash from the SD card
|
## Load the Blockhash from the SD card
|
||||||
#[[module.workflow.step]]
|
#[[module.workflow.step]]
|
||||||
|
@ -44,6 +44,8 @@ outputs = { token_address = "token_address", token_decimals = "token_decimals" }
|
||||||
[[module.workflow.step]]
|
[[module.workflow.step]]
|
||||||
type = "sol-get-blockhash"
|
type = "sol-get-blockhash"
|
||||||
|
|
||||||
|
inputs = { cluster = "cluster" }
|
||||||
|
|
||||||
outputs = { blockhash = "blockhash" }
|
outputs = { blockhash = "blockhash" }
|
||||||
|
|
||||||
[[module.workflow.step]]
|
[[module.workflow.step]]
|
||||||
|
@ -78,6 +80,13 @@ blockhash = "blockhash"
|
||||||
[module.workflow.step.outputs]
|
[module.workflow.step.outputs]
|
||||||
transaction = "signed_transaction"
|
transaction = "signed_transaction"
|
||||||
|
|
||||||
|
# Broadcast the transaction
|
||||||
|
[[module.workflow.step]]
|
||||||
|
type = "sol-broadcast"
|
||||||
|
|
||||||
|
inputs = { cluster = "cluster", transaction = "signed_transaction" }
|
||||||
|
outputs = { status = "status", url = "url" }
|
||||||
|
|
||||||
## Write the signed transaction to a file
|
## Write the signed transaction to a file
|
||||||
#[[module.workflow.step]]
|
#[[module.workflow.step]]
|
||||||
#type = "internal-save-file"
|
#type = "internal-save-file"
|
||||||
|
|
Loading…
Reference in New Issue