Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offers fixes #4669

Merged
merged 9 commits into from
Jul 21, 2021
4 changes: 2 additions & 2 deletions common/bolt12.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ struct feature_set;
/* BOLT-offers #12:
* - if `relative_expiry` is present:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `timestamp` plus `seconds_from_timestamp`.
* is greater than `created_at` plus `seconds_from_creation`.
* - otherwise:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `timestamp` plus 7200.
* is greater than `created_at` plus 7200.
*/
#define BOLT12_DEFAULT_REL_EXPIRY 7200

Expand Down
22 changes: 11 additions & 11 deletions devtools/bolt12-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,9 @@ static void print_payer_note(const char *payer_note)
(int)tal_bytelen(payer_note), payer_note);
}

static void print_timestamp(u64 timestamp)
static void print_created_at(u64 timestamp)
{
printf("timestamp: %"PRIu64" (%s)\n",
printf("created_at: %"PRIu64" (%s)\n",
timestamp, fmt_time(tmpctx, timestamp));
}

Expand All @@ -396,27 +396,27 @@ static void print_cltv(u32 cltv)
printf("min_final_cltv_expiry: %u\n", cltv);
}

static void print_relative_expiry(u64 *timestamp, u32 *relative)
static void print_relative_expiry(u64 *created_at, u32 *relative)
{
/* Ignore if already malformed */
if (!timestamp)
if (!created_at)
return;

/* BOLT-offers #12:
* - if `relative_expiry` is present:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `timestamp` plus `seconds_from_timestamp`.
* is greater than `created_at` plus `seconds_from_creation`.
* - otherwise:
* - MUST reject the invoice if the current time since 1970-01-01 UTC
* is greater than `timestamp` plus 7200.
* is greater than `created_at` plus 7200.
*/
if (!relative)
printf("relative_expiry: %u (%s) (default)\n",
BOLT12_DEFAULT_REL_EXPIRY,
fmt_time(tmpctx, *timestamp + BOLT12_DEFAULT_REL_EXPIRY));
fmt_time(tmpctx, *created_at + BOLT12_DEFAULT_REL_EXPIRY));
else
printf("relative_expiry: %u (%s)\n", *relative,
fmt_time(tmpctx, *timestamp + *relative));
fmt_time(tmpctx, *created_at + *relative));
}

