+impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, T, C, S, tb::False> {
+ /// Sets the payment metadata.
+ ///
+ /// By default features are set to *optionally* allow the sender to include the payment metadata.
+ /// If you wish to require that the sender include the metadata (and fail to parse the invoice if
+ /// they don't support payment metadata fields), you need to call
+ /// [`InvoiceBuilder::require_payment_metadata`] after this.
+ pub fn payment_metadata(mut self, payment_metadata: Vec<u8>) -> InvoiceBuilder<D, H, T, C, S, tb::True> {
+ self.tagged_fields.push(TaggedField::PaymentMetadata(payment_metadata));
+ let mut found_features = false;
+ for field in self.tagged_fields.iter_mut() {
+ if let TaggedField::Features(f) = field {
+ found_features = true;
+ f.set_payment_metadata_optional();
+ }
+ }
+ if !found_features {
+ let mut features = Bolt11InvoiceFeatures::empty();
+ features.set_payment_metadata_optional();
+ self.tagged_fields.push(TaggedField::Features(features));
+ }
+ self.set_flags()
+ }
+}
+
+impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, T, C, S, tb::True> {
+ /// Sets forwarding of payment metadata as required. A reader of the invoice which does not
+ /// support sending payment metadata will fail to read the invoice.
+ pub fn require_payment_metadata(mut self) -> InvoiceBuilder<D, H, T, C, S, tb::True> {
+ for field in self.tagged_fields.iter_mut() {
+ if let TaggedField::Features(f) = field {
+ f.set_payment_metadata_required();
+ }
+ }
+ self
+ }
+}
+
+impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, M: tb::Bool> InvoiceBuilder<D, H, T, C, tb::True, M> {