Skip to content

Commit 92fd9c9

Browse files
author
Hack.bg R&D
committed
fix(wasm): error messages
1 parent 6cd5eb4 commit 92fd9c9

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

src/lib.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,8 @@ pub fn witness_types (source: JsString) -> Maybe<Object> {
360360
/// Create compiler, providing chain constants.
361361
#[wasm_bindgen] pub fn compiler (options: JsValue) -> Maybe<Compiler> {
362362
Ok(Compiler {
363-
genesis: Arc::new(
364-
BlockHash::from_str(&get!(options, "genesis", arg_string)?)?
365-
),
366-
chain: get!(options, "chain", |input|if JsString::is_type_of(&input) {
367-
Ok(input.as_string().unwrap())
368-
} else {
369-
err!("chain not string")
370-
})?.into(),
363+
genesis: get!(options, "genesis", arg_block_hash)?.into(),
364+
chain: get!(options, "chain", arg_chain)?.into(),
371365
})
372366
}
373367

@@ -533,7 +527,7 @@ pub fn witness_types (source: JsString) -> Maybe<Object> {
533527
Ok(Address::p2tr(SECP256K1, key, root, None, match self.chain.as_ref() {
534528
"liquidtestnet" => &AddressParams::LIQUID_TESTNET,
535529
"elementsregtest" => &AddressParams::ELEMENTS,
536-
_ => return err!("invalid chain: {}; try elementsregtest, liqudtestnet", &self.chain)
530+
_ => return err!("unsupported chain: {}; try elementsregtest, liqudtestnet", &self.chain)
537531
}))
538532
}
539533

@@ -640,11 +634,19 @@ fn arg_pset_outs (array: JsValue) -> Maybe<Vec<Output>> {
640634
Ok(outputs)
641635
}
642636

643-
fn arg_string (input: JsValue) -> Maybe<String> {
637+
fn arg_block_hash (input: JsValue) -> Maybe<BlockHash> {
638+
if JsString::is_type_of(&input) {
639+
Ok(BlockHash::from_str(&required!("decode genesis": input.as_string())?)?)
640+
} else {
641+
err!("invalid block hash: {input:?}")
642+
}
643+
}
644+
645+
fn arg_chain (input: JsValue) -> Maybe<String> {
644646
if JsString::is_type_of(&input) {
645-
required!("decode input": input.as_string())
647+
required!("decode chain": input.as_string())
646648
} else {
647-
err!("invalid chain: {input:?}; try elementsregtest, liqudtestnet")
649+
err!("invalid chain: {input:?}, try liquidtestnet, elementsregtest")
648650
}
649651
}
650652

0 commit comments

Comments
 (0)