@@ -5,12 +5,10 @@ use serde_wasm_bindgen::to_value;
55use wasm_bindgen:: prelude:: * ;
66
77use miniscript:: bitcoin:: { Address , Network , ScriptBuf } ;
8- use miniscript:: { Descriptor , MiniscriptKey } ;
8+ use miniscript:: { Descriptor , ForEachKey , MiniscriptKey } ;
99
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 } ;
1412
1513#[ derive( Serialize ) ]
1614pub struct PlaygroundResult {
@@ -29,15 +27,18 @@ pub fn run_playground(code: &str, network: &str) -> Result<JsValue, JsValue> {
2927 let _run_playground = || -> Result < PlaygroundResult , Error > {
3028 let network = Network :: from_str ( network) ?;
3129
32- let value = eval ( code) ?;
33-
3430 let ( mut policy, mut desc, mut script, mut addr, mut key, mut tapinfo, mut other) =
3531 ( None , None , None , None , None , None , None ) ;
3632
37- match value {
33+ match eval ( code ) ? {
3834 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+ }
4142 policy = Some ( policy_) ;
4243 }
4344 Value :: Descriptor ( desc_) => desc = Some ( desc_) ,
0 commit comments