]> Untitled Git - bdk-cli/commitdiff
[cli] Split the internal and external policy paths
authorAlekos Filini <alekos.filini@gmail.com>
Fri, 13 Nov 2020 11:53:42 +0000 (12:53 +0100)
committerAlekos Filini <alekos.filini@gmail.com>
Fri, 13 Nov 2020 14:00:22 +0000 (15:00 +0100)
src/cli.rs

index 513d25f2a60bc1625206822a60d19b6d1b6a0c4a..ada49cce2f9f57a6a5a2c118c5239c8e10f6d067 100644 (file)
@@ -149,10 +149,18 @@ pub fn make_cli_subcommands<'a, 'b>() -> App<'a, 'b> {
                         .takes_value(true),
                 )
                 .arg(
-                    Arg::with_name("policy")
-                        .long("policy")
+                    Arg::with_name("external_policy")
+                        .long("external_policy")
                         .value_name("POLICY")
-                        .help("Selects which policy should be used to satisfy the descriptor")
+                        .help("Selects which policy should be used to satisfy the external descriptor")
+                        .takes_value(true)
+                        .number_of_values(1),
+                )
+                .arg(
+                    Arg::with_name("internal_policy")
+                        .long("internal_policy")
+                        .value_name("POLICY")
+                        .help("Selects which policy should be used to satisfy the internal descriptor")
                         .takes_value(true)
                         .number_of_values(1),
                 ),
@@ -430,10 +438,19 @@ where
                 .map_err(Error::Generic)?;
             tx_builder = tx_builder.unspendable(unspendable);
         }
-        if let Some(policy) = sub_matches.value_of("policy") {
+
+        let policies = vec![
+            sub_matches
+                .value_of("external_policy")
+                .map(|p| (p, ScriptType::External)),
+            sub_matches
+                .value_of("internal_policy")
+                .map(|p| (p, ScriptType::Internal)),
+        ];
+        for (policy, script_type) in policies.into_iter().filter_map(|x| x) {
             let policy = serde_json::from_str::<BTreeMap<String, Vec<usize>>>(&policy)
                 .map_err(|s| Error::Generic(s.to_string()))?;
-            tx_builder = tx_builder.policy_path(policy);
+            tx_builder = tx_builder.policy_path(policy, script_type);
         }
 
         let (psbt, details) = wallet.create_tx(tx_builder)?;