+
+ /// Returns whether the shutdown script is compatible with the features as defined by BOLT #2.
+ ///
+ /// Specifically, checks for compliance with feature `option_shutdown_anysegwit`.
+ pub fn is_compatible(&self, features: &InitFeatures) -> bool {
+ match &self.0 {
+ ShutdownScriptImpl::Legacy(_) => true,
+ ShutdownScriptImpl::Bolt2(script) => is_bolt2_compliant(script, features),
+ }
+ }
+}
+
+fn is_bolt2_compliant(script: &Script, features: &InitFeatures) -> bool {
+ if script.is_p2pkh() || script.is_p2sh() || script.is_v0_p2wpkh() || script.is_v0_p2wsh() {
+ true
+ } else if features.supports_shutdown_anysegwit() {
+ script.is_witness_program() && script.as_bytes()[0] != SEGWIT_V0.into_u8()
+ } else {
+ false
+ }