Merge pull request #2415 from wpaulino/update-fee-anchors
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Mon, 17 Jul 2023 19:45:51 +0000 (19:45 +0000)
committerGitHub <noreply@github.com>
Mon, 17 Jul 2023 19:45:51 +0000 (19:45 +0000)
Add min mempool estimate for feerate updates on anchor channels

34 files changed:
.github/workflows/build.yml
fuzz/src/bech32_parse.rs
fuzz/src/invoice_deser.rs
fuzz/src/invoice_request_deser.rs
fuzz/src/offer_deser.rs
fuzz/src/refund_deser.rs
lightning-invoice/src/de.rs
lightning-invoice/src/lib.rs
lightning-invoice/src/payment.rs
lightning-invoice/src/ser.rs
lightning-invoice/src/utils.rs
lightning-invoice/tests/ser_de.rs
lightning/src/chain/chaininterface.rs
lightning/src/chain/onchaintx.rs
lightning/src/chain/package.rs
lightning/src/events/bump_transaction.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/features.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/monitor_tests.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/payment_tests.rs
lightning/src/offers/invoice.rs
lightning/src/offers/invoice_error.rs
lightning/src/offers/invoice_request.rs
lightning/src/offers/offer.rs
lightning/src/offers/parse.rs
lightning/src/offers/refund.rs
lightning/src/onion_message/offers.rs
lightning/src/routing/router.rs
lightning/src/util/logger.rs
lightning/src/util/macro_logger.rs
lightning/src/util/test_utils.rs

index 9ebfd1257216271357018313999e0d9976e85cd5..525dcbe5f068b6eeaa3e865ee614e029f4168430 100644 (file)
@@ -147,7 +147,7 @@ jobs:
   check_commits:
     runs-on: ubuntu-latest
     env:
-      TOOLCHAIN: 1.57.0
+      TOOLCHAIN: stable
     steps:
       - name: Checkout source code
         uses: actions/checkout@v3
index f3dd5ac9d1e8f27264d548032ed12531c7314dbd..ff465ceea3948fd4d97ea2d18eb9ba49940f0c73 100644 (file)
@@ -9,7 +9,7 @@
 
 use crate::utils::test_logger;
 use core::convert::TryFrom;
-use lightning::offers::parse::{Bech32Encode, ParseError};
+use lightning::offers::parse::{Bech32Encode, Bolt12ParseError};
 
 #[inline]
 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
@@ -35,8 +35,8 @@ impl AsRef<[u8]> for Bytes {
 }
 
 impl TryFrom<Vec<u8>> for Bytes {
-       type Error = ParseError;
-       fn try_from(data: Vec<u8>) -> Result<Self, ParseError> {
+       type Error = Bolt12ParseError;
+       fn try_from(data: Vec<u8>) -> Result<Self, Bolt12ParseError> {
                Ok(Bytes(data))
        }
 }
index 7b93fd38db1a37ce4a32410f79266b50ef75dc1a..34bb955e2a7c0652826f573f29a5487f63f65e94 100644 (file)
@@ -8,13 +8,13 @@
 // licenses.
 
 use crate::utils::test_logger;
-use lightning::offers::invoice::Invoice;
+use lightning::offers::invoice::Bolt12Invoice;
 use lightning::util::ser::Writeable;
 use std::convert::TryFrom;
 
 #[inline]
 pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
-       if let Ok(invoice) = Invoice::try_from(data.to_vec()) {
+       if let Ok(invoice) = Bolt12Invoice::try_from(data.to_vec()) {
                let mut bytes = Vec::with_capacity(data.len());
                invoice.write(&mut bytes).unwrap();
                assert_eq!(data, bytes);
index f8fe34f2b8b5d647140af18a53558f7ba07b6fb2..ca9d06ab1f8612d3f6c5bf212c191d27c0cb9cc6 100644 (file)
@@ -14,9 +14,9 @@ use lightning::blinded_path::BlindedPath;
 use lightning::sign::EntropySource;
 use lightning::ln::PaymentHash;
 use lightning::ln::features::BlindedHopFeatures;
-use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice};
+use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
 use lightning::offers::invoice_request::InvoiceRequest;
-use lightning::offers::parse::SemanticError;
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::util::ser::Writeable;
 
 #[inline]
@@ -71,7 +71,7 @@ fn privkey(byte: u8) -> SecretKey {
 
 fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
        invoice_request: &'a InvoiceRequest, secp_ctx: &Secp256k1<T>
-) -> Result<UnsignedInvoice<'a>, SemanticError> {
+) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
        let entropy_source = Randomness {};
        let paths = vec![
                BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
index 213742d8c085b86aba02f0188df4b0d6e08240e3..53f67a3380db07d322f8b1fe1c72a75301e34cc0 100644 (file)
@@ -12,7 +12,7 @@ use crate::utils::test_logger;
 use core::convert::{Infallible, TryFrom};
 use lightning::offers::invoice_request::UnsignedInvoiceRequest;
 use lightning::offers::offer::{Amount, Offer, Quantity};
-use lightning::offers::parse::SemanticError;
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::util::ser::Writeable;
 
 #[inline]
@@ -41,13 +41,13 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
 
 fn build_response<'a>(
        offer: &'a Offer, pubkey: PublicKey
-) -> Result<UnsignedInvoiceRequest<'a>, SemanticError> {
+) -> Result<UnsignedInvoiceRequest<'a>, Bolt12SemanticError> {
        let mut builder = offer.request_invoice(vec![42; 64], pubkey)?;
 
        builder = match offer.amount() {
                None => builder.amount_msats(1000).unwrap(),
                Some(Amount::Bitcoin { amount_msats }) => builder.amount_msats(amount_msats + 1)?,
-               Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+               Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
        };
 
        builder = match offer.supported_quantity() {
index 618b129f9a1e5517fa5dcddb09f739308feee436..81b614d602b269259a9ce67fadbc86307c583334 100644 (file)
@@ -14,8 +14,8 @@ use lightning::blinded_path::BlindedPath;
 use lightning::sign::EntropySource;
 use lightning::ln::PaymentHash;
 use lightning::ln::features::BlindedHopFeatures;
-use lightning::offers::invoice::{BlindedPayInfo, UnsignedInvoice};
-use lightning::offers::parse::SemanticError;
+use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
+use lightning::offers::parse::Bolt12SemanticError;
 use lightning::offers::refund::Refund;
 use lightning::util::ser::Writeable;
 
@@ -60,7 +60,7 @@ fn privkey(byte: u8) -> SecretKey {
 
 fn build_response<'a, T: secp256k1::Signing + secp256k1::Verification>(
        refund: &'a Refund, signing_pubkey: PublicKey, secp_ctx: &Secp256k1<T>
-) -> Result<UnsignedInvoice<'a>, SemanticError> {
+) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
        let entropy_source = Randomness {};
        let paths = vec![
                BlindedPath::new_for_message(&[pubkey(43), pubkey(44), pubkey(42)], &entropy_source, secp_ctx).unwrap(),
index 01adf67d1af0816bcc78ddeeacd6473f680b71bf..5bfa9a042c364b749359f09a0ed96380a589cba6 100644 (file)
@@ -23,9 +23,9 @@ use num_traits::{CheckedAdd, CheckedMul};
 use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
 use secp256k1::PublicKey;
 
-use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
-       SemanticError, PrivateRoute, ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawInvoice,
-       constants, SignedRawInvoice, RawDataPart, InvoiceFeatures};
+use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, Bolt11InvoiceSignature, PositiveTimestamp,
+       Bolt11SemanticError, PrivateRoute, Bolt11ParseError, ParseOrSemanticError, Description, RawTaggedField, Currency, RawHrp, SiPrefix, RawBolt11Invoice,
+       constants, SignedRawBolt11Invoice, RawDataPart, Bolt11InvoiceFeatures};
 
 use self::hrp_sm::parse_hrp;
 
