@@ -76,8 +76,9 @@ use crate::offers::merkle::{
7676} ;
7777use crate :: offers:: nonce:: Nonce ;
7878use crate :: offers:: offer:: {
79- Amount , ExperimentalOfferTlvStream , ExperimentalOfferTlvStreamRef , Offer , OfferContents ,
80- OfferId , OfferTlvStream , OfferTlvStreamRef , EXPERIMENTAL_OFFER_TYPES , OFFER_TYPES ,
79+ Amount , CurrencyCode , ExperimentalOfferTlvStream , ExperimentalOfferTlvStreamRef , Offer ,
80+ OfferContents , OfferId , OfferTlvStream , OfferTlvStreamRef , EXPERIMENTAL_OFFER_TYPES ,
81+ OFFER_TYPES ,
8182} ;
8283use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
8384use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
@@ -94,6 +95,7 @@ use bitcoin::constants::ChainHash;
9495use bitcoin:: network:: Network ;
9596use bitcoin:: secp256k1:: schnorr:: Signature ;
9697use bitcoin:: secp256k1:: { self , Keypair , PublicKey , Secp256k1 } ;
98+ use core:: ops:: Deref ;
9799
98100#[ cfg( not( c_bindings) ) ]
99101use crate :: offers:: invoice:: { DerivedSigningPubkey , ExplicitSigningPubkey , InvoiceBuilder } ;
@@ -573,6 +575,35 @@ impl AsRef<TaggedHash> for UnsignedInvoiceRequest {
573575 }
574576}
575577
578+ /// A trait for converting fiat currencies into millisatoshi values.
579+ ///
580+ /// This is used for handling conversions between fiat currencies and Bitcoin denominated in millisatoshis
581+ /// when working with Bolt12 invoice requests.
582+ ///
583+ /// Implementors must provide a method to convert from a specified fiat currency (using ISO 4217 currency codes)
584+ /// to millisatoshis, handling any potential conversion errors.
585+ pub trait CurrencyConversion {
586+ /// Converts a fiat currency specified by its ISO 4217 code to millisatoshis.
587+ fn fiat_to_msats ( & self , iso4217_code : CurrencyCode ) -> Result < u64 , Bolt12SemanticError > ;
588+ }
589+
590+ /// A default implementation of the `CurrencyConversion` trait that does not support any currency conversions.
591+ pub struct DefaultCurrencyConversion { }
592+
593+ impl Deref for DefaultCurrencyConversion {
594+ type Target = Self ;
595+
596+ fn deref ( & self ) -> & Self :: Target {
597+ self
598+ }
599+ }
600+
601+ impl CurrencyConversion for DefaultCurrencyConversion {
602+ fn fiat_to_msats ( & self , _iso4217_code : CurrencyCode ) -> Result < u64 , Bolt12SemanticError > {
603+ Err ( Bolt12SemanticError :: UnsupportedCurrency )
604+ }
605+ }
606+
576607/// An `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`].
577608///
578609/// An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request
0 commit comments