Skip to content

Commit c29ebb4

Browse files
feat: wrap maxWeightToSatisfy
Issue: BTC-1460
1 parent 713ca46 commit c29ebb4

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

packages/wasm-miniscript/src/descriptor.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ impl WrapDescriptor {
8282
Ok(self.explicit_script()?.to_asm_string())
8383
}
8484

85+
#[wasm_bindgen(js_name = maxWeightToSatisfy)]
86+
pub fn max_weight_to_satisfy(&self) -> Result<u32, JsError> {
87+
let weight = (match &self.0 {
88+
WrapDescriptorEnum::Derivable(desc, _) => {
89+
desc.max_weight_to_satisfy()
90+
}
91+
WrapDescriptorEnum::Definite(desc) => desc.max_weight_to_satisfy(),
92+
WrapDescriptorEnum::String(desc) => desc.max_weight_to_satisfy(),
93+
})?;
94+
weight.to_wu().try_into().map_err(|_| JsError::new("Weight exceeds u32"))
95+
}
96+
8597
#[wasm_bindgen(js_name = fromString, skip_typescript)]
8698
pub fn from_string(descriptor: &str, pk_type: &str) -> Result<WrapDescriptor, JsError> {
8799
match pk_type {

packages/wasm-miniscript/test/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ describe("Descriptor fixtures", function () {
5858
fixture.script,
5959
);
6060
}
61+
62+
assert.ok(Number.isInteger(descriptor.maxWeightToSatisfy()));
6163
});
6264
});
6365
});

0 commit comments

Comments
 (0)