static void print_fallbacks(const struct tlv_invoice_fallbacks *fallbacks)
Expand Down Expand Up @@ -622,11 +622,11 @@ int main(int argc, char *argv[])
}
if (must_have(invoice, payer_key))
print_payer_key(invoice->payer_key, invoice->payer_info);
if (must_have(invoice, timestamp))
print_timestamp(*invoice->timestamp);
if (must_have(invoice, created_at))
print_created_at(*invoice->created_at);
if (invoice->payer_note)
print_payer_note(invoice->payer_note);
print_relative_expiry(invoice->timestamp,
print_relative_expiry(invoice->created_at,
invoice->relative_expiry);
if (must_have(invoice, payment_hash))
print_payment_hash(invoice->payment_hash);
Expand Down
8 changes: 4 additions & 4 deletions doc/lightning-decode.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions doc/lightning-decode.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ If **type** is "bolt12 invoice", and **valid** is *true*:
- **signature** (bip340sig): BIP-340 signature of the *node_id* on this offer
- **amount_msat** (msat): the amount in bitcoin
- **description** (string): the description of the purpose of the offer
- **timestamp** (u64): the UNIX timestamp of the invoice
- **created_at** (u64): the UNIX timestamp of invoice creation
- **payment_hash** (hex): the hash of the *payment_preimage* (always 64 characters)
- **relative_expiry** (u32): the number of seconds after *timestamp* when this expires
- **relative_expiry** (u32): the number of seconds after *created_at* when this expires
- **min_final_cltv_expiry** (u32): the number of blocks required by destination
- **offer_id** (hex, optional): the id of this offer (merkle hash of non-signature fields) (always 64 characters)
- **chains** (array of hexs, optional): which blockchains this offer is for (missing implies bitcoin mainnet only):
Expand Down Expand Up @@ -108,7 +108,7 @@ If **type** is "bolt12 invoice", and **valid** is *false*:
- **warning_invoice_missing_blinded_payinfo**: Has **paths** without payinfo
- **warning_invoice_invalid_blinded_payinfo**: Does not have exactly one payinfo for each of **paths**
- **warning_invoice_missing_recurrence_basetime**: Has **recurrence_counter** without **recurrence_basetime**
- **warning_invoice_missing_timestamp**: Missing **timestamp**
- **warning_invoice_missing_created_at**: Missing **created_at**
- **warning_invoice_missing_payment_hash**: Missing **payment_hash**
- **warning_invoice_refund_signature_missing_payer_key**: Missing **payer_key** for refund_signature
- **warning_invoice_refund_signature_invalid**: **refund_signature** incorrect
Expand Down Expand Up @@ -183,4 +183,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:8ca0b9178b8ea6575cd80291001263dc27f721664648086a7c1a02efcb545ee7)
[comment]: # ( SHA256STAMP:fbbfc116c23489d4f346b4d5eb06dd922592c543ec68e5a76b6822b2658bd46d)
4 changes: 2 additions & 2 deletions doc/lightning-disableoffer.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions doc/lightning-disableoffer.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Note: the returned object is the same format as **listoffers**.
[comment]: # (GENERATE-FROM-SCHEMA-START)
On success, an object is returned, containing:
- **offer_id** (hex): the merkle hash of the offer (always 64 characters)
- **active** (boolean): Whether the offer can produce invoices/payments (always "false")
- **active** (boolean): Whether the offer can produce invoices/payments (always *false*)
- **single_use** (boolean): Whether the offer is disabled after first successful use
- **bolt12** (string): The bolt12 string representing this offer
- **bolt12_unsigned** (string): The bolt12 string representing this offer, without signature
Expand Down Expand Up @@ -73,4 +73,4 @@ RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:5b96eca3e35f6c556b93db1743c617b59e69058c9421ece9cc99a9c8814c176b)
[comment]: # ( SHA256STAMP:8f0595c22a7684d99da3000cc19b2465991fa1d2ee435a395b7a1527330aa490)
19 changes: 13 additions & 6 deletions doc/lightning-offer.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions doc/lightning-offer.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ SYNOPSIS
DESCRIPTION
-----------

The **offer** RPC command creates an offer, which is a precursor to
creating one or more invoices. It automatically enables the processing of
an incoming invoice_request, and issuing of invoices.
The **offer** RPC command creates an offer (or returns an existing
one), which is a precursor to creating one or more invoices. It
automatically enables the processing of an incoming invoice_request,
and issuing of invoices.

Note that it creates two variants of the offer: a signed and an
unsigned one (which is smaller). Wallets should accept both: the
Expand Down Expand Up @@ -100,7 +101,8 @@ On success, an object is returned, containing:
- **single_use** (boolean): whether this expires as soon as it's paid (reflects the *single_use* parameter)
- **bolt12** (string): the bolt12 encoding of the offer
- **bolt12_unsigned** (string): the bolt12 encoding of the offer, without a signature
- **used** (boolean): True if an associated invoice has been paid (always *false*)
- **used** (boolean): True if an associated invoice has been paid
- **created** (boolean): false if the offer already existed
- **label** (string, optional): the (optional) user-specified label
[comment]: # (GENERATE-FROM-SCHEMA-END)

Expand All @@ -109,9 +111,12 @@ lightning process fails before responding, the caller should use
lightning-listoffers(7) to query whether this offer was created or
not.

If the offer already existed, and is still active, that is returned;
if it's not active then this call fails.

The following error codes may occur:
- -1: Catchall nonspecific error.
- 1000: Offer with this offer_id already exists.
- 1000: Offer with this offer_id already exists (but is not active).