@@ -44,20 +44,20 @@ mod hrp_sm {
        }
 
        impl States {
-               fn next_state(&self, read_symbol: char) -> Result<States, super::ParseError> {
+               fn next_state(&self, read_symbol: char) -> Result<States, super::Bolt11ParseError> {
                        match *self {
                                States::Start => {
                                        if read_symbol == 'l' {
                                                Ok(States::ParseL)
                                        } else {
-                                               Err(super::ParseError::MalformedHRP)
+                                               Err(super::Bolt11ParseError::MalformedHRP)
                                        }
                                }
                                States::ParseL => {
                                        if read_symbol == 'n' {
                                                Ok(States::ParseN)
                                        } else {
-                                               Err(super::ParseError::MalformedHRP)
+                                               Err(super::Bolt11ParseError::MalformedHRP)
                                        }
                                },
                                States::ParseN => {
@@ -80,10 +80,10 @@ mod hrp_sm {
                                        } else if ['m', 'u', 'n', 'p'].contains(&read_symbol) {
                                                Ok(States::ParseAmountSiPrefix)
                                        } else {
-                                               Err(super::ParseError::UnknownSiPrefix)
+                                               Err(super::Bolt11ParseError::UnknownSiPrefix)
                                        }
                                },
-                               States::ParseAmountSiPrefix => Err(super::ParseError::MalformedHRP),
+                               States::ParseAmountSiPrefix => Err(super::Bolt11ParseError::MalformedHRP),
                        }
                }
 
@@ -120,7 +120,7 @@ mod hrp_sm {
                        *range = Some(new_range);
                }
 
-               fn step(&mut self, c: char) -> Result<(), super::ParseError> {
+               fn step(&mut self, c: char) -> Result<(), super::Bolt11ParseError> {
                        let next_state = self.state.next_state(c)?;
                        match next_state {
                                States::ParseCurrencyPrefix => {
@@ -157,14 +157,14 @@ mod hrp_sm {
                }
        }
 
-       pub fn parse_hrp(input: &str) -> Result<(&str, &str, &str), super::ParseError> {
+       pub fn parse_hrp(input: &str) -> Result<(&str, &str, &str), super::Bolt11ParseError> {
                let mut sm = StateMachine::new();
                for c in input.chars() {
                        sm.step(c)?;
                }
 
                if !sm.is_final() {
-                       return Err(super::ParseError::MalformedHRP);
+                       return Err(super::Bolt11ParseError::MalformedHRP);
                }
 
                let currency = sm.currency_prefix().clone()
@@ -180,37 +180,37 @@ mod hrp_sm {
 
 
 impl FromStr for super::Currency {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_str(currency_prefix: &str) -> Result<Self, ParseError> {
+       fn from_str(currency_prefix: &str) -> Result<Self, Bolt11ParseError> {
                match currency_prefix {
                        "bc" => Ok(Currency::Bitcoin),
                        "tb" => Ok(Currency::BitcoinTestnet),
                        "bcrt" => Ok(Currency::Regtest),
                        "sb" => Ok(Currency::Simnet),
                        "tbs" => Ok(Currency::Signet),
-                       _ => Err(ParseError::UnknownCurrency)
+                       _ => Err(Bolt11ParseError::UnknownCurrency)
                }
        }
 }
 
 impl FromStr for SiPrefix {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_str(currency_prefix: &str) -> Result<Self, ParseError> {
+       fn from_str(currency_prefix: &str) -> Result<Self, Bolt11ParseError> {
                use crate::SiPrefix::*;
                match currency_prefix {
                        "m" => Ok(Milli),
                        "u" => Ok(Micro),
                        "n" => Ok(Nano),
                        "p" => Ok(Pico),
-                       _ => Err(ParseError::UnknownSiPrefix)
+                       _ => Err(Bolt11ParseError::UnknownSiPrefix)
                }
        }
 }
 
 /// ```
-/// use lightning_invoice::Invoice;
+/// use lightning_invoice::Bolt11Invoice;
 ///
 ///
 /// let invoice = "lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\
@@ -225,14 +225,14 @@ impl FromStr for SiPrefix {
 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
 /// j5r6drg6k6zcqj0fcwg";
 ///
-/// assert!(invoice.parse::<Invoice>().is_ok());
+/// assert!(invoice.parse::<Bolt11Invoice>().is_ok());
 /// ```
-impl FromStr for Invoice {
+impl FromStr for Bolt11Invoice {
        type Err = ParseOrSemanticError;
 
        fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
-               let signed = s.parse::<SignedRawInvoice>()?;
-               Ok(Invoice::from_signed(signed)?)
+               let signed = s.parse::<SignedRawBolt11Invoice>()?;
+               Ok(Bolt11Invoice::from_signed(signed)?)
        }
 }
 
@@ -251,10 +251,10 @@ impl FromStr for Invoice {
 /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
 /// j5r6drg6k6zcqj0fcwg";
 ///
-/// let parsed_1 = invoice.parse::<Invoice>();
+/// let parsed_1 = invoice.parse::<Bolt11Invoice>();
 ///
-/// let parsed_2 = match invoice.parse::<SignedRawInvoice>() {
-///    Ok(signed) => match Invoice::from_signed(signed) {
+/// let parsed_2 = match invoice.parse::<SignedRawBolt11Invoice>() {
+///    Ok(signed) => match Bolt11Invoice::from_signed(signed) {
 ///            Ok(invoice) => Ok(invoice),
 ///            Err(e) => Err(ParseOrSemanticError::SemanticError(e)),
 ///    },
@@ -264,8 +264,8 @@ impl FromStr for Invoice {
 /// assert!(parsed_1.is_ok());
 /// assert_eq!(parsed_1, parsed_2);
 /// ```
-impl FromStr for SignedRawInvoice {
-       type Err = ParseError;
+impl FromStr for SignedRawBolt11Invoice {
+       type Err = Bolt11ParseError;
 
        fn from_str(s: &str) -> Result<Self, Self::Err> {
                let (hrp, data, var) = bech32::decode(s)?;
@@ -273,32 +273,32 @@ impl FromStr for SignedRawInvoice {
                if var == bech32::Variant::Bech32m {
                        // Consider Bech32m addresses to be "Invalid Checksum", since that is what we'd get if
                        // we didn't support Bech32m (which lightning does not use).
-                       return Err(ParseError::Bech32Error(bech32::Error::InvalidChecksum));
+                       return Err(Bolt11ParseError::Bech32Error(bech32::Error::InvalidChecksum));
                }
 
                if data.len() < 104 {
-                       return Err(ParseError::TooShortDataPart);
+                       return Err(Bolt11ParseError::TooShortDataPart);
                }
 
                let raw_hrp: RawHrp = hrp.parse()?;
                let data_part = RawDataPart::from_base32(&data[..data.len()-104])?;
 
-               Ok(SignedRawInvoice {
-                       raw_invoice: RawInvoice {
+               Ok(SignedRawBolt11Invoice {
+                       raw_invoice: RawBolt11Invoice {
                                hrp: raw_hrp,
                                data: data_part,
                        },
-                       hash: RawInvoice::hash_from_parts(
+                       hash: RawBolt11Invoice::hash_from_parts(
                                hrp.as_bytes(),
                                &data[..data.len()-104]
                        ),
-                       signature: InvoiceSignature::from_base32(&data[data.len()-104..])?,
+                       signature: Bolt11InvoiceSignature::from_base32(&data[data.len()-104..])?,
                })
        }
 }
 
 impl FromStr for RawHrp {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
        fn from_str(hrp: &str) -> Result<Self, <Self as FromStr>::Err> {
                let parts = parse_hrp(hrp)?;
@@ -317,7 +317,7 @@ impl FromStr for RawHrp {
                        let si: SiPrefix = parts.2.parse()?;
                        if let Some(amt) = amount {
                                if amt.checked_mul(si.multiplier()).is_none() {
-                                       return Err(ParseError::IntegerOverflowError);
+                                       return Err(Bolt11ParseError::IntegerOverflowError);
                                }
                        }
                        Some(si)
@@ -332,11 +332,11 @@ impl FromStr for RawHrp {
 }
 
 impl FromBase32 for RawDataPart {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
        fn from_base32(data: &[u5]) -> Result<Self, Self::Err> {
                if data.len() < 7 { // timestamp length
-                       return Err(ParseError::TooShortDataPart);
+                       return Err(Bolt11ParseError::TooShortDataPart);
                }
 
                let timestamp = PositiveTimestamp::from_base32(&data[0..7])?;
@@ -350,11 +350,11 @@ impl FromBase32 for RawDataPart {
 }
 
 impl FromBase32 for PositiveTimestamp {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
        fn from_base32(b32: &[u5]) -> Result<Self, Self::Err> {
                if b32.len() != 7 {
-                       return Err(ParseError::InvalidSliceLength("PositiveTimestamp::from_base32()".into()));
+                       return Err(Bolt11ParseError::InvalidSliceLength("PositiveTimestamp::from_base32()".into()));
                }
                let timestamp: u64 = parse_int_be(b32, 32)
                        .expect("7*5bit < 64bit, no overflow possible");
@@ -365,17 +365,17 @@ impl FromBase32 for PositiveTimestamp {
        }
 }
 
-impl FromBase32 for InvoiceSignature {
-       type Err = ParseError;
+impl FromBase32 for Bolt11InvoiceSignature {
+       type Err = Bolt11ParseError;
        fn from_base32(signature: &[u5]) -> Result<Self, Self::Err> {
                if signature.len() != 104 {
-                       return Err(ParseError::InvalidSliceLength("InvoiceSignature::from_base32()".into()));
+                       return Err(Bolt11ParseError::InvalidSliceLength("Bolt11InvoiceSignature::from_base32()".into()));
                }
                let recoverable_signature_bytes = Vec::<u8>::from_base32(signature)?;
                let signature = &recoverable_signature_bytes[0..64];
                let recovery_id = RecoveryId::from_i32(recoverable_signature_bytes[64] as i32)?;
 
-               Ok(InvoiceSignature(RecoverableSignature::from_compact(
+               Ok(Bolt11InvoiceSignature(RecoverableSignature::from_compact(
                        signature,
                        recovery_id
                )?))
@@ -393,13 +393,13 @@ pub(crate) fn parse_int_be<T, U>(digits: &[U], base: T) -> Option<T>
        )
 }
 
-fn parse_tagged_parts(data: &[u5]) -> Result<Vec<RawTaggedField>, ParseError> {
+fn parse_tagged_parts(data: &[u5]) -> Result<Vec<RawTaggedField>, Bolt11ParseError> {
        let mut parts = Vec::<RawTaggedField>::new();
        let mut data = data;
 
        while !data.is_empty() {
                if data.len() < 3 {
-                       return Err(ParseError::UnexpectedEndOfTaggedFields);
+                       return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
                }
 
                // Ignore tag at data[0], it will be handled in the TaggedField parsers and
@@ -408,7 +408,7 @@ fn parse_tagged_parts(data: &[u5]) -> Result<Vec<RawTaggedField>, ParseError> {
                let last_element = 3 + len;
 
                if data.len() < last_element {
-                       return Err(ParseError::UnexpectedEndOfTaggedFields);
+                       return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
                }
 
                // Get the tagged field's data slice
@@ -421,7 +421,7 @@ fn parse_tagged_parts(data: &[u5]) -> Result<Vec<RawTaggedField>, ParseError> {
                        Ok(field) => {
                                parts.push(RawTaggedField::KnownSemantics(field))
                        },
-                       Err(ParseError::Skip)|Err(ParseError::Bech32Error(bech32::Error::InvalidLength)) => {
+                       Err(Bolt11ParseError::Skip)|Err(Bolt11ParseError::Bech32Error(bech32::Error::InvalidLength)) => {
                                parts.push(RawTaggedField::UnknownSemantics(field.into()))
                        },
                        Err(e) => {return Err(e)}
@@ -431,11 +431,11 @@ fn parse_tagged_parts(data: &[u5]) -> Result<Vec<RawTaggedField>, ParseError> {
 }
 
 impl FromBase32 for TaggedField {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field: &[u5]) -> Result<TaggedField, ParseError> {
+       fn from_base32(field: &[u5]) -> Result<TaggedField, Bolt11ParseError> {
                if field.len() < 3 {
-                       return Err(ParseError::UnexpectedEndOfTaggedFields);
+                       return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
                }
 
                let tag = field[0];
@@ -463,22 +463,22 @@ impl FromBase32 for TaggedField {
                        constants::TAG_PAYMENT_METADATA =>
                                Ok(TaggedField::PaymentMetadata(Vec::<u8>::from_base32(field_data)?)),
                        constants::TAG_FEATURES =>
-                               Ok(TaggedField::Features(InvoiceFeatures::from_base32(field_data)?)),
+                               Ok(TaggedField::Features(Bolt11InvoiceFeatures::from_base32(field_data)?)),
                        _ => {
                                // "A reader MUST skip over unknown fields"
-                               Err(ParseError::Skip)
+                               Err(Bolt11ParseError::Skip)
                        }
                }
        }
 }
 
 impl FromBase32 for Sha256 {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<Sha256, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<Sha256, Bolt11ParseError> {
                if field_data.len() != 52 {
                        // "A reader MUST skip over […] a p, [or] h […] field that does not have data_length 52 […]."
-                       Err(ParseError::Skip)
+                       Err(Bolt11ParseError::Skip)
                } else {
                        Ok(Sha256(sha256::Hash::from_slice(&Vec::<u8>::from_base32(field_data)?)
                                .expect("length was checked before (52 u5 -> 32 u8)")))
@@ -487,9 +487,9 @@ impl FromBase32 for Sha256 {
 }
 
 impl FromBase32 for Description {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<Description, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<Description, Bolt11ParseError> {
                let bytes = Vec::<u8>::from_base32(field_data)?;
                let description = String::from(str::from_utf8(&bytes)?);
                Ok(Description::new(description).expect(
@@ -499,12 +499,12 @@ impl FromBase32 for Description {
 }
 
 impl FromBase32 for PayeePubKey {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<PayeePubKey, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<PayeePubKey, Bolt11ParseError> {
                if field_data.len() != 53 {
                        // "A reader MUST skip over […] a n […] field that does not have data_length 53 […]."
-                       Err(ParseError::Skip)
+                       Err(Bolt11ParseError::Skip)
                } else {
                        let data_bytes = Vec::<u8>::from_base32(field_data)?;
                        let pub_key = PublicKey::from_slice(&data_bytes)?;
@@ -514,37 +514,37 @@ impl FromBase32 for PayeePubKey {
 }
 
 impl FromBase32 for ExpiryTime {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<ExpiryTime, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<ExpiryTime, Bolt11ParseError> {
                match parse_int_be::<u64, u5>(field_data, 32)
                        .map(ExpiryTime::from_seconds)
                {
                        Some(t) => Ok(t),
-                       None => Err(ParseError::IntegerOverflowError),
+                       None => Err(Bolt11ParseError::IntegerOverflowError),
                }
        }
 }
 
 impl FromBase32 for MinFinalCltvExpiryDelta {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<MinFinalCltvExpiryDelta, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<MinFinalCltvExpiryDelta, Bolt11ParseError> {
                let expiry = parse_int_be::<u64, u5>(field_data, 32);
                if let Some(expiry) = expiry {
                        Ok(MinFinalCltvExpiryDelta(expiry))
                } else {
-                       Err(ParseError::IntegerOverflowError)
+                       Err(Bolt11ParseError::IntegerOverflowError)
                }
        }
 }
 
 impl FromBase32 for Fallback {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<Fallback, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<Fallback, Bolt11ParseError> {
                if field_data.is_empty() {
-                       return Err(ParseError::UnexpectedEndOfTaggedFields);
+                       return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
                }
 
                let version = field_data[0];
@@ -553,7 +553,7 @@ impl FromBase32 for Fallback {
                match version.to_u8() {
                        0..=16 => {
                                if bytes.len() < 2 || bytes.len() > 40 {
-                                       return Err(ParseError::InvalidSegWitProgramLength);
+                                       return Err(Bolt11ParseError::InvalidSegWitProgramLength);
                                }
                                let version = WitnessVersion::try_from(version).expect("0 through 16 are valid SegWit versions");
                                Ok(Fallback::SegWitProgram {
@@ -564,30 +564,30 @@ impl FromBase32 for Fallback {
                        17 => {
                                let pkh = match PubkeyHash::from_slice(&bytes) {
                                        Ok(pkh) => pkh,
-                                       Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(ParseError::InvalidPubKeyHashLength),
+                                       Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidPubKeyHashLength),
                                };
                                Ok(Fallback::PubKeyHash(pkh))
                        }
                        18 => {
                                let sh = match ScriptHash::from_slice(&bytes) {
                                        Ok(sh) => sh,
-                                       Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(ParseError::InvalidScriptHashLength),
+                                       Err(bitcoin_hashes::Error::InvalidLength(_, _)) => return Err(Bolt11ParseError::InvalidScriptHashLength),
                                };
                                Ok(Fallback::ScriptHash(sh))
                        }
-                       _ => Err(ParseError::Skip)
+                       _ => Err(Bolt11ParseError::Skip)
                }
        }
 }
 
 impl FromBase32 for PrivateRoute {
-       type Err = ParseError;
+       type Err = Bolt11ParseError;
 
-       fn from_base32(field_data: &[u5]) -> Result<PrivateRoute, ParseError> {
+       fn from_base32(field_data: &[u5]) -> Result<PrivateRoute, Bolt11ParseError> {
                let bytes = Vec::<u8>::from_base32(field_data)?;
 
                if bytes.len() % 51 != 0 {
-                       return Err(ParseError::UnexpectedEndOfTaggedFields);
+                       return Err(Bolt11ParseError::UnexpectedEndOfTaggedFields);
                }
 
                let mut route_hops = Vec::<RouteHintHop>::new();
@@ -619,52 +619,52 @@ impl FromBase32 for PrivateRoute {
        }
 }
 
-impl Display for ParseError {
+impl Display for Bolt11ParseError {
        fn fmt(&self, f: &mut Formatter) -> fmt::Result {
                match *self {
                        // TODO: find a way to combine the first three arms (e as error::Error?)
-                       ParseError::Bech32Error(ref e) => {
+                       Bolt11ParseError::Bech32Error(ref e) => {
                                write!(f, "Invalid bech32: {}", e)
                        }
-                       ParseError::ParseAmountError(ref e) => {
+                       Bolt11ParseError::ParseAmountError(ref e) => {
                                write!(f, "Invalid amount in hrp ({})", e)
                        }
-                       ParseError::MalformedSignature(ref e) => {
+                       Bolt11ParseError::MalformedSignature(ref e) => {
                                write!(f, "Invalid secp256k1 signature: {}", e)
                        }
-                       ParseError::DescriptionDecodeError(ref e) => {
+                       Bolt11ParseError::DescriptionDecodeError(ref e) => {
                                write!(f, "Description is not a valid utf-8 string: {}", e)
                        }
-                       ParseError::InvalidSliceLength(ref function) => {
+                       Bolt11ParseError::InvalidSliceLength(ref function) => {
                                write!(f, "Slice in function {} had the wrong length", function)
                        }
-                       ParseError::BadPrefix => f.write_str("did not begin with 'ln'"),
-                       ParseError::UnknownCurrency => f.write_str("currency code unknown"),
-                       ParseError::UnknownSiPrefix => f.write_str("unknown SI prefix"),
-                       ParseError::MalformedHRP => f.write_str("malformed human readable part"),
-                       ParseError::TooShortDataPart => {
+                       Bolt11ParseError::BadPrefix => f.write_str("did not begin with 'ln'"),
+                       Bolt11ParseError::UnknownCurrency => f.write_str("currency code unknown"),
+                       Bolt11ParseError::UnknownSiPrefix => f.write_str("unknown SI prefix"),
+                       Bolt11ParseError::MalformedHRP => f.write_str("malformed human readable part"),
+                       Bolt11ParseError::TooShortDataPart => {
                                f.write_str("data part too short (should be at least 111 bech32 chars long)")
                        },
-                       ParseError::UnexpectedEndOfTaggedFields => {
+                       Bolt11ParseError::UnexpectedEndOfTaggedFields => {
                                f.write_str("tagged fields part ended unexpectedly")
                        },
-                       ParseError::PaddingError => f.write_str("some data field had bad padding"),
-                       ParseError::IntegerOverflowError => {
+                       Bolt11ParseError::PaddingError => f.write_str("some data field had bad padding"),
+                       Bolt11ParseError::IntegerOverflowError => {
                                f.write_str("parsed integer doesn't fit into receiving type")
                        },
-                       ParseError::InvalidSegWitProgramLength => {
+                       Bolt11ParseError::InvalidSegWitProgramLength => {
                                f.write_str("fallback SegWit program is too long or too short")
                        },
-                       ParseError::InvalidPubKeyHashLength => {
+                       Bolt11ParseError::InvalidPubKeyHashLength => {
                                f.write_str("fallback public key hash has a length unequal 20 bytes")
                        },
-                       ParseError::InvalidScriptHashLength => {
+                       Bolt11ParseError::InvalidScriptHashLength => {
                                f.write_str("fallback script hash has a length unequal 32 bytes")
                        },
-                       ParseError::InvalidRecoveryId => {
+                       Bolt11ParseError::InvalidRecoveryId => {
                                f.write_str("recovery id is out of range (should be in [0,3])")
                        },
-                       ParseError::Skip => {
+                       Bolt11ParseError::Skip => {
                                f.write_str("the tagged field has to be skipped because of an unexpected, but allowed property")
                        },
                }
@@ -681,14 +681,14 @@ impl Display for ParseOrSemanticError {
 }
 
 #[cfg(feature = "std")]
-impl error::Error for ParseError {}
+impl error::Error for Bolt11ParseError {}
 
 #[cfg(feature = "std")]
 impl error::Error for ParseOrSemanticError {}
 
 macro_rules! from_error {
     ($my_error:expr, $extern_error:ty) => {
-        impl From<$extern_error> for ParseError {
+        impl From<$extern_error> for Bolt11ParseError {
             fn from(e: $extern_error) -> Self {
                 $my_error(e)
             }
@@ -696,34 +696,34 @@ macro_rules! from_error {
     }
 }
 
-from_error!(ParseError::MalformedSignature, secp256k1::Error);
-from_error!(ParseError::ParseAmountError, ParseIntError);
-from_error!(ParseError::DescriptionDecodeError, str::Utf8Error);
+from_error!(Bolt11ParseError::MalformedSignature, secp256k1::Error);
+from_error!(Bolt11ParseError::ParseAmountError, ParseIntError);
+from_error!(Bolt11ParseError::DescriptionDecodeError, str::Utf8Error);
 
-impl From<bech32::Error> for ParseError {
+impl From<bech32::Error> for Bolt11ParseError {
        fn from(e: bech32::Error) -> Self {
                match e {
-                       bech32::Error::InvalidPadding => ParseError::PaddingError,
-                       _ => ParseError::Bech32Error(e)
+                       bech32::Error::InvalidPadding => Bolt11ParseError::PaddingError,
+                       _ => Bolt11ParseError::Bech32Error(e)
                }
        }
 }
 
-impl From<ParseError> for ParseOrSemanticError {
-       fn from(e: ParseError) -> Self {
+impl From<Bolt11ParseError> for ParseOrSemanticError {
+       fn from(e: Bolt11ParseError) -> Self {
                ParseOrSemanticError::ParseError(e)
        }
 }
 
-impl From<crate::SemanticError> for ParseOrSemanticError {
-       fn from(e: SemanticError) -> Self {
+impl From<crate::Bolt11SemanticError> for ParseOrSemanticError {
+       fn from(e: Bolt11SemanticError) -> Self {
                ParseOrSemanticError::SemanticError(e)
        }
 }
 
 #[cfg(test)]
 mod test {
-       use crate::de::ParseError;
+       use crate::de::Bolt11ParseError;
        use secp256k1::PublicKey;
        use bech32::u5;
        use bitcoin_hashes::hex::FromHex;
@@ -756,7 +756,7 @@ mod test {
                assert_eq!("bcrt".parse::<Currency>(), Ok(Currency::Regtest));
                assert_eq!("sb".parse::<Currency>(), Ok(Currency::Simnet));
                assert_eq!("tbs".parse::<Currency>(), Ok(Currency::Signet));
-               assert_eq!("something_else".parse::<Currency>(), Err(ParseError::UnknownCurrency))
+               assert_eq!("something_else".parse::<Currency>(), Err(Bolt11ParseError::UnknownCurrency))
        }
 
        #[test]
@@ -789,7 +789,7 @@ mod test {
                let input_unexpected_length = from_bech32(
                        "qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypyq".as_bytes()
                );
-               assert_eq!(Sha256::from_base32(&input_unexpected_length), Err(ParseError::Skip));
+               assert_eq!(Sha256::from_base32(&input_unexpected_length), Err(Bolt11ParseError::Skip));
        }
 
        #[test]
@@ -823,7 +823,7 @@ mod test {
                let input_unexpected_length = from_bech32(
                        "q0n326hr8v9zprg8gsvezcch06gfaqqhde2aj730yg0durunfhvq".as_bytes()
                );
-               assert_eq!(PayeePubKey::from_base32(&input_unexpected_length), Err(ParseError::Skip));
+               assert_eq!(PayeePubKey::from_base32(&input_unexpected_length), Err(Bolt11ParseError::Skip));
        }
 
        #[test]
@@ -836,7 +836,7 @@ mod test {
                assert_eq!(ExpiryTime::from_base32(&input), expected);
 
                let input_too_large = from_bech32("sqqqqqqqqqqqq".as_bytes());
-               assert_eq!(ExpiryTime::from_base32(&input_too_large), Err(ParseError::IntegerOverflowError));
+               assert_eq!(ExpiryTime::from_base32(&input_too_large), Err(Bolt11ParseError::IntegerOverflowError));
        }
 
        #[test]
@@ -885,23 +885,23 @@ mod test {
                        ),
                        (
                                vec![u5::try_from_u8(21).unwrap(); 41],
-                               Err(ParseError::Skip)
+                               Err(Bolt11ParseError::Skip)
                        ),
                        (
                                vec![],
-                               Err(ParseError::UnexpectedEndOfTaggedFields)
+                               Err(Bolt11ParseError::UnexpectedEndOfTaggedFields)
                        ),
                        (
                                vec![u5::try_from_u8(1).unwrap(); 81],
-                               Err(ParseError::InvalidSegWitProgramLength)
+                               Err(Bolt11ParseError::InvalidSegWitProgramLength)
                        ),
                        (
                                vec![u5::try_from_u8(17).unwrap(); 1],
-                               Err(ParseError::InvalidPubKeyHashLength)
+                               Err(Bolt11ParseError::InvalidPubKeyHashLength)
                        ),
                        (
                                vec![u5::try_from_u8(18).unwrap(); 1],
-                               Err(ParseError::InvalidScriptHashLength)
+                               Err(Bolt11ParseError::InvalidScriptHashLength)
                        )
                ];
 
@@ -963,23 +963,23 @@ mod test {
 
                assert_eq!(
                        PrivateRoute::from_base32(&[u5::try_from_u8(0).unwrap(); 40][..]),
-                       Err(ParseError::UnexpectedEndOfTaggedFields)
+                       Err(Bolt11ParseError::UnexpectedEndOfTaggedFields)
                );
        }
 
        #[test]
        fn test_payment_secret_and_features_de_and_ser() {
-               use lightning::ln::features::InvoiceFeatures;
+               use lightning::ln::features::Bolt11InvoiceFeatures;
                use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
                use crate::TaggedField::*;
-               use crate::{SiPrefix, SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart,
+               use crate::{SiPrefix, SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart,
                                 Currency, Sha256, PositiveTimestamp};
 
                // Feature bits 9, 15, and 99 are set.
-               let expected_features = InvoiceFeatures::from_le_bytes(vec![0, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8]);
+               let expected_features = Bolt11InvoiceFeatures::from_le_bytes(vec![0, 130, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8]);
                let invoice_str = "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q5sqqqqqqqqqqqqqqqpqsq67gye39hfg3zd8rgc80k32tvy9xk2xunwm5lzexnvpx6fd77en8qaq424dxgt56cag2dpt359k3ssyhetktkpqh24jqnjyw6uqd08sgptq44qu";
-               let invoice = SignedRawInvoice {
-                                       raw_invoice: RawInvoice {
+               let invoice = SignedRawBolt11Invoice {
+                                       raw_invoice: RawBolt11Invoice {
                                                hrp: RawHrp {
                                                        currency: Currency::Bitcoin,
                                                        raw_amount: Some(25),
@@ -998,7 +998,7 @@ mod test {
                                        hash: [0xb1, 0x96, 0x46, 0xc3, 0xbc, 0x56, 0x76, 0x1d, 0x20, 0x65, 0x6e, 0x0e, 0x32,
                                                                        0xec, 0xd2, 0x69, 0x27, 0xb7, 0x62, 0x6e, 0x2a, 0x8b, 0xe6, 0x97, 0x71, 0x9f,
                                                                        0xf8, 0x7e, 0x44, 0x54, 0x55, 0xb9],
-                                       signature: InvoiceSignature(RecoverableSignature::from_compact(
+                                       signature: Bolt11InvoiceSignature(RecoverableSignature::from_compact(
                                                                                &[0xd7, 0x90, 0x4c, 0xc4, 0xb7, 0x4a, 0x22, 0x26, 0x9c, 0x68, 0xc1, 0xdf, 0x68,
                                                                                        0xa9, 0x6c, 0x21, 0x4d, 0x65, 0x1b, 0x93, 0x76, 0xe9, 0xf1, 0x64, 0xd3, 0x60,
                                                                                        0x4d, 0xa4, 0xb7, 0xde, 0xcc, 0xce, 0x0e, 0x82, 0xaa, 0xab, 0x4c, 0x85, 0xd3,
@@ -1018,15 +1018,15 @@ mod test {
        fn test_raw_signed_invoice_deserialization() {
                use crate::TaggedField::*;
                use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
-               use crate::{SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
+               use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
                         PositiveTimestamp};
 
                assert_eq!(
                        "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmw\
                        wd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9\
                        ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w".parse(),
-                       Ok(SignedRawInvoice {
-                               raw_invoice: RawInvoice {
+                       Ok(SignedRawBolt11Invoice {
+                               raw_invoice: RawBolt11Invoice {
                                        hrp: RawHrp {
                                                currency: Currency::Bitcoin,
                                                raw_amount: None,
@@ -1051,7 +1051,7 @@ mod test {
                                        0x7b, 0x1d, 0x85, 0x8d, 0xb1, 0xd1, 0xf7, 0xab, 0x71, 0x37, 0xdc, 0xb7,
                                        0x83, 0x5d, 0xb2, 0xec, 0xd5, 0x18, 0xe1, 0xc9
                                ],
-                               signature: InvoiceSignature(RecoverableSignature::from_compact(
+                               signature: Bolt11InvoiceSignature(RecoverableSignature::from_compact(
                                        & [
                                                0x38u8, 0xec, 0x68, 0x91, 0x34, 0x5e, 0x20, 0x41, 0x45, 0xbe, 0x8a,
                                                0x3a, 0x99, 0xde, 0x38, 0xe9, 0x8a, 0x39, 0xd6, 0xa5, 0x69, 0x43,
index 8ccd9d979ab139899731d3724566b0b12e27069d..d1b381130c0714c566d48a38dcf8b843935b6f95 100644 (file)
 //! invoices and functions to create, encode and decode these. If you just want to use the standard
 //! en-/decoding functionality this should get you started:
 //!
-//!   * For parsing use `str::parse::<Invoice>(&self)` (see [`Invoice::from_str`])
+//!   * For parsing use `str::parse::<Bolt11Invoice>(&self)` (see [`Bolt11Invoice::from_str`])
 //!   * For constructing invoices use the [`InvoiceBuilder`]
 //!   * For serializing invoices use the [`Display`]/[`ToString`] traits
 //!
-//! [`Invoice::from_str`]: crate::Invoice#impl-FromStr
+//! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
 
 #[cfg(not(any(feature = "std", feature = "no-std")))]
 compile_error!("at least one of the `std` or `no-std` features must be enabled");
@@ -51,7 +51,7 @@ use bitcoin::{Address, Network, PubkeyHash, ScriptHash};
 use bitcoin::util::address::{Payload, WitnessVersion};
 use bitcoin_hashes::{Hash, sha256};
 use lightning::ln::PaymentSecret;
-use lightning::ln::features::InvoiceFeatures;
+use lightning::ln::features::Bolt11InvoiceFeatures;
 #[cfg(any(doc, test))]
 use lightning::routing::gossip::RoutingFees;
 use lightning::routing::router::RouteHint;
@@ -106,7 +106,7 @@ mod sync;
 /// reasons, but should generally result in an "invalid BOLT11 invoice" message for the user.
 #[allow(missing_docs)]
 #[derive(PartialEq, Eq, Debug, Clone)]
-pub enum ParseError {
+pub enum Bolt11ParseError {
        Bech32Error(bech32::Error),
        ParseAmountError(ParseIntError),
        MalformedSignature(secp256k1::Error),
@@ -136,10 +136,10 @@ pub enum ParseError {
 #[derive(PartialEq, Eq, Debug, Clone)]
 pub enum ParseOrSemanticError {
        /// The invoice couldn't be decoded
-       ParseError(ParseError),
+       ParseError(Bolt11ParseError),
 
        /// The invoice could be decoded but violates the BOLT11 standard
-       SemanticError(crate::SemanticError),
+       SemanticError(crate::Bolt11SemanticError),
 }
 
 /// The number of bits used to represent timestamps as defined in BOLT 11.
@@ -164,8 +164,8 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
 /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
 pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA: u64 = 18;
 
-/// Builder for [`Invoice`]s. It's the most convenient and advised way to use this library. It ensures
-/// that only a semantically and syntactically correct Invoice can be built using it.
+/// Builder for [`Bolt11Invoice`]s. It's the most convenient and advised way to use this library. It
+/// ensures that only a semantically and syntactically correct invoice can be built using it.
 ///
 /// ```
 /// extern crate secp256k1;
@@ -243,15 +243,15 @@ pub struct InvoiceBuilder<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S:
 
 /// Represents a syntactically and semantically correct lightning BOLT11 invoice.
 ///
-/// There are three ways to construct an `Invoice`:
+/// There are three ways to construct a `Bolt11Invoice`:
 ///  1. using [`InvoiceBuilder`]
-///  2. using [`Invoice::from_signed`]
-///  3. using `str::parse::<Invoice>(&str)` (see [`Invoice::from_str`])
+///  2. using [`Bolt11Invoice::from_signed`]
+///  3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
 ///
-/// [`Invoice::from_str`]: crate::Invoice#impl-FromStr
+/// [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
 #[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
-pub struct Invoice {
-       signed_invoice: SignedRawInvoice,
+pub struct Bolt11Invoice {
+       signed_invoice: SignedRawBolt11Invoice,
 }
 
 /// Represents the description of an invoice which has to be either a directly included string or
@@ -260,7 +260,7 @@ pub struct Invoice {
 /// This is not exported to bindings users as we don't have a good way to map the reference lifetimes making this
 /// practically impossible to use safely in languages like C.
 #[derive(Eq, PartialEq, Debug, Clone, Ord, PartialOrd)]
-pub enum InvoiceDescription<'f> {
+pub enum Bolt11InvoiceDescription<'f> {
        /// Reference to the directly supplied description in the invoice
        Direct(&'f Description),
 
@@ -268,36 +268,36 @@ pub enum InvoiceDescription<'f> {
        Hash(&'f Sha256),
 }
 
-/// Represents a signed [`RawInvoice`] with cached hash. The signature is not checked and may be
+/// Represents a signed [`RawBolt11Invoice`] with cached hash. The signature is not checked and may be
 /// invalid.
 ///
 /// # Invariants
-/// The hash has to be either from the deserialized invoice or from the serialized [`RawInvoice`].
+/// The hash has to be either from the deserialized invoice or from the serialized [`RawBolt11Invoice`].
 #[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
-pub struct SignedRawInvoice {
-       /// The rawInvoice that the signature belongs to
-       raw_invoice: RawInvoice,
+pub struct SignedRawBolt11Invoice {
+       /// The raw invoice that the signature belongs to
+       raw_invoice: RawBolt11Invoice,
 
-       /// Hash of the [`RawInvoice`] that will be used to check the signature.
+       /// Hash of the [`RawBolt11Invoice`] that will be used to check the signature.
        ///
-       /// * if the `SignedRawInvoice` was deserialized the hash is of from the original encoded form,
+       /// * if the `SignedRawBolt11Invoice` was deserialized the hash is of from the original encoded form,
        /// since it's not guaranteed that encoding it again will lead to the same result since integers
        /// could have been encoded with leading zeroes etc.
-       /// * if the `SignedRawInvoice` was constructed manually the hash will be the calculated hash
-       /// from the [`RawInvoice`]
+       /// * if the `SignedRawBolt11Invoice` was constructed manually the hash will be the calculated hash
+       /// from the [`RawBolt11Invoice`]
        hash: [u8; 32],
 
        /// signature of the payment request
-       signature: InvoiceSignature,
+       signature: Bolt11InvoiceSignature,
 }
 
-/// Represents an syntactically correct [`Invoice`] for a payment on the lightning network,
+/// Represents an syntactically correct [`Bolt11Invoice`] for a payment on the lightning network,
 /// but without the signature information.
 /// Decoding and encoding should not lead to information loss but may lead to different hashes.
 ///
-/// For methods without docs see the corresponding methods in [`Invoice`].
+/// For methods without docs see the corresponding methods in [`Bolt11Invoice`].
 #[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
-pub struct RawInvoice {
+pub struct RawBolt11Invoice {
        /// human readable part
        pub hrp: RawHrp,
 
@@ -305,7 +305,7 @@ pub struct RawInvoice {
        pub data: RawDataPart,
 }
 
-/// Data of the [`RawInvoice`] that is encoded in the human readable part.
+/// Data of the [`RawBolt11Invoice`] that is encoded in the human readable part.
 ///
 /// This is not exported to bindings users as we don't yet support `Option<Enum>`
 #[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
@@ -320,7 +320,7 @@ pub struct RawHrp {
        pub si_prefix: Option<SiPrefix>,
 }
 
-/// Data of the [`RawInvoice`] that is encoded in the data part
+/// Data of the [`RawBolt11Invoice`] that is encoded in the data part
 #[derive(Eq, PartialEq, Debug, Clone, Hash, Ord, PartialOrd)]
 pub struct RawDataPart {
        /// generation time of the invoice
@@ -448,7 +448,7 @@ pub enum TaggedField {
        PrivateRoute(PrivateRoute),
        PaymentSecret(PaymentSecret),
        PaymentMetadata(Vec<u8>),
-       Features(InvoiceFeatures),
+       Features(Bolt11InvoiceFeatures),
 }
 
 /// SHA-256 hash
@@ -499,15 +499,15 @@ pub enum Fallback {
 
 /// Recoverable signature
 #[derive(Clone, Debug, Hash, Eq, PartialEq)]
-pub struct InvoiceSignature(pub RecoverableSignature);
+pub struct Bolt11InvoiceSignature(pub RecoverableSignature);
 
-impl PartialOrd for InvoiceSignature {
+impl PartialOrd for Bolt11InvoiceSignature {
        fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
                self.0.serialize_compact().1.partial_cmp(&other.0.serialize_compact().1)
        }
 }
 
-impl Ord for InvoiceSignature {
+impl Ord for Bolt11InvoiceSignature {
        fn cmp(&self, other: &Self) -> Ordering {
                self.0.serialize_compact().1.cmp(&other.0.serialize_compact().1)
        }
@@ -621,9 +621,9 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
 }
 
 impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBuilder<D, H, tb::True, C, S, M> {
-       /// Builds a [`RawInvoice`] if no [`CreationError`] occurred while construction any of the
+       /// Builds a [`RawBolt11Invoice`] if no [`CreationError`] occurred while construction any of the
        /// fields.
-       pub fn build_raw(self) -> Result<RawInvoice, CreationError> {
+       pub fn build_raw(self) -> Result<RawBolt11Invoice, CreationError> {
 
                // If an error occurred at any time before, return it now
                if let Some(e) = self.error {
@@ -647,7 +647,7 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBui
                        tagged_fields,
                };
 
-               Ok(RawInvoice {
+               Ok(RawBolt11Invoice {
                        hrp,
                        data,
                })
@@ -671,12 +671,12 @@ impl<H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Bool> InvoiceBui
        }
 
        /// Set the description or description hash. This function is only available if no description (hash) was set.
-       pub fn invoice_description(self, description: InvoiceDescription) -> InvoiceBuilder<tb::True, H, T, C, S, M> {
+       pub fn invoice_description(self, description: Bolt11InvoiceDescription) -> InvoiceBuilder<tb::True, H, T, C, S, M> {
                match description {
-                       InvoiceDescription::Direct(desc) => {
+                       Bolt11InvoiceDescription::Direct(desc) => {
                                self.description(desc.clone().into_inner())
                        }
-                       InvoiceDescription::Hash(hash) => {
+                       Bolt11InvoiceDescription::Hash(hash) => {
                                self.description_hash(hash.0)
                        }
                }
@@ -744,7 +744,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, M: tb::Bool> InvoiceBui
                }
                self.tagged_fields.push(TaggedField::PaymentSecret(payment_secret));
                if !found_features {
-                       let mut features = InvoiceFeatures::empty();
+                       let mut features = Bolt11InvoiceFeatures::empty();
                        features.set_variable_length_onion_required();
                        features.set_payment_secret_required();
                        self.tagged_fields.push(TaggedField::Features(features));
@@ -770,7 +770,7 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBui
                        }
                }
                if !found_features {
-                       let mut features = InvoiceFeatures::empty();
+                       let mut features = Bolt11InvoiceFeatures::empty();
                        features.set_payment_metadata_optional();
                        self.tagged_fields.push(TaggedField::Features(features));
                }
@@ -807,7 +807,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
        /// Builds and signs an invoice using the supplied `sign_function`. This function MAY NOT fail
        /// and MUST produce a recoverable signature valid for the given hash and if applicable also for
        /// the included payee public key.
-       pub fn build_signed<F>(self, sign_function: F) -> Result<Invoice, CreationError>
+       pub fn build_signed<F>(self, sign_function: F) -> Result<Bolt11Invoice, CreationError>
                where F: FnOnce(&Message) -> RecoverableSignature
        {
                let invoice = self.try_build_signed::<_, ()>(|hash| {
@@ -824,7 +824,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
        /// Builds and signs an invoice using the supplied `sign_function`. This function MAY fail with
        /// an error of type `E` and MUST produce a recoverable signature valid for the given hash and
        /// if applicable also for the included payee public key.
-       pub fn try_build_signed<F, E>(self, sign_function: F) -> Result<Invoice, SignOrCreationError<E>>
+       pub fn try_build_signed<F, E>(self, sign_function: F) -> Result<Bolt11Invoice, SignOrCreationError<E>>
                where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
        {
                let raw = match self.build_raw() {
@@ -837,7 +837,7 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
                        Err(e) => return Err(SignOrCreationError::SignError(e)),
                };
 
-               let invoice = Invoice {
+               let invoice = Bolt11Invoice {
                        signed_invoice: signed,
                };
 
@@ -850,27 +850,27 @@ impl<M: tb::Bool> InvoiceBuilder<tb::True, tb::True, tb::True, tb::True, tb::Tru
 }
 
 
-impl SignedRawInvoice {
-       /// Disassembles the `SignedRawInvoice` into its three parts:
+impl SignedRawBolt11Invoice {
+       /// Disassembles the `SignedRawBolt11Invoice` into its three parts:
        ///  1. raw invoice
        ///  2. hash of the raw invoice
        ///  3. signature
-       pub fn into_parts(self) -> (RawInvoice, [u8; 32], InvoiceSignature) {
+       pub fn into_parts(self) -> (RawBolt11Invoice, [u8; 32], Bolt11InvoiceSignature) {
                (self.raw_invoice, self.hash, self.signature)
        }
 
-       /// The [`RawInvoice`] which was signed.
-       pub fn raw_invoice(&self) -> &RawInvoice {
+       /// The [`RawBolt11Invoice`] which was signed.
+       pub fn raw_invoice(&self) -> &RawBolt11Invoice {
                &self.raw_invoice
        }
 
-       /// The hash of the [`RawInvoice`] that was signed.
+       /// The hash of the [`RawBolt11Invoice`] that was signed.
        pub fn signable_hash(&self) -> &[u8; 32] {
                &self.hash
        }
 
        /// Signature for the invoice.
-       pub fn signature(&self) -> &InvoiceSignature {
+       pub fn signature(&self) -> &Bolt11InvoiceSignature {
                &self.signature
        }
 
@@ -968,7 +968,7 @@ macro_rules! find_all_extract {
 }
 
 #[allow(missing_docs)]
-impl RawInvoice {
+impl RawBolt11Invoice {
        /// Hash the HRP as bytes and signatureless data part.
        fn hash_from_parts(hrp_bytes: &[u8], data_without_signature: &[u5]) -> [u8; 32] {
                let preimage = construct_invoice_preimage(hrp_bytes, data_without_signature);
@@ -977,23 +977,23 @@ impl RawInvoice {
                hash
        }
 
-       /// Calculate the hash of the encoded `RawInvoice` which should be signed.
+       /// Calculate the hash of the encoded `RawBolt11Invoice` which should be signed.
        pub fn signable_hash(&self) -> [u8; 32] {
                use bech32::ToBase32;
 
-               RawInvoice::hash_from_parts(
+               RawBolt11Invoice::hash_from_parts(
                        self.hrp.to_string().as_bytes(),
                        &self.data.to_base32()
                )
        }
 
        /// Signs the invoice using the supplied `sign_method`. This function MAY fail with an error of
-       /// type `E`. Since the signature of a [`SignedRawInvoice`] is not required to be valid there
+       /// type `E`. Since the signature of a [`SignedRawBolt11Invoice`] is not required to be valid there
        /// are no constraints regarding the validity of the produced signature.
        ///
        /// This is not exported to bindings users as we don't currently support passing function pointers into methods
        /// explicitly.
-       pub fn sign<F, E>(self, sign_method: F) -> Result<SignedRawInvoice, E>
+       pub fn sign<F, E>(self, sign_method: F) -> Result<SignedRawBolt11Invoice, E>
                where F: FnOnce(&Message) -> Result<RecoverableSignature, E>
        {
                let raw_hash = self.signable_hash();
@@ -1001,10 +1001,10 @@ impl RawInvoice {
                        .expect("Hash is 32 bytes long, same as MESSAGE_SIZE");
                let signature = sign_method(&hash)?;
 
-               Ok(SignedRawInvoice {
+               Ok(SignedRawBolt11Invoice {
                        raw_invoice: self,
                        hash: raw_hash,
-                       signature: InvoiceSignature(signature),
+                       signature: Bolt11InvoiceSignature(signature),
                })
        }
 
@@ -1059,7 +1059,7 @@ impl RawInvoice {
                find_extract!(self.known_tagged_fields(), TaggedField::PaymentMetadata(ref x), x)
        }
 
-       pub fn features(&self) -> Option<&InvoiceFeatures> {
+       pub fn features(&self) -> Option<&Bolt11InvoiceFeatures> {
                find_extract!(self.known_tagged_fields(), TaggedField::Features(ref x), x)
        }
 
@@ -1142,28 +1142,28 @@ impl From<PositiveTimestamp> for SystemTime {
        }
 }
 
-impl Invoice {
-       /// The hash of the [`RawInvoice`] that was signed.
+impl Bolt11Invoice {
+       /// The hash of the [`RawBolt11Invoice`] that was signed.
        pub fn signable_hash(&self) -> [u8; 32] {
                self.signed_invoice.hash
        }
 
-       /// Transform the `Invoice` into it's unchecked version
-       pub fn into_signed_raw(self) -> SignedRawInvoice {
+       /// Transform the `Bolt11Invoice` into its unchecked version.
+       pub fn into_signed_raw(self) -> SignedRawBolt11Invoice {
                self.signed_invoice
        }
 
        /// Check that all mandatory fields are present
-       fn check_field_counts(&self) -> Result<(), SemanticError> {
+       fn check_field_counts(&self) -> Result<(), Bolt11SemanticError> {
                // "A writer MUST include exactly one p field […]."
                let payment_hash_cnt = self.tagged_fields().filter(|&tf| match *tf {
                        TaggedField::PaymentHash(_) => true,
                        _ => false,
                }).count();
                if payment_hash_cnt < 1 {
-                       return Err(SemanticError::NoPaymentHash);
+                       return Err(Bolt11SemanticError::NoPaymentHash);
                } else if payment_hash_cnt > 1 {
-                       return Err(SemanticError::MultiplePaymentHashes);
+                       return Err(Bolt11SemanticError::MultiplePaymentHashes);
                }
 
                // "A writer MUST include either exactly one d or exactly one h field."
@@ -1172,9 +1172,9 @@ impl Invoice {
                        _ => false,
                }).count();
                if  description_cnt < 1 {
-                       return Err(SemanticError::NoDescription);
+                       return Err(Bolt11SemanticError::NoDescription);
                } else if description_cnt > 1 {
-                       return  Err(SemanticError::MultipleDescriptions);
+                       return  Err(Bolt11SemanticError::MultipleDescriptions);
                }
 
                self.check_payment_secret()?;
@@ -1183,33 +1183,33 @@ impl Invoice {
        }
 
        /// Checks that there is exactly one payment secret field
-       fn check_payment_secret(&self) -> Result<(), SemanticError> {
+       fn check_payment_secret(&self) -> Result<(), Bolt11SemanticError> {
                // "A writer MUST include exactly one `s` field."
                let payment_secret_count = self.tagged_fields().filter(|&tf| match *tf {
                        TaggedField::PaymentSecret(_) => true,
                        _ => false,
                }).count();
                if payment_secret_count < 1 {
-                       return Err(SemanticError::NoPaymentSecret);
+                       return Err(Bolt11SemanticError::NoPaymentSecret);
                } else if payment_secret_count > 1 {
-                       return Err(SemanticError::MultiplePaymentSecrets);
+                       return Err(Bolt11SemanticError::MultiplePaymentSecrets);
                }
 
                Ok(())
        }
 
        /// Check that amount is a whole number of millisatoshis
-       fn check_amount(&self) -> Result<(), SemanticError> {
+       fn check_amount(&self) -> Result<(), Bolt11SemanticError> {
                if let Some(amount_pico_btc) = self.amount_pico_btc() {
                        if amount_pico_btc % 10 != 0 {
-                               return Err(SemanticError::ImpreciseAmount);
+                               return Err(Bolt11SemanticError::ImpreciseAmount);
                        }
                }
                Ok(())
        }
 
        /// Check that feature bits are set as required
-       fn check_feature_bits(&self) -> Result<(), SemanticError> {
+       fn check_feature_bits(&self) -> Result<(), Bolt11SemanticError> {
                self.check_payment_secret()?;
 
                // "A writer MUST set an s field if and only if the payment_secret feature is set."
@@ -1220,12 +1220,12 @@ impl Invoice {
                        _ => false,
                });
                match features {
-                       None => Err(SemanticError::InvalidFeatures),
+                       None => Err(Bolt11SemanticError::InvalidFeatures),
                        Some(TaggedField::Features(features)) => {
                                if features.requires_unknown_bits() {
-                                       Err(SemanticError::InvalidFeatures)
+                                       Err(Bolt11SemanticError::InvalidFeatures)
                                } else if !features.supports_payment_secret() {
-                                       Err(SemanticError::InvalidFeatures)
+                                       Err(Bolt11SemanticError::InvalidFeatures)
                                } else {
                                        Ok(())
                                }
@@ -1235,24 +1235,24 @@ impl Invoice {
        }
 
        /// Check that the invoice is signed correctly and that key recovery works
-       pub fn check_signature(&self) -> Result<(), SemanticError> {
+       pub fn check_signature(&self) -> Result<(), Bolt11SemanticError> {
                match self.signed_invoice.recover_payee_pub_key() {
                        Err(secp256k1::Error::InvalidRecoveryId) =>
-                               return Err(SemanticError::InvalidRecoveryId),
+                               return Err(Bolt11SemanticError::InvalidRecoveryId),
                        Err(secp256k1::Error::InvalidSignature) =>
-                               return Err(SemanticError::InvalidSignature),
+                               return Err(Bolt11SemanticError::InvalidSignature),
                        Err(e) => panic!("no other error may occur, got {:?}", e),
                        Ok(_) => {},
                }
 
                if !self.signed_invoice.check_signature() {
-                       return Err(SemanticError::InvalidSignature);
+                       return Err(Bolt11SemanticError::InvalidSignature);
                }
 
                Ok(())
        }
 
-       /// Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants.
+       /// Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
        /// ```
        /// use lightning_invoice::*;
        ///
@@ -1268,12 +1268,12 @@ impl Invoice {
        /// 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
        /// j5r6drg6k6zcqj0fcwg";
        ///
-       /// let signed = invoice.parse::<SignedRawInvoice>().unwrap();
+       /// let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
        ///
-       /// assert!(Invoice::from_signed(signed).is_ok());
+       /// assert!(Bolt11Invoice::from_signed(signed).is_ok());
        /// ```
-       pub fn from_signed(signed_invoice: SignedRawInvoice) -> Result<Self, SemanticError> {
-               let invoice = Invoice {
+       pub fn from_signed(signed_invoice: SignedRawBolt11Invoice) -> Result<Self, Bolt11SemanticError> {
+               let invoice = Bolt11Invoice {
                        signed_invoice,
                };
                invoice.check_field_counts()?;
@@ -1284,18 +1284,18 @@ impl Invoice {
                Ok(invoice)
        }
 
-       /// Returns the `Invoice`'s timestamp (should equal its creation time)
+       /// Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
        #[cfg(feature = "std")]
        pub fn timestamp(&self) -> SystemTime {
                self.signed_invoice.raw_invoice().data.timestamp.as_time()
        }
 
-       /// Returns the `Invoice`'s timestamp as a duration since the Unix epoch
+       /// Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
        pub fn duration_since_epoch(&self) -> Duration {
                self.signed_invoice.raw_invoice().data.timestamp.0
        }
 
-       /// Returns an iterator over all tagged fields of this Invoice.
+       /// Returns an iterator over all tagged fields of this `Bolt11Invoice`.
        ///
        /// This is not exported to bindings users as there is not yet a manual mapping for a FilterMap
        pub fn tagged_fields(&self)
@@ -1310,12 +1310,12 @@ impl Invoice {
 
        /// Return the description or a hash of it for longer ones
        ///
-       /// This is not exported to bindings users because we don't yet export InvoiceDescription
-       pub fn description(&self) -> InvoiceDescription {
+       /// This is not exported to bindings users because we don't yet export Bolt11InvoiceDescription
+       pub fn description(&self) -> Bolt11InvoiceDescription {
                if let Some(direct) = self.signed_invoice.description() {
-                       return InvoiceDescription::Direct(direct);
+                       return Bolt11InvoiceDescription::Direct(direct);
                } else if let Some(hash) = self.signed_invoice.description_hash() {
-                       return InvoiceDescription::Hash(hash);
+                       return Bolt11InvoiceDescription::Hash(hash);
                }
                unreachable!("ensured by constructor");
        }
@@ -1336,7 +1336,7 @@ impl Invoice {
        }
 
        /// Get the invoice features if they were included in the invoice
-       pub fn features(&self) -> Option<&InvoiceFeatures> {
+       pub fn features(&self) -> Option<&Bolt11InvoiceFeatures> {
                self.signed_invoice.features()
        }
 
@@ -1591,7 +1591,7 @@ impl Deref for PrivateRoute {
        }
 }
 
-impl Deref for InvoiceSignature {
+impl Deref for Bolt11InvoiceSignature {
        type Target = RecoverableSignature;
 
        fn deref(&self) -> &RecoverableSignature {
@@ -1599,15 +1599,15 @@ impl Deref for InvoiceSignature {
        }
 }
 
-impl Deref for SignedRawInvoice {
-       type Target = RawInvoice;
+impl Deref for SignedRawBolt11Invoice {
+       type Target = RawBolt11Invoice;
 
-       fn deref(&self) -> &RawInvoice {
+       fn deref(&self) -> &RawBolt11Invoice {
                &self.raw_invoice
        }
 }
 
-/// Errors that may occur when constructing a new [`RawInvoice`] or [`Invoice`]
+/// Errors that may occur when constructing a new [`RawBolt11Invoice`] or [`Bolt11Invoice`]
 #[derive(Eq, PartialEq, Debug, Clone)]
 pub enum CreationError {
        /// The supplied description string was longer than 639 __bytes__ (see [`Description::new`])
@@ -1651,10 +1651,10 @@ impl Display for CreationError {
 #[cfg(feature = "std")]
 impl std::error::Error for CreationError { }
 
-/// Errors that may occur when converting a [`RawInvoice`] to an [`Invoice`]. They relate to the
-/// requirements sections in BOLT #11
+/// Errors that may occur when converting a [`RawBolt11Invoice`] to a [`Bolt11Invoice`]. They relate to
+/// the requirements sections in BOLT #11
 #[derive(Eq, PartialEq, Debug, Clone)]
-pub enum SemanticError {
+pub enum Bolt11SemanticError {
        /// The invoice is missing the mandatory payment hash
        NoPaymentHash,
 
@@ -1687,25 +1687,25 @@ pub enum SemanticError {
        ImpreciseAmount,
 }
 
-impl Display for SemanticError {
+impl Display for Bolt11SemanticError {
        fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
                match self {
-                       SemanticError::NoPaymentHash => f.write_str("The invoice is missing the mandatory payment hash"),
-                       SemanticError::MultiplePaymentHashes => f.write_str("The invoice has multiple payment hashes which isn't allowed"),
-                       SemanticError::NoDescription => f.write_str("No description or description hash are part of the invoice"),
-                       SemanticError::MultipleDescriptions => f.write_str("The invoice contains multiple descriptions and/or description hashes which isn't allowed"),
-                       SemanticError::NoPaymentSecret => f.write_str("The invoice is missing the mandatory payment secret"),
-                       SemanticError::MultiplePaymentSecrets => f.write_str("The invoice contains multiple payment secrets"),
-                       SemanticError::InvalidFeatures => f.write_str("The invoice's features are invalid"),
-                       SemanticError::InvalidRecoveryId => f.write_str("The recovery id doesn't fit the signature/pub key"),
-                       SemanticError::InvalidSignature => f.write_str("The invoice's signature is invalid"),
-                       SemanticError::ImpreciseAmount => f.write_str("The invoice's amount was not a whole number of millisatoshis"),
+                       Bolt11SemanticError::NoPaymentHash => f.write_str("The invoice is missing the mandatory payment hash"),
+                       Bolt11SemanticError::MultiplePaymentHashes => f.write_str("The invoice has multiple payment hashes which isn't allowed"),
+                       Bolt11SemanticError::NoDescription => f.write_str("No description or description hash are part of the invoice"),
+                       Bolt11SemanticError::MultipleDescriptions => f.write_str("The invoice contains multiple descriptions and/or description hashes which isn't allowed"),
+                       Bolt11SemanticError::NoPaymentSecret => f.write_str("The invoice is missing the mandatory payment secret"),
+                       Bolt11SemanticError::MultiplePaymentSecrets => f.write_str("The invoice contains multiple payment secrets"),
+                       Bolt11SemanticError::InvalidFeatures => f.write_str("The invoice's features are invalid"),
+                       Bolt11SemanticError::InvalidRecoveryId => f.write_str("The recovery id doesn't fit the signature/pub key"),
+                       Bolt11SemanticError::InvalidSignature => f.write_str("The invoice's signature is invalid"),
+                       Bolt11SemanticError::ImpreciseAmount => f.write_str("The invoice's amount was not a whole number of millisatoshis"),
                }
        }
 }
 
 #[cfg(feature = "std")]
-impl std::error::Error for SemanticError { }
+impl std::error::Error for Bolt11SemanticError { }
 
 /// When signing using a fallible method either an user-supplied `SignError` or a [`CreationError`]
 /// may occur.
@@ -1728,16 +1728,16 @@ impl<S> Display for SignOrCreationError<S> {
 }
 
 #[cfg(feature = "serde")]
-impl Serialize for Invoice {
+impl Serialize for Bolt11Invoice {
        fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
                serializer.serialize_str(self.to_string().as_str())
        }
 }
 #[cfg(feature = "serde")]
-impl<'de> Deserialize<'de> for Invoice {
-       fn deserialize<D>(deserializer: D) -> Result<Invoice, D::Error> where D: Deserializer<'de> {
+impl<'de> Deserialize<'de> for Bolt11Invoice {
+       fn deserialize<D>(deserializer: D) -> Result<Bolt11Invoice, D::Error> where D: Deserializer<'de> {
                let bolt11 = String::deserialize(deserializer)?
-                       .parse::<Invoice>()
+                       .parse::<Bolt11Invoice>()
                        .map_err(|e| D::Error::custom(format_args!("{:?}", e)))?;
 
                Ok(bolt11)
@@ -1760,10 +1760,10 @@ mod test {
 
        #[test]
        fn test_calc_invoice_hash() {
-               use crate::{RawInvoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
+               use crate::{RawBolt11Invoice, RawHrp, RawDataPart, Currency, PositiveTimestamp};
                use crate::TaggedField::*;
 
-               let invoice = RawInvoice {
+               let invoice = RawBolt11Invoice {
                        hrp: RawHrp {
                                currency: Currency::Bitcoin,
                                raw_amount: None,
@@ -1797,11 +1797,11 @@ mod test {
                use secp256k1::Secp256k1;
                use secp256k1::ecdsa::{RecoveryId, RecoverableSignature};
                use secp256k1::{SecretKey, PublicKey};
-               use crate::{SignedRawInvoice, InvoiceSignature, RawInvoice, RawHrp, RawDataPart, Currency, Sha256,
+               use crate::{SignedRawBolt11Invoice, Bolt11InvoiceSignature, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256,
                         PositiveTimestamp};
 
-               let invoice = SignedRawInvoice {
-                       raw_invoice: RawInvoice {
+               let invoice = SignedRawBolt11Invoice {
+                       raw_invoice: RawBolt11Invoice {
                                hrp: RawHrp {
                                        currency: Currency::Bitcoin,
                                        raw_amount: None,
@@ -1826,7 +1826,7 @@ mod test {
                                0x7b, 0x1d, 0x85, 0x8d, 0xb1, 0xd1, 0xf7, 0xab, 0x71, 0x37, 0xdc, 0xb7,
                                0x83, 0x5d, 0xb2, 0xec, 0xd5, 0x18, 0xe1, 0xc9
                        ],
-                       signature: InvoiceSignature(RecoverableSignature::from_compact(
+                       signature: Bolt11InvoiceSignature(RecoverableSignature::from_compact(
                                & [
                                        0x38u8, 0xec, 0x68, 0x91, 0x34, 0x5e, 0x20, 0x41, 0x45, 0xbe, 0x8a,
                                        0x3a, 0x99, 0xde, 0x38, 0xe9, 0x8a, 0x39, 0xd6, 0xa5, 0x69, 0x43,
@@ -1863,15 +1863,15 @@ mod test {
        #[test]
        fn test_check_feature_bits() {
                use crate::TaggedField::*;
-               use lightning::ln::features::InvoiceFeatures;
+               use lightning::ln::features::Bolt11InvoiceFeatures;
                use secp256k1::Secp256k1;
                use secp256k1::SecretKey;
-               use crate::{RawInvoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, Invoice,
-                        SemanticError};
+               use crate::{Bolt11Invoice, RawBolt11Invoice, RawHrp, RawDataPart, Currency, Sha256, PositiveTimestamp, 
+                        Bolt11SemanticError};
 
                let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
                let payment_secret = lightning::ln::PaymentSecret([21; 32]);
-               let invoice_template = RawInvoice {
+               let invoice_template = RawBolt11Invoice {
                        hrp: RawHrp {
                                currency: Currency::Bitcoin,
                                raw_amount: None,
@@ -1898,18 +1898,18 @@ mod test {
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::InvalidFeatures));
 
                // Missing feature bits
                let invoice = {
                        let mut invoice = invoice_template.clone();
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
-                       invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
+                       invoice.data.tagged_fields.push(Features(Bolt11InvoiceFeatures::empty()).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::InvalidFeatures));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::InvalidFeatures));
 
-               let mut payment_secret_features = InvoiceFeatures::empty();
+               let mut payment_secret_features = Bolt11InvoiceFeatures::empty();
                payment_secret_features.set_payment_secret_required();
 
                // Including payment secret and feature bits
@@ -1919,22 +1919,22 @@ mod test {
                        invoice.data.tagged_fields.push(Features(payment_secret_features.clone()).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert!(Invoice::from_signed(invoice).is_ok());
+               assert!(Bolt11Invoice::from_signed(invoice).is_ok());
 
                // No payment secret or features
                let invoice = {
                        let invoice = invoice_template.clone();
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::NoPaymentSecret));
 
                // No payment secret or feature bits
                let invoice = {
                        let mut invoice = invoice_template.clone();
-                       invoice.data.tagged_fields.push(Features(InvoiceFeatures::empty()).into());
+                       invoice.data.tagged_fields.push(Features(Bolt11InvoiceFeatures::empty()).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::NoPaymentSecret));
 
                // Missing payment secret
                let invoice = {
@@ -1942,7 +1942,7 @@ mod test {
                        invoice.data.tagged_fields.push(Features(payment_secret_features).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::NoPaymentSecret));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::NoPaymentSecret));
 
                // Multiple payment secrets
                let invoice = {
@@ -1951,7 +1951,7 @@ mod test {
                        invoice.data.tagged_fields.push(PaymentSecret(payment_secret).into());
                        invoice.sign::<_, ()>(|hash| Ok(Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)))
                }.unwrap();
-               assert_eq!(Invoice::from_signed(invoice), Err(SemanticError::MultiplePaymentSecrets));
+               assert_eq!(Bolt11Invoice::from_signed(invoice), Err(Bolt11SemanticError::MultiplePaymentSecrets));
        }
 
        #[test]
@@ -2142,12 +2142,12 @@ mod test {
                assert_eq!(invoice.private_routes(), vec![&PrivateRoute(route_1), &PrivateRoute(route_2)]);
                assert_eq!(
                        invoice.description(),
-                       InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap()))
+                       Bolt11InvoiceDescription::Hash(&Sha256(sha256::Hash::from_slice(&[3;32][..]).unwrap()))
                );
                assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&[21;32][..]).unwrap());
                assert_eq!(invoice.payment_secret(), &PaymentSecret([42; 32]));
 
-               let mut expected_features = InvoiceFeatures::empty();
+               let mut expected_features = Bolt11InvoiceFeatures::empty();
                expected_features.set_variable_length_onion_required();
                expected_features.set_payment_secret_required();
                expected_features.set_basic_mpp_optional();
@@ -2176,7 +2176,7 @@ mod test {
                                Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
                        })
                        .unwrap();
-               let invoice = Invoice::from_signed(signed_invoice).unwrap();
+               let invoice = Bolt11Invoice::from_signed(signed_invoice).unwrap();
 
                assert_eq!(invoice.min_final_cltv_expiry_delta(), DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA);
                assert_eq!(invoice.expiry_time(), Duration::from_secs(DEFAULT_EXPIRY_TIME));
@@ -2202,7 +2202,7 @@ mod test {
                                Ok(secp_ctx.sign_ecdsa_recoverable(hash, &privkey))
                        })
                        .unwrap();
-               let invoice = Invoice::from_signed(signed_invoice).unwrap();
+               let invoice = Bolt11Invoice::from_signed(signed_invoice).unwrap();
 
                assert!(invoice.would_expire(Duration::from_secs(1234567 + DEFAULT_EXPIRY_TIME + 1)));
        }
@@ -2221,9 +2221,9 @@ mod test {
                        p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\
                        8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\
                        j5r6drg6k6zcqj0fcwg";
-               let invoice = invoice_str.parse::<super::Invoice>().unwrap();
+               let invoice = invoice_str.parse::<super::Bolt11Invoice>().unwrap();
                let serialized_invoice = serde_json::to_string(&invoice).unwrap();
-               let deserialized_invoice: super::Invoice = serde_json::from_str(serialized_invoice.as_str()).unwrap();
+               let deserialized_invoice: super::Bolt11Invoice = serde_json::from_str(serialized_invoice.as_str()).unwrap();
                assert_eq!(invoice, deserialized_invoice);
                assert_eq!(invoice_str, deserialized_invoice.to_string().as_str());
                assert_eq!(invoice_str, serialized_invoice.as_str().trim_matches('\"'));
index bf161dbbf0ebc34e78bf5309761621f4ad1662ee..42408540ee41e7a9e1f9d8ba6c711c6def7b565d 100644 (file)
@@ -9,7 +9,7 @@
 
 //! Convenient utilities for paying Lightning invoices and sending spontaneous payments.
 
-use crate::Invoice;
+use crate::Bolt11Invoice;
 
 use bitcoin_hashes::Hash;
 
@@ -25,15 +25,15 @@ use core::fmt::Debug;
 use core::ops::Deref;
 use core::time::Duration;
 
-/// Pays the given [`Invoice`], retrying if needed based on [`Retry`].
+/// Pays the given [`Bolt11Invoice`], retrying if needed based on [`Retry`].
 ///
-/// [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
+/// [`Bolt11Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
 /// as the payment is still pending. If the payment succeeds, you must ensure that a second payment
 /// with the same [`PaymentHash`] is never sent.
 ///
 /// If you wish to use a different payment idempotency token, see [`pay_invoice_with_id`].
 pub fn pay_invoice<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
-       invoice: &Invoice, retry_strategy: Retry,
+       invoice: &Bolt11Invoice, retry_strategy: Retry,
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>
 ) -> Result<PaymentId, PaymentError>
 where
@@ -51,17 +51,18 @@ where
                .map(|()| payment_id)
 }
 
-/// Pays the given [`Invoice`] with a custom idempotency key, retrying if needed based on [`Retry`].
+/// Pays the given [`Bolt11Invoice`] with a custom idempotency key, retrying if needed based on
+/// [`Retry`].
 ///
 /// Note that idempotency is only guaranteed as long as the payment is still pending. Once the
 /// payment completes or fails, no idempotency guarantees are made.
 ///
-/// You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
-/// has never been paid before.
+/// You should ensure that the [`Bolt11Invoice::payment_hash`] is unique and the same
+/// [`PaymentHash`] has never been paid before.
 ///
 /// See [`pay_invoice`] for a variant which uses the [`PaymentHash`] for the idempotency token.
 pub fn pay_invoice_with_id<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
-       invoice: &Invoice, payment_id: PaymentId, retry_strategy: Retry,
+       invoice: &Bolt11Invoice, payment_id: PaymentId, retry_strategy: Retry,
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>
 ) -> Result<(), PaymentError>
 where
@@ -78,17 +79,17 @@ where
        pay_invoice_using_amount(invoice, amt_msat, payment_id, retry_strategy, channelmanager)
 }
 
-/// Pays the given zero-value [`Invoice`] using the given amount, retrying if needed based on
+/// Pays the given zero-value [`Bolt11Invoice`] using the given amount, retrying if needed based on
 /// [`Retry`].
 ///
-/// [`Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
+/// [`Bolt11Invoice::payment_hash`] is used as the [`PaymentId`], which ensures idempotency as long
 /// as the payment is still pending. If the payment succeeds, you must ensure that a second payment
 /// with the same [`PaymentHash`] is never sent.
 ///
 /// If you wish to use a different payment idempotency token, see
 /// [`pay_zero_value_invoice_with_id`].
 pub fn pay_zero_value_invoice<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
-       invoice: &Invoice, amount_msats: u64, retry_strategy: Retry,
+       invoice: &Bolt11Invoice, amount_msats: u64, retry_strategy: Retry,
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>
 ) -> Result<PaymentId, PaymentError>
 where
@@ -107,19 +108,19 @@ where
                .map(|()| payment_id)
 }
 
-/// Pays the given zero-value [`Invoice`] using the given amount and custom idempotency key,
+/// Pays the given zero-value [`Bolt11Invoice`] using the given amount and custom idempotency key,
 /// retrying if needed based on [`Retry`].
 ///
 /// Note that idempotency is only guaranteed as long as the payment is still pending. Once the
 /// payment completes or fails, no idempotency guarantees are made.
 ///
-/// You should ensure that the [`Invoice::payment_hash`] is unique and the same [`PaymentHash`]
-/// has never been paid before.
+/// You should ensure that the [`Bolt11Invoice::payment_hash`] is unique and the same
+/// [`PaymentHash`] has never been paid before.
 ///
 /// See [`pay_zero_value_invoice`] for a variant which uses the [`PaymentHash`] for the
 /// idempotency token.
 pub fn pay_zero_value_invoice_with_id<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
-       invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
+       invoice: &Bolt11Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>
 ) -> Result<(), PaymentError>
 where
@@ -141,7 +142,7 @@ where
 }
 
 fn pay_invoice_using_amount<P: Deref>(
-       invoice: &Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
+       invoice: &Bolt11Invoice, amount_msats: u64, payment_id: PaymentId, retry_strategy: Retry,
        payer: P
 ) -> Result<(), PaymentError> where P::Target: Payer {
        let payment_hash = PaymentHash((*invoice.payment_hash()).into_inner());
@@ -164,20 +165,20 @@ fn pay_invoice_using_amount<P: Deref>(
        payer.send_payment(payment_hash, recipient_onion, payment_id, route_params, retry_strategy)
 }
 
-fn expiry_time_from_unix_epoch(invoice: &Invoice) -> Duration {
+fn expiry_time_from_unix_epoch(invoice: &Bolt11Invoice) -> Duration {
        invoice.signed_invoice.raw_invoice.data.timestamp.0 + invoice.expiry_time()
 }
 
 /// An error that may occur when making a payment.
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub enum PaymentError {
-       /// An error resulting from the provided [`Invoice`] or payment hash.
+       /// An error resulting from the provided [`Bolt11Invoice`] or payment hash.
        Invoice(&'static str),
        /// An error occurring when sending a payment.
        Sending(RetryableSendFailure),
 }
 
-/// A trait defining behavior of an [`Invoice`] payer.
+/// A trait defining behavior of a [`Bolt11Invoice`] payer.
 ///
 /// Useful for unit testing internal methods.
 trait Payer {
@@ -283,7 +284,7 @@ mod tests {
                duration_since_epoch
        }
 
-       fn invoice(payment_preimage: PaymentPreimage) -> Invoice {
+       fn invoice(payment_preimage: PaymentPreimage) -> Bolt11Invoice {
                let payment_hash = Sha256::hash(&payment_preimage.0);
                let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
 
@@ -300,7 +301,7 @@ mod tests {
                        .unwrap()
        }
 
-       fn zero_value_invoice(payment_preimage: PaymentPreimage) -> Invoice {
+       fn zero_value_invoice(payment_preimage: PaymentPreimage) -> Bolt11Invoice {
                let payment_hash = Sha256::hash(&payment_preimage.0);
                let private_key = SecretKey::from_slice(&[42; 32]).unwrap();
 
index 0dca180cab370a79e9358b89d7f1e1d2e51a8c95..dc5dba45da0fe46c24bbf6f8b664dbef76f175b5 100644 (file)
@@ -3,8 +3,8 @@ use core::fmt::{Display, Formatter};
 use bech32::{ToBase32, u5, WriteBase32, Base32Len};
 use crate::prelude::*;
 
-use super::{Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, InvoiceSignature, PositiveTimestamp,
-       PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawInvoice, RawDataPart};
+use super::{Bolt11Invoice, Sha256, TaggedField, ExpiryTime, MinFinalCltvExpiryDelta, Fallback, PayeePubKey, Bolt11InvoiceSignature, PositiveTimestamp,
+       PrivateRoute, Description, RawTaggedField, Currency, RawHrp, SiPrefix, constants, SignedRawBolt11Invoice, RawDataPart};
 
 /// Converts a stream of bytes written to it to base32. On finalization the according padding will
 /// be applied. That means the results of writing two data blocks with one or two `BytesToBase32`
@@ -106,13 +106,13 @@ fn bytes_size_to_base32_size(byte_size: usize) -> usize {
        }
 }
 
-impl Display for Invoice {
+impl Display for Bolt11Invoice {
        fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
                self.signed_invoice.fmt(f)
        }
 }
 
-impl Display for SignedRawInvoice {
+impl Display for SignedRawBolt11Invoice {
        fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
                let hrp = self.raw_invoice.hrp.to_string();
                let mut data  = self.raw_invoice.data.to_base32();
@@ -456,7 +456,7 @@ impl ToBase32 for TaggedField {
        }
 }
 
-impl ToBase32 for InvoiceSignature {
+impl ToBase32 for Bolt11InvoiceSignature {
        fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
                let mut converter = BytesToBase32::new(writer);
                let (recovery_id, signature) = self.0.serialize_compact();
index 199aad064694c975d6e97cc132e3b460a84c1b71..25a7cf77d5e981bfc68b662a9cce862432fbcaa8 100644 (file)
@@ -1,8 +1,8 @@
 //! Convenient utilities to create an invoice.
 
-use crate::{CreationError, Currency, Invoice, InvoiceBuilder, SignOrCreationError};
+use crate::{Bolt11Invoice, CreationError, Currency, InvoiceBuilder, SignOrCreationError};
 
-use crate::{prelude::*, Description, InvoiceDescription, Sha256};
+use crate::{prelude::*, Description, Bolt11InvoiceDescription, Sha256};
 use bech32::ToBase32;
 use bitcoin_hashes::Hash;
 use lightning::chain;
@@ -64,14 +64,14 @@ pub fn create_phantom_invoice<ES: Deref, NS: Deref, L: Deref>(
        amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: String,
        invoice_expiry_delta_secs: u32, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
        node_signer: NS, logger: L, network: Currency, min_final_cltv_expiry_delta: Option<u16>, duration_since_epoch: Duration,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
 where
        ES::Target: EntropySource,
        NS::Target: NodeSigner,
        L::Target: Logger,
 {
        let description = Description::new(description).map_err(SignOrCreationError::CreationError)?;
-       let description = InvoiceDescription::Direct(&description,);
+       let description = Bolt11InvoiceDescription::Direct(&description,);
        _create_phantom_invoice::<ES, NS, L>(
                amt_msat, payment_hash, description, invoice_expiry_delta_secs, phantom_route_hints,
                entropy_source, node_signer, logger, network, min_final_cltv_expiry_delta, duration_since_epoch,
@@ -120,14 +120,14 @@ pub fn create_phantom_invoice_with_description_hash<ES: Deref, NS: Deref, L: Der
        amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, invoice_expiry_delta_secs: u32,
        description_hash: Sha256, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
        node_signer: NS, logger: L, network: Currency, min_final_cltv_expiry_delta: Option<u16>, duration_since_epoch: Duration,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
 where
        ES::Target: EntropySource,
        NS::Target: NodeSigner,
        L::Target: Logger,
 {
        _create_phantom_invoice::<ES, NS, L>(
-               amt_msat, payment_hash, InvoiceDescription::Hash(&description_hash),
+               amt_msat, payment_hash, Bolt11InvoiceDescription::Hash(&description_hash),
                invoice_expiry_delta_secs, phantom_route_hints, entropy_source, node_signer, logger, network,
                min_final_cltv_expiry_delta, duration_since_epoch,
        )
@@ -136,10 +136,10 @@ where
 const MAX_CHANNEL_HINTS: usize = 3;
 
 fn _create_phantom_invoice<ES: Deref, NS: Deref, L: Deref>(
-       amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: InvoiceDescription,
+       amt_msat: Option<u64>, payment_hash: Option<PaymentHash>, description: Bolt11InvoiceDescription,
        invoice_expiry_delta_secs: u32, phantom_route_hints: Vec<PhantomRouteHints>, entropy_source: ES,
        node_signer: NS, logger: L, network: Currency, min_final_cltv_expiry_delta: Option<u16>, duration_since_epoch: Duration,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
 where
        ES::Target: EntropySource,
        NS::Target: NodeSigner,
@@ -157,10 +157,10 @@ where
        }
 
        let invoice = match description {
-               InvoiceDescription::Direct(description) => {
+               Bolt11InvoiceDescription::Direct(description) => {
                        InvoiceBuilder::new(network).description(description.0.clone())
                }
-               InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
+               Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
        };
 
        // If we ever see performance here being too slow then we should probably take this ExpandedKey as a parameter instead.
@@ -219,7 +219,7 @@ where
        let data_without_signature = raw_invoice.data.to_base32();
        let signed_raw_invoice = raw_invoice.sign(|_| node_signer.sign_invoice(hrp_bytes, &data_without_signature, Recipient::PhantomNode));
        match signed_raw_invoice {
-               Ok(inv) => Ok(Invoice::from_signed(inv).unwrap()),
+               Ok(inv) => Ok(Bolt11Invoice::from_signed(inv).unwrap()),
                Err(e) => Err(SignOrCreationError::SignError(e))
        }
 }
@@ -333,7 +333,7 @@ pub fn create_invoice_from_channelmanager<M: Deref, T: Deref, ES: Deref, NS: Der
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
        network: Currency, amt_msat: Option<u64>, description: String, invoice_expiry_delta_secs: u32,
        min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
 where
        M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
        T::Target: BroadcasterInterface,
@@ -374,7 +374,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash<M: Deref, T: Der
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
        network: Currency, amt_msat: Option<u64>, description_hash: Sha256,
        invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
 where
        M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
        T::Target: BroadcasterInterface,
@@ -404,7 +404,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
        network: Currency, amt_msat: Option<u64>, description_hash: Sha256,
        duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
                where
                        M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
                        T::Target: BroadcasterInterface,
@@ -417,7 +417,7 @@ pub fn create_invoice_from_channelmanager_with_description_hash_and_duration_sin
 {
        _create_invoice_from_channelmanager_and_duration_since_epoch(
                channelmanager, node_signer, logger, network, amt_msat,
-               InvoiceDescription::Hash(&description_hash),
+               Bolt11InvoiceDescription::Hash(&description_hash),
                duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
        )
 }
@@ -429,7 +429,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
        network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,
        invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
                where
                        M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
                        T::Target: BroadcasterInterface,
@@ -442,7 +442,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
 {
        _create_invoice_from_channelmanager_and_duration_since_epoch(
                channelmanager, node_signer, logger, network, amt_msat,
-               InvoiceDescription::Direct(
+               Bolt11InvoiceDescription::Direct(
                        &Description::new(description).map_err(SignOrCreationError::CreationError)?,
                ),
                duration_since_epoch, invoice_expiry_delta_secs, min_final_cltv_expiry_delta,
@@ -451,9 +451,9 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T:
 
 fn _create_invoice_from_channelmanager_and_duration_since_epoch<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
-       network: Currency, amt_msat: Option<u64>, description: InvoiceDescription,
+       network: Currency, amt_msat: Option<u64>, description: Bolt11InvoiceDescription,
        duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
                where
                        M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
                        T::Target: BroadcasterInterface,
@@ -486,7 +486,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
        network: Currency, amt_msat: Option<u64>, description: String, duration_since_epoch: Duration,
        invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
        where
                M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
                T::Target: BroadcasterInterface,
@@ -503,7 +503,7 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
                .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
        _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash(
                channelmanager, node_signer, logger, network, amt_msat,
-               InvoiceDescription::Direct(
+               Bolt11InvoiceDescription::Direct(
                        &Description::new(description).map_err(SignOrCreationError::CreationError)?,
                ),
                duration_since_epoch, invoice_expiry_delta_secs, payment_hash, payment_secret,
@@ -513,10 +513,10 @@ pub fn create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_
 
 fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_hash<M: Deref, T: Deref, ES: Deref, NS: Deref, SP: Deref, F: Deref, R: Deref, L: Deref>(
        channelmanager: &ChannelManager<M, T, ES, NS, SP, F, R, L>, node_signer: NS, logger: L,
-       network: Currency, amt_msat: Option<u64>, description: InvoiceDescription, duration_since_epoch: Duration,
-       invoice_expiry_delta_secs: u32, payment_hash: PaymentHash, payment_secret: PaymentSecret,
-       min_final_cltv_expiry_delta: Option<u16>,
-) -> Result<Invoice, SignOrCreationError<()>>
+       network: Currency, amt_msat: Option<u64>, description: Bolt11InvoiceDescription,
+       duration_since_epoch: Duration, invoice_expiry_delta_secs: u32, payment_hash: PaymentHash,
+       payment_secret: PaymentSecret, min_final_cltv_expiry_delta: Option<u16>,
+) -> Result<Bolt11Invoice, SignOrCreationError<()>>
        where
                M::Target: chain::Watch<<SP::Target as SignerProvider>::Signer>,
                T::Target: BroadcasterInterface,
@@ -537,10 +537,10 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
        log_trace!(logger, "Creating invoice with payment hash {}", log_bytes!(payment_hash.0));
 
        let invoice = match description {
-               InvoiceDescription::Direct(description) => {
+               Bolt11InvoiceDescription::Direct(description) => {
                        InvoiceBuilder::new(network).description(description.0.clone())
                }
-               InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
+               Bolt11InvoiceDescription::Hash(hash) => InvoiceBuilder::new(network).description_hash(hash.0),
        };
 
        let mut invoice = invoice
@@ -571,7 +571,7 @@ fn _create_invoice_from_channelmanager_and_duration_since_epoch_with_payment_has
        let data_without_signature = raw_invoice.data.to_base32();
        let signed_raw_invoice = raw_invoice.sign(|_| node_signer.sign_invoice(hrp_bytes, &data_without_signature, Recipient::Node));
        match signed_raw_invoice {
-               Ok(inv) => Ok(Invoice::from_signed(inv).unwrap()),
+               Ok(inv) => Ok(Bolt11Invoice::from_signed(inv).unwrap()),
                Err(e) => Err(SignOrCreationError::SignError(e))
        }
 }
@@ -794,7 +794,7 @@ fn prefer_current_channel(min_inbound_capacity_msat: Option<u64>, current_channe
 mod test {
        use core::cell::RefCell;
        use core::time::Duration;
-       use crate::{Currency, Description, InvoiceDescription, SignOrCreationError, CreationError};
+       use crate::{Currency, Description, Bolt11InvoiceDescription, SignOrCreationError, CreationError};
        use bitcoin_hashes::{Hash, sha256};
        use bitcoin_hashes::sha256::Hash as Sha256;
        use lightning::sign::PhantomKeysManager;
@@ -852,7 +852,7 @@ mod test {
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
                // If no `min_final_cltv_expiry_delta` is specified, then it should be `MIN_FINAL_CLTV_EXPIRY_DELTA`.
                assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
-               assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
+               assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
                assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
 
                // Invoice SCIDs should always use inbound SCID aliases over the real channel ID, if one is
@@ -948,7 +948,7 @@ mod test {
                ).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
-               assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
+               assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Testing description_hash".as_bytes()))));
        }
 
        #[test]
@@ -965,7 +965,7 @@ mod test {
                ).unwrap();
                assert_eq!(invoice.amount_pico_btc(), Some(100_000));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
-               assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
+               assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
                assert_eq!(invoice.payment_hash(), &sha256::Hash::from_slice(&payment_hash.0[..]).unwrap());
        }
 
@@ -1317,7 +1317,7 @@ mod test {
                };
 
                assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
-               assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
+               assert_eq!(invoice.description(), Bolt11InvoiceDescription::Direct(&Description("test".to_string())));
                assert_eq!(invoice.route_hints().len(), 2);
                assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
                assert!(!invoice.features().unwrap().supports_basic_mpp());
@@ -1455,7 +1455,7 @@ mod test {
                assert_eq!(invoice.amount_pico_btc(), Some(200_000));
                assert_eq!(invoice.min_final_cltv_expiry_delta(), MIN_FINAL_CLTV_EXPIRY_DELTA as u64);
                assert_eq!(invoice.expiry_time(), Duration::from_secs(non_default_invoice_expiry_secs.into()));
-               assert_eq!(invoice.description(), InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
+               assert_eq!(invoice.description(), Bolt11InvoiceDescription::Hash(&crate::Sha256(Sha256::hash("Description hash phantom invoice".as_bytes()))));
        }
 
        #[test]
index ef5a4d32b30a0caa7c397217fb808a64ca2be877..e21b82eae3c7e0053b9efc5f02383716574f026f 100644 (file)
@@ -19,7 +19,7 @@ use std::collections::HashSet;
 use std::time::Duration;
 use std::str::FromStr;
 
-fn get_test_tuples() -> Vec<(String, SignedRawInvoice, bool, bool)> {
+fn get_test_tuples() -> Vec<(String, SignedRawBolt11Invoice, bool, bool)> {
        vec![
                (
                        "lnbc1pvjluezsp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq9qrsgq357wnc5r2ueh7ck6q93dj32dlqnls087fxdwk8qakdyafkq3yap9us6v52vjjsrvywa6rt52cm9r9zqt8r2t7mlcwspyetp5h2tztugp9lfyql".to_owned(),
@@ -389,7 +389,7 @@ fn get_test_tuples() -> Vec<(String, SignedRawInvoice, bool, bool)> {
 fn invoice_deserialize() {
        for (serialized, deserialized, ignore_feature_diff, ignore_unknown_fields) in get_test_tuples() {
                eprintln!("Testing invoice {}...", serialized);
-               let parsed = serialized.parse::<SignedRawInvoice>().unwrap();
+               let parsed = serialized.parse::<SignedRawBolt11Invoice>().unwrap();
 
                let (parsed_invoice, _, parsed_sig) = parsed.into_parts();
                let (deserialized_invoice, _, deserialized_sig) = deserialized.into_parts();
@@ -412,35 +412,35 @@ fn invoice_deserialize() {
                }
                assert_eq!(deserialized_hunks, parsed_hunks);
 
-               Invoice::from_signed(serialized.parse::<SignedRawInvoice>().unwrap()).unwrap();
+               Bolt11Invoice::from_signed(serialized.parse::<SignedRawBolt11Invoice>().unwrap()).unwrap();
        }
 }
 
 #[test]
 fn test_bolt_invalid_invoices() {
        // Tests the BOLT 11 invalid invoice test vectors
-       assert_eq!(Invoice::from_str(
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc25m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5vdhkven9v5sxyetpdeessp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q4psqqqqqqqqqqqqqqqqsgqtqyx5vggfcsll4wu246hz02kp85x4katwsk9639we5n5yngc3yhqkm35jnjw4len8vrnqnf5ejh0mzj9n3vz2px97evektfm2l6wqccp3y7372"
-               ), Err(ParseOrSemanticError::SemanticError(SemanticError::InvalidFeatures)));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::SemanticError(Bolt11SemanticError::InvalidFeatures)));
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrnt"
-               ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::InvalidChecksum))));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::ParseError(Bolt11ParseError::Bech32Error(bech32::Error::InvalidChecksum))));
+       assert_eq!(Bolt11Invoice::from_str(
                "pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny"
-               ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MissingSeparator))));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::ParseError(Bolt11ParseError::Bech32Error(bech32::Error::MissingSeparator))));
+       assert_eq!(Bolt11Invoice::from_str(
                "LNBC2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpquwpc4curk03c9wlrswe78q4eyqc7d8d0xqzpuyk0sg5g70me25alkluzd2x62aysf2pyy8edtjeevuv4p2d5p76r4zkmneet7uvyakky2zr4cusd45tftc9c5fh0nnqpnl2jfll544esqchsrny"
-               ), Err(ParseOrSemanticError::ParseError(ParseError::Bech32Error(bech32::Error::MixedCase))));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::ParseError(Bolt11ParseError::Bech32Error(bech32::Error::MixedCase))));
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpusp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9qrsgqwgt7mcn5yqw3yx0w94pswkpq6j9uh6xfqqqtsk4tnarugeektd4hg5975x9am52rz4qskukxdmjemg92vvqz8nvmsye63r5ykel43pgz7zq0g2"
-               ), Err(ParseOrSemanticError::SemanticError(SemanticError::InvalidSignature)));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::SemanticError(Bolt11SemanticError::InvalidSignature)));
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6na6hlh"
-               ), Err(ParseOrSemanticError::ParseError(ParseError::TooShortDataPart)));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::ParseError(Bolt11ParseError::TooShortDataPart)));
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc2500x1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpusp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9qrsgqrrzc4cvfue4zp3hggxp47ag7xnrlr8vgcmkjxk3j5jqethnumgkpqp23z9jclu3v0a7e0aruz366e9wqdykw6dxhdzcjjhldxq0w6wgqcnu43j"
-               ), Err(ParseOrSemanticError::ParseError(ParseError::UnknownSiPrefix)));
-       assert_eq!(Invoice::from_str(
+               ), Err(ParseOrSemanticError::ParseError(Bolt11ParseError::UnknownSiPrefix)));
+       assert_eq!(Bolt11Invoice::from_str(
                "lnbc2500000001p1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpusp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9qrsgq0lzc236j96a95uv0m3umg28gclm5lqxtqqwk32uuk4k6673k6n5kfvx3d2h8s295fad45fdhmusm8sjudfhlf6dcsxmfvkeywmjdkxcp99202x"
-               ), Err(ParseOrSemanticError::SemanticError(SemanticError::ImpreciseAmount)));
+               ), Err(ParseOrSemanticError::SemanticError(Bolt11SemanticError::ImpreciseAmount)));
 }
index 4204d714f1b12be5a7a1a04fed5092746562c827..6073ed61aaf0cc88beea1c899b687fbb407fbc93 100644 (file)
 //! disconnections, transaction broadcasting, and feerate information requests.
 
 use core::{cmp, ops::Deref};
+use core::convert::TryInto;
 
 use bitcoin::blockdata::transaction::Transaction;
 
+// TODO: Define typed abstraction over feerates to handle their conversions.
+pub(crate) fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
+       (fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
+}
+pub(crate) const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
+       ((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
+}
+
 /// An interface to send a transaction to the Bitcoin network.
 pub trait BroadcasterInterface {
        /// Sends a list of transactions out to (hopefully) be mined.
index 6b0c7485610353917ef348f2ec54d1828070eea1..171caf7006e873615e11fd1f8ea0b999d5f24411 100644 (file)
@@ -22,6 +22,7 @@ use bitcoin::hash_types::{Txid, BlockHash};
 use bitcoin::secp256k1::{Secp256k1, ecdsa::Signature};
 use bitcoin::secp256k1;
 
+use crate::chain::chaininterface::compute_feerate_sat_per_1000_weight;
 use crate::sign::{ChannelSigner, EntropySource, SignerProvider};
 use crate::ln::msgs::DecodeError;
 use crate::ln::PaymentPreimage;
@@ -623,9 +624,24 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                        return inputs.find_map(|input| match input {
                                // Commitment inputs with anchors support are the only untractable inputs supported
                                // thus far that require external funding.
-                               PackageSolvingData::HolderFundingOutput(..) => {
+                               PackageSolvingData::HolderFundingOutput(output) => {
                                        debug_assert_eq!(tx.txid(), self.holder_commitment.trust().txid(),
                                                "Holder commitment transaction mismatch");
+
+                                       let conf_target = ConfirmationTarget::HighPriority;
+                                       let package_target_feerate_sat_per_1000_weight = cached_request
+                                               .compute_package_feerate(fee_estimator, conf_target, force_feerate_bump);
+                                       if let Some(input_amount_sat) = output.funding_amount {
+                                               let fee_sat = input_amount_sat - tx.output.iter().map(|output| output.value).sum::<u64>();
+                                               if compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64) >=
+                                                        package_target_feerate_sat_per_1000_weight
+                                               {
+                                                       log_debug!(logger, "Commitment transaction {} already meets required feerate {} sat/kW",
+                                                               tx.txid(), package_target_feerate_sat_per_1000_weight);
+                                                       return Some((new_timer, 0, OnchainClaim::Tx(tx.clone())));
+                                               }
+                                       }
+
                                        // We'll locate an anchor output we can spend within the commitment transaction.
                                        let funding_pubkey = &self.channel_transaction_parameters.holder_pubkeys.funding_pubkey;
                                        match chan_utils::get_anchor_output(&tx, funding_pubkey) {
@@ -633,9 +649,6 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                                                Some((idx, _)) => {
                                                        // TODO: Use a lower confirmation target when both our and the
                                                        // counterparty's latest commitment don't have any HTLCs present.
-                                                       let conf_target = ConfirmationTarget::HighPriority;
-                                                       let package_target_feerate_sat_per_1000_weight = cached_request
-                                                               .compute_package_feerate(fee_estimator, conf_target, force_feerate_bump);
                                                        Some((
                                                                new_timer,
                                                                package_target_feerate_sat_per_1000_weight as u64,
@@ -739,6 +752,9 @@ impl<ChannelSigner: WriteableEcdsaChannelSigner> OnchainTxHandler<ChannelSigner>
                        ) {
                                req.set_timer(new_timer);
                                req.set_feerate(new_feerate);
+                               // Once a pending claim has an id assigned, it remains fixed until the claim is
+                               // satisfied, regardless of whether the claim switches between different variants of
+                               // `OnchainClaim`.
                                let claim_id = match claim {
                                        OnchainClaim::Tx(tx) => {
                                                log_info!(logger, "Broadcasting onchain {}", log_tx!(tx));
index 9e61cbc4598772c1a9fa8cdd31a2f330dbd8c548..b66a2f70d3369f4aff6e012025b3e995d6918a9e 100644 (file)
@@ -429,7 +429,7 @@ impl Readable for HolderHTLCOutput {
 #[derive(Clone, PartialEq, Eq)]
 pub(crate) struct HolderFundingOutput {
        funding_redeemscript: Script,
-       funding_amount: Option<u64>,
+       pub(crate) funding_amount: Option<u64>,
        channel_type_features: ChannelTypeFeatures,
 }
 
index 1f28bcfb9389d82040237fd3b3807166116c234d..bf56a84ca469b3bac5b4bff53eac17134800e251 100644 (file)
 //! [`Event`]: crate::events::Event
 
 use alloc::collections::BTreeMap;
-use core::convert::TryInto;
 use core::ops::Deref;
 
-use crate::chain::chaininterface::BroadcasterInterface;
+use crate::chain::chaininterface::{BroadcasterInterface, compute_feerate_sat_per_1000_weight, fee_for_weight, FEERATE_FLOOR_SATS_PER_KW};
 use crate::chain::ClaimId;
 use crate::io_extras::sink;
 use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
@@ -44,14 +43,6 @@ const BASE_INPUT_SIZE: u64 = 32 /* txid */ + 4 /* vout */ + 4 /* sequence */;
 
 const BASE_INPUT_WEIGHT: u64 = BASE_INPUT_SIZE * WITNESS_SCALE_FACTOR as u64;
 
-// TODO: Define typed abstraction over feerates to handle their conversions.
-fn compute_feerate_sat_per_1000_weight(fee_sat: u64, weight: u64) -> u32 {
-       (fee_sat * 1000 / weight).try_into().unwrap_or(u32::max_value())
-}
-const fn fee_for_weight(feerate_sat_per_1000_weight: u32, weight: u64) -> u64 {
-       ((feerate_sat_per_1000_weight as u64 * weight) + 1000 - 1) / 1000
-}
-
 /// The parameters required to derive a channel signer via [`SignerProvider`].
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct ChannelDerivationParameters {
@@ -149,6 +140,15 @@ pub struct HTLCDescriptor {
 }
 
 impl HTLCDescriptor {
+       /// Returns the outpoint of the HTLC output in the commitment transaction. This is the outpoint
+       /// being spent by the HTLC input in the HTLC transaction.
+       pub fn outpoint(&self) -> OutPoint {
+               OutPoint {
+                       txid: self.commitment_txid,
+                       vout: self.htlc.transaction_output_index.unwrap(),
+               }
+       }
+
        /// Returns the UTXO to be spent by the HTLC input, which can be obtained via
        /// [`Self::unsigned_tx_input`].
        pub fn previous_utxo<C: secp256k1::Signing + secp256k1::Verification>(&self, secp: &Secp256k1<C>) -> TxOut {
@@ -489,19 +489,28 @@ pub trait WalletSource {
 /// A wrapper over [`WalletSource`] that implements [`CoinSelection`] by preferring UTXOs that would
 /// avoid conflicting double spends. If not enough UTXOs are available to do so, conflicting double
 /// spends may happen.
-pub struct Wallet<W: Deref> where W::Target: WalletSource {
+pub struct Wallet<W: Deref, L: Deref>
+where
+       W::Target: WalletSource,
+       L::Target: Logger
+{
        source: W,
+       logger: L,
        // TODO: Do we care about cleaning this up once the UTXOs have a confirmed spend? We can do so
        // by checking whether any UTXOs that exist in the map are no longer returned in
        // `list_confirmed_utxos`.
        locked_utxos: Mutex<HashMap<OutPoint, ClaimId>>,
 }
 
-impl<W: Deref> Wallet<W> where W::Target: WalletSource {
+impl<W: Deref, L: Deref> Wallet<W, L>
+where
+       W::Target: WalletSource,
+       L::Target: Logger
+{
        /// Returns a new instance backed by the given [`WalletSource`] that serves as an implementation
        /// of [`CoinSelectionSource`].
-       pub fn new(source: W) -> Self {
-               Self { source, locked_utxos: Mutex::new(HashMap::new()) }
+       pub fn new(source: W, logger: L) -> Self {
+               Self { source, logger, locked_utxos: Mutex::new(HashMap::new()) }
        }
 
        /// Performs coin selection on the set of UTXOs obtained from
@@ -521,6 +530,7 @@ impl<W: Deref> Wallet<W> where W::Target: WalletSource {
                let mut eligible_utxos = utxos.iter().filter_map(|utxo| {
                        if let Some(utxo_claim_id) = locked_utxos.get(&utxo.outpoint) {
                                if *utxo_claim_id != claim_id && !force_conflicting_utxo_spend {
+                                       log_trace!(self.logger, "Skipping UTXO {} to prevent conflicting spend", utxo.outpoint);
                                        return None;
                                }
                        }
@@ -535,6 +545,7 @@ impl<W: Deref> Wallet<W> where W::Target: WalletSource {
                        if should_spend {
                                Some((utxo, fee_to_spend_utxo))
                        } else {
+                               log_trace!(self.logger, "Skipping UTXO {} due to dust proximity after spend", utxo.outpoint);
                                None
                        }
                }).collect::<Vec<_>>();
@@ -552,6 +563,8 @@ impl<W: Deref> Wallet<W> where W::Target: WalletSource {
                        selected_utxos.push(utxo.clone());
                }
                if selected_amount < target_amount_sat + total_fees {
+                       log_debug!(self.logger, "Insufficient funds to meet target feerate {} sat/kW",
+                               target_feerate_sat_per_1000_weight);
                        return Err(());
                }
                for utxo in &selected_utxos {
@@ -568,6 +581,7 @@ impl<W: Deref> Wallet<W> where W::Target: WalletSource {
                );
                let change_output_amount = remaining_amount.saturating_sub(change_output_fee);
                let change_output = if change_output_amount < change_script.dust_value().to_sat() {
+                       log_debug!(self.logger, "Coin selection attempt did not yield change output");
                        None
                } else {
                        Some(TxOut { script_pubkey: change_script, value: change_output_amount })
@@ -580,7 +594,11 @@ impl<W: Deref> Wallet<W> where W::Target: WalletSource {
        }
 }
 
-impl<W: Deref> CoinSelectionSource for Wallet<W> where W::Target: WalletSource {
+impl<W: Deref, L: Deref> CoinSelectionSource for Wallet<W, L>
+where
+       W::Target: WalletSource,
+       L::Target: Logger
+{
        fn select_confirmed_utxos(
                &self, claim_id: ClaimId, must_spend: &[Input], must_pay_to: &[TxOut],
                target_feerate_sat_per_1000_weight: u32,
@@ -598,6 +616,8 @@ impl<W: Deref> CoinSelectionSource for Wallet<W> where W::Target: WalletSource {
                        ((BASE_TX_SIZE + total_output_size) * WITNESS_SCALE_FACTOR as u64);
                let target_amount_sat = must_pay_to.iter().map(|output| output.value).sum();
                let do_coin_selection = |force_conflicting_utxo_spend: bool, tolerate_high_network_feerates: bool| {
+                       log_debug!(self.logger, "Attempting coin selection targeting {} sat/kW (force_conflicting_utxo_spend = {}, tolerate_high_network_feerates = {})",
+                               target_feerate_sat_per_1000_weight, force_conflicting_utxo_spend, tolerate_high_network_feerates);
                        self.select_confirmed_utxos_internal(
                                &utxos, claim_id, force_conflicting_utxo_spend, tolerate_high_network_feerates,
                                target_feerate_sat_per_1000_weight, preexisting_tx_weight, target_amount_sat,
@@ -670,6 +690,7 @@ where
                        // match, but we still need to have at least one output in the transaction for it to be
                        // considered standard. We choose to go with an empty OP_RETURN as it is the cheapest
                        // way to include a dummy output.
+                       log_debug!(self.logger, "Including dummy OP_RETURN output since an output is needed and a change output was not provided");
                        tx.output.push(TxOut {
                                value: 0,
                                script_pubkey: Script::new_op_return(&[]),
@@ -677,71 +698,83 @@ where
                }
        }
 
-       /// Returns an unsigned transaction spending an anchor output of the commitment transaction, and
-       /// any additional UTXOs sourced, to bump the commitment transaction's fee.
-       fn build_anchor_tx(
-               &self, claim_id: ClaimId, target_feerate_sat_per_1000_weight: u32,
-               commitment_tx: &Transaction, anchor_descriptor: &AnchorDescriptor,
-       ) -> Result<Transaction, ()> {
+       /// Handles a [`BumpTransactionEvent::ChannelClose`] event variant by producing a fully-signed
+       /// transaction spending an anchor output of the commitment transaction to bump its fee and
+       /// broadcasts them to the network as a package.
+       fn handle_channel_close(
+               &self, claim_id: ClaimId, package_target_feerate_sat_per_1000_weight: u32,
+               commitment_tx: &Transaction, commitment_tx_fee_sat: u64, anchor_descriptor: &AnchorDescriptor,
+       ) -> Result<(), ()> {
+               // Our commitment transaction already has fees allocated to it, so we should take them into
+               // account. We compute its feerate and subtract it from the package target, using the result
+               // as the target feerate for our anchor transaction. Unfortunately, this results in users
+               // overpaying by a small margin since we don't yet know the anchor transaction size, and
+               // avoiding the small overpayment only makes our API even more complex.
+               let commitment_tx_sat_per_1000_weight: u32 = compute_feerate_sat_per_1000_weight(
+                       commitment_tx_fee_sat, commitment_tx.weight() as u64,
+               );
+               let anchor_target_feerate_sat_per_1000_weight = core::cmp::max(
+                       package_target_feerate_sat_per_1000_weight - commitment_tx_sat_per_1000_weight,
+                       FEERATE_FLOOR_SATS_PER_KW,
+               );
+
+               log_debug!(self.logger, "Peforming coin selection for anchor transaction targeting {} sat/kW",
+                       anchor_target_feerate_sat_per_1000_weight);
                let must_spend = vec![Input {
                        outpoint: anchor_descriptor.outpoint,
                        previous_utxo: anchor_descriptor.previous_utxo(),
                        satisfaction_weight: commitment_tx.weight() as u64 + ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT,
                }];
                let coin_selection = self.utxo_source.select_confirmed_utxos(
-                       claim_id, &must_spend, &[], target_feerate_sat_per_1000_weight,
+                       claim_id, &must_spend, &[], anchor_target_feerate_sat_per_1000_weight,
                )?;
 
-               let mut tx = Transaction {
+               let mut anchor_tx = Transaction {
                        version: 2,
                        lock_time: PackedLockTime::ZERO, // TODO: Use next best height.
                        input: vec![anchor_descriptor.unsigned_tx_input()],
                        output: vec![],
                };
-               self.process_coin_selection(&mut tx, coin_selection);
-               Ok(tx)
-       }
+               #[cfg(debug_assertions)]
+               let total_satisfaction_weight =
+                       coin_selection.confirmed_utxos.iter().map(|utxo| utxo.satisfaction_weight).sum::<u64>() +
+                               ANCHOR_INPUT_WITNESS_WEIGHT + EMPTY_SCRIPT_SIG_WEIGHT;
 
-       /// Handles a [`BumpTransactionEvent::ChannelClose`] event variant by producing a fully-signed
-       /// transaction spending an anchor output of the commitment transaction to bump its fee and
-       /// broadcasts them to the network as a package.
-       fn handle_channel_close(
-               &self, claim_id: ClaimId, package_target_feerate_sat_per_1000_weight: u32,
-               commitment_tx: &Transaction, commitment_tx_fee_sat: u64, anchor_descriptor: &AnchorDescriptor,
-       ) -> Result<(), ()> {
-               // Compute the feerate the anchor transaction must meet to meet the overall feerate for the
-               // package (commitment + anchor transactions).
-               let commitment_tx_sat_per_1000_weight: u32 = compute_feerate_sat_per_1000_weight(
-                       commitment_tx_fee_sat, commitment_tx.weight() as u64,
-               );
-               if commitment_tx_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight {
-                       // If the commitment transaction already has a feerate high enough on its own, broadcast
-                       // it as is without a child.
-                       self.broadcaster.broadcast_transactions(&[&commitment_tx]);
-                       return Ok(());
-               }
+               self.process_coin_selection(&mut anchor_tx, coin_selection);
+               let anchor_txid = anchor_tx.txid();
 
-               let mut anchor_tx = self.build_anchor_tx(
-                       claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_descriptor,
-               )?;
                debug_assert_eq!(anchor_tx.output.len(), 1);
+               #[cfg(debug_assertions)]
+               let unsigned_tx_weight = anchor_tx.weight() as u64 - (anchor_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
 
+               log_debug!(self.logger, "Signing anchor transaction {}", anchor_txid);
                self.utxo_source.sign_tx(&mut anchor_tx)?;
                let signer = anchor_descriptor.derive_channel_signer(&self.signer_provider);
                let anchor_sig = signer.sign_holder_anchor_input(&anchor_tx, 0, &self.secp)?;
                anchor_tx.input[0].witness = anchor_descriptor.tx_input_witness(&anchor_sig);
 
+               #[cfg(debug_assertions)] {
+                       let signed_tx_weight = anchor_tx.weight() as u64;
+                       let expected_signed_tx_weight = unsigned_tx_weight + total_satisfaction_weight;
+                       // Our estimate should be within a 1% error margin of the actual weight and we should
+                       // never underestimate.
+                       assert!(expected_signed_tx_weight >= signed_tx_weight &&
+                               expected_signed_tx_weight - (expected_signed_tx_weight / 100) <= signed_tx_weight);
+               }
+
+               log_info!(self.logger, "Broadcasting anchor transaction {} to bump channel close with txid {}",
+                       anchor_txid, commitment_tx.txid());
                self.broadcaster.broadcast_transactions(&[&commitment_tx, &anchor_tx]);
                Ok(())
        }
 
-       /// Returns an unsigned, fee-bumped HTLC transaction, along with the set of signers required to
-       /// fulfill the witness for each HTLC input within it.
-       fn build_htlc_tx(
+       /// Handles a [`BumpTransactionEvent::HTLCResolution`] event variant by producing a
+       /// fully-signed, fee-bumped HTLC transaction that is broadcast to the network.
+       fn handle_htlc_resolution(
                &self, claim_id: ClaimId, target_feerate_sat_per_1000_weight: u32,
                htlc_descriptors: &[HTLCDescriptor], tx_lock_time: PackedLockTime,
-       ) -> Result<Transaction, ()> {
-               let mut tx = Transaction {
+       ) -> Result<(), ()> {
+               let mut htlc_tx = Transaction {
                        version: 2,
                        lock_time: tx_lock_time,
                        input: vec![],
@@ -759,28 +792,26 @@ where
                                        HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT
                                },
                        });
-                       tx.input.push(htlc_input);
+                       htlc_tx.input.push(htlc_input);
                        let htlc_output = htlc_descriptor.tx_output(&self.secp);
-                       tx.output.push(htlc_output);
+                       htlc_tx.output.push(htlc_output);
                }
 
+               log_debug!(self.logger, "Peforming coin selection for HTLC transaction targeting {} sat/kW",
+                       target_feerate_sat_per_1000_weight);
                let coin_selection = self.utxo_source.select_confirmed_utxos(
-                       claim_id, &must_spend, &tx.output, target_feerate_sat_per_1000_weight,
+                       claim_id, &must_spend, &htlc_tx.output, target_feerate_sat_per_1000_weight,
                )?;
-               self.process_coin_selection(&mut tx, coin_selection);
-               Ok(tx)
-       }
+               #[cfg(debug_assertions)]
+               let total_satisfaction_weight =
+                       coin_selection.confirmed_utxos.iter().map(|utxo| utxo.satisfaction_weight).sum::<u64>() +
+                               must_spend.iter().map(|input| input.satisfaction_weight).sum::<u64>();
+               self.process_coin_selection(&mut htlc_tx, coin_selection);
 
-       /// Handles a [`BumpTransactionEvent::HTLCResolution`] event variant by producing a
-       /// fully-signed, fee-bumped HTLC transaction that is broadcast to the network.
-       fn handle_htlc_resolution(
-               &self, claim_id: ClaimId, target_feerate_sat_per_1000_weight: u32,
-               htlc_descriptors: &[HTLCDescriptor], tx_lock_time: PackedLockTime,
-       ) -> Result<(), ()> {
-               let mut htlc_tx = self.build_htlc_tx(
-                       claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,
-               )?;
+               #[cfg(debug_assertions)]
+               let unsigned_tx_weight = htlc_tx.weight() as u64 - (htlc_tx.input.len() as u64 * EMPTY_SCRIPT_SIG_WEIGHT);
 
+               log_debug!(self.logger, "Signing HTLC transaction {}", htlc_tx.txid());
                self.utxo_source.sign_tx(&mut htlc_tx)?;
                let mut signers = BTreeMap::new();
                for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
@@ -791,6 +822,16 @@ where
                        htlc_tx.input[idx].witness = htlc_descriptor.tx_input_witness(&htlc_sig, &witness_script);
                }
 
+               #[cfg(debug_assertions)] {
+                       let signed_tx_weight = htlc_tx.weight() as u64;
+                       let expected_signed_tx_weight = unsigned_tx_weight + total_satisfaction_weight;
+                       // Our estimate should be within a 1% error margin of the actual weight and we should
+                       // never underestimate.
+                       assert!(expected_signed_tx_weight >= signed_tx_weight &&
+                               expected_signed_tx_weight - (expected_signed_tx_weight / 100) <= signed_tx_weight);
+               }
+
+               log_info!(self.logger, "Broadcasting {}", log_tx!(htlc_tx));
                self.broadcaster.broadcast_transactions(&[&htlc_tx]);
                Ok(())
        }
@@ -800,8 +841,10 @@ where
                match event {
                        BumpTransactionEvent::ChannelClose {
                                claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx,
-                               anchor_descriptor, commitment_tx_fee_satoshis,  ..
+                               commitment_tx_fee_satoshis, anchor_descriptor, ..
                        } => {
+                               log_info!(self.logger, "Handling channel close bump (claim_id = {}, commitment_txid = {})",
+                                       log_bytes!(claim_id.0), commitment_tx.txid());
                                if let Err(_) = self.handle_channel_close(
                                        *claim_id, *package_target_feerate_sat_per_1000_weight, commitment_tx,
                                        *commitment_tx_fee_satoshis, anchor_descriptor,
@@ -813,6 +856,8 @@ where
                        BumpTransactionEvent::HTLCResolution {
                                claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,
                        } => {
+                               log_info!(self.logger, "Handling HTLC bump (claim_id = {}, htlcs_to_claim = {})",
+                                       log_bytes!(claim_id.0), log_iter!(htlc_descriptors.iter().map(|d| d.outpoint())));
                                if let Err(_) = self.handle_htlc_resolution(
                                        *claim_id, *target_feerate_sat_per_1000_weight, htlc_descriptors, *tx_lock_time,
                                ) {
index 707c27908eddabd5efdbabeda8278af225b02950..8d4c40b64d06b303c7aab3b183adbc98dcf8829d 100644 (file)
@@ -2346,6 +2346,7 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
                RecipientOnionFields::secret_only(payment_secret_2), PaymentId(payment_hash_2.0)).unwrap();
        check_added_monitors!(nodes[0], 0);
 
+       let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        chanmon_cfgs[0].persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
        nodes[0].node.claim_funds(payment_preimage_0);
@@ -2365,8 +2366,9 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
                // disconnect the peers. Note that the fuzzer originally found this issue because
                // deserializing a ChannelManager in this state causes an assertion failure.
                if reload_a {
-                       let chan_0_monitor_serialized = get_monitor!(nodes[0], chan_id).encode();
                        reload_node!(nodes[0], &nodes[0].node.encode(), &[&chan_0_monitor_serialized], persister, new_chain_monitor, nodes_0_deserialized);
+                       persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
+                       persister.set_update_ret(ChannelMonitorUpdateStatus::InProgress);
                } else {
                        nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id());
                }
@@ -2406,9 +2408,14 @@ fn do_channel_holding_cell_serialize(disconnect: bool, reload_a: bool) {
                        assert_eq!(pending_cs.commitment_signed, cs);
                } else { panic!(); }
 
-               // There should be no monitor updates as we are still pending awaiting a failed one.
-               check_added_monitors!(nodes[0], 0);
-               check_added_monitors!(nodes[1], 0);
+               if reload_a {
+                       // The two pending monitor updates were replayed (but are still pending).
+                       check_added_monitors(&nodes[0], 2);
+               } else {
+                       // There should be no monitor updates as we are still pending awaiting a failed one.
+                       check_added_monitors(&nodes[0], 0);
+               }
+               check_added_monitors(&nodes[1], 0);
        }
 
        // If we finish updating the monitor, we should free the holding cell right away (this did
index 79c5f017ba4a40e7ead67f8e623379db2baf301d..982aed7529832f04832acca14e39211fd7f3ce36 100644 (file)
@@ -43,7 +43,7 @@ use crate::ln::{inbound_payment, PaymentHash, PaymentPreimage, PaymentSecret};
 use crate::ln::channel::{Channel, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel};
 use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
 #[cfg(any(feature = "_test_utils", test))]
-use crate::ln::features::InvoiceFeatures;
+use crate::ln::features::Bolt11InvoiceFeatures;
 use crate::routing::gossip::NetworkGraph;
 use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
 use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringFeeParameters};
@@ -530,6 +530,13 @@ enum BackgroundEvent {
                funding_txo: OutPoint,
                update: ChannelMonitorUpdate
        },
+       /// Some [`ChannelMonitorUpdate`] (s) completed before we were serialized but we still have
+       /// them marked pending, thus we need to run any [`MonitorUpdateCompletionAction`] (s) pending
+       /// on a channel.
+       MonitorUpdatesComplete {
+               counterparty_node_id: PublicKey,
+               channel_id: [u8; 32],
+       },
 }
 
 #[derive(Debug)]
@@ -4194,6 +4201,22 @@ where
                                        }
                                        let _ = handle_error!(self, res, counterparty_node_id);
                                },
+                               BackgroundEvent::MonitorUpdatesComplete { counterparty_node_id, channel_id } => {
+                                       let per_peer_state = self.per_peer_state.read().unwrap();
+                                       if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) {
+                                               let mut peer_state_lock = peer_state_mutex.lock().unwrap();
+                                               let peer_state = &mut *peer_state_lock;
+                                               if let Some(chan) = peer_state.channel_by_id.get_mut(&channel_id) {
+                                                       handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan);
+                                               } else {
+                                                       let update_actions = peer_state.monitor_update_blocked_actions
+                                                               .remove(&channel_id).unwrap_or(Vec::new());
+                                                       mem::drop(peer_state_lock);
+                                                       mem::drop(per_peer_state);
+                                                       self.handle_monitor_update_completion_actions(update_actions);
+                                               }
+                                       }
+                               },
                        }
                }
                NotifyOption::DoPersist
@@ -5016,24 +5039,29 @@ where
                if peer_state_mutex_opt.is_none() { return }
                peer_state_lock = peer_state_mutex_opt.unwrap().lock().unwrap();
                let peer_state = &mut *peer_state_lock;
-               let mut channel = {
-                       match peer_state.channel_by_id.entry(funding_txo.to_channel_id()){
-                               hash_map::Entry::Occupied(chan) => chan,
-                               hash_map::Entry::Vacant(_) => return,
-                       }
-               };
+               let channel =
+                       if let Some(chan) = peer_state.channel_by_id.get_mut(&funding_txo.to_channel_id()) {
+                               chan
+                       } else {
+                               let update_actions = peer_state.monitor_update_blocked_actions
+                                       .remove(&funding_txo.to_channel_id()).unwrap_or(Vec::new());
+                               mem::drop(peer_state_lock);
+                               mem::drop(per_peer_state);
+                               self.handle_monitor_update_completion_actions(update_actions);
+                               return;
+                       };
                let remaining_in_flight =
                        if let Some(pending) = peer_state.in_flight_monitor_updates.get_mut(funding_txo) {
                                pending.retain(|upd| upd.update_id > highest_applied_update_id);
                                pending.len()
                        } else { 0 };
                log_trace!(self.logger, "ChannelMonitor updated to {}. Current highest is {}. {} pending in-flight updates.",
-                       highest_applied_update_id, channel.get().context.get_latest_monitor_update_id(),
+                       highest_applied_update_id, channel.context.get_latest_monitor_update_id(),
                        remaining_in_flight);
-               if !channel.get().is_awaiting_monitor_update() || channel.get().context.get_latest_monitor_update_id() != highest_applied_update_id {
+               if !channel.is_awaiting_monitor_update() || channel.context.get_latest_monitor_update_id() != highest_applied_update_id {
                        return;
                }
-               handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel.get_mut());
+               handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, channel);
        }
 
        /// Accepts a request to open a channel after a [`Event::OpenChannelRequest`].
@@ -6912,13 +6940,13 @@ where
                provided_node_features(&self.default_configuration)
        }
 
-       /// Fetches the set of [`InvoiceFeatures`] flags which are provided by or required by
+       /// Fetches the set of [`Bolt11InvoiceFeatures`] flags which are provided by or required by
        /// [`ChannelManager`].
        ///
        /// Note that the invoice feature flags can vary depending on if the invoice is a "phantom invoice"
        /// or not. Thus, this method is not public.
        #[cfg(any(feature = "_test_utils", test))]
-       pub fn invoice_features(&self) -> InvoiceFeatures {
+       pub fn invoice_features(&self) -> Bolt11InvoiceFeatures {
                provided_invoice_features(&self.default_configuration)
        }
 
@@ -7350,13 +7378,13 @@ pub(crate) fn provided_node_features(config: &UserConfig) -> NodeFeatures {
        provided_init_features(config).to_context()
 }
 
-/// Fetches the set of [`InvoiceFeatures`] flags which are provided by or required by
+/// Fetches the set of [`Bolt11InvoiceFeatures`] flags which are provided by or required by
 /// [`ChannelManager`].
 ///
 /// Note that the invoice feature flags can vary depending on if the invoice is a "phantom invoice"
 /// or not. Thus, this method is not public.
 #[cfg(any(feature = "_test_utils", test))]
-pub(crate) fn provided_invoice_features(config: &UserConfig) -> InvoiceFeatures {
+pub(crate) fn provided_invoice_features(config: &UserConfig) -> Bolt11InvoiceFeatures {
        provided_init_features(config).to_context()
 }
 
@@ -8533,6 +8561,16 @@ where
                                                        update: update.clone(),
                                                });
                                }
+                               if $chan_in_flight_upds.is_empty() {
+                                       // We had some updates to apply, but it turns out they had completed before we
+                                       // were serialized, we just weren't notified of that. Thus, we may have to run
+                                       // the completion actions for any monitor updates, but otherwise are done.
+                                       pending_background_events.push(
+                                               BackgroundEvent::MonitorUpdatesComplete {
+                                                       counterparty_node_id: $counterparty_node_id,
+                                                       channel_id: $funding_txo.to_channel_id(),
+                                               });
+                               }
                                if $peer_state.in_flight_monitor_updates.insert($funding_txo, $chan_in_flight_upds).is_some() {
                                        log_error!(args.logger, "Duplicate in-flight monitor update set for the same channel!");
                                        return Err(DecodeError::InvalidValue);
@@ -8925,6 +8963,12 @@ where
                                                                blocked_peer_state.lock().unwrap().actions_blocking_raa_monitor_updates
                                                                        .entry(blocked_channel_outpoint.to_channel_id())
                                                                        .or_insert_with(Vec::new).push(blocking_action.clone());
+                                                       } else {
+                                                               // If the channel we were blocking has closed, we don't need to
+                                                               // worry about it - the blocked monitor update should never have
+                                                               // been released from the `Channel` object so it can't have
+                                                               // completed, and if the channel closed there's no reason to bother
+                                                               // anymore.
                                                        }
                                                }
                                        }
index ca6ea70b61da7312de22b1e28749a51cb3f28941..6309eea413adb4d913c45379baad6eca16bdeb83 100644 (file)
@@ -168,7 +168,7 @@ mod sealed {
                ZeroConf | Keysend,
        ]);
        define_context!(ChannelContext, []);
-       define_context!(InvoiceContext, [
+       define_context!(Bolt11InvoiceContext, [
                // Byte 0
                ,
                // Byte 1
@@ -369,17 +369,17 @@ mod sealed {
        define_feature!(7, GossipQueries, [InitContext, NodeContext],
                "Feature flags for `gossip_queries`.", set_gossip_queries_optional, set_gossip_queries_required,
                supports_gossip_queries, requires_gossip_queries);
-       define_feature!(9, VariableLengthOnion, [InitContext, NodeContext, InvoiceContext],
+       define_feature!(9, VariableLengthOnion, [InitContext, NodeContext, Bolt11InvoiceContext],
                "Feature flags for `var_onion_optin`.", set_variable_length_onion_optional,
                set_variable_length_onion_required, supports_variable_length_onion,
                requires_variable_length_onion);
        define_feature!(13, StaticRemoteKey, [InitContext, NodeContext, ChannelTypeContext],
                "Feature flags for `option_static_remotekey`.", set_static_remote_key_optional,
                set_static_remote_key_required, supports_static_remote_key, requires_static_remote_key);
-       define_feature!(15, PaymentSecret, [InitContext, NodeContext, InvoiceContext],
+       define_feature!(15, PaymentSecret, [InitContext, NodeContext, Bolt11InvoiceContext],
                "Feature flags for `payment_secret`.", set_payment_secret_optional, set_payment_secret_required,
                supports_payment_secret, requires_payment_secret);
-       define_feature!(17, BasicMPP, [InitContext, NodeContext, InvoiceContext, Bolt12InvoiceContext],
+       define_feature!(17, BasicMPP, [InitContext, NodeContext, Bolt11InvoiceContext, Bolt12InvoiceContext],
                "Feature flags for `basic_mpp`.", set_basic_mpp_optional, set_basic_mpp_required,
                supports_basic_mpp, requires_basic_mpp);
        define_feature!(19, Wumbo, [InitContext, NodeContext],
@@ -403,7 +403,7 @@ mod sealed {
        define_feature!(47, SCIDPrivacy, [InitContext, NodeContext, ChannelTypeContext],
                "Feature flags for only forwarding with SCID aliasing. Called `option_scid_alias` in the BOLTs",
                set_scid_privacy_optional, set_scid_privacy_required, supports_scid_privacy, requires_scid_privacy);
-       define_feature!(49, PaymentMetadata, [InvoiceContext],
+       define_feature!(49, PaymentMetadata, [Bolt11InvoiceContext],
                "Feature flags for payment metadata in invoices.", set_payment_metadata_optional,
                set_payment_metadata_required, supports_payment_metadata, requires_payment_metadata);
        define_feature!(51, ZeroConf, [InitContext, NodeContext, ChannelTypeContext],
@@ -416,7 +416,7 @@ mod sealed {
 
        #[cfg(test)]
        define_feature!(123456789, UnknownFeature,
-               [NodeContext, ChannelContext, InvoiceContext, OfferContext, InvoiceRequestContext, Bolt12InvoiceContext, BlindedHopContext],
+               [NodeContext, ChannelContext, Bolt11InvoiceContext, OfferContext, InvoiceRequestContext, Bolt12InvoiceContext, BlindedHopContext],
                "Feature flags for an unknown feature used in testing.", set_unknown_feature_optional,
                set_unknown_feature_required, supports_unknown_test_feature, requires_unknown_test_feature);
 }
@@ -492,7 +492,7 @@ pub type NodeFeatures = Features<sealed::NodeContext>;
 /// Features used within a `channel_announcement` message.
 pub type ChannelFeatures = Features<sealed::ChannelContext>;
 /// Features used within an invoice.
-pub type InvoiceFeatures = Features<sealed::InvoiceContext>;
+pub type Bolt11InvoiceFeatures = Features<sealed::Bolt11InvoiceContext>;
 /// Features used within an `offer`.
 pub type OfferFeatures = Features<sealed::OfferContext>;
 /// Features used within an `invoice_request`.
@@ -538,8 +538,8 @@ impl InitFeatures {
        }
 }
 
-impl InvoiceFeatures {
-       /// Converts `InvoiceFeatures` to `Features<C>`. Only known `InvoiceFeatures` relevant to
+impl Bolt11InvoiceFeatures {
+       /// Converts `Bolt11InvoiceFeatures` to `Features<C>`. Only known `Bolt11InvoiceFeatures` relevant to
        /// context `C` are included in the result.
        pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
                self.to_context_internal()
@@ -549,15 +549,15 @@ impl InvoiceFeatures {
        /// features (since they were not announced in a node announcement). However, keysend payments
        /// don't have an invoice to pull the payee's features from, so this method is provided for use in
        /// [`PaymentParameters::for_keysend`], thus omitting the need for payers to manually construct an
-       /// `InvoiceFeatures` for [`find_route`].
+       /// `Bolt11InvoiceFeatures` for [`find_route`].
        ///
        /// MPP keysend is not widely supported yet, so we parameterize support to allow the user to
        /// choose whether their router should find multi-part routes.
        ///
        /// [`PaymentParameters::for_keysend`]: crate::routing::router::PaymentParameters::for_keysend
        /// [`find_route`]: crate::routing::router::find_route
-       pub(crate) fn for_keysend(allow_mpp: bool) -> InvoiceFeatures {
-               let mut res = InvoiceFeatures::empty();
+       pub(crate) fn for_keysend(allow_mpp: bool) -> Bolt11InvoiceFeatures {
+               let mut res = Bolt11InvoiceFeatures::empty();
                res.set_variable_length_onion_optional();
                if allow_mpp {
                        res.set_basic_mpp_optional();
@@ -567,8 +567,8 @@ impl InvoiceFeatures {
 }
 
 impl Bolt12InvoiceFeatures {
-       /// Converts `Bolt12InvoiceFeatures` to `Features<C>`. Only known `Bolt12InvoiceFeatures` relevant
-       /// to context `C` are included in the result.
+       /// Converts [`Bolt12InvoiceFeatures`] to [`Features<C>`]. Only known [`Bolt12InvoiceFeatures`]
+       /// relevant to context `C` are included in the result.
        pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
                self.to_context_internal()
        }
@@ -604,7 +604,7 @@ impl ChannelTypeFeatures {
        }
 }
 
-impl ToBase32 for InvoiceFeatures {
+impl ToBase32 for Bolt11InvoiceFeatures {
        fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
                // Explanation for the "4": the normal way to round up when dividing is to add the divisor
                // minus one before dividing
@@ -634,16 +634,16 @@ impl ToBase32 for InvoiceFeatures {
        }
 }
 
-impl Base32Len for InvoiceFeatures {
+impl Base32Len for Bolt11InvoiceFeatures {
        fn base32_len(&self) -> usize {
                self.to_base32().len()
        }
 }
 
-impl FromBase32 for InvoiceFeatures {
+impl FromBase32 for Bolt11InvoiceFeatures {
        type Err = bech32::Error;
 
-       fn from_base32(field_data: &[u5]) -> Result<InvoiceFeatures, bech32::Error> {
+       fn from_base32(field_data: &[u5]) -> Result<Bolt11InvoiceFeatures, bech32::Error> {
                // Explanation for the "7": the normal way to round up when dividing is to add the divisor
                // minus one before dividing
                let length_bytes = (field_data.len() * 5 + 7) / 8 as usize;
@@ -662,7 +662,7 @@ impl FromBase32 for InvoiceFeatures {
                while !res_bytes.is_empty() && res_bytes[res_bytes.len() - 1] == 0 {
                        res_bytes.pop();
                }
-               Ok(InvoiceFeatures::from_le_bytes(res_bytes))
+               Ok(Bolt11InvoiceFeatures::from_le_bytes(res_bytes))
        }
 }
 
@@ -903,7 +903,7 @@ macro_rules! impl_feature_len_prefixed_write {
 impl_feature_len_prefixed_write!(InitFeatures);
 impl_feature_len_prefixed_write!(ChannelFeatures);
 impl_feature_len_prefixed_write!(NodeFeatures);
-impl_feature_len_prefixed_write!(InvoiceFeatures);
+impl_feature_len_prefixed_write!(Bolt11InvoiceFeatures);
 impl_feature_len_prefixed_write!(Bolt12InvoiceFeatures);
 impl_feature_len_prefixed_write!(BlindedHopFeatures);
 
@@ -943,7 +943,7 @@ impl<T: sealed::Context> Readable for WithoutLength<Features<T>> {
 
 #[cfg(test)]
 mod tests {
-       use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, InvoiceFeatures, NodeFeatures, OfferFeatures, sealed};
+       use super::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, Bolt11InvoiceFeatures, NodeFeatures, OfferFeatures, sealed};
        use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, u5};
        use crate::util::ser::{Readable, WithoutLength, Writeable};
 
@@ -1058,17 +1058,17 @@ mod tests {
        fn convert_to_context_with_unknown_flags() {
                // Ensure the `from` context has fewer known feature bytes than the `to` context.
                assert!(<sealed::ChannelContext as sealed::Context>::KNOWN_FEATURE_MASK.len() <
-                       <sealed::InvoiceContext as sealed::Context>::KNOWN_FEATURE_MASK.len());
+                       <sealed::Bolt11InvoiceContext as sealed::Context>::KNOWN_FEATURE_MASK.len());
                let mut channel_features = ChannelFeatures::empty();
                channel_features.set_unknown_feature_optional();
                assert!(channel_features.supports_unknown_bits());
-               let invoice_features: InvoiceFeatures = channel_features.to_context_internal();
+               let invoice_features: Bolt11InvoiceFeatures = channel_features.to_context_internal();
                assert!(!invoice_features.supports_unknown_bits());
        }
 
        #[test]
        fn set_feature_bits() {
-               let mut features = InvoiceFeatures::empty();
+               let mut features = Bolt11InvoiceFeatures::empty();
                features.set_basic_mpp_optional();
                features.set_payment_secret_required();
                assert!(features.supports_basic_mpp());
@@ -1079,7 +1079,7 @@ mod tests {
 
        #[test]
        fn set_custom_bits() {
-               let mut features = InvoiceFeatures::empty();
+               let mut features = Bolt11InvoiceFeatures::empty();
                features.set_variable_length_onion_optional();
                assert_eq!(features.flags[1], 0b00000010);
 
@@ -1089,19 +1089,19 @@ mod tests {
                assert_eq!(features.flags[31], 0b00000000);
                assert_eq!(features.flags[32], 0b00000101);
 
-               let known_bit = <sealed::InvoiceContext as sealed::PaymentSecret>::EVEN_BIT;
-               let byte_offset = <sealed::InvoiceContext as sealed::PaymentSecret>::BYTE_OFFSET;
+               let known_bit = <sealed::Bolt11InvoiceContext as sealed::PaymentSecret>::EVEN_BIT;
+               let byte_offset = <sealed::Bolt11InvoiceContext as sealed::PaymentSecret>::BYTE_OFFSET;
                assert_eq!(byte_offset, 1);
                assert_eq!(features.flags[byte_offset], 0b00000010);
                assert!(features.set_required_custom_bit(known_bit).is_err());
                assert_eq!(features.flags[byte_offset], 0b00000010);
 
-               let mut features = InvoiceFeatures::empty();
+               let mut features = Bolt11InvoiceFeatures::empty();
                assert!(features.set_optional_custom_bit(256).is_ok());
                assert!(features.set_optional_custom_bit(259).is_ok());
                assert_eq!(features.flags[32], 0b00001010);
 
-               let mut features = InvoiceFeatures::empty();
+               let mut features = Bolt11InvoiceFeatures::empty();
                assert!(features.set_required_custom_bit(257).is_ok());
                assert!(features.set_required_custom_bit(258).is_ok());
                assert_eq!(features.flags[32], 0b00000101);
@@ -1138,7 +1138,7 @@ mod tests {
                        u5::try_from_u8(16).unwrap(),
                        u5::try_from_u8(1).unwrap(),
                ];
-               let features = InvoiceFeatures::from_le_bytes(vec![1, 2, 3, 4, 5, 42, 100, 101]);
+               let features = Bolt11InvoiceFeatures::from_le_bytes(vec![1, 2, 3, 4, 5, 42, 100, 101]);
 
                // Test length calculation.
                assert_eq!(features.base32_len(), 13);
@@ -1148,13 +1148,13 @@ mod tests {
                assert_eq!(features_as_u5s, features_serialized);
 
                // Test deserialization.
-               let features_deserialized = InvoiceFeatures::from_base32(&features_as_u5s).unwrap();
+               let features_deserialized = Bolt11InvoiceFeatures::from_base32(&features_as_u5s).unwrap();
                assert_eq!(features, features_deserialized);
        }
 
        #[test]
        fn test_channel_type_mapping() {
-               // If we map an InvoiceFeatures with StaticRemoteKey optional, it should map into a
+               // If we map an Bolt11InvoiceFeatures with StaticRemoteKey optional, it should map into a
                // required-StaticRemoteKey ChannelTypeFeatures.
                let mut init_features = InitFeatures::empty();
                init_features.set_static_remote_key_optional();
index 024690d00daad73da84072674bcc2094d32df149..220557e4ca3ecfbde2ab1c7dd9a443a6787b8925 100644 (file)
@@ -15,6 +15,7 @@ use crate::sign::EntropySource;
 use crate::chain::channelmonitor::ChannelMonitor;
 use crate::chain::transaction::OutPoint;
 use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentPurpose, PaymentFailureReason};
+use crate::events::bump_transaction::{BumpTransactionEventHandler, Wallet, WalletSource};
 use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
 use crate::ln::channelmanager::{AChannelManager, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentSendFailure, RecipientOnionFields, PaymentId, MIN_CLTV_EXPIRY_DELTA};
 use crate::routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate};
@@ -32,13 +33,11 @@ use crate::util::ser::{ReadableArgs, Writeable};
 
 use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
-use bitcoin::network::constants::Network;
-
 use bitcoin::hash_types::BlockHash;
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::Hash as _;
-
-use bitcoin::secp256k1::PublicKey;
+use bitcoin::network::constants::Network;
+use bitcoin::secp256k1::{PublicKey, SecretKey};
 
 use crate::io;
 use crate::prelude::*;
@@ -289,6 +288,19 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: Block, sk
        }
        call_claimable_balances(node);
        node.node.test_process_background_events();
+
+       for tx in &block.txdata {
+               for input in &tx.input {
+                       node.wallet_source.remove_utxo(input.previous_output);
+               }
+               let wallet_script = node.wallet_source.get_change_script().unwrap();
+               for (idx, output) in tx.output.iter().enumerate() {
+                       if output.script_pubkey == wallet_script {
+                               let outpoint = bitcoin::OutPoint { txid: tx.txid(), vout: idx as u32 };
+                               node.wallet_source.add_utxo(outpoint, output.value);
+                       }
+               }
+       }
 }
 
 pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32) {
@@ -375,6 +387,13 @@ pub struct Node<'a, 'b: 'a, 'c: 'b> {
        pub blocks: Arc<Mutex<Vec<(Block, u32)>>>,
        pub connect_style: Rc<RefCell<ConnectStyle>>,
        pub override_init_features: Rc<RefCell<Option<InitFeatures>>>,
+       pub wallet_source: Arc<test_utils::TestWalletSource>,
+       pub bump_tx_handler: BumpTransactionEventHandler<
+               &'c test_utils::TestBroadcaster,
+               Arc<Wallet<Arc<test_utils::TestWalletSource>, &'c test_utils::TestLogger>>,
+               &'b test_utils::TestKeysInterface,
+               &'c test_utils::TestLogger,
+       >,
 }
 impl<'a, 'b, 'c> Node<'a, 'b, 'c> {
        pub fn best_block_hash(&self) -> BlockHash {
@@ -2622,6 +2641,7 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
 
        for i in 0..node_count {
                let gossip_sync = P2PGossipSync::new(cfgs[i].network_graph.as_ref(), None, cfgs[i].logger);
+               let wallet_source = Arc::new(test_utils::TestWalletSource::new(SecretKey::from_slice(&[i as u8 + 1; 32]).unwrap()));
                nodes.push(Node{
                        chain_source: cfgs[i].chain_source, tx_broadcaster: cfgs[i].tx_broadcaster,
                        fee_estimator: cfgs[i].fee_estimator, router: &cfgs[i].router,
@@ -2632,6 +2652,11 @@ pub fn create_network<'a, 'b: 'a, 'c: 'b>(node_count: usize, cfgs: &'b Vec<NodeC
                        blocks: Arc::clone(&cfgs[i].tx_broadcaster.blocks),
                        connect_style: Rc::clone(&connect_style),
                        override_init_features: Rc::clone(&cfgs[i].override_init_features),
+                       wallet_source: Arc::clone(&wallet_source),
+                       bump_tx_handler: BumpTransactionEventHandler::new(
+                               cfgs[i].tx_broadcaster, Arc::new(Wallet::new(Arc::clone(&wallet_source), cfgs[i].logger)),
+                               &cfgs[i].keys_manager, cfgs[i].logger,
+                       ),
                })
        }
 
index 41ecd9da0fbef63970ba37a69291086e30159254..a916dbfc9e26d13cdd12e7d29ec667772d8e7dd7 100644 (file)
@@ -9,14 +9,13 @@
 
 //! Further functional tests which test blockchain reorganizations.
 
-use crate::sign::{ChannelSigner, EcdsaChannelSigner};
+use crate::sign::EcdsaChannelSigner;
 use crate::chain::channelmonitor::{ANTI_REORG_DELAY, LATENCY_GRACE_PERIOD_BLOCKS, Balance};
 use crate::chain::transaction::OutPoint;
-use crate::chain::chaininterface::LowerBoundedFeeEstimator;
-use crate::events::bump_transaction::BumpTransactionEvent;
+use crate::chain::chaininterface::{LowerBoundedFeeEstimator, compute_feerate_sat_per_1000_weight};
+use crate::events::bump_transaction::{BumpTransactionEvent, WalletSource};
 use crate::events::{Event, MessageSendEvent, MessageSendEventsProvider, ClosureReason, HTLCDestination};
 use crate::ln::channel;
-use crate::ln::chan_utils;
 use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, PaymentId, RecipientOnionFields};
 use crate::ln::msgs::ChannelMessageHandler;
 use crate::util::config::UserConfig;
@@ -1743,6 +1742,17 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
        check_closed_event(&nodes[0], 1, ClosureReason::CommitmentTxConfirmed, false);
        check_added_monitors(&nodes[0], 1);
 
+       let coinbase_tx = Transaction {
+               version: 2,
+               lock_time: PackedLockTime::ZERO,
+               input: vec![TxIn { ..Default::default() }],
+               output: vec![TxOut { // UTXO to attach fees to `htlc_tx` on anchors
+                       value: Amount::ONE_BTC.to_sat(),
+                       script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(),
+               }],
+       };
+       nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value);
+
        // Set up a helper closure we'll use throughout our test. We should only expect retries without
        // bumps if fees have not increased after a block has been connected (assuming the height timer
        // re-evaluates at every block) or after `ChainMonitor::rebroadcast_pending_claims` is called.
@@ -1750,42 +1760,25 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
        let mut check_htlc_retry = |should_retry: bool, should_bump: bool| -> Option<Transaction> {
                let (htlc_tx, htlc_tx_feerate) = if anchors {
                        assert!(nodes[0].tx_broadcaster.txn_broadcast().is_empty());
-                       let mut events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
+                       let events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
                        assert_eq!(events.len(), if should_retry { 1 } else { 0 });
                        if !should_retry {
                                return None;
                        }
-                       #[allow(unused_assignments)]
-                       let mut tx = Transaction {
-                               version: 2,
-                               lock_time: bitcoin::PackedLockTime::ZERO,
-                               input: vec![],
-                               output: vec![],
-                       };
-                       #[allow(unused_assignments)]
-                       let mut feerate = 0;
-                       feerate = if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {
-                               target_feerate_sat_per_1000_weight, mut htlc_descriptors, tx_lock_time, ..
-                       }) = events.pop().unwrap() {
-                               let secp = Secp256k1::new();
-                               assert_eq!(htlc_descriptors.len(), 1);
-                               let descriptor = htlc_descriptors.pop().unwrap();
-                               assert_eq!(descriptor.commitment_txid, commitment_txn[0].txid());
-                               let htlc_output_idx = descriptor.htlc.transaction_output_index.unwrap() as usize;
-                               assert!(htlc_output_idx < commitment_txn[0].output.len());
-                               tx.lock_time = tx_lock_time;
-                               // Note that we don't care about actually making the HTLC transaction meet the
-                               // feerate for the test, we just want to make sure the feerates we receive from
-                               // the events never decrease.
-                               tx.input.push(descriptor.unsigned_tx_input());
-                               tx.output.push(descriptor.tx_output(&secp));
-                               let signer = descriptor.derive_channel_signer(&nodes[0].keys_manager);
-                               let our_sig = signer.sign_holder_htlc_transaction(&mut tx, 0, &descriptor, &secp).unwrap();
-                               let witness_script = descriptor.witness_script(&secp);
-                               tx.input[0].witness = descriptor.tx_input_witness(&our_sig, &witness_script);
-                               target_feerate_sat_per_1000_weight as u64
-                       } else { panic!("unexpected event"); };
-                       (tx, feerate)
+                       match &events[0] {
+                               Event::BumpTransaction(event) => {
+                                       nodes[0].bump_tx_handler.handle_event(&event);
+                                       let mut txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
+                                       assert_eq!(txn.len(), 1);
+                                       let htlc_tx = txn.pop().unwrap();
+                                       check_spends!(&htlc_tx, &commitment_txn[0], &coinbase_tx);
+                                       let htlc_tx_fee = HTLC_AMT_SAT + coinbase_tx.output[0].value -
+                                               htlc_tx.output.iter().map(|output| output.value).sum::<u64>();
+                                       let htlc_tx_weight = htlc_tx.weight() as u64;
+                                       (htlc_tx, compute_feerate_sat_per_1000_weight(htlc_tx_fee, htlc_tx_weight))
+                               }
+                               _ => panic!("Unexpected event"),
+                       }
                } else {
                        assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
                        let mut txn = nodes[0].tx_broadcaster.txn_broadcast();
@@ -1796,8 +1789,8 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
                        let htlc_tx = txn.pop().unwrap();
                        check_spends!(htlc_tx, commitment_txn[0]);
                        let htlc_tx_fee = HTLC_AMT_SAT - htlc_tx.output[0].value;
-                       let htlc_tx_feerate = htlc_tx_fee * 1000 / htlc_tx.weight() as u64;
-                       (htlc_tx, htlc_tx_feerate)
+                       let htlc_tx_weight = htlc_tx.weight() as u64;
+                       (htlc_tx, compute_feerate_sat_per_1000_weight(htlc_tx_fee, htlc_tx_weight))
                };
                if should_bump {
                        assert!(htlc_tx_feerate > prev_htlc_tx_feerate.take().unwrap());
@@ -1837,9 +1830,11 @@ fn do_test_monitor_rebroadcast_pending_claims(anchors: bool) {
 
        // Mine the HTLC transaction to ensure we don't retry claims while they're confirmed.
        mine_transaction(&nodes[0], &htlc_tx);
-       // If we have a `ConnectStyle` that advertises the new block first without the transasctions,
+       // If we have a `ConnectStyle` that advertises the new block first without the transactions,
        // we'll receive an extra bumped claim.
        if nodes[0].connect_style.borrow().updates_best_block_first() {
+               nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value);
+               nodes[0].wallet_source.remove_utxo(bitcoin::OutPoint { txid: htlc_tx.txid(), vout: 1 });
                check_htlc_retry(true, anchors);
        }
        nodes[0].chain_monitor.chain_monitor.rebroadcast_pending_claims();
@@ -1860,7 +1855,6 @@ fn test_yield_anchors_events() {
        // allowing the consumer to provide additional fees to the commitment transaction to be
        // broadcast. Once the commitment transaction confirms, events for the HTLC resolution should be
        // emitted by LDK, such that the consumer can attach fees to the zero fee HTLC transactions.
-       let secp = Secp256k1::new();
        let mut chanmon_cfgs = create_chanmon_cfgs(2);
        let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
        let mut anchors_config = UserConfig::default();
@@ -1878,6 +1872,7 @@ fn test_yield_anchors_events() {
 
        assert!(nodes[0].node.get_and_clear_pending_events().is_empty());
 
+       *nodes[0].fee_estimator.sat_per_kw.lock().unwrap() *= 2;
        connect_blocks(&nodes[0], TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS + 1);
        check_closed_broadcast!(&nodes[0], true);
        assert!(nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().is_empty());
@@ -1890,26 +1885,23 @@ fn test_yield_anchors_events() {
        let mut holder_events = nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events();
        assert_eq!(holder_events.len(), 1);
        let (commitment_tx, anchor_tx) = match holder_events.pop().unwrap() {
-               Event::BumpTransaction(BumpTransactionEvent::ChannelClose { commitment_tx, anchor_descriptor, .. })  => {
-                       assert_eq!(commitment_tx.input.len(), 1);
-                       assert_eq!(commitment_tx.output.len(), 6);
-                       let mut anchor_tx = Transaction {
+               Event::BumpTransaction(event) => {
+                       let coinbase_tx = Transaction {
                                version: 2,
                                lock_time: PackedLockTime::ZERO,
-                               input: vec![
-                                       TxIn { previous_output: anchor_descriptor.outpoint, ..Default::default() },
-                                       TxIn { ..Default::default() },
-                               ],
-                               output: vec![TxOut {
+                               input: vec![TxIn { ..Default::default() }],
+                               output: vec![TxOut { // UTXO to attach fees to `anchor_tx`
                                        value: Amount::ONE_BTC.to_sat(),
-                                       script_pubkey: Script::new_op_return(&[]),
+                                       script_pubkey: nodes[0].wallet_source.get_change_script().unwrap(),
                                }],
                        };
-                       let signer = anchor_descriptor.derive_channel_signer(&nodes[0].keys_manager);
-                       let funding_sig = signer.sign_holder_anchor_input(&mut anchor_tx, 0, &secp).unwrap();
-                       anchor_tx.input[0].witness = chan_utils::build_anchor_input_witness(
-                               &signer.pubkeys().funding_pubkey, &funding_sig
-                       );
+                       nodes[0].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, coinbase_tx.output[0].value);
+                       nodes[0].bump_tx_handler.handle_event(&event);
+                       let mut txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
+                       assert_eq!(txn.len(), 2);
+                       let anchor_tx = txn.pop().unwrap();
+                       let commitment_tx = txn.pop().unwrap();
+                       check_spends!(anchor_tx, coinbase_tx, commitment_tx);
                        (commitment_tx, anchor_tx)
                },
                _ => panic!("Unexpected event"),
@@ -1933,28 +1925,12 @@ fn test_yield_anchors_events() {
        let mut htlc_txs = Vec::with_capacity(2);
        for event in holder_events {
                match event {
-                       Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { htlc_descriptors, tx_lock_time, .. }) => {
-                               assert_eq!(htlc_descriptors.len(), 1);
-                               let htlc_descriptor = &htlc_descriptors[0];
-                               let mut htlc_tx = Transaction {
-                                       version: 2,
-                                       lock_time: tx_lock_time,
-                                       input: vec![
-                                               htlc_descriptor.unsigned_tx_input(), // HTLC input
-                                               TxIn { ..Default::default() } // Fee input
-                                       ],
-                                       output: vec![
-                                               htlc_descriptor.tx_output(&secp), // HTLC output
-                                               TxOut { // Fee input change
-                                                       value: Amount::ONE_BTC.to_sat(),
-                                                       script_pubkey: Script::new_op_return(&[]),
-                                               }
-                                       ]
-                               };
-                               let signer = htlc_descriptor.derive_channel_signer(&nodes[0].keys_manager);
-                               let our_sig = signer.sign_holder_htlc_transaction(&mut htlc_tx, 0, htlc_descriptor, &secp).unwrap();
-                               let witness_script = htlc_descriptor.witness_script(&secp);
-                               htlc_tx.input[0].witness = htlc_descriptor.tx_input_witness(&our_sig, &witness_script);
+                       Event::BumpTransaction(event) => {
+                               nodes[0].bump_tx_handler.handle_event(&event);
+                               let mut txn = nodes[0].tx_broadcaster.unique_txn_broadcast();
+                               assert_eq!(txn.len(), 1);
+                               let htlc_tx = txn.pop().unwrap();
+                               check_spends!(htlc_tx, commitment_tx, anchor_tx);
                                htlc_txs.push(htlc_tx);
                        },
                        _ => panic!("Unexpected event"),
@@ -2054,11 +2030,12 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
        // Bob force closes by restarting with the outdated state, prompting the ChannelMonitors to
        // broadcast the latest commitment transaction known to them, which in our case is the one with
        // the HTLCs still pending.
+       *nodes[1].fee_estimator.sat_per_kw.lock().unwrap() *= 2;
        nodes[1].node.timer_tick_occurred();
        check_added_monitors(&nodes[1], 2);
        check_closed_event!(&nodes[1], 2, ClosureReason::OutdatedChannelManager);
        let (revoked_commitment_a, revoked_commitment_b) = {
-               let txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap().split_off(0);
+               let txn = nodes[1].tx_broadcaster.unique_txn_broadcast();
                assert_eq!(txn.len(), 2);
                assert_eq!(txn[0].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs
                assert_eq!(txn[1].output.len(), 6); // 2 HTLC outputs + 1 to_self output + 1 to_remote output + 2 anchor outputs
@@ -2077,71 +2054,32 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
        assert!(nodes[0].chain_monitor.chain_monitor.get_and_clear_pending_events().is_empty());
        let events = nodes[1].chain_monitor.chain_monitor.get_and_clear_pending_events();
        assert_eq!(events.len(), 2);
-       let anchor_tx = {
-               let secret_key = SecretKey::from_slice(&[1; 32]).unwrap();
-               let public_key = PublicKey::new(secret_key.public_key(&secp));
-               let fee_utxo_script = Script::new_v0_p2wpkh(&public_key.wpubkey_hash().unwrap());
+       let mut anchor_txs = Vec::with_capacity(events.len());
+       for (idx, event) in events.into_iter().enumerate() {
+               let utxo_value = Amount::ONE_BTC.to_sat() * (idx + 1) as u64;
                let coinbase_tx = Transaction {
                        version: 2,
                        lock_time: PackedLockTime::ZERO,
                        input: vec![TxIn { ..Default::default() }],
                        output: vec![TxOut { // UTXO to attach fees to `anchor_tx`
-                               value: Amount::ONE_BTC.to_sat(),
-                               script_pubkey: fee_utxo_script.clone(),
-                       }],
-               };
-               let mut anchor_tx = Transaction {
-                       version: 2,
-                       lock_time: PackedLockTime::ZERO,
-                       input: vec![
-                               TxIn { // Fee input
-                                       previous_output: bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 },
-                                       ..Default::default()
-                               },
-                       ],
-                       output: vec![TxOut { // Fee input change
-                               value: coinbase_tx.output[0].value / 2 ,
-                               script_pubkey: Script::new_op_return(&[]),
+                               value: utxo_value,
+                               script_pubkey: nodes[1].wallet_source.get_change_script().unwrap(),
                        }],
                };
-               let mut signers = Vec::with_capacity(2);
-               for event in events {
-                       match event {
-                               Event::BumpTransaction(BumpTransactionEvent::ChannelClose { anchor_descriptor, .. })  => {
-                                       anchor_tx.input.push(TxIn {
-                                               previous_output: anchor_descriptor.outpoint,
-                                               ..Default::default()
-                                       });
-                                       let signer = anchor_descriptor.derive_channel_signer(&nodes[1].keys_manager);
-                                       signers.push(signer);
-                               },
-                               _ => panic!("Unexpected event"),
-                       }
-               }
-               for (i, signer) in signers.into_iter().enumerate() {
-                       let anchor_idx = i + 1;
-                       let funding_sig = signer.sign_holder_anchor_input(&mut anchor_tx, anchor_idx, &secp).unwrap();
-                       anchor_tx.input[anchor_idx].witness = chan_utils::build_anchor_input_witness(
-                               &signer.pubkeys().funding_pubkey, &funding_sig
-                       );
-               }
-               let fee_utxo_sig = {
-                       let witness_script = Script::new_p2pkh(&public_key.pubkey_hash());
-                       let sighash = hash_to_message!(&SighashCache::new(&anchor_tx).segwit_signature_hash(
-                               0, &witness_script, coinbase_tx.output[0].value, EcdsaSighashType::All
-                       ).unwrap()[..]);
-                       let sig = sign(&secp, &sighash, &secret_key);
-                       let mut sig = sig.serialize_der().to_vec();
-                       sig.push(EcdsaSighashType::All as u8);
-                       sig
+               nodes[1].wallet_source.add_utxo(bitcoin::OutPoint { txid: coinbase_tx.txid(), vout: 0 }, utxo_value);
+               match event {
+                       Event::BumpTransaction(event) => nodes[1].bump_tx_handler.handle_event(&event),
+                       _ => panic!("Unexpected event"),
                };
-               anchor_tx.input[0].witness = Witness::from_vec(vec![fee_utxo_sig, public_key.to_bytes()]);
-               check_spends!(anchor_tx, coinbase_tx, revoked_commitment_a, revoked_commitment_b);
-               anchor_tx
+               let txn = nodes[1].tx_broadcaster.txn_broadcast();
+               assert_eq!(txn.len(), 2);
+               let (commitment_tx, anchor_tx) = (&txn[0], &txn[1]);
+               check_spends!(anchor_tx, coinbase_tx, commitment_tx);
+               anchor_txs.push(anchor_tx.clone());
        };
 
        for node in &nodes {
-               mine_transactions(node, &[&revoked_commitment_a, &revoked_commitment_b, &anchor_tx]);
+               mine_transactions(node, &[&revoked_commitment_a, &anchor_txs[0], &revoked_commitment_b, &anchor_txs[1]]);
        }
        check_added_monitors!(&nodes[0], 2);
        check_closed_broadcast(&nodes[0], 2, true);
@@ -2211,6 +2149,8 @@ fn test_anchors_aggregated_revoked_htlc_tx() {
                };
                let mut descriptors = Vec::with_capacity(4);
                for event in events {
+                       // We don't use the `BumpTransactionEventHandler` here because it does not support
+                       // creating one transaction from multiple `HTLCResolution` events.
                        if let Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { mut htlc_descriptors, tx_lock_time, .. }) = event {
                                assert_eq!(htlc_descriptors.len(), 2);
                                for htlc_descriptor in &htlc_descriptors {
index e5faedfe7fc39c958cc52f1c40fbcbc09bcebf27..1230d48ba1ed6d37df3a7f73f1737dc5b873c733 100644 (file)
@@ -20,7 +20,7 @@ use crate::ln::channelmanager::{HTLCForwardInfo, FailureCode, CLTV_FAR_FAR_AWAY,
 use crate::ln::onion_utils;
 use crate::routing::gossip::{NetworkUpdate, RoutingFees};
 use crate::routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintHop};
-use crate::ln::features::{InitFeatures, InvoiceFeatures};
+use crate::ln::features::{InitFeatures, Bolt11InvoiceFeatures};
 use crate::ln::msgs;
 use crate::ln::msgs::{ChannelMessageHandler, ChannelUpdate};
 use crate::ln::wire::Encode;
@@ -862,7 +862,7 @@ fn test_always_create_tlv_format_onion_payloads() {
        create_announced_chan_between_nodes(&nodes, 1, 2);
 
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_bolt11_features(InvoiceFeatures::empty()).unwrap();
+               .with_bolt11_features(Bolt11InvoiceFeatures::empty()).unwrap();
        let (route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 40000);
 
        let hops = &route.paths[0].hops;
index fa607f680981f3d68d81229834ad1becb6ed8b66..b23b6364182da0f8445f1da0f108dddfbf8ad86c 100644 (file)
@@ -18,7 +18,7 @@ use crate::chain::transaction::OutPoint;
 use crate::events::{ClosureReason, Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, PathFailure, PaymentFailureReason};
 use crate::ln::channel::EXPIRE_PREV_CONFIG_TICKS;
 use crate::ln::channelmanager::{BREAKDOWN_TIMEOUT, ChannelManager, MPP_TIMEOUT_TICKS, MIN_CLTV_EXPIRY_DELTA, PaymentId, PaymentSendFailure, IDEMPOTENCY_TIMEOUT_TICKS, RecentPaymentDetails, RecipientOnionFields, HTLCForwardInfo, PendingHTLCRouting, PendingAddHTLCInfo};
-use crate::ln::features::InvoiceFeatures;
+use crate::ln::features::Bolt11InvoiceFeatures;
 use crate::ln::{msgs, PaymentSecret, PaymentPreimage};
 use crate::ln::msgs::ChannelMessageHandler;
 use crate::ln::outbound_payment::Retry;
@@ -1903,7 +1903,7 @@ fn do_automatic_retries(test: AutoRetry) {
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
        let amt_msat = 1000;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2122,7 +2122,7 @@ fn auto_retry_partial_failure() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2334,7 +2334,7 @@ fn auto_retry_zero_attempts_send_error() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2374,7 +2374,7 @@ fn fails_paying_after_rejected_by_payee() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2421,7 +2421,7 @@ fn retry_multi_path_single_failed_payment() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2514,7 +2514,7 @@ fn immediate_retry_on_failure() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2602,7 +2602,7 @@ fn no_extra_retries_on_back_to_back_fail() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2804,7 +2804,7 @@ fn test_simple_partial_retry() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
@@ -2970,7 +2970,7 @@ fn test_threaded_payment_retries() {
        let payment_expiry_secs = SystemTime::UNIX_EPOCH.elapsed().unwrap().as_secs() + 60 * 60;
        #[cfg(not(feature = "std"))]
        let payment_expiry_secs = 60 * 60;
-       let mut invoice_features = InvoiceFeatures::empty();
+       let mut invoice_features = Bolt11InvoiceFeatures::empty();
        invoice_features.set_variable_length_onion_required();
        invoice_features.set_payment_secret_required();
        invoice_features.set_basic_mpp_optional();
index fb1f78fd64445c406d582830eebd97d4c107c16b..279e31dd66a78cf86691ca9c9e2d7f83653a189b 100644 (file)
@@ -9,9 +9,9 @@
 
 //! Data structures and encoding for `invoice` messages.
 //!
-//! An [`Invoice`] can be built from a parsed [`InvoiceRequest`] for the "offer to be paid" flow or
-//! from a [`Refund`] as an "offer for money" flow. The expected recipient of the payment then sends
-//! the invoice to the intended payer, who will then pay it.
+//! A [`Bolt12Invoice`] can be built from a parsed [`InvoiceRequest`] for the "offer to be paid"
+//! flow or from a [`Refund`] as an "offer for money" flow. The expected recipient of the payment
+//! then sends the invoice to the intended payer, who will then pay it.
 //!
 //! The payment recipient must include a [`PaymentHash`], so as to reveal the preimage upon payment
 //! receipt, and one or more [`BlindedPath`]s for the payer to use when sending the payment.
@@ -34,7 +34,7 @@
 //! # fn create_payment_paths() -> Vec<(BlindedPayInfo, BlindedPath)> { unimplemented!() }
 //! # fn create_payment_hash() -> PaymentHash { unimplemented!() }
 //! #
-//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
+//! # fn parse_invoice_request(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
 //! let payment_paths = create_payment_paths();
 //! let payment_hash = create_payment_hash();
 //! let secp_ctx = Secp256k1::new();
@@ -62,7 +62,7 @@
 //! # Ok(())
 //! # }
 //!
-//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::ParseError> {
+//! # fn parse_refund(bytes: Vec<u8>) -> Result<(), lightning::offers::parse::Bolt12ParseError> {
 //! # let payment_paths = create_payment_paths();
 //! # let payment_hash = create_payment_hash();
 //! # let secp_ctx = Secp256k1::new();
@@ -112,7 +112,7 @@ use crate::ln::msgs::DecodeError;
 use crate::offers::invoice_request::{INVOICE_REQUEST_PAYER_ID_TYPE, INVOICE_REQUEST_TYPES, IV_BYTES as INVOICE_REQUEST_IV_BYTES, InvoiceRequest, InvoiceRequestContents, InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
 use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, TlvStream, WithoutSignatures, self};
 use crate::offers::offer::{Amount, OFFER_TYPES, OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::refund::{IV_BYTES as REFUND_IV_BYTES, Refund, RefundContents};
 use crate::offers::signer;
@@ -128,7 +128,7 @@ const DEFAULT_RELATIVE_EXPIRY: Duration = Duration::from_secs(7200);
 
 pub(super) const SIGNATURE_TAG: &'static str = concat!("lightning", "invoice", "signature");
 
-/// Builds an [`Invoice`] from either:
+/// Builds a [`Bolt12Invoice`] from either:
 /// - an [`InvoiceRequest`] for the "offer to be paid" flow or
 /// - a [`Refund`] for the "offer for money" flow.
 ///
@@ -146,17 +146,17 @@ pub struct InvoiceBuilder<'a, S: SigningPubkeyStrategy> {
        signing_pubkey_strategy: core::marker::PhantomData<S>,
 }
 
-/// Indicates how [`Invoice::signing_pubkey`] was set.
+/// Indicates how [`Bolt12Invoice::signing_pubkey`] was set.
 ///
 /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
 pub trait SigningPubkeyStrategy {}
 
-/// [`Invoice::signing_pubkey`] was explicitly set.
+/// [`Bolt12Invoice::signing_pubkey`] was explicitly set.
 ///
 /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
 pub struct ExplicitSigningPubkey {}
 
-/// [`Invoice::signing_pubkey`] was derived.
+/// [`Bolt12Invoice::signing_pubkey`] was derived.
 ///
 /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
 pub struct DerivedSigningPubkey {}
@@ -168,7 +168,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
        pub(super) fn for_offer(
                invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
                created_at: Duration, payment_hash: PaymentHash
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = Self::check_amount_msats(invoice_request)?;
                let signing_pubkey = invoice_request.contents.inner.offer.signing_pubkey();
                let contents = InvoiceContents::ForOffer {
@@ -184,7 +184,7 @@ impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
        pub(super) fn for_refund(
                refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
                payment_hash: PaymentHash, signing_pubkey: PublicKey
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = refund.amount_msats();
                let contents = InvoiceContents::ForRefund {
                        refund: refund.contents.clone(),
@@ -201,7 +201,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        pub(super) fn for_offer_using_keys(
                invoice_request: &'a InvoiceRequest, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
                created_at: Duration, payment_hash: PaymentHash, keys: KeyPair
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = Self::check_amount_msats(invoice_request)?;
                let signing_pubkey = invoice_request.contents.inner.offer.signing_pubkey();
                let contents = InvoiceContents::ForOffer {
@@ -217,7 +217,7 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        pub(super) fn for_refund_using_keys(
                refund: &'a Refund, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, created_at: Duration,
                payment_hash: PaymentHash, keys: KeyPair,
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                let amount_msats = refund.amount_msats();
                let signing_pubkey = keys.public_key();
                let contents = InvoiceContents::ForRefund {
@@ -232,16 +232,16 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
 }
 
 impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
-       fn check_amount_msats(invoice_request: &InvoiceRequest) -> Result<u64, SemanticError> {
+       fn check_amount_msats(invoice_request: &InvoiceRequest) -> Result<u64, Bolt12SemanticError> {
                match invoice_request.amount_msats() {
                        Some(amount_msats) => Ok(amount_msats),
                        None => match invoice_request.contents.inner.offer.amount() {
                                Some(Amount::Bitcoin { amount_msats }) => {
                                        amount_msats.checked_mul(invoice_request.quantity().unwrap_or(1))
-                                               .ok_or(SemanticError::InvalidAmount)
+                                               .ok_or(Bolt12SemanticError::InvalidAmount)
                                },
-                               Some(Amount::Currency { .. }) => Err(SemanticError::UnsupportedCurrency),
-                               None => Err(SemanticError::MissingAmount),
+                               Some(Amount::Currency { .. }) => Err(Bolt12SemanticError::UnsupportedCurrency),
+                               None => Err(Bolt12SemanticError::MissingAmount),
                        },
                }
        }
@@ -258,9 +258,9 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
 
        fn new(
                invreq_bytes: &'a Vec<u8>, contents: InvoiceContents, keys: Option<KeyPair>
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                if contents.fields().payment_paths.is_empty() {
-                       return Err(SemanticError::MissingPaths);
+                       return Err(Bolt12SemanticError::MissingPaths);
                }
 
                Ok(Self {
@@ -271,8 +271,9 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
                })
        }
 
-       /// Sets the [`Invoice::relative_expiry`] as seconds since [`Invoice::created_at`]. Any expiry
-       /// that has already passed is valid and can be checked for using [`Invoice::is_expired`].
+       /// Sets the [`Bolt12Invoice::relative_expiry`] as seconds since [`Bolt12Invoice::created_at`].
+       /// Any expiry that has already passed is valid and can be checked for using
+       /// [`Bolt12Invoice::is_expired`].
        ///
        /// Successive calls to this method will override the previous setting.
        pub fn relative_expiry(mut self, relative_expiry_secs: u32) -> Self {
@@ -281,7 +282,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
                self
        }
 
-       /// Adds a P2WSH address to [`Invoice::fallbacks`].
+       /// Adds a P2WSH address to [`Bolt12Invoice::fallbacks`].
        ///
        /// Successive calls to this method will add another address. Caller is responsible for not
        /// adding duplicate addresses and only calling if capable of receiving to P2WSH addresses.
@@ -294,7 +295,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
                self
        }
 
-       /// Adds a P2WPKH address to [`Invoice::fallbacks`].
+       /// Adds a P2WPKH address to [`Bolt12Invoice::fallbacks`].
        ///
        /// Successive calls to this method will add another address. Caller is responsible for not
        /// adding duplicate addresses and only calling if capable of receiving to P2WPKH addresses.
@@ -307,7 +308,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
                self
        }
 
-       /// Adds a P2TR address to [`Invoice::fallbacks`].
+       /// Adds a P2TR address to [`Bolt12Invoice::fallbacks`].
        ///
        /// Successive calls to this method will add another address. Caller is responsible for not
        /// adding duplicate addresses and only calling if capable of receiving to P2TR addresses.
@@ -320,7 +321,7 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
                self
        }
 
-       /// Sets [`Invoice::features`] to indicate MPP may be used. Otherwise, MPP is disallowed.
+       /// Sets [`Bolt12Invoice::features`] to indicate MPP may be used. Otherwise, MPP is disallowed.
        pub fn allow_mpp(mut self) -> Self {
                self.invoice.fields_mut().features.set_basic_mpp_optional();
                self
@@ -328,33 +329,33 @@ impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
 }
 
 impl<'a> InvoiceBuilder<'a, ExplicitSigningPubkey> {
-       /// Builds an unsigned [`Invoice`] after checking for valid semantics. It can be signed by
-       /// [`UnsignedInvoice::sign`].
-       pub fn build(self) -> Result<UnsignedInvoice<'a>, SemanticError> {
+       /// Builds an unsigned [`Bolt12Invoice`] after checking for valid semantics. It can be signed by
+       /// [`UnsignedBolt12Invoice::sign`].
+       pub fn build(self) -> Result<UnsignedBolt12Invoice<'a>, Bolt12SemanticError> {
                #[cfg(feature = "std")] {
                        if self.invoice.is_offer_or_refund_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
                let InvoiceBuilder { invreq_bytes, invoice, .. } = self;
-               Ok(UnsignedInvoice { invreq_bytes, invoice })
+               Ok(UnsignedBolt12Invoice { invreq_bytes, invoice })
        }
 }
 
 impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
-       /// Builds a signed [`Invoice`] after checking for valid semantics.
+       /// Builds a signed [`Bolt12Invoice`] after checking for valid semantics.
        pub fn build_and_sign<T: secp256k1::Signing>(
                self, secp_ctx: &Secp256k1<T>
-       ) -> Result<Invoice, SemanticError> {
+       ) -> Result<Bolt12Invoice, Bolt12SemanticError> {
                #[cfg(feature = "std")] {
                        if self.invoice.is_offer_or_refund_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
                let InvoiceBuilder { invreq_bytes, invoice, keys, .. } = self;
-               let unsigned_invoice = UnsignedInvoice { invreq_bytes, invoice };
+               let unsigned_invoice = UnsignedBolt12Invoice { invreq_bytes, invoice };
 
                let keys = keys.unwrap();
                let invoice = unsigned_invoice
@@ -364,13 +365,13 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
        }
 }
 
-/// A semantically valid [`Invoice`] that hasn't been signed.
-pub struct UnsignedInvoice<'a> {
+/// A semantically valid [`Bolt12Invoice`] that hasn't been signed.
+pub struct UnsignedBolt12Invoice<'a> {
        invreq_bytes: &'a Vec<u8>,
        invoice: InvoiceContents,
 }
 
-impl<'a> UnsignedInvoice<'a> {
+impl<'a> UnsignedBolt12Invoice<'a> {
        /// The public key corresponding to the key needed to sign the invoice.
        pub fn signing_pubkey(&self) -> PublicKey {
                self.invoice.fields().signing_pubkey
@@ -379,7 +380,7 @@ impl<'a> UnsignedInvoice<'a> {
        /// Signs the invoice using the given function.
        ///
        /// This is not exported to bindings users as functions aren't currently mapped.
-       pub fn sign<F, E>(self, sign: F) -> Result<Invoice, SignError<E>>
+       pub fn sign<F, E>(self, sign: F) -> Result<Bolt12Invoice, SignError<E>>
        where
                F: FnOnce(&Message) -> Result<Signature, E>
        {
@@ -402,7 +403,7 @@ impl<'a> UnsignedInvoice<'a> {
                };
                signature_tlv_stream.write(&mut bytes).unwrap();
 
-               Ok(Invoice {
+               Ok(Bolt12Invoice {
                        bytes,
                        contents: self.invoice,
                        signature,
@@ -410,39 +411,37 @@ impl<'a> UnsignedInvoice<'a> {
        }
 }
 
-/// An `Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
+/// A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
 ///
 /// An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
 /// directly after scanning a refund. It includes all the information needed to pay a recipient.
 ///
-/// This is not exported to bindings users as its name conflicts with the BOLT 11 Invoice type.
-///
 /// [`Offer`]: crate::offers::offer::Offer
 /// [`Refund`]: crate::offers::refund::Refund
 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
-pub struct Invoice {
+pub struct Bolt12Invoice {
        bytes: Vec<u8>,
        contents: InvoiceContents,
        signature: Signature,
 }
 
-/// The contents of an [`Invoice`] for responding to either an [`Offer`] or a [`Refund`].
+/// The contents of an [`Bolt12Invoice`] for responding to either an [`Offer`] or a [`Refund`].
 ///
 /// [`Offer`]: crate::offers::offer::Offer
 /// [`Refund`]: crate::offers::refund::Refund
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 enum InvoiceContents {
-       /// Contents for an [`Invoice`] corresponding to an [`Offer`].
+       /// Contents for an [`Bolt12Invoice`] corresponding to an [`Offer`].
        ///
        /// [`Offer`]: crate::offers::offer::Offer
        ForOffer {
                invoice_request: InvoiceRequestContents,
                fields: InvoiceFields,
        },
-       /// Contents for an [`Invoice`] corresponding to a [`Refund`].
+       /// Contents for an [`Bolt12Invoice`] corresponding to a [`Refund`].
        ///
        /// [`Refund`]: crate::offers::refund::Refund
        ForRefund {
@@ -464,7 +463,7 @@ struct InvoiceFields {
        signing_pubkey: PublicKey,
 }
 
-impl Invoice {
+impl Bolt12Invoice {
        /// A complete description of the purpose of the originating offer or refund. Intended to be
        /// displayed to the user but with the caveat that it has not been verified in any way.
        pub fn description(&self) -> PrintableString {
@@ -475,7 +474,7 @@ impl Invoice {
        /// needed for routing payments across them.
        ///
        /// Blinded paths provide recipient privacy by obfuscating its node id. Note, however, that this
-       /// privacy is lost if a public node id is used for [`Invoice::signing_pubkey`].
+       /// privacy is lost if a public node id is used for [`Bolt12Invoice::signing_pubkey`].
        pub fn payment_paths(&self) -> &[(BlindedPayInfo, BlindedPath)] {
                &self.contents.fields().payment_paths[..]
        }
@@ -485,8 +484,8 @@ impl Invoice {
                self.contents.fields().created_at
        }
 
-       /// Duration since [`Invoice::created_at`] when the invoice has expired and therefore should no
-       /// longer be paid.
+       /// Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
+       /// should no longer be paid.
        pub fn relative_expiry(&self) -> Duration {
                self.contents.fields().relative_expiry.unwrap_or(DEFAULT_RELATIVE_EXPIRY)
        }
@@ -579,7 +578,7 @@ impl Invoice {
                self.contents.fields().signing_pubkey
        }
 
-       /// Signature of the invoice verified using [`Invoice::signing_pubkey`].
+       /// Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
        pub fn signature(&self) -> Signature {
                self.signature
        }
@@ -716,7 +715,7 @@ impl InvoiceFields {
        }
 }
 
-impl Writeable for Invoice {
+impl Writeable for Bolt12Invoice {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                WithoutLength(&self.bytes).write(writer)
        }
@@ -728,12 +727,12 @@ impl Writeable for InvoiceContents {
        }
 }
 
-impl TryFrom<Vec<u8>> for Invoice {
-       type Error = ParseError;
+impl TryFrom<Vec<u8>> for Bolt12Invoice {
+       type Error = Bolt12ParseError;
 
        fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
                let parsed_invoice = ParsedMessage::<FullInvoiceTlvStream>::try_from(bytes)?;
-               Invoice::try_from(parsed_invoice)
+               Bolt12Invoice::try_from(parsed_invoice)
        }
 }
 
@@ -840,8 +839,8 @@ type PartialInvoiceTlvStreamRef<'a> = (
        InvoiceTlvStreamRef<'a>,
 );
 
-impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Invoice {
-       type Error = ParseError;
+impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
+       type Error = Bolt12ParseError;
 
        fn try_from(invoice: ParsedMessage<FullInvoiceTlvStream>) -> Result<Self, Self::Error> {
                let ParsedMessage { bytes, tlv_stream } = invoice;
@@ -854,18 +853,18 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Invoice {
                )?;
 
                let signature = match signature {
-                       None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       None => return Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                        Some(signature) => signature,
                };
                let pubkey = contents.fields().signing_pubkey;
                merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, pubkey)?;
 
-               Ok(Invoice { bytes, contents, signature })
+               Ok(Bolt12Invoice { bytes, contents, signature })
        }
 }
 
 impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: PartialInvoiceTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -879,11 +878,11 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                ) = tlv_stream;
 
                let payment_paths = match (blindedpay, paths) {
-                       (_, None) => return Err(SemanticError::MissingPaths),
-                       (None, _) => return Err(SemanticError::InvalidPayInfo),
-                       (_, Some(paths)) if paths.is_empty() => return Err(SemanticError::MissingPaths),
+                       (_, None) => return Err(Bolt12SemanticError::MissingPaths),
+                       (None, _) => return Err(Bolt12SemanticError::InvalidPayInfo),
+                       (_, Some(paths)) if paths.is_empty() => return Err(Bolt12SemanticError::MissingPaths),
                        (Some(blindedpay), Some(paths)) if paths.len() != blindedpay.len() => {
-                               return Err(SemanticError::InvalidPayInfo);
+                               return Err(Bolt12SemanticError::InvalidPayInfo);
                        },
                        (Some(blindedpay), Some(paths)) => {
                                blindedpay.into_iter().zip(paths.into_iter()).collect::<Vec<_>>()
@@ -891,7 +890,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                };
 
                let created_at = match created_at {
-                       None => return Err(SemanticError::MissingCreationTime),
+                       None => return Err(Bolt12SemanticError::MissingCreationTime),
                        Some(timestamp) => Duration::from_secs(timestamp),
                };
 
@@ -900,19 +899,19 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                        .map(Duration::from_secs);
 
                let payment_hash = match payment_hash {
-                       None => return Err(SemanticError::MissingPaymentHash),
+                       None => return Err(Bolt12SemanticError::MissingPaymentHash),
                        Some(payment_hash) => payment_hash,
                };
 
                let amount_msats = match amount {
-                       None => return Err(SemanticError::MissingAmount),
+                       None => return Err(Bolt12SemanticError::MissingAmount),
                        Some(amount) => amount,
                };
 
                let features = features.unwrap_or_else(Bolt12InvoiceFeatures::empty);
 
                let signing_pubkey = match node_id {
-                       None => return Err(SemanticError::MissingSigningPubkey),
+                       None => return Err(Bolt12SemanticError::MissingSigningPubkey),
                        Some(node_id) => node_id,
                };
 
@@ -924,7 +923,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
                match offer_tlv_stream.node_id {
                        Some(expected_signing_pubkey) => {
                                if fields.signing_pubkey != expected_signing_pubkey {
-                                       return Err(SemanticError::InvalidSigningPubkey);
+                                       return Err(Bolt12SemanticError::InvalidSigningPubkey);
                                }
 
                                let invoice_request = InvoiceRequestContents::try_from(
@@ -944,7 +943,7 @@ impl TryFrom<PartialInvoiceTlvStream> for InvoiceContents {
 
 #[cfg(test)]
 mod tests {
-       use super::{DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, Invoice, InvoiceTlvStreamRef, SIGNATURE_TAG};
+       use super::{Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, FallbackAddress, FullInvoiceTlvStreamRef, InvoiceTlvStreamRef, SIGNATURE_TAG};
 
        use bitcoin::blockdata::script::Script;
        use bitcoin::hashes::Hash;
@@ -962,7 +961,7 @@ mod tests {
        use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
        use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
        use crate::offers::offer::{OfferBuilder, OfferTlvStreamRef, Quantity};
-       use crate::offers::parse::{ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::refund::RefundBuilder;
        use crate::offers::test_utils::*;
@@ -1066,7 +1065,7 @@ mod tests {
                        ),
                );
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
        }
@@ -1144,7 +1143,7 @@ mod tests {
                        ),
                );
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
        }
@@ -1181,7 +1180,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -1209,7 +1208,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -1254,7 +1253,7 @@ mod tests {
                        payment_paths(), payment_hash(), now(), &expanded_key, &secp_ctx
                ) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidMetadata),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidMetadata),
                }
 
                let desc = "foo".to_string();
@@ -1270,7 +1269,7 @@ mod tests {
                        payment_paths(), payment_hash(), now(), &expanded_key, &secp_ctx
                ) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidMetadata),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidMetadata),
                }
        }
 
@@ -1377,7 +1376,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1494,33 +1493,33 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.paths = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaths)),
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.blindedpay = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidPayInfo)),
                }
 
                let empty_payment_paths = vec![];
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.paths = Some(Iterable(empty_payment_paths.iter().map(|(_, path)| path)));
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaths)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaths)),
                }
 
                let mut payment_paths = payment_paths();
@@ -1528,9 +1527,9 @@ mod tests {
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.blindedpay = Some(Iterable(payment_paths.iter().map(|(payinfo, _)| payinfo)));
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidPayInfo)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidPayInfo)),
                }
        }
 
@@ -1549,17 +1548,17 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.created_at = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingCreationTime));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingCreationTime));
                        },
                }
        }
@@ -1580,7 +1579,7 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               match Invoice::try_from(buffer) {
+               match Bolt12Invoice::try_from(buffer) {
                        Ok(invoice) => assert_eq!(invoice.relative_expiry(), Duration::from_secs(3600)),
                        Err(e) => panic!("error parsing invoice: {:?}", e),
                }
@@ -1601,17 +1600,17 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.payment_hash = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPaymentHash));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaymentHash));
                        },
                }
        }
@@ -1631,16 +1630,16 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.amount = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
        }
 
@@ -1660,7 +1659,7 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               match Invoice::try_from(buffer) {
+               match Bolt12Invoice::try_from(buffer) {
                        Ok(invoice) => {
                                let mut features = Bolt12InvoiceFeatures::empty();
                                features.set_basic_mpp_optional();
@@ -1705,7 +1704,7 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               match Invoice::try_from(buffer) {
+               match Bolt12Invoice::try_from(buffer) {
                        Ok(invoice) => {
                                assert_eq!(
                                        invoice.fallbacks(),
@@ -1749,17 +1748,17 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               if let Err(e) = Invoice::try_from(buffer) {
+               if let Err(e) = Bolt12Invoice::try_from(buffer) {
                        panic!("error parsing invoice: {:?}", e);
                }
 
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.node_id = None;
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
 
@@ -1767,10 +1766,10 @@ mod tests {
                let mut tlv_stream = invoice.as_tlv_stream();
                tlv_stream.3.node_id = Some(&invalid_pubkey);
 
-               match Invoice::try_from(tlv_stream.to_bytes()) {
+               match Bolt12Invoice::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidSigningPubkey));
                        },
                }
        }
@@ -1789,9 +1788,9 @@ mod tests {
                        .invoice
                        .write(&mut buffer).unwrap();
 
-               match Invoice::try_from(buffer) {
+               match Bolt12Invoice::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                }
        }
 
@@ -1812,10 +1811,10 @@ mod tests {
                let mut buffer = Vec::new();
                invoice.write(&mut buffer).unwrap();
 
-               match Invoice::try_from(buffer) {
+               match Bolt12Invoice::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
+                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
                        },
                }
        }
@@ -1838,9 +1837,9 @@ mod tests {
                BigSize(32).write(&mut encoded_invoice).unwrap();
                [42u8; 32].write(&mut encoded_invoice).unwrap();
 
-               match Invoice::try_from(encoded_invoice) {
+               match Bolt12Invoice::try_from(encoded_invoice) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
index e843264b4e3ed851afc5642fc1e8b5d0869854e5..122049b9295438b0147224a76c6efbc75455146c 100644 (file)
 
 use crate::io;
 use crate::ln::msgs::DecodeError;
-use crate::offers::parse::SemanticError;
+use crate::offers::parse::Bolt12SemanticError;
 use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
 use crate::util::string::UntrustedString;
 
 use crate::prelude::*;
 
-/// An error in response to an [`InvoiceRequest`] or an [`Invoice`].
+/// An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
 ///
 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub struct InvoiceError {
-       /// The field in the [`InvoiceRequest`] or the [`Invoice`] that contained an error.
+       /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
        ///
        /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        pub erroneous_field: Option<ErroneousField>,
 
        /// An explanation of the error.
        pub message: UntrustedString,
 }
 
-/// The field in the [`InvoiceRequest`] or the [`Invoice`] that contained an error.
+/// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
 ///
 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub struct ErroneousField {
@@ -93,8 +93,8 @@ impl Readable for InvoiceError {
        }
 }
 
-impl From<SemanticError> for InvoiceError {
-       fn from(error: SemanticError) -> Self {
+impl From<Bolt12SemanticError> for InvoiceError {
+       fn from(error: Bolt12SemanticError) -> Self {
                InvoiceError {
                        erroneous_field: None,
                        message: UntrustedString(format!("{:?}", error)),
index f51d2526781270d9e17b059b2a71fdc3bd1b04ad..f014bf120021b52b613a6726f988e8fb6b076f1b 100644 (file)
 //!
 //! An [`InvoiceRequest`] can be built from a parsed [`Offer`] as an "offer to be paid". It is
 //! typically constructed by a customer and sent to the merchant who had published the corresponding
-//! offer. The recipient of the request responds with an [`Invoice`].
+//! offer. The recipient of the request responds with a [`Bolt12Invoice`].
 //!
 //! For an "offer for money" (e.g., refund, ATM withdrawal), where an offer doesn't exist as a
 //! precursor, see [`Refund`].
 //!
-//! [`Invoice`]: crate::offers::invoice::Invoice
+//! [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 //! [`Refund`]: crate::offers::refund::Refund
 //!
 //! ```
@@ -30,7 +30,7 @@
 //! use lightning::offers::offer::Offer;
 //! use lightning::util::ser::Writeable;
 //!
-//! # fn parse() -> Result<(), lightning::offers::parse::ParseError> {
+//! # fn parse() -> Result<(), lightning::offers::parse::Bolt12ParseError> {
 //! let secp_ctx = Secp256k1::new();
 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32])?);
 //! let pubkey = PublicKey::from(keys);
@@ -68,7 +68,7 @@ use crate::ln::msgs::DecodeError;
 use crate::offers::invoice::{BlindedPayInfo, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
 use crate::offers::merkle::{SignError, SignatureTlvStream, SignatureTlvStreamRef, self};
 use crate::offers::offer::{Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
 use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::signer::{Metadata, MetadataMaterial};
 use crate::util::ser::{HighZeroBytesDroppedBigSize, SeekReadable, WithoutLength, Writeable, Writer};
@@ -171,10 +171,10 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// by the offer.
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn chain(mut self, network: Network) -> Result<Self, SemanticError> {
+       pub fn chain(mut self, network: Network) -> Result<Self, Bolt12SemanticError> {
                let chain = ChainHash::using_genesis_block(network);
                if !self.offer.supports_chain(chain) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                self.invoice_request.chain = Some(chain);
@@ -187,7 +187,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// Successive calls to this method will override the previous setting.
        ///
        /// [`quantity`]: Self::quantity
-       pub fn amount_msats(mut self, amount_msats: u64) -> Result<Self, SemanticError> {
+       pub fn amount_msats(mut self, amount_msats: u64) -> Result<Self, Bolt12SemanticError> {
                self.invoice_request.offer.check_amount_msats_for_quantity(
                        Some(amount_msats), self.invoice_request.quantity
                )?;
@@ -199,7 +199,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        /// does not conform to [`Offer::is_valid_quantity`].
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn quantity(mut self, quantity: u64) -> Result<Self, SemanticError> {
+       pub fn quantity(mut self, quantity: u64) -> Result<Self, Bolt12SemanticError> {
                self.invoice_request.offer.check_quantity(Some(quantity))?;
                self.invoice_request.quantity = Some(quantity);
                Ok(self)
@@ -215,17 +215,17 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
 
        fn build_with_checks(mut self) -> Result<
                (UnsignedInvoiceRequest<'a>, Option<KeyPair>, Option<&'b Secp256k1<T>>),
-               SemanticError
+               Bolt12SemanticError
        > {
                #[cfg(feature = "std")] {
                        if self.offer.is_expired() {
-                               return Err(SemanticError::AlreadyExpired);
+                               return Err(Bolt12SemanticError::AlreadyExpired);
                        }
                }
 
                let chain = self.invoice_request.chain();
                if !self.offer.supports_chain(chain) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                if chain == self.offer.implied_chain() {
@@ -233,7 +233,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
                }
 
                if self.offer.amount().is_none() && self.invoice_request.amount_msats.is_none() {
-                       return Err(SemanticError::MissingAmount);
+                       return Err(Bolt12SemanticError::MissingAmount);
                }
 
                self.invoice_request.offer.check_quantity(self.invoice_request.quantity)?;
@@ -247,7 +247,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
        fn build_without_checks(mut self) ->
                (UnsignedInvoiceRequest<'a>, Option<KeyPair>, Option<&'b Secp256k1<T>>)
        {
-               // Create the metadata for stateless verification of aInvoice.
+               // Create the metadata for stateless verification of a Bolt12Invoice.
                let mut keys = None;
                let secp_ctx = self.secp_ctx.clone();
                if self.invoice_request.payer.0.has_derivation_material() {
@@ -290,7 +290,7 @@ impl<'a, 'b, P: PayerIdStrategy, T: secp256k1::Signing> InvoiceRequestBuilder<'a
 impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerId, T> {
        /// Builds an unsigned [`InvoiceRequest`] after checking for valid semantics. It can be signed
        /// by [`UnsignedInvoiceRequest::sign`].
-       pub fn build(self) -> Result<UnsignedInvoiceRequest<'a>, SemanticError> {
+       pub fn build(self) -> Result<UnsignedInvoiceRequest<'a>, Bolt12SemanticError> {
                let (unsigned_invoice_request, keys, _) = self.build_with_checks()?;
                debug_assert!(keys.is_none());
                Ok(unsigned_invoice_request)
@@ -299,7 +299,7 @@ impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, ExplicitPayerI
 
 impl<'a, 'b, T: secp256k1::Signing> InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T> {
        /// Builds a signed [`InvoiceRequest`] after checking for valid semantics.
-       pub fn build_and_sign(self) -> Result<InvoiceRequest, SemanticError> {
+       pub fn build_and_sign(self) -> Result<InvoiceRequest, Bolt12SemanticError> {
                let (unsigned_invoice_request, keys, secp_ctx) = self.build_with_checks()?;
                debug_assert!(keys.is_some());
 
@@ -381,12 +381,12 @@ impl<'a> UnsignedInvoiceRequest<'a> {
        }
 }
 
-/// An `InvoiceRequest` is a request for an [`Invoice`] formulated from an [`Offer`].
+/// An `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`].
 ///
 /// An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request
 /// specifies these such that its recipient can send an invoice for payment.
 ///
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 /// [`Offer`]: crate::offers::offer::Offer
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
@@ -396,9 +396,9 @@ pub struct InvoiceRequest {
        signature: Signature,
 }
 
-/// The contents of an [`InvoiceRequest`], which may be shared with an [`Invoice`].
+/// The contents of an [`InvoiceRequest`], which may be shared with an [`Bolt12Invoice`].
 ///
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub(super) struct InvoiceRequestContents {
@@ -481,7 +481,7 @@ impl InvoiceRequest {
        #[cfg(feature = "std")]
        pub fn respond_with(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -492,8 +492,8 @@ impl InvoiceRequest {
        /// Creates an [`InvoiceBuilder`] for the request with the given required fields.
        ///
        /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
-       /// `created_at`, which is used to set [`Invoice::created_at`]. Useful for `no-std` builds where
-       /// [`std::time::SystemTime`] is not available.
+       /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds
+       /// where [`std::time::SystemTime`] is not available.
        ///
        /// The caller is expected to remember the preimage of `payment_hash` in order to claim a payment
        /// for the invoice.
@@ -507,32 +507,32 @@ impl InvoiceRequest {
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
+       /// [`Bolt12Invoice::created_at`]: crate::offers::invoice::Bolt12Invoice::created_at
        pub fn respond_with_no_std(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                InvoiceBuilder::for_offer(self, payment_paths, created_at, payment_hash)
        }
 
        /// Creates an [`InvoiceBuilder`] for the request using the given required fields and that uses
-       /// derived signing keys from the originating [`Offer`] to sign the [`Invoice`]. Must use the
-       /// same [`ExpandedKey`] as the one used to create the offer.
+       /// derived signing keys from the originating [`Offer`] to sign the [`Bolt12Invoice`]. Must use
+       /// the same [`ExpandedKey`] as the one used to create the offer.
        ///
        /// See [`InvoiceRequest::respond_with`] for further details.
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        #[cfg(feature = "std")]
        pub fn verify_and_respond_using_derived_keys<T: secp256k1::Signing>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -543,25 +543,25 @@ impl InvoiceRequest {
        }
 
        /// Creates an [`InvoiceBuilder`] for the request using the given required fields and that uses
-       /// derived signing keys from the originating [`Offer`] to sign the [`Invoice`]. Must use the
-       /// same [`ExpandedKey`] as the one used to create the offer.
+       /// derived signing keys from the originating [`Offer`] to sign the [`Bolt12Invoice`]. Must use
+       /// the same [`ExpandedKey`] as the one used to create the offer.
        ///
        /// See [`InvoiceRequest::respond_with_no_std`] for further details.
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        pub fn verify_and_respond_using_derived_keys_no_std<T: secp256k1::Signing>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration, expanded_key: &ExpandedKey, secp_ctx: &Secp256k1<T>
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                let keys = match self.verify(expanded_key, secp_ctx) {
-                       Err(()) => return Err(SemanticError::InvalidMetadata),
-                       Ok(None) => return Err(SemanticError::InvalidMetadata),
+                       Err(()) => return Err(Bolt12SemanticError::InvalidMetadata),
+                       Ok(None) => return Err(Bolt12SemanticError::InvalidMetadata),
                        Ok(Some(keys)) => keys,
                };
 
@@ -569,10 +569,10 @@ impl InvoiceRequest {
        }
 
        /// Verifies that the request was for an offer created using the given key. Returns the derived
-       /// keys need to sign an [`Invoice`] for the request if they could be extracted from the
+       /// keys need to sign an [`Bolt12Invoice`] for the request if they could be extracted from the
        /// metadata.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        pub fn verify<T: secp256k1::Signing>(
                &self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
        ) -> Result<Option<KeyPair>, ()> {
@@ -708,7 +708,7 @@ type PartialInvoiceRequestTlvStreamRef<'a> = (
 );
 
 impl TryFrom<Vec<u8>> for InvoiceRequest {
-       type Error = ParseError;
+       type Error = Bolt12ParseError;
 
        fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
                let invoice_request = ParsedMessage::<FullInvoiceRequestTlvStream>::try_from(bytes)?;
@@ -722,7 +722,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
                )?;
 
                let signature = match signature {
-                       None => return Err(ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       None => return Err(Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                        Some(signature) => signature,
                };
                merkle::verify_signature(&signature, SIGNATURE_TAG, &bytes, contents.payer_id)?;
@@ -732,7 +732,7 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
 }
 
 impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: PartialInvoiceRequestTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -742,17 +742,17 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                ) = tlv_stream;
 
                let payer = match metadata {
-                       None => return Err(SemanticError::MissingPayerMetadata),
+                       None => return Err(Bolt12SemanticError::MissingPayerMetadata),
                        Some(metadata) => PayerContents(Metadata::Bytes(metadata)),
                };
                let offer = OfferContents::try_from(offer_tlv_stream)?;
 
                if !offer.supports_chain(chain.unwrap_or_else(|| offer.implied_chain())) {
-                       return Err(SemanticError::UnsupportedChain);
+                       return Err(Bolt12SemanticError::UnsupportedChain);
                }
 
                if offer.amount().is_none() && amount.is_none() {
-                       return Err(SemanticError::MissingAmount);
+                       return Err(Bolt12SemanticError::MissingAmount);
                }
 
                offer.check_quantity(quantity)?;
@@ -761,7 +761,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
                let features = features.unwrap_or_else(InvoiceRequestFeatures::empty);
 
                let payer_id = match payer_id {
-                       None => return Err(SemanticError::MissingPayerId),
+                       None => return Err(Bolt12SemanticError::MissingPayerId),
                        Some(payer_id) => payer_id,
                };
 
@@ -789,10 +789,10 @@ mod tests {
        use crate::ln::features::InvoiceRequestFeatures;
        use crate::ln::inbound_payment::ExpandedKey;
        use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
-       use crate::offers::invoice::{Invoice, SIGNATURE_TAG as INVOICE_SIGNATURE_TAG};
+       use crate::offers::invoice::{Bolt12Invoice, SIGNATURE_TAG as INVOICE_SIGNATURE_TAG};
        use crate::offers::merkle::{SignError, SignatureTlvStreamRef, self};
        use crate::offers::offer::{Amount, OfferBuilder, OfferTlvStreamRef, Quantity};
-       use crate::offers::parse::{ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
@@ -882,7 +882,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::AlreadyExpired),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::AlreadyExpired),
                }
        }
 
@@ -930,7 +930,7 @@ mod tests {
                let mut encoded_invoice = bytes;
                signature_tlv_stream.write(&mut encoded_invoice).unwrap();
 
-               let invoice = Invoice::try_from(encoded_invoice).unwrap();
+               let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
                assert!(!invoice.verify(&expanded_key, &secp_ctx));
 
                // Fails verification with altered metadata
@@ -954,7 +954,7 @@ mod tests {
                let mut encoded_invoice = bytes;
                signature_tlv_stream.write(&mut encoded_invoice).unwrap();
 
-               let invoice = Invoice::try_from(encoded_invoice).unwrap();
+               let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
                assert!(!invoice.verify(&expanded_key, &secp_ctx));
        }
 
@@ -1000,7 +1000,7 @@ mod tests {
                let mut encoded_invoice = bytes;
                signature_tlv_stream.write(&mut encoded_invoice).unwrap();
 
-               let invoice = Invoice::try_from(encoded_invoice).unwrap();
+               let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
                assert!(!invoice.verify(&expanded_key, &secp_ctx));
 
                // Fails verification with altered payer id
@@ -1024,7 +1024,7 @@ mod tests {
                let mut encoded_invoice = bytes;
                signature_tlv_stream.write(&mut encoded_invoice).unwrap();
 
-               let invoice = Invoice::try_from(encoded_invoice).unwrap();
+               let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
                assert!(!invoice.verify(&expanded_key, &secp_ctx));
        }
 
@@ -1091,7 +1091,7 @@ mod tests {
                        .chain(Network::Bitcoin)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedChain),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1102,7 +1102,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedChain),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
                }
        }
 
@@ -1149,7 +1149,7 @@ mod tests {
                        .amount_msats(999)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1161,7 +1161,7 @@ mod tests {
                        .amount_msats(1000)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1171,7 +1171,7 @@ mod tests {
                        .amount_msats(MAX_VALUE_MSAT + 1)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1184,7 +1184,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InsufficientAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InsufficientAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1193,7 +1193,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingAmount),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1205,7 +1205,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1260,7 +1260,7 @@ mod tests {
                        .quantity(2)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnexpectedQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnexpectedQuantity),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1285,7 +1285,7 @@ mod tests {
                        .quantity(11)
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidQuantity),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1309,7 +1309,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity),
                }
 
                match OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1320,7 +1320,7 @@ mod tests {
                        .build()
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::MissingQuantity),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::MissingQuantity),
                }
        }
 
@@ -1387,7 +1387,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1438,7 +1438,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnsupportedChain)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnsupportedChain)),
                }
        }
 
@@ -1483,7 +1483,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1499,7 +1499,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InsufficientAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InsufficientAmount)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1515,7 +1515,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnsupportedCurrency));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnsupportedCurrency));
                        },
                }
 
@@ -1533,7 +1533,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount)),
                }
        }
 
@@ -1573,7 +1573,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedQuantity));
                        },
                }
 
@@ -1609,7 +1609,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidQuantity)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1642,7 +1642,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingQuantity)),
                }
 
                let invoice_request = OfferBuilder::new("foo".into(), recipient_pubkey())
@@ -1658,7 +1658,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingQuantity)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingQuantity)),
                }
        }
 
@@ -1678,7 +1678,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerMetadata));
                        },
                }
        }
@@ -1698,7 +1698,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerId)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId)),
                }
        }
 
@@ -1718,7 +1718,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
        }
@@ -1736,7 +1736,7 @@ mod tests {
 
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSignature)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSignature)),
                }
        }
 
@@ -1757,7 +1757,7 @@ mod tests {
                match InvoiceRequest::try_from(buffer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
+                               assert_eq!(e, Bolt12ParseError::InvalidSignature(secp256k1::Error::InvalidSignature));
                        },
                }
        }
@@ -1782,7 +1782,7 @@ mod tests {
 
                match InvoiceRequest::try_from(encoded_invoice_request) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
index 9c8489778b08eaee1e444fe3f2584345c5224582..d801be9d26fb969c0b89af9b84a5e7408726efea 100644 (file)
@@ -24,7 +24,7 @@
 //!
 //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
 //! use lightning::offers::offer::{Offer, OfferBuilder, Quantity};
-//! use lightning::offers::parse::ParseError;
+//! use lightning::offers::parse::Bolt12ParseError;
 //! use lightning::util::ser::{Readable, Writeable};
 //!
 //! # use lightning::blinded_path::BlindedPath;
@@ -35,7 +35,7 @@
 //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
 //! #
 //! # #[cfg(feature = "std")]
-//! # fn build() -> Result<(), ParseError> {
+//! # fn build() -> Result<(), Bolt12ParseError> {
 //! let secp_ctx = Secp256k1::new();
 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
 //! let pubkey = PublicKey::from(keys);
@@ -82,7 +82,7 @@ use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
 use crate::ln::msgs::MAX_VALUE_MSAT;
 use crate::offers::invoice_request::{DerivedPayerId, ExplicitPayerId, InvoiceRequestBuilder};
 use crate::offers::merkle::TlvStream;
-use crate::offers::parse::{Bech32Encode, ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::signer::{Metadata, MetadataMaterial, self};
 use crate::util::ser::{HighZeroBytesDroppedBigSize, WithoutLength, Writeable, Writer};
 use crate::util::string::PrintableString;
@@ -146,7 +146,7 @@ impl<'a> OfferBuilder<'a, ExplicitMetadata, secp256k1::SignOnly> {
        /// Sets the [`Offer::metadata`] to the given bytes.
        ///
        /// Successive calls to this method will override the previous setting.
-       pub fn metadata(mut self, metadata: Vec<u8>) -> Result<Self, SemanticError> {
+       pub fn metadata(mut self, metadata: Vec<u8>) -> Result<Self, Bolt12SemanticError> {
                self.offer.metadata = Some(Metadata::Bytes(metadata));
                Ok(self)
        }
@@ -252,14 +252,14 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
        }
 
        /// Builds an [`Offer`] from the builder's settings.
-       pub fn build(mut self) -> Result<Offer, SemanticError> {
+       pub fn build(mut self) -> Result<Offer, Bolt12SemanticError> {
                match self.offer.amount {
                        Some(Amount::Bitcoin { amount_msats }) => {
                                if amount_msats > MAX_VALUE_MSAT {
-                                       return Err(SemanticError::InvalidAmount);
+                                       return Err(Bolt12SemanticError::InvalidAmount);
                                }
                        },
-                       Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+                       Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
                        None => {},
                }
 
@@ -319,8 +319,8 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
 /// An `Offer` is a potentially long-lived proposal for payment of a good or service.
 ///
 /// An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
-/// customer may request an [`Invoice`] for a specific quantity and using an amount sufficient to
-/// cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
+/// customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
+/// to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
 ///
 /// Offers may be denominated in currency other than bitcoin but are ultimately paid using the
 /// latter.
@@ -328,7 +328,7 @@ impl<'a, M: MetadataStrategy, T: secp256k1::Signing> OfferBuilder<'a, M, T> {
 /// Through the use of [`BlindedPath`]s, offers provide recipient privacy.
 ///
 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub struct Offer {
@@ -338,10 +338,11 @@ pub struct Offer {
        pub(super) contents: OfferContents,
 }
 
-/// The contents of an [`Offer`], which may be shared with an [`InvoiceRequest`] or an [`Invoice`].
+/// The contents of an [`Offer`], which may be shared with an [`InvoiceRequest`] or a
+/// [`Bolt12Invoice`].
 ///
 /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub(super) struct OfferContents {
@@ -451,8 +452,8 @@ impl Offer {
        /// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
        ///   request, and
        /// - sets the [`InvoiceRequest::metadata`] when [`InvoiceRequestBuilder::build`] is called such
-       ///   that it can be used by [`Invoice::verify`] to determine if the invoice was requested using
-       ///   a base [`ExpandedKey`] from which the payer id was derived.
+       ///   that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was requested
+       ///   using a base [`ExpandedKey`] from which the payer id was derived.
        ///
        /// Useful to protect the sender's privacy.
        ///
@@ -460,16 +461,16 @@ impl Offer {
        ///
        /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
        /// [`InvoiceRequest::metadata`]: crate::offers::invoice_request::InvoiceRequest::metadata
-       /// [`Invoice::verify`]: crate::offers::invoice::Invoice::verify
+       /// [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
        /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
        pub fn request_invoice_deriving_payer_id<'a, 'b, ES: Deref, T: secp256k1::Signing>(
                &'a self, expanded_key: &ExpandedKey, entropy_source: ES, secp_ctx: &'b Secp256k1<T>
-       ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T>, SemanticError>
+       ) -> Result<InvoiceRequestBuilder<'a, 'b, DerivedPayerId, T>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::deriving_payer_id(self, expanded_key, entropy_source, secp_ctx))
@@ -485,19 +486,19 @@ impl Offer {
        /// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
        pub fn request_invoice_deriving_metadata<ES: Deref>(
                &self, payer_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, SemanticError>
+       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::deriving_metadata(self, payer_id, expanded_key, entropy_source))
        }
 
        /// Creates an [`InvoiceRequestBuilder`] for the offer with the given `metadata` and `payer_id`,
-       /// which will be reflected in the `Invoice` response.
+       /// which will be reflected in the `Bolt12Invoice` response.
        ///
        /// The `metadata` is useful for including information about the derivation of `payer_id` such
        /// that invoice response handling can be stateless. Also serves as payer-provided entropy while
@@ -513,9 +514,9 @@ impl Offer {
        /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
        pub fn request_invoice(
                &self, metadata: Vec<u8>, payer_id: PublicKey
-       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, SemanticError> {
+       ) -> Result<InvoiceRequestBuilder<ExplicitPayerId, secp256k1::SignOnly>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                Ok(InvoiceRequestBuilder::new(self, metadata, payer_id))
@@ -571,24 +572,24 @@ impl OfferContents {
 
        pub(super) fn check_amount_msats_for_quantity(
                &self, amount_msats: Option<u64>, quantity: Option<u64>
-       ) -> Result<(), SemanticError> {
+       ) -> Result<(), Bolt12SemanticError> {
                let offer_amount_msats = match self.amount {
                        None => 0,
                        Some(Amount::Bitcoin { amount_msats }) => amount_msats,
-                       Some(Amount::Currency { .. }) => return Err(SemanticError::UnsupportedCurrency),
+                       Some(Amount::Currency { .. }) => return Err(Bolt12SemanticError::UnsupportedCurrency),
                };
 
                if !self.expects_quantity() || quantity.is_some() {
                        let expected_amount_msats = offer_amount_msats.checked_mul(quantity.unwrap_or(1))
-                               .ok_or(SemanticError::InvalidAmount)?;
+                               .ok_or(Bolt12SemanticError::InvalidAmount)?;
                        let amount_msats = amount_msats.unwrap_or(expected_amount_msats);
 
                        if amount_msats < expected_amount_msats {
-                               return Err(SemanticError::InsufficientAmount);
+                               return Err(Bolt12SemanticError::InsufficientAmount);
                        }
 
                        if amount_msats > MAX_VALUE_MSAT {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        }
                }
 
@@ -599,13 +600,13 @@ impl OfferContents {
                self.supported_quantity
        }
 
-       pub(super) fn check_quantity(&self, quantity: Option<u64>) -> Result<(), SemanticError> {
+       pub(super) fn check_quantity(&self, quantity: Option<u64>) -> Result<(), Bolt12SemanticError> {
                let expects_quantity = self.expects_quantity();
                match quantity {
-                       None if expects_quantity => Err(SemanticError::MissingQuantity),
-                       Some(_) if !expects_quantity => Err(SemanticError::UnexpectedQuantity),
+                       None if expects_quantity => Err(Bolt12SemanticError::MissingQuantity),
+                       Some(_) if !expects_quantity => Err(Bolt12SemanticError::UnexpectedQuantity),
                        Some(quantity) if !self.is_valid_quantity(quantity) => {
-                               Err(SemanticError::InvalidQuantity)
+                               Err(Bolt12SemanticError::InvalidQuantity)
                        },
                        _ => Ok(()),
                }
@@ -767,7 +768,7 @@ impl Bech32Encode for Offer {
 }
 
 impl FromStr for Offer {
-       type Err = ParseError;
+       type Err = Bolt12ParseError;
 
        fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
                Self::from_bech32_str(s)
@@ -775,7 +776,7 @@ impl FromStr for Offer {
 }
 
 impl TryFrom<Vec<u8>> for Offer {
-       type Error = ParseError;
+       type Error = Bolt12ParseError;
 
        fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
                let offer = ParsedMessage::<OfferTlvStream>::try_from(bytes)?;
@@ -786,7 +787,7 @@ impl TryFrom<Vec<u8>> for Offer {
 }
 
 impl TryFrom<OfferTlvStream> for OfferContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: OfferTlvStream) -> Result<Self, Self::Error> {
                let OfferTlvStream {
@@ -799,15 +800,15 @@ impl TryFrom<OfferTlvStream> for OfferContents {
                let amount = match (currency, amount) {
                        (None, None) => None,
                        (None, Some(amount_msats)) if amount_msats > MAX_VALUE_MSAT => {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        },
                        (None, Some(amount_msats)) => Some(Amount::Bitcoin { amount_msats }),
-                       (Some(_), None) => return Err(SemanticError::MissingAmount),
+                       (Some(_), None) => return Err(Bolt12SemanticError::MissingAmount),
                        (Some(iso4217_code), Some(amount)) => Some(Amount::Currency { iso4217_code, amount }),
                };
 
                let description = match description {
-                       None => return Err(SemanticError::MissingDescription),
+                       None => return Err(Bolt12SemanticError::MissingDescription),
                        Some(description) => description,
                };
 
@@ -823,7 +824,7 @@ impl TryFrom<OfferTlvStream> for OfferContents {
                };
 
                let signing_pubkey = match node_id {
-                       None => return Err(SemanticError::MissingSigningPubkey),
+                       None => return Err(Bolt12SemanticError::MissingSigningPubkey),
                        Some(node_id) => node_id,
                };
 
@@ -855,7 +856,7 @@ mod tests {
        use crate::ln::features::OfferFeatures;
        use crate::ln::inbound_payment::ExpandedKey;
        use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
-       use crate::offers::parse::{ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
        use crate::util::string::PrintableString;
@@ -1089,7 +1090,7 @@ mod tests {
                assert_eq!(tlv_stream.currency, Some(b"USD"));
                match builder.build() {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnsupportedCurrency),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedCurrency),
                }
 
                let offer = OfferBuilder::new("foo".into(), pubkey(42))
@@ -1104,7 +1105,7 @@ mod tests {
                let invalid_amount = Amount::Bitcoin { amount_msats: MAX_VALUE_MSAT + 1 };
                match OfferBuilder::new("foo".into(), pubkey(42)).amount(invalid_amount).build() {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1258,7 +1259,7 @@ mod tests {
                        .request_invoice(vec![1; 32], pubkey(43))
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1304,7 +1305,7 @@ mod tests {
 
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount)),
                }
 
                let mut tlv_stream = offer.as_tlv_stream();
@@ -1316,7 +1317,7 @@ mod tests {
 
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount)),
                }
        }
 
@@ -1336,7 +1337,7 @@ mod tests {
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingDescription));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingDescription));
                        },
                }
        }
@@ -1426,7 +1427,7 @@ mod tests {
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingSigningPubkey));
                        },
                }
        }
@@ -1443,14 +1444,14 @@ mod tests {
 
                match Offer::try_from(encoded_offer) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
 
 #[cfg(test)]
 mod bech32_tests {
-       use super::{Offer, ParseError};
+       use super::{Bolt12ParseError, Offer};
        use bitcoin::bech32;
        use crate::ln::msgs::DecodeError;
 
@@ -1492,7 +1493,7 @@ mod bech32_tests {
                for encoded_offer in &offers {
                        match encoded_offer.parse::<Offer>() {
                                Ok(_) => panic!("Valid offer: {}", encoded_offer),
-                               Err(e) => assert_eq!(e, ParseError::InvalidContinuation),
+                               Err(e) => assert_eq!(e, Bolt12ParseError::InvalidContinuation),
                        }
                }
 
@@ -1503,7 +1504,7 @@ mod bech32_tests {
                let encoded_offer = "lni1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxg";
                match encoded_offer.parse::<Offer>() {
                        Ok(_) => panic!("Valid offer: {}", encoded_offer),
-                       Err(e) => assert_eq!(e, ParseError::InvalidBech32Hrp),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::InvalidBech32Hrp),
                }
        }
 
@@ -1512,7 +1513,7 @@ mod bech32_tests {
                let encoded_offer = "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxo";
                match encoded_offer.parse::<Offer>() {
                        Ok(_) => panic!("Valid offer: {}", encoded_offer),
-                       Err(e) => assert_eq!(e, ParseError::Bech32(bech32::Error::InvalidChar('o'))),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Bech32(bech32::Error::InvalidChar('o'))),
                }
        }
 
@@ -1521,7 +1522,7 @@ mod bech32_tests {
                let encoded_offer = "lno1pqps7sjqpgtyzm3qv4uxzmtsd3jjqer9wd3hy6tsw35k7msjzfpy7nz5yqcnygrfdej82um5wf5k2uckyypwa3eyt44h6txtxquqh7lz5djge4afgfjn7k4rgrkuag0jsd5xvxgqqqqq";
                match encoded_offer.parse::<Offer>() {
                        Ok(_) => panic!("Valid offer: {}", encoded_offer),
-                       Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
index 42ed2e002d1f29b60169c86954f39cece3101647..b722499f251ad5213e1d27bbdb613da2c6aba2f7 100644 (file)
@@ -29,24 +29,24 @@ mod sealed {
        use bitcoin::bech32::{FromBase32, ToBase32};
        use core::convert::TryFrom;
        use core::fmt;
-       use super::ParseError;
+       use super::Bolt12ParseError;
 
        use crate::prelude::*;
 
        /// Indicates a message can be encoded using bech32.
-       pub trait Bech32Encode: AsRef<[u8]> + TryFrom<Vec<u8>, Error=ParseError> {
+       pub trait Bech32Encode: AsRef<[u8]> + TryFrom<Vec<u8>, Error=Bolt12ParseError> {
                /// Human readable part of the message's bech32 encoding.
                const BECH32_HRP: &'static str;
 
                /// Parses a bech32-encoded message into a TLV stream.
-               fn from_bech32_str(s: &str) -> Result<Self, ParseError> {
+               fn from_bech32_str(s: &str) -> Result<Self, Bolt12ParseError> {
                        // Offer encoding may be split by '+' followed by optional whitespace.
                        let encoded = match s.split('+').skip(1).next() {
                                Some(_) => {
                                        for chunk in s.split('+') {
                                                let chunk = chunk.trim_start();
                                                if chunk.is_empty() || chunk.contains(char::is_whitespace) {
-                                                       return Err(ParseError::InvalidContinuation);
+                                                       return Err(Bolt12ParseError::InvalidContinuation);
                                                }
                                        }
 
@@ -59,7 +59,7 @@ mod sealed {
                        let (hrp, data) = bech32::decode_without_checksum(encoded.as_ref())?;
 
                        if hrp != Self::BECH32_HRP {
-                               return Err(ParseError::InvalidBech32Hrp);
+                               return Err(Bolt12ParseError::InvalidBech32Hrp);
                        }
 
                        let data = Vec::<u8>::from_base32(&data)?;
@@ -116,10 +116,8 @@ impl<T: SeekReadable> TryFrom<Vec<u8>> for ParsedMessage<T> {
 }
 
 /// Error when parsing a bech32 encoded message using [`str::parse`].
-///
-/// This is not exported to bindings users as its name conflicts with the BOLT 11 ParseError type.
 #[derive(Debug, PartialEq)]
-pub enum ParseError {
+pub enum Bolt12ParseError {
        /// The bech32 encoding does not conform to the BOLT 12 requirements for continuing messages
        /// across multiple parts (i.e., '+' followed by whitespace).
        InvalidContinuation,
@@ -131,16 +129,14 @@ pub enum ParseError {
        /// The bech32 decoded string could not be decoded as the expected message type.
        Decode(DecodeError),
        /// The parsed message has invalid semantics.
-       InvalidSemantics(SemanticError),
+       InvalidSemantics(Bolt12SemanticError),
        /// The parsed message has an invalid signature.
        InvalidSignature(secp256k1::Error),
 }
 
 /// Error when interpreting a TLV stream as a specific type.
-///
-/// This is not exported to bindings users as its name conflicts with the BOLT 11 SemanticError type.
 #[derive(Debug, PartialEq)]
-pub enum SemanticError {
+pub enum Bolt12SemanticError {
        /// The current [`std::time::SystemTime`] is past the offer or invoice's expiration.
        AlreadyExpired,
        /// The provided chain hash does not correspond to a supported chain.
@@ -195,25 +191,25 @@ pub enum SemanticError {
        MissingSignature,
 }
 
-impl From<bech32::Error> for ParseError {
+impl From<bech32::Error> for Bolt12ParseError {
        fn from(error: bech32::Error) -> Self {
                Self::Bech32(error)
        }
 }
 
-impl From<DecodeError> for ParseError {
+impl From<DecodeError> for Bolt12ParseError {
        fn from(error: DecodeError) -> Self {
                Self::Decode(error)
        }
 }
 
-impl From<SemanticError> for ParseError {
-       fn from(error: SemanticError) -> Self {
+impl From<Bolt12SemanticError> for Bolt12ParseError {
+       fn from(error: Bolt12SemanticError) -> Self {
                Self::InvalidSemantics(error)
        }
 }
 
-impl From<secp256k1::Error> for ParseError {
+impl From<secp256k1::Error> for Bolt12ParseError {
        fn from(error: secp256k1::Error) -> Self {
                Self::InvalidSignature(error)
        }
index 07e759917acc54d5973c613e3e8d9826297f805c..2c8dffeb1516abfa7961d144581d412657861c2a 100644 (file)
 //! Data structures and encoding for refunds.
 //!
 //! A [`Refund`] is an "offer for money" and is typically constructed by a merchant and presented
-//! directly to the customer. The recipient responds with an [`Invoice`] to be paid.
+//! directly to the customer. The recipient responds with a [`Bolt12Invoice`] to be paid.
 //!
 //! This is an [`InvoiceRequest`] produced *not* in response to an [`Offer`].
 //!
-//! [`Invoice`]: crate::offers::invoice::Invoice
+//! [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 //! [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
 //! [`Offer`]: crate::offers::offer::Offer
 //!
@@ -28,7 +28,7 @@
 //!
 //! use bitcoin::network::constants::Network;
 //! use bitcoin::secp256k1::{KeyPair, PublicKey, Secp256k1, SecretKey};
-//! use lightning::offers::parse::ParseError;
+//! use lightning::offers::parse::Bolt12ParseError;
 //! use lightning::offers::refund::{Refund, RefundBuilder};
 //! use lightning::util::ser::{Readable, Writeable};
 //!
@@ -40,7 +40,7 @@
 //! # fn create_another_blinded_path() -> BlindedPath { unimplemented!() }
 //! #
 //! # #[cfg(feature = "std")]
-//! # fn build() -> Result<(), ParseError> {
+//! # fn build() -> Result<(), Bolt12ParseError> {
 //! let secp_ctx = Secp256k1::new();
 //! let keys = KeyPair::from_secret_key(&secp_ctx, &SecretKey::from_slice(&[42; 32]).unwrap());
 //! let pubkey = PublicKey::from(keys);
@@ -88,7 +88,7 @@ use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
 use crate::offers::invoice::{BlindedPayInfo, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder};
 use crate::offers::invoice_request::{InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
 use crate::offers::offer::{OfferTlvStream, OfferTlvStreamRef};
-use crate::offers::parse::{Bech32Encode, ParseError, ParsedMessage, SemanticError};
+use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
 use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
 use crate::offers::signer::{Metadata, MetadataMaterial, self};
 use crate::util::ser::{SeekReadable, WithoutLength, Writeable, Writer};
@@ -121,9 +121,9 @@ impl<'a> RefundBuilder<'a, secp256k1::SignOnly> {
        /// [`Refund::amount_msats`].
        pub fn new(
                description: String, metadata: Vec<u8>, payer_id: PublicKey, amount_msats: u64
-       ) -> Result<Self, SemanticError> {
+       ) -> Result<Self, Bolt12SemanticError> {
                if amount_msats > MAX_VALUE_MSAT {
-                       return Err(SemanticError::InvalidAmount);
+                       return Err(Bolt12SemanticError::InvalidAmount);
                }
 
                let metadata = Metadata::Bytes(metadata);
@@ -152,9 +152,9 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        pub fn deriving_payer_id<ES: Deref>(
                description: String, node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES,
                secp_ctx: &'a Secp256k1<T>, amount_msats: u64
-       ) -> Result<Self, SemanticError> where ES::Target: EntropySource {
+       ) -> Result<Self, Bolt12SemanticError> where ES::Target: EntropySource {
                if amount_msats > MAX_VALUE_MSAT {
-                       return Err(SemanticError::InvalidAmount);
+                       return Err(Bolt12SemanticError::InvalidAmount);
                }
 
                let nonce = Nonce::from_entropy_source(entropy_source);
@@ -207,12 +207,12 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        }
 
        /// Sets [`Refund::quantity`] of items. This is purely for informational purposes. It is useful
-       /// when the refund pertains to an [`Invoice`] that paid for more than one item from an
+       /// when the refund pertains to a [`Bolt12Invoice`] that paid for more than one item from an
        /// [`Offer`] as specified by [`InvoiceRequest::quantity`].
        ///
        /// Successive calls to this method will override the previous setting.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        /// [`InvoiceRequest::quantity`]: crate::offers::invoice_request::InvoiceRequest::quantity
        /// [`Offer`]: crate::offers::offer::Offer
        pub fn quantity(mut self, quantity: u64) -> Self {
@@ -229,12 +229,12 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        }
 
        /// Builds a [`Refund`] after checking for valid semantics.
-       pub fn build(mut self) -> Result<Refund, SemanticError> {
+       pub fn build(mut self) -> Result<Refund, Bolt12SemanticError> {
                if self.refund.chain() == self.refund.implied_chain() {
                        self.refund.chain = None;
                }
 
-               // Create the metadata for stateless verification of aInvoice.
+               // Create the metadata for stateless verification of a Bolt12Invoice.
                if self.refund.payer.0.has_derivation_material() {
                        let mut metadata = core::mem::take(&mut self.refund.payer.0);
 
@@ -272,13 +272,13 @@ impl<'a, T: secp256k1::Signing> RefundBuilder<'a, T> {
        }
 }
 
-/// A `Refund` is a request to send an [`Invoice`] without a preceding [`Offer`].
+/// A `Refund` is a request to send an [`Bolt12Invoice`] without a preceding [`Offer`].
 ///
 /// Typically, after an invoice is paid, the recipient may publish a refund allowing the sender to
 /// recoup their funds. A refund may be used more generally as an "offer for money", such as with a
 /// bitcoin ATM.
 ///
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 /// [`Offer`]: crate::offers::offer::Offer
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
@@ -287,9 +287,9 @@ pub struct Refund {
        pub(super) contents: RefundContents,
 }
 
-/// The contents of a [`Refund`], which may be shared with an [`Invoice`].
+/// The contents of a [`Refund`], which may be shared with an [`Bolt12Invoice`].
 ///
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug)]
 #[cfg_attr(test, derive(PartialEq))]
 pub(super) struct RefundContents {
@@ -396,7 +396,7 @@ impl Refund {
        pub fn respond_with(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                signing_pubkey: PublicKey,
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                let created_at = std::time::SystemTime::now()
                        .duration_since(std::time::SystemTime::UNIX_EPOCH)
                        .expect("SystemTime::now() should come after SystemTime::UNIX_EPOCH");
@@ -407,8 +407,8 @@ impl Refund {
        /// Creates an [`InvoiceBuilder`] for the refund with the given required fields.
        ///
        /// Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
-       /// `created_at`, which is used to set [`Invoice::created_at`]. Useful for `no-std` builds where
-       /// [`std::time::SystemTime`] is not available.
+       /// `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds
+       /// where [`std::time::SystemTime`] is not available.
        ///
        /// The caller is expected to remember the preimage of `payment_hash` in order to
        /// claim a payment for the invoice.
@@ -425,31 +425,31 @@ impl Refund {
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice::created_at`]: crate::offers::invoice::Invoice::created_at
+       /// [`Bolt12Invoice::created_at`]: crate::offers::invoice::Bolt12Invoice::created_at
        pub fn respond_with_no_std(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                signing_pubkey: PublicKey, created_at: Duration
-       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, SemanticError> {
+       ) -> Result<InvoiceBuilder<ExplicitSigningPubkey>, Bolt12SemanticError> {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                InvoiceBuilder::for_refund(self, payment_paths, created_at, payment_hash, signing_pubkey)
        }
 
        /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
-       /// derived signing keys to sign the [`Invoice`].
+       /// derived signing keys to sign the [`Bolt12Invoice`].
        ///
        /// See [`Refund::respond_with`] for further details.
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        #[cfg(feature = "std")]
        pub fn respond_using_derived_keys<ES: Deref>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
@@ -463,22 +463,22 @@ impl Refund {
        }
 
        /// Creates an [`InvoiceBuilder`] for the refund using the given required fields and that uses
-       /// derived signing keys to sign the [`Invoice`].
+       /// derived signing keys to sign the [`Bolt12Invoice`].
        ///
        /// See [`Refund::respond_with_no_std`] for further details.
        ///
        /// This is not exported to bindings users as builder patterns don't map outside of move semantics.
        ///
-       /// [`Invoice`]: crate::offers::invoice::Invoice
+       /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
        pub fn respond_using_derived_keys_no_std<ES: Deref>(
                &self, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>, payment_hash: PaymentHash,
                created_at: core::time::Duration, expanded_key: &ExpandedKey, entropy_source: ES
-       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, SemanticError>
+       ) -> Result<InvoiceBuilder<DerivedSigningPubkey>, Bolt12SemanticError>
        where
                ES::Target: EntropySource,
        {
                if self.features().requires_unknown_bits() {
-                       return Err(SemanticError::UnknownRequiredFeatures);
+                       return Err(Bolt12SemanticError::UnknownRequiredFeatures);
                }
 
                let nonce = Nonce::from_entropy_source(entropy_source);
@@ -606,7 +606,7 @@ impl Bech32Encode for Refund {
 }
 
 impl FromStr for Refund {
-       type Err = ParseError;
+       type Err = Bolt12ParseError;
 
        fn from_str(s: &str) -> Result<Self, <Self as FromStr>::Err> {
                Refund::from_bech32_str(s)
@@ -614,7 +614,7 @@ impl FromStr for Refund {
 }
 
 impl TryFrom<Vec<u8>> for Refund {
-       type Error = ParseError;
+       type Error = Bolt12ParseError;
 
        fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
                let refund = ParsedMessage::<RefundTlvStream>::try_from(bytes)?;
@@ -626,7 +626,7 @@ impl TryFrom<Vec<u8>> for Refund {
 }
 
 impl TryFrom<RefundTlvStream> for RefundContents {
-       type Error = SemanticError;
+       type Error = Bolt12SemanticError;
 
        fn try_from(tlv_stream: RefundTlvStream) -> Result<Self, Self::Error> {
                let (
@@ -639,45 +639,45 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                ) = tlv_stream;
 
                let payer = match payer_metadata {
-                       None => return Err(SemanticError::MissingPayerMetadata),
+                       None => return Err(Bolt12SemanticError::MissingPayerMetadata),
                        Some(metadata) => PayerContents(Metadata::Bytes(metadata)),
                };
 
                if metadata.is_some() {
-                       return Err(SemanticError::UnexpectedMetadata);
+                       return Err(Bolt12SemanticError::UnexpectedMetadata);
                }
 
                if chains.is_some() {
-                       return Err(SemanticError::UnexpectedChain);
+                       return Err(Bolt12SemanticError::UnexpectedChain);
                }
 
                if currency.is_some() || offer_amount.is_some() {
-                       return Err(SemanticError::UnexpectedAmount);
+                       return Err(Bolt12SemanticError::UnexpectedAmount);
                }
 
                let description = match description {
-                       None => return Err(SemanticError::MissingDescription),
+                       None => return Err(Bolt12SemanticError::MissingDescription),
                        Some(description) => description,
                };
 
                if offer_features.is_some() {
-                       return Err(SemanticError::UnexpectedFeatures);
+                       return Err(Bolt12SemanticError::UnexpectedFeatures);
                }
 
                let absolute_expiry = absolute_expiry.map(Duration::from_secs);
 
                if quantity_max.is_some() {
-                       return Err(SemanticError::UnexpectedQuantity);
+                       return Err(Bolt12SemanticError::UnexpectedQuantity);
                }
 
                if node_id.is_some() {
-                       return Err(SemanticError::UnexpectedSigningPubkey);
+                       return Err(Bolt12SemanticError::UnexpectedSigningPubkey);
                }
 
                let amount_msats = match amount {
-                       None => return Err(SemanticError::MissingAmount),
+                       None => return Err(Bolt12SemanticError::MissingAmount),
                        Some(amount_msats) if amount_msats > MAX_VALUE_MSAT => {
-                               return Err(SemanticError::InvalidAmount);
+                               return Err(Bolt12SemanticError::InvalidAmount);
                        },
                        Some(amount_msats) => amount_msats,
                };
@@ -685,7 +685,7 @@ impl TryFrom<RefundTlvStream> for RefundContents {
                let features = features.unwrap_or_else(InvoiceRequestFeatures::empty);
 
                let payer_id = match payer_id {
-                       None => return Err(SemanticError::MissingPayerId),
+                       None => return Err(Bolt12SemanticError::MissingPayerId),
                        Some(payer_id) => payer_id,
                };
 
@@ -718,7 +718,7 @@ mod tests {
        use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
        use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
        use crate::offers::offer::OfferTlvStreamRef;
-       use crate::offers::parse::{ParseError, SemanticError};
+       use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
        use crate::offers::payer::PayerTlvStreamRef;
        use crate::offers::test_utils::*;
        use crate::util::ser::{BigSize, Writeable};
@@ -795,7 +795,7 @@ mod tests {
        fn fails_building_refund_with_invalid_amount() {
                match RefundBuilder::new("foo".into(), vec![1; 32], payer_pubkey(), MAX_VALUE_MSAT + 1) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::InvalidAmount),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::InvalidAmount),
                }
        }
 
@@ -1064,7 +1064,7 @@ mod tests {
                        .respond_with_no_std(payment_paths(), payment_hash(), recipient_pubkey(), now())
                {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, SemanticError::UnknownRequiredFeatures),
+                       Err(e) => assert_eq!(e, Bolt12SemanticError::UnknownRequiredFeatures),
                }
        }
 
@@ -1082,7 +1082,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerMetadata));
                        },
                }
        }
@@ -1101,7 +1101,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingDescription));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingDescription));
                        },
                }
        }
@@ -1120,7 +1120,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingAmount));
                        },
                }
 
@@ -1130,7 +1130,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::InvalidAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::InvalidAmount));
                        },
                }
        }
@@ -1149,7 +1149,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::MissingPayerId));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPayerId));
                        },
                }
        }
@@ -1218,7 +1218,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedMetadata));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedMetadata));
                        },
                }
 
@@ -1229,7 +1229,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedChain));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedChain));
                        },
                }
 
@@ -1240,7 +1240,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedAmount));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedAmount));
                        },
                }
 
@@ -1251,7 +1251,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedFeatures));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedFeatures));
                        },
                }
 
@@ -1261,7 +1261,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedQuantity));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedQuantity));
                        },
                }
 
@@ -1272,7 +1272,7 @@ mod tests {
                match Refund::try_from(tlv_stream.to_bytes()) {
                        Ok(_) => panic!("expected error"),
                        Err(e) => {
-                               assert_eq!(e, ParseError::InvalidSemantics(SemanticError::UnexpectedSigningPubkey));
+                               assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::UnexpectedSigningPubkey));
                        },
                }
        }
@@ -1292,7 +1292,7 @@ mod tests {
 
                match Refund::try_from(encoded_refund) {
                        Ok(_) => panic!("expected error"),
-                       Err(e) => assert_eq!(e, ParseError::Decode(DecodeError::InvalidValue)),
+                       Err(e) => assert_eq!(e, Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
index f82afdd618a5bfa78ac02a7e0bfd6476cac4bbdd..9a1f59b84592eac465b718e8ee89c6037c24423e 100644 (file)
@@ -14,8 +14,8 @@ use crate::io::{self, Read};
 use crate::ln::msgs::DecodeError;
 use crate::offers::invoice_error::InvoiceError;
 use crate::offers::invoice_request::InvoiceRequest;
-use crate::offers::invoice::Invoice;
-use crate::offers::parse::ParseError;
+use crate::offers::invoice::Bolt12Invoice;
+use crate::offers::parse::Bolt12ParseError;
 use crate::util::logger::Logger;
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
 
@@ -30,8 +30,8 @@ const INVOICE_ERROR_TLV_TYPE: u64 = 68;
 ///
 /// [`OnionMessage`]: crate::ln::msgs::OnionMessage
 pub trait OffersMessageHandler {
-       /// Handles the given message by either responding with an [`Invoice`], sending a payment, or
-       /// replying with an error.
+       /// Handles the given message by either responding with an [`Bolt12Invoice`], sending a payment,
+       /// or replying with an error.
        fn handle_message(&self, message: OffersMessage) -> Option<OffersMessage>;
 }
 
@@ -40,15 +40,15 @@ pub trait OffersMessageHandler {
 /// [`OnionMessage`]: crate::ln::msgs::OnionMessage
 #[derive(Debug)]
 pub enum OffersMessage {
-       /// A request for an [`Invoice`] for a particular [`Offer`].
+       /// A request for a [`Bolt12Invoice`] for a particular [`Offer`].
        ///
        /// [`Offer`]: crate::offers::offer::Offer
        InvoiceRequest(InvoiceRequest),
 
-       /// An [`Invoice`] sent in response to an [`InvoiceRequest`] or a [`Refund`].
+       /// A [`Bolt12Invoice`] sent in response to an [`InvoiceRequest`] or a [`Refund`].
        ///
        /// [`Refund`]: crate::offers::refund::Refund
-       Invoice(Invoice),
+       Invoice(Bolt12Invoice),
 
        /// An error from handling an [`OffersMessage`].
        InvoiceError(InvoiceError),
@@ -72,11 +72,11 @@ impl OffersMessage {
                }
        }
 
-       fn parse(tlv_type: u64, bytes: Vec<u8>) -> Result<Self, ParseError> {
+       fn parse(tlv_type: u64, bytes: Vec<u8>) -> Result<Self, Bolt12ParseError> {
                match tlv_type {
                        INVOICE_REQUEST_TLV_TYPE => Ok(Self::InvoiceRequest(InvoiceRequest::try_from(bytes)?)),
-                       INVOICE_TLV_TYPE => Ok(Self::Invoice(Invoice::try_from(bytes)?)),
-                       _ => Err(ParseError::Decode(DecodeError::InvalidValue)),
+                       INVOICE_TLV_TYPE => Ok(Self::Invoice(Bolt12Invoice::try_from(bytes)?)),
+                       _ => Err(Bolt12ParseError::Decode(DecodeError::InvalidValue)),
                }
        }
 }
@@ -103,12 +103,12 @@ impl<L: Logger + ?Sized> ReadableArgs<(u64, &L)> for OffersMessage {
 
                match Self::parse(tlv_type, bytes) {
                        Ok(message) => Ok(message),
-                       Err(ParseError::Decode(e)) => Err(e),
-                       Err(ParseError::InvalidSemantics(e)) => {
+                       Err(Bolt12ParseError::Decode(e)) => Err(e),
+                       Err(Bolt12ParseError::InvalidSemantics(e)) => {
                                log_trace!(logger, "Invalid semantics for TLV type {}: {:?}", tlv_type, e);
                                Err(DecodeError::InvalidValue)
                        },
-                       Err(ParseError::InvalidSignature(e)) => {
+                       Err(Bolt12ParseError::InvalidSignature(e)) => {
                                log_trace!(logger, "Invalid signature for TLV type {}: {:?}", tlv_type, e);
                                Err(DecodeError::InvalidValue)
                        },
index d3539579c50ae16d8a8d92eb806af6364243327d..9242e98b1ab5061eca462e31b479f3e34602a8e3 100644 (file)
@@ -16,9 +16,9 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use crate::blinded_path::{BlindedHop, BlindedPath};
 use crate::ln::PaymentHash;
 use crate::ln::channelmanager::{ChannelDetails, PaymentId};
-use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, InvoiceFeatures, NodeFeatures};
+use crate::ln::features::{Bolt11InvoiceFeatures, Bolt12InvoiceFeatures, ChannelFeatures, NodeFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
-use crate::offers::invoice::{BlindedPayInfo, Invoice as Bolt12Invoice};
+use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice};
 use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
 use crate::routing::scoring::{ChannelUsage, LockableScore, Score};
 use crate::util::ser::{Writeable, Readable, ReadableArgs, Writer};
@@ -271,9 +271,9 @@ impl_writeable_tlv_based!(RouteHop, {
 });
 
 /// The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
-/// their BOLT12 [`Invoice`].
+/// their [`Bolt12Invoice`].
 ///
-/// [`Invoice`]: crate::offers::invoice::Invoice
+/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
 #[derive(Clone, Debug, Hash, PartialEq, Eq)]
 pub struct BlindedTail {
        /// The hops of the [`BlindedPath`] provided by the recipient.
@@ -640,7 +640,7 @@ impl PaymentParameters {
        /// [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
        pub fn for_keysend(payee_pubkey: PublicKey, final_cltv_expiry_delta: u32, allow_mpp: bool) -> Self {
                Self::from_node_id(payee_pubkey, final_cltv_expiry_delta)
-                       .with_bolt11_features(InvoiceFeatures::for_keysend(allow_mpp))
+                       .with_bolt11_features(Bolt11InvoiceFeatures::for_keysend(allow_mpp))
                        .expect("PaymentParameters::from_node_id should always initialize the payee as unblinded")
        }
 
@@ -680,7 +680,7 @@ impl PaymentParameters {
        /// [`PaymentParameters::from_bolt12_invoice`].
        ///
        /// This is not exported to bindings users since bindings don't support move semantics
-       pub fn with_bolt11_features(self, features: InvoiceFeatures) -> Result<Self, ()> {
+       pub fn with_bolt11_features(self, features: Bolt11InvoiceFeatures) -> Result<Self, ()> {
                match self.payee {
                        Payee::Blinded { .. } => Err(()),
                        Payee::Clear { route_hints, node_id, final_cltv_expiry_delta, .. } =>
@@ -766,7 +766,7 @@ pub enum Payee {
                /// does not contain any features.
                ///
                /// [`for_keysend`]: PaymentParameters::for_keysend
-               features: Option<InvoiceFeatures>,
+               features: Option<Bolt11InvoiceFeatures>,
                /// The minimum CLTV delta at the end of the route. This value must not be zero.
                final_cltv_expiry_delta: u32,
        },
@@ -819,11 +819,11 @@ impl Payee {
 }
 
 enum FeaturesRef<'a> {
-       Bolt11(&'a InvoiceFeatures),
+       Bolt11(&'a Bolt11InvoiceFeatures),
        Bolt12(&'a Bolt12InvoiceFeatures),
 }
 enum Features {
-       Bolt11(InvoiceFeatures),
+       Bolt11(Bolt11InvoiceFeatures),
        Bolt12(Bolt12InvoiceFeatures),
 }
 
@@ -834,7 +834,7 @@ impl Features {
                        _ => None,
                }
        }
-       fn bolt11(self) -> Option<InvoiceFeatures> {
+       fn bolt11(self) -> Option<Bolt11InvoiceFeatures> {
                match self {
                        Self::Bolt11(f) => Some(f),
                        _ => None,
@@ -6104,7 +6104,7 @@ mod tests {
 
                let params = ProbabilisticScoringFeeParameters::default();
                let mut scorer = ProbabilisticScorer::new(ProbabilisticScoringDecayParameters::default(), &graph, &logger);
-               let features = super::InvoiceFeatures::empty();
+               let features = super::Bolt11InvoiceFeatures::empty();
 
                super::bench_utils::generate_test_routes(&graph, &mut scorer, &params, features, random_init_seed(), 0, 2);
        }
@@ -6680,7 +6680,7 @@ pub(crate) mod bench_utils {
        use crate::chain::transaction::OutPoint;
        use crate::sign::{EntropySource, KeysManager};
        use crate::ln::channelmanager::{self, ChannelCounterparty, ChannelDetails};
-       use crate::ln::features::InvoiceFeatures;
+       use crate::ln::features::Bolt11InvoiceFeatures;
        use crate::routing::gossip::NetworkGraph;
        use crate::util::config::UserConfig;
        use crate::util::ser::ReadableArgs;
@@ -6772,7 +6772,7 @@ pub(crate) mod bench_utils {
        }
 
        pub(crate) fn generate_test_routes<S: Score>(graph: &NetworkGraph<&TestLogger>, scorer: &mut S,
-               score_params: &S::ScoreParams, features: InvoiceFeatures, mut seed: u64,
+               score_params: &S::ScoreParams, features: Bolt11InvoiceFeatures, mut seed: u64,
                starting_amount: u64, route_count: usize,
        ) -> Vec<(ChannelDetails, PaymentParameters, u64)> {
                let payer = payer_pubkey();
@@ -6853,7 +6853,7 @@ pub mod benches {
        use super::*;
        use crate::sign::{EntropySource, KeysManager};
        use crate::ln::channelmanager;
-       use crate::ln::features::InvoiceFeatures;
+       use crate::ln::features::Bolt11InvoiceFeatures;
        use crate::routing::gossip::NetworkGraph;
        use crate::routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringFeeParameters, ProbabilisticScoringDecayParameters};
        use crate::util::config::UserConfig;
@@ -6871,7 +6871,7 @@ pub mod benches {
                let logger = TestLogger::new();
                let network_graph = bench_utils::read_network_graph(&logger).unwrap();
                let scorer = FixedPenaltyScorer::with_penalty(0);
-               generate_routes(bench, &network_graph, scorer, &(), InvoiceFeatures::empty(), 0,
+               generate_routes(bench, &network_graph, scorer, &(), Bolt11InvoiceFeatures::empty(), 0,
                        "generate_routes_with_zero_penalty_scorer");
        }
 
@@ -6889,7 +6889,7 @@ pub mod benches {
                let network_graph = bench_utils::read_network_graph(&logger).unwrap();
                let params = ProbabilisticScoringFeeParameters::default();
                let scorer = ProbabilisticScorer::new(ProbabilisticScoringDecayParameters::default(), &network_graph, &logger);
-               generate_routes(bench, &network_graph, scorer, &params, InvoiceFeatures::empty(), 0,
+               generate_routes(bench, &network_graph, scorer, &params, Bolt11InvoiceFeatures::empty(), 0,
                        "generate_routes_with_probabilistic_scorer");
        }
 
@@ -6915,7 +6915,7 @@ pub mod benches {
 
        fn generate_routes<S: Score>(
                bench: &mut Criterion, graph: &NetworkGraph<&TestLogger>, mut scorer: S,
-               score_params: &S::ScoreParams, features: InvoiceFeatures, starting_amount: u64,
+               score_params: &S::ScoreParams, features: Bolt11InvoiceFeatures, starting_amount: u64,
                bench_name: &'static str,
        ) {
                let payer = bench_utils::payer_pubkey();
index aac83f42a3c2f82a5520fc380f4006ca345288e2..722a81f7ab665b15961363a1f064377718e36dd3 100644 (file)
@@ -169,6 +169,29 @@ impl<'a> core::fmt::Display for DebugBytes<'a> {
        }
 }
 
+/// Wrapper for logging `Iterator`s.
+///
+/// This is not exported to bindings users as fmt can't be used in C
+#[doc(hidden)]
+pub struct DebugIter<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone>(pub core::cell::RefCell<I>);
+impl<T: fmt::Display, I: core::iter::Iterator<Item = T> + Clone> fmt::Display for DebugIter<T, I> {
+       fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+               use core::ops::DerefMut;
+               write!(f, "[")?;
+               let iter_ref = self.0.clone();
+               let mut iter = iter_ref.borrow_mut();
+               for item in iter.deref_mut() {
+                       write!(f, "{}", item)?;
+                       break;
+               }
+               for item in iter.deref_mut() {
+                       write!(f, ", {}", item)?;
+               }
+               write!(f, "]")?;
+               Ok(())
+       }
+}
+
 #[cfg(test)]
 mod tests {
        use crate::util::logger::{Logger, Level};
index 8742e8e84d0bf27670fb0cb71af3c372e089b9e3..4703bcdb32a2a00719f4d7a5eb1edd37aa2d75ec 100644 (file)
@@ -17,6 +17,12 @@ use crate::routing::router::Route;
 use crate::ln::chan_utils::HTLCClaim;
 use crate::util::logger::DebugBytes;
 
+macro_rules! log_iter {
+       ($obj: expr) => {
+               $crate::util::logger::DebugIter(core::cell::RefCell::new($obj))
+       }
+}
+
 /// Logs a pubkey in hex format.
 #[macro_export]
 macro_rules! log_pubkey {
index 212f1f4b60a392f6ad605fe599f200b3c543b778..bf5aa02bb41e310f92d06253487ca39d6c2ed8df 100644 (file)
@@ -18,6 +18,7 @@ use crate::chain::channelmonitor::MonitorEvent;
 use crate::chain::transaction::OutPoint;
 use crate::sign;
 use crate::events;
+use crate::events::bump_transaction::{WalletSource, Utxo};
 use crate::ln::channelmanager;
 use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
 use crate::ln::{msgs, wire};
@@ -32,6 +33,7 @@ use crate::util::enforcing_trait_impls::{EnforcingSigner, EnforcementState};
 use crate::util::logger::{Logger, Level, Record};
 use crate::util::ser::{Readable, ReadableArgs, Writer, Writeable};
 
+use bitcoin::EcdsaSighashType;
 use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
@@ -40,6 +42,7 @@ use bitcoin::blockdata::opcodes;
 use bitcoin::blockdata::block::Block;
 use bitcoin::network::constants::Network;
 use bitcoin::hash_types::{BlockHash, Txid};
+use bitcoin::util::sighash::SighashCache;
 
 use bitcoin::secp256k1::{SecretKey, PublicKey, Secp256k1, ecdsa::Signature, Scalar};
 use bitcoin::secp256k1::ecdh::SharedSecret;
@@ -1067,3 +1070,65 @@ impl Drop for TestScorer {
                }
        }
 }
+
+pub struct TestWalletSource {
+       secret_key: SecretKey,
+       utxos: RefCell<Vec<Utxo>>,
+       secp: Secp256k1<bitcoin::secp256k1::All>,
+}
+
+impl TestWalletSource {
+       pub fn new(secret_key: SecretKey) -> Self {
+               Self {
+                       secret_key,
+                       utxos: RefCell::new(Vec::new()),
+                       secp: Secp256k1::new(),
+               }
+       }
+
+       pub fn add_utxo(&self, outpoint: bitcoin::OutPoint, value: u64) -> TxOut {
+               let public_key = bitcoin::PublicKey::new(self.secret_key.public_key(&self.secp));
+               let utxo = Utxo::new_p2pkh(outpoint, value, &public_key.pubkey_hash());
+               self.utxos.borrow_mut().push(utxo.clone());
+               utxo.output
+       }
+
+       pub fn add_custom_utxo(&self, utxo: Utxo) -> TxOut {
+               let output = utxo.output.clone();
+               self.utxos.borrow_mut().push(utxo);
+               output
+       }
+
+       pub fn remove_utxo(&self, outpoint: bitcoin::OutPoint) {
+               self.utxos.borrow_mut().retain(|utxo| utxo.outpoint != outpoint);
+       }
+}
+
+impl WalletSource for TestWalletSource {
+    fn list_confirmed_utxos(&self) -> Result<Vec<Utxo>, ()> {
+               Ok(self.utxos.borrow().clone())
+    }
+
+    fn get_change_script(&self) -> Result<Script, ()> {
+               let public_key = bitcoin::PublicKey::new(self.secret_key.public_key(&self.secp));
+               Ok(Script::new_p2pkh(&public_key.pubkey_hash()))
+    }
+
+    fn sign_tx(&self, tx: &mut Transaction) -> Result<(), ()> {
+               let utxos = self.utxos.borrow();
+               for i in 0..tx.input.len() {
+                       if let Some(utxo) = utxos.iter().find(|utxo| utxo.outpoint == tx.input[i].previous_output) {
+                               let sighash = SighashCache::new(&*tx)
+                                       .legacy_signature_hash(i, &utxo.output.script_pubkey, EcdsaSighashType::All as u32)
+                                       .map_err(|_| ())?;
+                               let sig = self.secp.sign_ecdsa(&sighash.as_hash().into(), &self.secret_key);
+                               let bitcoin_sig = bitcoin::EcdsaSig { sig, hash_ty: EcdsaSighashType::All }.to_vec();
+                               tx.input[i].script_sig = Builder::new()
+                                       .push_slice(&bitcoin_sig)
+                                       .push_slice(&self.secret_key.public_key(&self.secp).serialize())
+                                       .into_script();
+                       }
+               }
+               Ok(())
+    }
+}