]> Untitled Git - bdk/commitdiff
[examples] Fix Miniscript variants issue in compiler example
authorDominik Spicher <dominik.spicher@inacta.ch>
Fri, 7 Aug 2020 14:08:23 +0000 (16:08 +0200)
committerDominik Spicher <dominik.spicher@inacta.ch>
Fri, 7 Aug 2020 14:08:23 +0000 (16:08 +0200)
miniscript has extended the `Miniscript` struct to be generic
over a `ScriptContext`. This context is different for the `Sh`
variant (`Legacy`) than for the `Wsh` and `ShWsh` variants
(`Segwitv0`). Therefore, Rust is not happy with the single
`compiled` variable if it is used as an argument for all three
variants.

examples/compiler.rs

index 09cad94822505dc10c4c0c6834748b19122cb6f5..04558fba478b84b25c5509036d47dff50466e900 100644 (file)
@@ -63,12 +63,11 @@ fn main() {
     info!("Compiling policy: {}", policy_str);
 
     let policy = Concrete::<String>::from_str(&policy_str).unwrap();
-    let compiled = policy.compile().unwrap();
 
     let descriptor = match matches.value_of("TYPE").unwrap() {
-        "sh" => Descriptor::Sh(compiled),
-        "wsh" => Descriptor::Wsh(compiled),
-        "sh-wsh" => Descriptor::ShWsh(compiled),
+        "sh" => Descriptor::Sh(policy.compile().unwrap()),
+        "wsh" => Descriptor::Wsh(policy.compile().unwrap()),
+        "sh-wsh" => Descriptor::ShWsh(policy.compile().unwrap()),
         _ => panic!("Invalid type"),
     };