Skip to content

Commit 9158e30

Browse files
committed
f - rename payer_note
1 parent bf3d166 commit 9158e30

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lightning/src/ln/offers_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
416416
amount_msats: None,
417417
features: InvoiceRequestFeatures::empty(),
418418
quantity: None,
419-
payer_note: None,
419+
payer_note_truncated: None,
420420
},
421421
});
422422
assert_eq!(invoice_request.amount_msats(), None);
@@ -570,7 +570,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
570570
amount_msats: None,
571571
features: InvoiceRequestFeatures::empty(),
572572
quantity: None,
573-
payer_note: None,
573+
payer_note_truncated: None,
574574
},
575575
});
576576
assert_eq!(invoice_request.amount_msats(), None);
@@ -693,7 +693,7 @@ fn pays_for_offer_without_blinded_paths() {
693693
amount_msats: None,
694694
features: InvoiceRequestFeatures::empty(),
695695
quantity: None,
696-
payer_note: None,
696+
payer_note_truncated: None,
697697
},
698698
});
699699

lightning/src/offers/invoice_request.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ impl VerifiedInvoiceRequest {
887887
amount_msats: *amount_msats,
888888
features: features.clone(),
889889
quantity: *quantity,
890-
payer_note: payer_note.clone().map(|mut s| { s.truncate(512); UntrustedString(s) }),
890+
payer_note_truncated: payer_note.clone()
891+
.map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
891892
}
892893
}
893894
}
@@ -1142,10 +1143,13 @@ pub struct InvoiceRequestFields {
11421143
pub quantity: Option<u64>,
11431144

11441145
/// A payer-provided note which will be seen by the recipient and reflected back in the invoice
1145-
/// response.
1146-
pub payer_note: Option<UntrustedString>,
1146+
/// response. Truncated to [`PAYER_NOTE_LIMIT`] characters.
1147+
pub payer_note_truncated: Option<UntrustedString>,
11471148
}
11481149

1150+
/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
1151+
pub const PAYER_NOTE_LIMIT: usize = 512;
1152+
11491153
impl Writeable for InvoiceRequestFields {
11501154
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
11511155
write_tlv_fields!(writer, {
@@ -1154,7 +1158,7 @@ impl Writeable for InvoiceRequestFields {
11541158
(4, self.amount_msats, option),
11551159
(6, WithoutLength(&self.features), required),
11561160
(8, self.quantity, option),
1157-
(10, self.payer_note, option),
1161+
(10, self.payer_note_truncated, option),
11581162
});
11591163
Ok(())
11601164
}
@@ -1168,19 +1172,20 @@ impl Readable for InvoiceRequestFields {
11681172
(4, amount_msats, option),
11691173
(6, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))),
11701174
(8, quantity, option),
1171-
(10, payer_note, option),
1175+
(10, payer_note_truncated, option),
11721176
});
11731177
let features = features.unwrap_or(InvoiceRequestFeatures::empty());
11741178

11751179
Ok(InvoiceRequestFields {
1176-
payer_id: payer_id.0.unwrap(), chain, amount_msats, features, quantity, payer_note
1180+
payer_id: payer_id.0.unwrap(), chain, amount_msats, features, quantity,
1181+
payer_note_truncated,
11771182
})
11781183
}
11791184
}
11801185

11811186
#[cfg(test)]
11821187
mod tests {
1183-
use super::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestTlvStreamRef, SIGNATURE_TAG, UnsignedInvoiceRequest};
1188+
use super::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestTlvStreamRef, PAYER_NOTE_LIMIT, SIGNATURE_TAG, UnsignedInvoiceRequest};
11841189

11851190
use bitcoin::blockdata::constants::ChainHash;
11861191
use bitcoin::network::constants::Network;
@@ -2268,7 +2273,7 @@ mod tests {
22682273
.chain(Network::Testnet).unwrap()
22692274
.amount_msats(1001).unwrap()
22702275
.quantity(1).unwrap()
2271-
.payer_note("0".repeat(1024))
2276+
.payer_note("0".repeat(PAYER_NOTE_LIMIT * 2))
22722277
.build().unwrap()
22732278
.sign(payer_sign).unwrap();
22742279
match invoice_request.verify(&expanded_key, &secp_ctx) {
@@ -2282,7 +2287,7 @@ mod tests {
22822287
amount_msats: Some(1001),
22832288
features: InvoiceRequestFeatures::empty(),
22842289
quantity: Some(1),
2285-
payer_note: Some(UntrustedString("0".repeat(512))),
2290+
payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
22862291
}
22872292
);
22882293
},

0 commit comments

Comments
 (0)