@@ -76,8 +76,9 @@ use crate::offers::merkle::{
76
76
} ;
77
77
use crate :: offers:: nonce:: Nonce ;
78
78
use 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 ,
81
82
} ;
82
83
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
83
84
use crate :: offers:: payer:: { PayerContents , PayerTlvStream , PayerTlvStreamRef } ;
@@ -94,6 +95,7 @@ use bitcoin::constants::ChainHash;
94
95
use bitcoin:: network:: Network ;
95
96
use bitcoin:: secp256k1:: schnorr:: Signature ;
96
97
use bitcoin:: secp256k1:: { self , Keypair , PublicKey , Secp256k1 } ;
98
+ use core:: ops:: Deref ;
97
99
98
100
#[ cfg( not( c_bindings) ) ]
99
101
use crate :: offers:: invoice:: { DerivedSigningPubkey , ExplicitSigningPubkey , InvoiceBuilder } ;
@@ -573,6 +575,35 @@ impl AsRef<TaggedHash> for UnsignedInvoiceRequest {
573
575
}
574
576
}
575
577
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
+
576
607
/// An `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`].
577
608
///
578
609
/// An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request
0 commit comments