Skip to content

Commit 400be07

Browse files
committed
Review feedback
1 parent b375b7d commit 400be07

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

src/descriptor/covenants/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ mod tests {
739739
fn string_rtt(desc_str: &str) {
740740
let desc = Descriptor::<String>::from_str(desc_str).unwrap();
741741
assert_eq!(desc.to_string_no_chksum(), desc_str);
742-
let cov_desc = desc.as_cov();
742+
let cov_desc = desc.as_cov().unwrap();
743743
assert_eq!(cov_desc.to_string(), desc.to_string());
744744
}
745745
#[test]
@@ -836,7 +836,7 @@ mod tests {
836836
cov_sk: secp256k1::SecretKey,
837837
) -> Result<(), Error> {
838838
assert_eq!(desc.desc_type(), DescriptorType::Cov);
839-
let desc = desc.as_cov();
839+
let desc = desc.as_cov().unwrap();
840840
// Now create a transaction spending this.
841841
let mut spend_tx = Transaction {
842842
version: 2,
@@ -1062,7 +1062,7 @@ mod tests {
10621062
spend_tx.output[2].value = confidential::Value::Explicit(2_000);
10631063

10641064
// Try to satisfy the covenant part
1065-
let desc = desc.as_cov();
1065+
let desc = desc.as_cov().unwrap();
10661066
let script_code = desc.cov_script_code();
10671067
let cov_sat = CovSatisfier::new_segwitv0(
10681068
&spend_tx,

src/descriptor/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
432432

433433
/// Unwrap a descriptor as a covenant descriptor
434434
/// Panics if the descriptor is not of [DescriptorType::Cov]
435-
pub fn as_cov(&self) -> &CovenantDescriptor<Pk> {
435+
pub fn as_cov(&self) -> Result<&CovenantDescriptor<Pk>, Error> {
436436
if let Descriptor::Cov(cov) = self {
437-
cov
437+
Ok(cov)
438438
} else {
439-
panic!("Called as_cov on a non-covenant descriptor")
439+
Err(Error::CovError(CovError::BadCovDescriptor))
440440
}
441441
}
442442

src/miniscript/astelem.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl StackCtxOperations for script::Builder {
633633
let mut builder = self;
634634
// Initial Witness
635635
let max_elems = MAX_SCRIPT_ELEMENT_SIZE / MAX_STANDARD_P2WSH_STACK_ITEM_SIZE;
636-
for _ in 0..(max_elems - 1) {
636+
for _ in 0..max_elems {
637637
builder = builder.push_opcode(opcodes::all::OP_CAT);
638638
}
639639
builder = builder
@@ -801,9 +801,9 @@ impl<Pk: MiniscriptKey, Ctx: ScriptContext> Terminal<Pk, Ctx> {
801801
Terminal::False => 1,
802802
Terminal::Version(_n) => 4 + 1 + 1 + 4, // opcodes + push opcodes + target size
803803
Terminal::OutputsPref(ref pref) => {
804-
// CAT CAT CAT CAT CAT <pref> SWAP CAT /*Now we hashoutputs on stack */
804+
// CAT CAT CAT CAT CAT CAT <pref> SWAP CAT /*Now we hashoutputs on stack */
805805
// HASH256 DEPTH <10> SUB PICK EQUAL
806-
7 + pref.len() + 1 /* line1 opcodes + pref.push */
806+
8 + pref.len() + 1 /* line1 opcodes + pref.push */
807807
+ 6 /* line 2 */
808808
}
809809
Terminal::Alt(ref sub) => sub.node.script_size() + 2,

src/miniscript/decode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn parse<Ctx: ScriptContext>(
293293
tokens,
294294
Tk::Num(10) => match_token!(
295295
tokens,
296-
Tk::Hash256, Tk::Cat, Tk::Swap, Tk::Push(bytes), Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat =>
296+
Tk::Hash256, Tk::Cat, Tk::Swap, Tk::Push(bytes), Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat =>
297297
{
298298
non_term.push(NonTerm::Verify);
299299
term.reduce0(Terminal::OutputsPref(bytes))?
@@ -368,7 +368,7 @@ pub fn parse<Ctx: ScriptContext>(
368368
tokens,
369369
Tk::Num(10) => match_token!(
370370
tokens,
371-
Tk::Hash256, Tk::Cat, Tk::Swap, Tk::Push(bytes), Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat =>
371+
Tk::Hash256, Tk::Cat, Tk::Swap, Tk::Push(bytes), Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat, Tk::Cat =>
372372
term.reduce0(Terminal::OutputsPref(bytes))?,
373373
),
374374
),

src/miniscript/types/extra_props.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,13 @@ impl Property for ExtData {
347347
// Assume txouts fill out all the 520 bytes
348348
let max_wit_sz = MAX_SCRIPT_ELEMENT_SIZE - pref.len();
349349
ExtData {
350-
pk_cost: 7 + pref.len() + 1 + 6, // See script_size() in astelem.rs
350+
pk_cost: 8 + pref.len() + 1 + 6, // See script_size() in astelem.rs
351351
has_free_verify: true,
352-
ops_count_static: 12,
353-
ops_count_sat: Some(12),
354-
ops_count_nsat: Some(12),
355-
stack_elem_count_sat: Some(6),
356-
stack_elem_count_dissat: Some(6),
352+
ops_count_static: 13,
353+
ops_count_sat: Some(13),
354+
ops_count_nsat: Some(13),
355+
stack_elem_count_sat: Some(7),
356+
stack_elem_count_dissat: Some(7),
357357
max_sat_size: Some((max_wit_sz, max_wit_sz)),
358358
max_dissat_size: Some((0, 0)), // all empty should dissatisfy
359359
timelock_info: TimeLockInfo::default(),

0 commit comments

Comments
 (0)