]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add InvoiceBuilder::features_unchecked
authorJeffrey Czyz <jkczyz@gmail.com>
Wed, 31 Jul 2024 20:57:14 +0000 (15:57 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Wed, 14 Aug 2024 15:55:58 +0000 (10:55 -0500)
In order to test handling of unknown required features in a
Bolt12Invoice, add a test-only function to allow setting arbitrary
feature bits.

lightning/src/offers/invoice.rs
lightning/src/offers/invoice_macros.rs

index 835a077f294b97a3b60b19e22d5e529af052430c..5a9cb349ce19294fcd2e8a3bdc17dffb4635af13 100644 (file)
@@ -117,6 +117,8 @@ use crate::ln::features::{BlindedHopFeatures, Bolt12InvoiceFeatures, InvoiceRequ
 use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
 use crate::ln::msgs::DecodeError;
 use crate::offers::invoice_macros::{invoice_accessors_common, invoice_builder_methods_common};
+#[cfg(test)]
+use crate::offers::invoice_macros::invoice_builder_methods_test;
 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, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, TlvStream, WithoutSignatures, self};
 use crate::offers::nonce::Nonce;
@@ -385,6 +387,9 @@ impl<'a> InvoiceBuilder<'a, DerivedSigningPubkey> {
 impl<'a, S: SigningPubkeyStrategy> InvoiceBuilder<'a, S> {
        invoice_builder_methods!(self, Self, Self, self, S, mut);
        invoice_builder_methods_common!(self, Self, self.invoice.fields_mut(), Self, self, S, Bolt12Invoice, mut);
+
+       #[cfg(test)]
+       invoice_builder_methods_test!(self, Self, self.invoice.fields_mut(), Self, self, mut);
 }
 
 #[cfg(all(c_bindings, not(test)))]
@@ -399,6 +404,7 @@ impl<'a> InvoiceWithExplicitSigningPubkeyBuilder<'a> {
        invoice_explicit_signing_pubkey_builder_methods!(self, &mut Self);
        invoice_builder_methods!(self, &mut Self, &mut Self, self, ExplicitSigningPubkey);
        invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, ExplicitSigningPubkey, Bolt12Invoice);
+       invoice_builder_methods_test!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self);
 }
 
 #[cfg(all(c_bindings, not(test)))]
@@ -413,6 +419,7 @@ impl<'a> InvoiceWithDerivedSigningPubkeyBuilder<'a> {
        invoice_derived_signing_pubkey_builder_methods!(self, &mut Self);
        invoice_builder_methods!(self, &mut Self, &mut Self, self, DerivedSigningPubkey);
        invoice_builder_methods_common!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self, DerivedSigningPubkey, Bolt12Invoice);
+       invoice_builder_methods_test!(self, &mut Self, self.invoice.fields_mut(), &mut Self, self);
 }
 
 #[cfg(c_bindings)]
index b79bb8c9e884b61432d2712069ba2559e51c9813..e1875fbc87fc07f45c4d47dcab6883acecb07f3d 100644 (file)
@@ -82,6 +82,21 @@ macro_rules! invoice_builder_methods_common { (
        }
 } }
 
+#[cfg(test)]
+macro_rules! invoice_builder_methods_test { (
+       $self: ident, $self_type: ty, $invoice_fields: expr, $return_type: ty, $return_value: expr
+       $(, $self_mut: tt)?
+) => {
+       #[cfg_attr(c_bindings, allow(dead_code))]
+       pub(crate) fn features_unchecked(
+               $($self_mut)* $self: $self_type, features: Bolt12InvoiceFeatures
+       ) -> $return_type {
+               $invoice_fields.features = features;
+               $return_value
+       }
+
+} }
+
 macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice_type: ty) => {
        /// Paths to the recipient originating from publicly reachable nodes, including information
        /// needed for routing payments across them.
@@ -133,3 +148,5 @@ macro_rules! invoice_accessors_common { ($self: ident, $contents: expr, $invoice
 
 pub(super) use invoice_accessors_common;
 pub(super) use invoice_builder_methods_common;
+#[cfg(test)]
+pub(super) use invoice_builder_methods_test;