AUTHOR
------
Expand All @@ -128,4 +133,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:0f9cfd3cc68aaba20af0eee763c93b475016619d960e3f5bbc0b762a809f0fef)
[comment]: # ( SHA256STAMP:53f1460e28d45129b2c00b7116c87eb47a5b717f7912f499e864f4aa28b320fa)
4 changes: 3 additions & 1 deletion doc/lightning-offerout.7

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion doc/lightning-offerout.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ On success, an object is returned, containing:
- **bolt12** (string): the bolt12 encoding of the offer
- **bolt12_unsigned** (string): the bolt12 encoding of the offer, without a signature
- **used** (boolean): True if an incoming invoice has been paid (always *false*)
- **created** (boolean): false if the offer already existed
- **label** (string, optional): the (optional) user-specified label
[comment]: # (GENERATE-FROM-SCHEMA-END)

Expand Down Expand Up @@ -97,4 +98,4 @@ RESOURCES

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:2b7e7b543a88a10dbfbca2508e034af79f43ed0845abdb9df1fdf7e28ee33c26)
[comment]: # ( SHA256STAMP:14fada9336956a08b6d55c4ce01fcb62726cbdef9a065f1966335f61c4e91ce5)
14 changes: 9 additions & 5 deletions doc/schemas/decode.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
}
},
"then": {
"required": [ "node_id", "signature", "amount_msat", "description", "timestamp", "payment_hash", "relative_expiry", "min_final_cltv_expiry" ],
"required": [ "node_id", "signature", "amount_msat", "description", "created_at", "payment_hash", "relative_expiry", "min_final_cltv_expiry" ],
"additionalProperties": false,
"properties": {
"type": { },
Expand Down Expand Up @@ -378,8 +378,11 @@
"description": "the payer-provided blob to derive payer_key"
},
"timestamp": {
"deprecated": true
},
"created_at": {
"type": "u64",
"description": "the UNIX timestamp of the invoice"
"description": "the UNIX timestamp of invoice creation"
},
"payment_hash": {
"type": "hex",
Expand All @@ -389,7 +392,7 @@
},
"relative_expiry": {
"type": "u32",
"description": "the number of seconds after *timestamp* when this expires"
"description": "the number of seconds after *created_at* when this expires"
},
"min_final_cltv_expiry": {
"type": "u32",
Expand Down Expand Up @@ -462,6 +465,7 @@
"payer_key": { },
"payer_info": { },
"timestamp": { },
"created_at": { },
"payment_hash": { },
"relative_expiry": { },
"min_final_cltv_expiry": { },
Expand All @@ -487,9 +491,9 @@
"type": "string",
"description": "Has **recurrence_counter** without **recurrence_basetime**"
},
"warning_invoice_missing_timestamp": {
"warning_invoice_missing_created_at": {
"type": "string",
"description": "Missing **timestamp**"
"description": "Missing **created_at**"
},
"warning_invoice_missing_payment_hash": {
"type": "string",
Expand Down
2 changes: 1 addition & 1 deletion doc/schemas/disableoffer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"active": {
"type": "boolean",
"enum": [ "false" ],
"enum": [ false ],
"description": "Whether the offer can produce invoices/payments"
},
"single_use": {
Expand Down
7 changes: 5 additions & 2 deletions doc/schemas/offer.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used" ],
"required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used", "created" ],
"properties": {
"offer_id": {
"type": "hex",
Expand All @@ -29,9 +29,12 @@
},
"used": {
"type": "boolean",
"enum": [ false ],
"description": "True if an associated invoice has been paid"
},
"created": {
"type": "boolean",
"description": "false if the offer already existed"
},
"label": {
"type": "string",
"description": "the (optional) user-specified label"
Expand Down
6 changes: 5 additions & 1 deletion doc/schemas/offerout.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used" ],
"required": [ "offer_id", "active", "single_use", "bolt12", "bolt12_unsigned", "used", "created" ],
"properties": {
"offer_id": {
"type": "hex",
Expand Down Expand Up @@ -33,6 +33,10 @@
"enum": [ false ],
"description": "True if an incoming invoice has been paid"
},
"created": {
"type": "boolean",
"description": "false if the offer already existed"
},
"label": {
"type": "string",
"description": "the (optional) user-specified label"
Expand Down
Loading