+ fn metadata(&self) -> Option<&Vec<u8>> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } =>
+ invoice_request.inner.offer.metadata(),
+ InvoiceContents::ForRefund { .. } => None,
+ }
+ }
+
+ fn amount(&self) -> Option<&Amount> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } =>
+ invoice_request.inner.offer.amount(),
+ InvoiceContents::ForRefund { .. } => None,
+ }
+ }
+
+ fn description(&self) -> PrintableString {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ invoice_request.inner.offer.description()
+ },
+ InvoiceContents::ForRefund { refund, .. } => refund.description(),
+ }
+ }
+
+ fn offer_features(&self) -> Option<&OfferFeatures> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ Some(invoice_request.inner.offer.features())
+ },
+ InvoiceContents::ForRefund { .. } => None,
+ }
+ }
+
+ fn absolute_expiry(&self) -> Option<Duration> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ invoice_request.inner.offer.absolute_expiry()
+ },
+ InvoiceContents::ForRefund { refund, .. } => refund.absolute_expiry(),
+ }
+ }
+
+ fn issuer(&self) -> Option<PrintableString> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ invoice_request.inner.offer.issuer()
+ },
+ InvoiceContents::ForRefund { refund, .. } => refund.issuer(),
+ }
+ }
+
+ fn message_paths(&self) -> &[BlindedPath] {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ invoice_request.inner.offer.paths()
+ },
+ InvoiceContents::ForRefund { refund, .. } => refund.paths(),
+ }
+ }
+
+ fn supported_quantity(&self) -> Option<Quantity> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => {
+ Some(invoice_request.inner.offer.supported_quantity())
+ },
+ InvoiceContents::ForRefund { .. } => None,
+ }
+ }
+
+ fn payer_metadata(&self) -> &[u8] {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.metadata(),
+ InvoiceContents::ForRefund { refund, .. } => refund.metadata(),
+ }
+ }
+
+ fn invoice_request_features(&self) -> &InvoiceRequestFeatures {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.features(),
+ InvoiceContents::ForRefund { refund, .. } => refund.features(),
+ }
+ }
+
+ fn quantity(&self) -> Option<u64> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.quantity(),
+ InvoiceContents::ForRefund { refund, .. } => refund.quantity(),
+ }
+ }
+
+ fn payer_id(&self) -> PublicKey {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.payer_id(),
+ InvoiceContents::ForRefund { refund, .. } => refund.payer_id(),
+ }
+ }
+
+ fn payer_note(&self) -> Option<PrintableString> {
+ match self {
+ InvoiceContents::ForOffer { invoice_request, .. } => invoice_request.payer_note(),
+ InvoiceContents::ForRefund { refund, .. } => refund.payer_note(),
+ }
+ }
+
+ fn payment_paths(&self) -> &[(BlindedPayInfo, BlindedPath)] {
+ &self.fields().payment_paths[..]
+ }
+
+ fn created_at(&self) -> Duration {
+ self.fields().created_at
+ }
+
+ fn relative_expiry(&self) -> Duration {
+ self.fields().relative_expiry.unwrap_or(DEFAULT_RELATIVE_EXPIRY)
+ }
+
+ #[cfg(feature = "std")]
+ fn is_expired(&self) -> bool {
+ let absolute_expiry = self.created_at().checked_add(self.relative_expiry());
+ match absolute_expiry {
+ Some(seconds_from_epoch) => match SystemTime::UNIX_EPOCH.elapsed() {
+ Ok(elapsed) => elapsed > seconds_from_epoch,
+ Err(_) => false,
+ },
+ None => false,
+ }
+ }
+
+ fn payment_hash(&self) -> PaymentHash {
+ self.fields().payment_hash
+ }
+
+ fn amount_msats(&self) -> u64 {
+ self.fields().amount_msats
+ }
+
+ fn fallbacks(&self) -> Vec<Address> {
+ let chain = self.chain();
+ let network = if chain == ChainHash::using_genesis_block(Network::Bitcoin) {
+ Network::Bitcoin
+ } else if chain == ChainHash::using_genesis_block(Network::Testnet) {
+ Network::Testnet
+ } else if chain == ChainHash::using_genesis_block(Network::Signet) {
+ Network::Signet
+ } else if chain == ChainHash::using_genesis_block(Network::Regtest) {
+ Network::Regtest
+ } else {
+ return Vec::new()
+ };
+
+ let to_valid_address = |address: &FallbackAddress| {
+ let version = match WitnessVersion::try_from(address.version) {
+ Ok(version) => version,
+ Err(_) => return None,
+ };
+
+ let program = &address.program;
+ let witness_program = match WitnessProgram::new(version, program.clone()) {
+ Ok(witness_program) => witness_program,
+ Err(_) => return None,
+ };
+ Some(Address::new(network, Payload::WitnessProgram(witness_program)))
+ };
+
+ self.fields().fallbacks
+ .as_ref()
+ .map(|fallbacks| fallbacks.iter().filter_map(to_valid_address).collect())
+ .unwrap_or_else(Vec::new)
+ }
+
+ fn features(&self) -> &Bolt12InvoiceFeatures {
+ &self.fields().features
+ }
+
+ fn signing_pubkey(&self) -> PublicKey {
+ self.fields().signing_pubkey
+ }
+