mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-23 15:04:19 +01:00
bolt12: update to latest spec.
Main changes are: 1. Uses point32 instead of pubkey32. 2. Uses issuer instead of vendor. 3. Uses byte instead of u8. 4. blinded_path num_hops is now a byte, not u16 (we don't use that yet!). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-EXPERIMENTAL: bolt12: `vendor` is deprecated: the field is now called `issuer`.
This commit is contained in:
committed by
Christian Decker
parent
8f582e770c
commit
45bf7a3974
@@ -329,18 +329,18 @@ static struct command_result *handle_invreq_response(struct command *cmd,
|
||||
}
|
||||
|
||||
/* BOLT-offers #12:
|
||||
* - SHOULD confirm authorization if `vendor` does not exactly
|
||||
* - SHOULD confirm authorization if `issuer` does not exactly
|
||||
* match the `offer`
|
||||
*/
|
||||
if (field_diff(sent->offer, inv, vendor)) {
|
||||
if (!inv->vendor)
|
||||
json_add_stringn(out, "vendor_removed",
|
||||
sent->offer->vendor,
|
||||
tal_bytelen(sent->offer->vendor));
|
||||
if (field_diff(sent->offer, inv, issuer)) {
|
||||
if (!inv->issuer)
|
||||
json_add_stringn(out, "issuer_removed",
|
||||
sent->offer->issuer,
|
||||
tal_bytelen(sent->offer->issuer));
|
||||
else
|
||||
json_add_stringn(out, "vendor",
|
||||
inv->vendor,
|
||||
tal_bytelen(inv->vendor));
|
||||
json_add_stringn(out, "issuer",
|
||||
inv->issuer,
|
||||
tal_bytelen(inv->issuer));
|
||||
}
|
||||
/* BOLT-offers #12:
|
||||
* - SHOULD confirm authorization if `msat` is not within the amount
|
||||
|
||||
@@ -425,9 +425,14 @@ static void json_add_offer(struct json_stream *js, const struct tlv_offer *offer
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (offer->vendor)
|
||||
json_add_stringn(js, "vendor", offer->vendor,
|
||||
tal_bytelen(offer->vendor));
|
||||
if (offer->issuer) {
|
||||
json_add_stringn(js, "issuer", offer->issuer,
|
||||
tal_bytelen(offer->issuer));
|
||||
if (deprecated_apis) {
|
||||
json_add_stringn(js, "vendor", offer->issuer,
|
||||
tal_bytelen(offer->issuer));
|
||||
}
|
||||
}
|
||||
if (offer->features)
|
||||
json_add_hex_talarr(js, "features", offer->features);
|
||||
if (offer->absolute_expiry)
|
||||
@@ -587,9 +592,14 @@ static void json_add_b12_invoice(struct json_stream *js,
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (invoice->vendor)
|
||||
json_add_stringn(js, "vendor", invoice->vendor,
|
||||
tal_bytelen(invoice->vendor));
|
||||
if (invoice->issuer) {
|
||||
json_add_stringn(js, "issuer", invoice->issuer,
|
||||
tal_bytelen(invoice->issuer));
|
||||
if (deprecated_apis) {
|
||||
json_add_stringn(js, "vendor", invoice->issuer,
|
||||
tal_bytelen(invoice->issuer));
|
||||
}
|
||||
}
|
||||
if (invoice->features)
|
||||
json_add_hex_talarr(js, "features", invoice->features);
|
||||
if (invoice->paths) {
|
||||
@@ -858,14 +868,14 @@ static const struct plugin_command commands[] = {
|
||||
"offer",
|
||||
"payment",
|
||||
"Create an offer to accept money",
|
||||
"Create an offer for invoices of {amount} with {description}, optional {vendor}, internal {label}, {quantity_min}, {quantity_max}, {absolute_expiry}, {recurrence}, {recurrence_base}, {recurrence_paywindow}, {recurrence_limit} and {single_use}",
|
||||
"Create an offer for invoices of {amount} with {description}, optional {issuer}, internal {label}, {quantity_min}, {quantity_max}, {absolute_expiry}, {recurrence}, {recurrence_base}, {recurrence_paywindow}, {recurrence_limit} and {single_use}",
|
||||
json_offer
|
||||
},
|
||||
{
|
||||
"offerout",
|
||||
"payment",
|
||||
"Create an offer to send money",
|
||||
"Create an offer to pay invoices of {amount} with {description}, optional {vendor}, internal {label}, {absolute_expiry} and {refund_for}",
|
||||
"Create an offer to pay invoices of {amount} with {description}, optional {issuer}, internal {label}, {absolute_expiry} and {refund_for}",
|
||||
json_offerout
|
||||
},
|
||||
{
|
||||
|
||||
@@ -774,7 +774,7 @@ static struct command_result *listoffers_done(struct command *cmd,
|
||||
->bits[BOLT11_FEATURE]);
|
||||
/* FIXME: Insert paths and payinfo */
|
||||
|
||||
ir->inv->vendor = tal_dup_talarr(ir->inv, char, ir->offer->vendor);
|
||||
ir->inv->issuer = tal_dup_talarr(ir->inv, char, ir->offer->issuer);
|
||||
ir->inv->node_id = tal_dup(ir->inv, struct point32, ir->offer->node_id);
|
||||
/* BOLT-offers #12:
|
||||
* - MUST set (or not set) `quantity` exactly as the invoice_request
|
||||
|
||||
@@ -314,16 +314,46 @@ struct command_result *json_offer(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
const char *desc, *vendor;
|
||||
const char *desc, *issuer;
|
||||
struct tlv_offer *offer;
|
||||
struct offer_info *offinfo = tal(cmd, struct offer_info);
|
||||
|
||||
offinfo->offer = offer = tlv_offer_new(offinfo);
|
||||
|
||||
/* "issuer" used to be called "vendor" */
|
||||
if (deprecated_apis
|
||||
&& params
|
||||
&& params->type == JSMN_OBJECT
|
||||
&& json_get_member(buffer, params, "vendor")) {
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("amount", param_amount, offer),
|
||||
p_req("description", param_escaped_string, &desc),
|
||||
p_opt("vendor", param_escaped_string, &issuer),
|
||||
p_opt("label", param_escaped_string, &offinfo->label),
|
||||
p_opt("quantity_min", param_u64, &offer->quantity_min),
|
||||
p_opt("quantity_max", param_u64, &offer->quantity_max),
|
||||
p_opt("absolute_expiry", param_u64, &offer->absolute_expiry),
|
||||
p_opt("recurrence", param_recurrence, &offer->recurrence),
|
||||
p_opt("recurrence_base",
|
||||
param_recurrence_base,
|
||||
&offer->recurrence_base),
|
||||
p_opt("recurrence_paywindow",
|
||||
param_recurrence_paywindow,
|
||||
&offer->recurrence_paywindow),
|
||||
p_opt("recurrence_limit",
|
||||
param_number,
|
||||
&offer->recurrence_limit),
|
||||
p_opt_def("single_use", param_bool,
|
||||
&offinfo->single_use, false),
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
goto after_params;
|
||||
}
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("amount", param_amount, offer),
|
||||
p_req("description", param_escaped_string, &desc),
|
||||
p_opt("vendor", param_escaped_string, &vendor),
|
||||
p_opt("issuer", param_escaped_string, &issuer),
|
||||
p_opt("label", param_escaped_string, &offinfo->label),
|
||||
p_opt("quantity_min", param_u64, &offer->quantity_min),
|
||||
p_opt("quantity_max", param_u64, &offer->quantity_max),
|
||||
@@ -344,6 +374,7 @@ struct command_result *json_offer(struct command *cmd,
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
after_params:
|
||||
if (!offers_enabled)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"experimental-offers not enabled");
|
||||
@@ -398,9 +429,9 @@ struct command_result *json_offer(struct command *cmd,
|
||||
}
|
||||
|
||||
offer->description = tal_dup_arr(offer, char, desc, strlen(desc), 0);
|
||||
if (vendor) {
|
||||
offer->vendor
|
||||
= tal_dup_arr(offer, char, vendor, strlen(vendor), 0);
|
||||
if (issuer) {
|
||||
offer->issuer
|
||||
= tal_dup_arr(offer, char, issuer, strlen(issuer), 0);
|
||||
}
|
||||
|
||||
offer->node_id = tal_dup(offer, struct point32, &id);
|
||||
@@ -427,16 +458,34 @@ struct command_result *json_offerout(struct command *cmd,
|
||||
const char *buffer,
|
||||
const jsmntok_t *params)
|
||||
{
|
||||
const char *desc, *vendor, *label;
|
||||
const char *desc, *issuer, *label;
|
||||
struct tlv_offer *offer;
|
||||
struct out_req *req;
|
||||
|
||||
offer = tlv_offer_new(cmd);
|
||||
|
||||
/* "issuer" used to be called "vendor" */
|
||||
if (deprecated_apis
|
||||
&& params
|
||||
&& params->type == JSMN_OBJECT
|
||||
&& json_get_member(buffer, params, "vendor")) {
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("amount", param_msat_or_any, offer),
|
||||
p_req("description", param_escaped_string, &desc),
|
||||
p_opt("vendor", param_escaped_string, &issuer),
|
||||
p_opt("label", param_escaped_string, &label),
|
||||
p_opt("absolute_expiry", param_u64, &offer->absolute_expiry),
|
||||
p_opt("refund_for", param_invoice_payment_hash, &offer->refund_for),
|
||||
/* FIXME: hints support! */
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
goto after_params;
|
||||
}
|
||||
|
||||
if (!param(cmd, buffer, params,
|
||||
p_req("amount", param_msat_or_any, offer),
|
||||
p_req("description", param_escaped_string, &desc),
|
||||
p_opt("vendor", param_escaped_string, &vendor),
|
||||
p_opt("issuer", param_escaped_string, &issuer),
|
||||
p_opt("label", param_escaped_string, &label),
|
||||
p_opt("absolute_expiry", param_u64, &offer->absolute_expiry),
|
||||
p_opt("refund_for", param_invoice_payment_hash, &offer->refund_for),
|
||||
@@ -444,6 +493,7 @@ struct command_result *json_offerout(struct command *cmd,
|
||||
NULL))
|
||||
return command_param_failed();
|
||||
|
||||
after_params:
|
||||
if (!offers_enabled)
|
||||
return command_fail(cmd, LIGHTNINGD,
|
||||
"experimental-offers not enabled");
|
||||
@@ -463,9 +513,9 @@ struct command_result *json_offerout(struct command *cmd,
|
||||
}
|
||||
|
||||
offer->description = tal_dup_arr(offer, char, desc, strlen(desc), 0);
|
||||
if (vendor)
|
||||
offer->vendor = tal_dup_arr(offer, char,
|
||||
vendor, strlen(vendor), 0);
|
||||
if (issuer)
|
||||
offer->issuer = tal_dup_arr(offer, char,
|
||||
issuer, strlen(issuer), 0);
|
||||
|
||||
offer->node_id = tal_dup(offer, struct point32, &id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user