Skip to content

Commit

Permalink
f - rename payer_note
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Apr 14, 2024
1 parent bf3d166 commit 9158e30
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lightning/src/ln/offers_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
amount_msats: None,
features: InvoiceRequestFeatures::empty(),
quantity: None,
payer_note: None,
payer_note_truncated: None,
},
});
assert_eq!(invoice_request.amount_msats(), None);
Expand Down Expand Up @@ -570,7 +570,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
amount_msats: None,
features: InvoiceRequestFeatures::empty(),
quantity: None,
payer_note: None,
payer_note_truncated: None,
},
});
assert_eq!(invoice_request.amount_msats(), None);
Expand Down Expand Up @@ -693,7 +693,7 @@ fn pays_for_offer_without_blinded_paths() {
amount_msats: None,
features: InvoiceRequestFeatures::empty(),
quantity: None,
payer_note: None,
payer_note_truncated: None,
},
});

Expand Down
23 changes: 14 additions & 9 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,8 @@ impl VerifiedInvoiceRequest {
amount_msats: *amount_msats,
features: features.clone(),
quantity: *quantity,
payer_note: payer_note.clone().map(|mut s| { s.truncate(512); UntrustedString(s) }),
payer_note_truncated: payer_note.clone()
.map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
}
}
}
Expand Down Expand Up @@ -1142,10 +1143,13 @@ pub struct InvoiceRequestFields {
pub quantity: Option<u64>,

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

/// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
pub const PAYER_NOTE_LIMIT: usize = 512;

impl Writeable for InvoiceRequestFields {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
write_tlv_fields!(writer, {
Expand All @@ -1154,7 +1158,7 @@ impl Writeable for InvoiceRequestFields {
(4, self.amount_msats, option),
(6, WithoutLength(&self.features), required),
(8, self.quantity, option),
(10, self.payer_note, option),
(10, self.payer_note_truncated, option),
});
Ok(())
}
Expand All @@ -1168,19 +1172,20 @@ impl Readable for InvoiceRequestFields {
(4, amount_msats, option),
(6, features, (option, encoding: (InvoiceRequestFeatures, WithoutLength))),
(8, quantity, option),
(10, payer_note, option),
(10, payer_note_truncated, option),
});
let features = features.unwrap_or(InvoiceRequestFeatures::empty());

Ok(InvoiceRequestFields {
payer_id: payer_id.0.unwrap(), chain, amount_msats, features, quantity, payer_note
payer_id: payer_id.0.unwrap(), chain, amount_msats, features, quantity,
payer_note_truncated,
})
}
}

#[cfg(test)]
mod tests {
use super::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestTlvStreamRef, SIGNATURE_TAG, UnsignedInvoiceRequest};
use super::{InvoiceRequest, InvoiceRequestFields, InvoiceRequestTlvStreamRef, PAYER_NOTE_LIMIT, SIGNATURE_TAG, UnsignedInvoiceRequest};

use bitcoin::blockdata::constants::ChainHash;
use bitcoin::network::constants::Network;
Expand Down Expand Up @@ -2268,7 +2273,7 @@ mod tests {
.chain(Network::Testnet).unwrap()
.amount_msats(1001).unwrap()
.quantity(1).unwrap()
.payer_note("0".repeat(1024))
.payer_note("0".repeat(PAYER_NOTE_LIMIT * 2))
.build().unwrap()
.sign(payer_sign).unwrap();
match invoice_request.verify(&expanded_key, &secp_ctx) {
Expand All @@ -2282,7 +2287,7 @@ mod tests {
amount_msats: Some(1001),
features: InvoiceRequestFeatures::empty(),
quantity: Some(1),
payer_note: Some(UntrustedString("0".repeat(512))),
payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
}
);
},
Expand Down

0 comments on commit 9158e30

Please sign in to comment.