diff --git a/lightning/src/ln/features.rs b/lightning/src/ln/features.rs index 8485ca7e6b0..b568d5595a5 100644 --- a/lightning/src/ln/features.rs +++ b/lightning/src/ln/features.rs @@ -9,20 +9,21 @@ //! Implementations of extensions on features. -use lightning_types::features::{InitFeatures, NodeFeatures, ChannelFeatures}; -use lightning_types::features::{Bolt11InvoiceFeatures, OfferFeatures, InvoiceRequestFeatures}; -use lightning_types::features::{Bolt12InvoiceFeatures, BlindedHopFeatures}; use lightning_types::features::ChannelTypeFeatures; +use lightning_types::features::{BlindedHopFeatures, Bolt12InvoiceFeatures}; +use lightning_types::features::{Bolt11InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures}; +use lightning_types::features::{ChannelFeatures, InitFeatures, NodeFeatures}; #[allow(unused_imports)] use crate::prelude::*; -use crate::{io, io_extras}; use crate::ln::msgs::DecodeError; -use crate::util::ser::{Writer, Readable, Writeable, WithoutLength}; +use crate::util::ser::{Readable, WithoutLength, Writeable, Writer}; +use crate::{io, io_extras}; fn write_be(w: &mut W, le_flags: &[u8]) -> Result<(), io::Error> { - for f in le_flags.iter().rev() { // Swap back to big-endian + // Swap back to big-endian + for f in le_flags.iter().rev() { f.write(w)?; } Ok(()) @@ -42,7 +43,7 @@ macro_rules! impl_feature_len_prefixed_write { Ok(Self::from_be_bytes(Vec::::read(r)?)) } } - } + }; } impl_feature_len_prefixed_write!(InitFeatures); impl_feature_len_prefixed_write!(ChannelFeatures); @@ -64,7 +65,7 @@ macro_rules! impl_feature_tlv_write { Ok(WithoutLength::::read(r)?.0) } } - } + }; } impl_feature_tlv_write!(ChannelTypeFeatures); @@ -86,7 +87,7 @@ macro_rules! impl_feature_write_without_length { Ok(WithoutLength($features::from_be_bytes(v))) } } - } + }; } impl_feature_write_without_length!(Bolt12InvoiceFeatures); diff --git a/lightning/src/ln/script.rs b/lightning/src/ln/script.rs index 518128b6657..96deae93876 100644 --- a/lightning/src/ln/script.rs +++ b/lightning/src/ln/script.rs @@ -1,14 +1,15 @@ //! Abstractions for scripts used in the Lightning Network. -use bitcoin::{WitnessProgram, WPubkeyHash, WScriptHash}; +use bitcoin::hashes::Hash; use bitcoin::opcodes::all::OP_PUSHBYTES_0 as SEGWIT_V0; use bitcoin::script::{Script, ScriptBuf}; -use bitcoin::hashes::Hash; use bitcoin::secp256k1::PublicKey; +use bitcoin::{WPubkeyHash, WScriptHash, WitnessProgram}; use crate::ln::channelmanager; -use crate::types::features::InitFeatures; use crate::ln::msgs::DecodeError; +use crate::types::features::InitFeatures; +use crate::util::config::UserConfig; use crate::util::ser::{Readable, Writeable, Writer}; use crate::io; @@ -28,7 +29,7 @@ pub struct InvalidShutdownScript { /// The script that did not meet the requirements from [BOLT #2]. /// /// [BOLT #2]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md - pub script: ScriptBuf + pub script: ScriptBuf, } #[derive(Clone, PartialEq, Eq)] @@ -82,7 +83,9 @@ impl ShutdownScript { /// # Errors /// /// This function may return an error if `program` is invalid for the segwit `version`. - pub fn new_witness_program(witness_program: &WitnessProgram) -> Result { + pub fn new_witness_program( + witness_program: &WitnessProgram, + ) -> Result { Self::try_from(ScriptBuf::new_witness_program(witness_program)) } @@ -128,7 +131,8 @@ impl TryFrom for ShutdownScript { type Error = InvalidShutdownScript; fn try_from(script: ScriptBuf) -> Result { - Self::try_from((script, &channelmanager::provided_init_features(&crate::util::config::UserConfig::default()))) + let features = channelmanager::provided_init_features(&UserConfig::default()); + Self::try_from((script, &features)) } } @@ -149,14 +153,15 @@ impl TryFrom<(ScriptBuf, &InitFeatures)> for ShutdownScript { impl Into for ShutdownScript { fn into(self) -> ScriptBuf { match self.0 { - ShutdownScriptImpl::Legacy(pubkey) => - ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize())), + ShutdownScriptImpl::Legacy(pubkey) => { + ScriptBuf::new_p2wpkh(&WPubkeyHash::hash(&pubkey.serialize())) + }, ShutdownScriptImpl::Bolt2(script_pubkey) => script_pubkey, } } } -impl core::fmt::Display for ShutdownScript{ +impl core::fmt::Display for ShutdownScript { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match &self.0 { ShutdownScriptImpl::Legacy(_) => self.clone().into_inner().fmt(f), @@ -169,18 +174,22 @@ impl core::fmt::Display for ShutdownScript{ mod shutdown_script_tests { use super::ShutdownScript; - use bitcoin::{WitnessProgram, WitnessVersion}; use bitcoin::opcodes; use bitcoin::script::{Builder, ScriptBuf}; use bitcoin::secp256k1::Secp256k1; use bitcoin::secp256k1::{PublicKey, SecretKey}; + use bitcoin::{WitnessProgram, WitnessVersion}; - use crate::types::features::InitFeatures; use crate::prelude::*; + use crate::types::features::InitFeatures; fn pubkey() -> bitcoin::key::PublicKey { let secp_ctx = Secp256k1::signing_only(); - let secret_key = SecretKey::from_slice(&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]).unwrap(); + let secret_key = SecretKey::from_slice(&[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, + ]) + .unwrap(); bitcoin::key::PublicKey::new(PublicKey::from_secret_key(&secp_ctx, &secret_key)) } diff --git a/rustfmt_excluded_files b/rustfmt_excluded_files index a15c1f1613a..de717db86ae 100644 --- a/rustfmt_excluded_files +++ b/rustfmt_excluded_files @@ -13,9 +13,7 @@ lightning/src/ln/blinded_payment_tests.rs lightning/src/ln/chan_utils.rs lightning/src/ln/chanmon_update_fail_tests.rs lightning/src/ln/channel.rs -lightning/src/ln/channel_id.rs lightning/src/ln/channelmanager.rs -lightning/src/ln/features.rs lightning/src/ln/functional_test_utils.rs lightning/src/ln/functional_tests.rs lightning/src/ln/inbound_payment.rs @@ -34,7 +32,6 @@ lightning/src/ln/peer_handler.rs lightning/src/ln/priv_short_conf_tests.rs lightning/src/ln/reload_tests.rs lightning/src/ln/reorg_tests.rs -lightning/src/ln/script.rs lightning/src/ln/shutdown_tests.rs lightning/src/routing/mod.rs lightning/src/routing/router.rs