@@ -91,11 +91,11 @@ use crate::blinded_path::BlindedPath;
91
91
use crate :: ln:: channelmanager:: PaymentId ;
92
92
use crate :: ln:: features:: OfferFeatures ;
93
93
use crate :: ln:: inbound_payment:: { ExpandedKey , IV_LEN , Nonce } ;
94
- use crate :: ln:: msgs:: MAX_VALUE_MSAT ;
94
+ use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
95
95
use crate :: offers:: merkle:: TlvStream ;
96
96
use crate :: offers:: parse:: { Bech32Encode , Bolt12ParseError , Bolt12SemanticError , ParsedMessage } ;
97
97
use crate :: offers:: signer:: { Metadata , MetadataMaterial , self } ;
98
- use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , WithoutLength , Writeable , Writer } ;
98
+ use crate :: util:: ser:: { HighZeroBytesDroppedBigSize , Readable , WithoutLength , Writeable , Writer } ;
99
99
use crate :: util:: string:: PrintableString ;
100
100
101
101
#[ cfg( not( c_bindings) ) ]
@@ -114,6 +114,23 @@ use std::time::SystemTime;
114
114
115
115
pub ( super ) const IV_BYTES : & [ u8 ; IV_LEN ] = b"LDK Offer ~~~~~~" ;
116
116
117
+ /// An identifier for an [`Offer`] built using [`DerivedMetadata`].
118
+ #[ derive( Clone , Copy , Debug , PartialEq ) ]
119
+ pub struct OfferId ( Nonce ) ;
120
+
121
+ impl Writeable for OfferId {
122
+ fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
123
+ self . 0 . 0 . write ( w)
124
+ }
125
+ }
126
+
127
+ impl Readable for OfferId {
128
+ fn read < R : io:: Read > ( r : & mut R ) -> Result < Self , DecodeError > {
129
+ let buf: [ u8 ; Nonce :: LENGTH ] = Readable :: read ( r) ?;
130
+ Ok ( OfferId ( Nonce ( buf) ) )
131
+ }
132
+ }
133
+
117
134
/// Builds an [`Offer`] for the "offer to be paid" flow.
118
135
///
119
136
/// See [module-level documentation] for usage.
@@ -123,7 +140,7 @@ pub(super) const IV_BYTES: &[u8; IV_LEN] = b"LDK Offer ~~~~~~";
123
140
/// [module-level documentation]: self
124
141
pub struct OfferBuilder < ' a , M : MetadataStrategy , T : secp256k1:: Signing > {
125
142
offer : OfferContents ,
126
- metadata_strategy : core :: marker :: PhantomData < M > ,
143
+ metadata_strategy : M ,
127
144
secp_ctx : Option < & ' a Secp256k1 < T > > ,
128
145
}
129
146
@@ -151,7 +168,7 @@ pub struct OfferWithExplicitMetadataBuilder<'a> {
151
168
#[ cfg( c_bindings) ]
152
169
pub struct OfferWithDerivedMetadataBuilder < ' a > {
153
170
offer : OfferContents ,
154
- metadata_strategy : core :: marker :: PhantomData < DerivedMetadata > ,
171
+ metadata_strategy : DerivedMetadata ,
155
172
secp_ctx : Option < & ' a Secp256k1 < secp256k1:: All > > ,
156
173
}
157
174
@@ -163,12 +180,13 @@ pub trait MetadataStrategy {}
163
180
/// [`Offer::metadata`] may be explicitly set or left empty.
164
181
///
165
182
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
183
+ #[ derive( Default ) ]
166
184
pub struct ExplicitMetadata { }
167
185
168
186
/// [`Offer::metadata`] will be derived.
169
187
///
170
188
/// This is not exported to bindings users as builder patterns don't map outside of move semantics.
171
- pub struct DerivedMetadata { }
189
+ pub struct DerivedMetadata ( OfferId ) ;
172
190
173
191
impl MetadataStrategy for ExplicitMetadata { }
174
192
@@ -197,7 +215,7 @@ macro_rules! offer_explicit_metadata_builder_methods { (
197
215
features: OfferFeatures :: empty( ) , absolute_expiry: None , issuer: None , paths: None ,
198
216
supported_quantity: Quantity :: One , signing_pubkey,
199
217
} ,
200
- metadata_strategy: core :: marker :: PhantomData ,
218
+ metadata_strategy: Default :: default ( ) ,
201
219
secp_ctx: None ,
202
220
}
203
221
}
@@ -236,10 +254,15 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => {
236
254
features: OfferFeatures :: empty( ) , absolute_expiry: None , issuer: None , paths: None ,
237
255
supported_quantity: Quantity :: One , signing_pubkey: node_id,
238
256
} ,
239
- metadata_strategy: core :: marker :: PhantomData ,
257
+ metadata_strategy: DerivedMetadata ( OfferId ( nonce ) ) ,
240
258
secp_ctx: Some ( secp_ctx) ,
241
259
}
242
260
}
261
+
262
+ /// Returns an identifier for the [`Offer`] constructed by the builder.
263
+ pub fn offer_id( & self ) -> OfferId {
264
+ self . metadata_strategy. 0
265
+ }
243
266
} }
244
267
245
268
macro_rules! offer_builder_methods { (
0 commit comments