@@ -42,6 +42,8 @@ use bitcoin::secp256k1::PublicKey;
4242use bitcoin:: secp256k1:: { Message , Secp256k1 } ;
4343use bitcoin:: secp256k1:: ecdsa:: RecoverableSignature ;
4444
45+ use rgb_lib:: ContractId ;
46+
4547use core:: cmp:: Ordering ;
4648use core:: fmt:: { Display , Formatter , self } ;
4749use core:: iter:: FilterMap ;
@@ -98,6 +100,7 @@ pub enum Bolt11ParseError {
98100 InvalidScriptHashLength ,
99101 InvalidRecoveryId ,
100102 InvalidSliceLength ( String ) ,
103+ InvalidContractId ,
101104
102105 /// Not an error, but used internally to signal that a part of the invoice should be ignored
103106 /// according to BOLT11
@@ -432,6 +435,8 @@ pub enum TaggedField {
432435 PaymentSecret ( PaymentSecret ) ,
433436 PaymentMetadata ( Vec < u8 > ) ,
434437 Features ( Bolt11InvoiceFeatures ) ,
438+ RgbAmount ( RgbAmount ) ,
439+ RgbContractId ( RgbContractId ) ,
435440}
436441
437442/// SHA-256 hash
@@ -468,6 +473,14 @@ pub struct ExpiryTime(Duration);
468473#[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
469474pub struct MinFinalCltvExpiryDelta ( pub u64 ) ;
470475
476+ /// Requested amount for the RGB asset
477+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
478+ pub struct RgbAmount ( pub u64 ) ;
479+
480+ /// Requested RGB contract ID
481+ #[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
482+ pub struct RgbContractId ( pub ContractId ) ;
483+
471484/// Fallback address in case no LN payment is possible
472485#[ allow( missing_docs) ]
473486#[ derive( Clone , Debug , Hash , Eq , PartialEq , Ord , PartialOrd ) ]
@@ -518,6 +531,8 @@ pub mod constants {
518531 pub const TAG_PAYMENT_SECRET : u8 = 16 ;
519532 pub const TAG_PAYMENT_METADATA : u8 = 27 ;
520533 pub const TAG_FEATURES : u8 = 5 ;
534+ pub const TAG_RGB_AMOUNT : u8 = 30 ;
535+ pub const TAG_RGB_CONTRACT_ID : u8 = 31 ;
521536}
522537
523538impl InvoiceBuilder < tb:: False , tb:: False , tb:: False , tb:: False , tb:: False , tb:: False > {
@@ -607,6 +622,18 @@ impl<D: tb::Bool, H: tb::Bool, T: tb::Bool, C: tb::Bool, S: tb::Bool, M: tb::Boo
607622 }
608623 self
609624 }
625+
626+ /// Sets the RGB amount.
627+ pub fn rgb_amount ( mut self , rgb_amount : u64 ) -> Self {
628+ self . tagged_fields . push ( TaggedField :: RgbAmount ( RgbAmount ( rgb_amount) ) ) ;
629+ self
630+ }
631+
632+ /// Sets the RGB contract ID.
633+ pub fn rgb_contract_id ( mut self , rgb_contract_id : ContractId ) -> Self {
634+ self . tagged_fields . push ( TaggedField :: RgbContractId ( RgbContractId ( rgb_contract_id) ) ) ;
635+ self
636+ }
610637}
611638
612639impl < D : tb:: Bool , H : tb:: Bool , C : tb:: Bool , S : tb:: Bool , M : tb:: Bool > InvoiceBuilder < D , H , tb:: True , C , S , M > {
@@ -1065,6 +1092,14 @@ impl RawBolt11Invoice {
10651092 find_extract ! ( self . known_tagged_fields( ) , TaggedField :: Features ( ref x) , x)
10661093 }
10671094
1095+ pub fn rgb_amount ( & self ) -> Option < & RgbAmount > {
1096+ find_extract ! ( self . known_tagged_fields( ) , TaggedField :: RgbAmount ( ref x) , x)
1097+ }
1098+
1099+ pub fn rgb_contract_id ( & self ) -> Option < & RgbContractId > {
1100+ find_extract ! ( self . known_tagged_fields( ) , TaggedField :: RgbContractId ( ref x) , x)
1101+ }
1102+
10681103 /// This is not exported to bindings users as we don't support Vec<&NonOpaqueType>
10691104 pub fn fallbacks ( & self ) -> Vec < & Fallback > {
10701105 find_all_extract ! ( self . known_tagged_fields( ) , TaggedField :: Fallback ( ref x) , x) . collect ( )
@@ -1483,6 +1518,18 @@ impl Bolt11Invoice {
14831518 fn amount_pico_btc ( & self ) -> Option < u64 > {
14841519 self . signed_invoice . amount_pico_btc ( )
14851520 }
1521+
1522+ /// Returns the invoice's `rgb_amount` if present
1523+ pub fn rgb_amount ( & self ) -> Option < u64 > {
1524+ self . signed_invoice . rgb_amount ( )
1525+ . map ( |x| x. 0 )
1526+ }
1527+
1528+ /// Returns the invoice's `rgb_contract_id` if present
1529+ pub fn rgb_contract_id ( & self ) -> Option < ContractId > {
1530+ self . signed_invoice . rgb_contract_id ( )
1531+ . map ( |x| x. 0 )
1532+ }
14861533}
14871534
14881535impl From < TaggedField > for RawTaggedField {
@@ -1506,6 +1553,8 @@ impl TaggedField {
15061553 TaggedField :: PaymentSecret ( _) => constants:: TAG_PAYMENT_SECRET ,
15071554 TaggedField :: PaymentMetadata ( _) => constants:: TAG_PAYMENT_METADATA ,
15081555 TaggedField :: Features ( _) => constants:: TAG_FEATURES ,
1556+ TaggedField :: RgbAmount ( _) => constants:: TAG_RGB_AMOUNT ,
1557+ TaggedField :: RgbContractId ( _) => constants:: TAG_RGB_CONTRACT_ID ,
15091558 } ;
15101559
15111560 u5:: try_from_u8 ( tag) . expect ( "all tags defined are <32" )
0 commit comments