@@ -5,12 +5,10 @@ use serde_wasm_bindgen::to_value;
5
5
use wasm_bindgen:: prelude:: * ;
6
6
7
7
use miniscript:: bitcoin:: { Address , Network , ScriptBuf } ;
8
- use miniscript:: { Descriptor , MiniscriptKey } ;
8
+ use miniscript:: { Descriptor , ForEachKey , MiniscriptKey } ;
9
9
10
- use crate :: util:: { DescriptorExt , TapInfoExt } ;
11
- use crate :: {
12
- parse, Error , Evaluate , Execute , ExprRepr , Library , PrettyDisplay , Scope , ScopeRef , Value ,
13
- } ;
10
+ use crate :: util:: { DescriptorExt , PrettyDisplay , TapInfoExt } ;
11
+ use crate :: { parse, Error , Evaluate , Execute , ExprRepr , Library , Scope , ScopeRef , Value } ;
14
12
15
13
#[ derive( Serialize ) ]
16
14
pub struct PlaygroundResult {
@@ -29,15 +27,18 @@ pub fn run_playground(code: &str, network: &str) -> Result<JsValue, JsValue> {
29
27
let _run_playground = || -> Result < PlaygroundResult , Error > {
30
28
let network = Network :: from_str ( network) ?;
31
29
32
- let value = eval ( code) ?;
33
-
34
30
let ( mut policy, mut desc, mut script, mut addr, mut key, mut tapinfo, mut other) =
35
31
( None , None , None , None , None , None , None ) ;
36
32
37
- match value {
33
+ match eval ( code ) ? {
38
34
Value :: Policy ( policy_) => {
39
- // Convert policies into a wsh() descriptor
40
- desc = Some ( Descriptor :: new_wsh ( policy_. compile ( ) ?) ?) ;
35
+ // Compile policies into a wsh() descriptor
36
+ if policy_. for_each_key ( |pk| !pk. is_x_only_key ( ) ) {
37
+ // Has to explicitly check for x-only keys as a temporary workaround to avoid panicking
38
+ // https://github.com/rust-bitcoin/rust-miniscript/pull/761
39
+ let ms = policy_. compile ( ) . ok ( ) ;
40
+ desc = ms. and_then ( |ms| Descriptor :: new_wsh ( ms) . ok ( ) ) ;
41
+ }
41
42
policy = Some ( policy_) ;
42
43
}
43
44
Value :: Descriptor ( desc_) => desc = Some ( desc_) ,
0 commit comments