Skip to content

Commit a45c7c5

Browse files
committed
f Reuse try_from for new_op_return
1 parent f5102b0 commit a45c7c5

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

lightning/src/ln/script.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,13 @@ impl ShutdownScript {
8181
/// This is only needed and valid for channels supporting `option_simple_close`. Please refer
8282
/// to [BOLT-2] for more information.
8383
///
84-
/// Will return [`InvalidShutdownScript`] if the given data is not [BOLT-2] compliant based on
85-
/// the given features.
84+
/// # Errors
85+
///
86+
/// This function may return an error if `program` is not [BOLT-2] compliant.
8687
///
8788
/// [BOLT-2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-negotiation-closing_complete-and-closing_sig
88-
pub fn new_op_return<T: AsRef<PushBytes>>(
89-
data: T, features: &InitFeatures,
90-
) -> Result<Self, InvalidShutdownScript> {
91-
let script = ScriptBuf::new_op_return(data);
92-
if !is_bolt2_compliant(&script, features) {
93-
return Err(InvalidShutdownScript { script });
94-
}
95-
Ok(Self(ShutdownScriptImpl::Bolt2(script)))
89+
pub fn new_op_return<T: AsRef<PushBytes>>(data: T) -> Result<Self, InvalidShutdownScript> {
90+
Self::try_from(ScriptBuf::new_op_return(data))
9691
}
9792

9893
/// Generates a witness script pubkey from the given segwit version and program.
@@ -238,10 +233,8 @@ mod shutdown_script_tests {
238233
use bitcoin::secp256k1::{PublicKey, SecretKey};
239234
use bitcoin::{WitnessProgram, WitnessVersion};
240235

241-
use crate::ln::channelmanager::provided_init_features;
242236
use crate::prelude::*;
243237
use crate::types::features::InitFeatures;
244-
use crate::util::config::UserConfig;
245238

246239
fn pubkey() -> bitcoin::key::PublicKey {
247240
let secp_ctx = Secp256k1::signing_only();
@@ -317,9 +310,8 @@ mod shutdown_script_tests {
317310
#[test]
318311
fn generates_op_return_from_data() {
319312
let data = [6; 6];
320-
let features = provided_init_features(&UserConfig::default());
321313
let op_return_script = ScriptBuf::new_op_return(&data);
322-
let shutdown_script = ShutdownScript::new_op_return(&data, &features).unwrap();
314+
let shutdown_script = ShutdownScript::new_op_return(&data).unwrap();
323315
assert!(shutdown_script.is_compatible(&simple_close_features()));
324316
assert!(!shutdown_script.is_compatible(&InitFeatures::empty()));
325317
assert_eq!(shutdown_script.into_inner(), op_return_script);
@@ -380,9 +372,8 @@ mod shutdown_script_tests {
380372
assert!(ShutdownScript::try_from(pushdata_script).is_err());
381373

382374
// - In `ShutdownScript::new_op_return` the OP_RETURN data is longer than 80 bytes.
383-
let features = provided_init_features(&UserConfig::default());
384375
let big_buffer = &[1u8; 81][..];
385376
let push_bytes: &PushBytes = big_buffer.try_into().unwrap();
386-
assert!(ShutdownScript::new_op_return(&push_bytes, &features).is_err());
377+
assert!(ShutdownScript::new_op_return(&push_bytes).is_err());
387378
}
388379
}

0 commit comments

Comments
 (0)