common/bolt12: add code to generate offer_id, extract parts of streams.

The new spec removes the offer_id, in favor of mirroring all the
fields.  So we need a way of generating a convenient identifier to
identify the offer, and this works.

We also want to extract parts of streams elsewhere, so expose that.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2022-11-09 13:02:00 +10:30
committed by Christian Decker
parent c2c9f45dac
commit aa73878831
5 changed files with 226 additions and 0 deletions

View File

@@ -120,4 +120,21 @@ void offer_period_paywindow(const struct tlv_offer_recurrence *recurrence,
*/
bool bolt12_has_prefix(const char *str);
/**
* tlv_span: Find span of this inclusive range of tlv types
* @tlvstream: the tlv stream
* @minfield: lowest field to find
* @maxfield: highest field to find
* @start: (out) optional offset of start.
*
* Returns length, so 0 means nothing found.
*/
size_t tlv_span(const u8 *tlvstream, size_t minfield, size_t maxfield,
size_t *start);
/* Get offer_id referred to by various structures. */
void offer_offer_id(const struct tlv_offer *offer, struct sha256 *id);
void invreq_offer_id(const struct tlv_invoice_request *invreq, struct sha256 *id);
void invoice_offer_id(const struct tlv_invoice *invoice, struct sha256 *id);
#endif /* LIGHTNING_COMMON_BOLT12_H */