Browse Source

invoice: handle bolt12 strings if EXPERIMENTAL_FEATURES.

The database still calls them `bolt11`, but we treat them depending on
prefix.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa
Rusty Russell 4 years ago
committed by Christian Decker
parent
commit
4c4288e3e5
  1. 10
      common/json.c
  2. 2
      common/json.h
  3. 4
      lightningd/invoice.c
  4. 2
      wallet/db_postgres_sqlgen.c
  5. 2
      wallet/db_sqlite3_sqlgen.c
  6. 2
      wallet/invoices.c
  7. 2
      wallet/statements_gettextgen.po
  8. 4
      wallet/wallet.h

10
common/json.c

@ -895,3 +895,13 @@ void json_add_errcode(struct json_stream *result, const char *fieldname,
{
json_add_member(result, fieldname, false, "%"PRIerrcode, code);
}
void json_add_invstring(struct json_stream *result, const char *invstring)
{
#if EXPERIMENTAL_FEATURES
if (strstarts(invstring, "lni"))
json_add_string(result, "bolt12", invstring);
else
#endif
json_add_string(result, "bolt11", invstring);
}

2
common/json.h

@ -229,5 +229,7 @@ void json_add_tok(struct json_stream *result, const char *fieldname,
void json_add_errcode(struct json_stream *result, const char *fieldname,
errcode_t code);
/* Add "bolt11" or "bolt12" field, depending on invstring. */
void json_add_invstring(struct json_stream *result, const char *invstring);
#endif /* LIGHTNING_COMMON_JSON_H */

4
lightningd/invoice.c

@ -57,7 +57,7 @@ static void json_add_invoice(struct json_stream *response,
const struct invoice_details *inv)
{
json_add_escaped_string(response, "label", inv->label);
json_add_string(response, "bolt11", inv->bolt11);
json_add_invstring(response, inv->invstring);
json_add_sha256(response, "payment_hash", &inv->rhash);
if (inv->msat)
json_add_amount_msat_compat(response, *inv->msat,
@ -741,7 +741,7 @@ static void gossipd_incoming_channels_reply(struct subd *gossipd,
response = json_stream_success(info->cmd);
json_add_sha256(response, "payment_hash", &details->rhash);
json_add_u64(response, "expires_at", details->expiry_time);
json_add_string(response, "bolt11", details->bolt11);
json_add_string(response, "bolt11", details->invstring);
notify_invoice_creation(info->cmd->ld, info->b11->msat,
info->payment_preimage, info->label);

2
wallet/db_postgres_sqlgen.c

@ -1762,4 +1762,4 @@ struct db_query db_postgres_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */
// SHA256STAMP:682d4f3ac081ef003be6eba257a5e5e023fee5169592c760c8878288ee12f212
// SHA256STAMP:93d29f78f9f38cc779f4fbea480b90ce38899ff1c2f534e4160b2bf8a05b57ee

2
wallet/db_sqlite3_sqlgen.c

@ -1762,4 +1762,4 @@ struct db_query db_sqlite3_queries[] = {
#endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */
// SHA256STAMP:682d4f3ac081ef003be6eba257a5e5e023fee5169592c760c8878288ee12f212
// SHA256STAMP:93d29f78f9f38cc779f4fbea480b90ce38899ff1c2f534e4160b2bf8a05b57ee

2
wallet/invoices.c

@ -107,7 +107,7 @@ static struct invoice_details *wallet_stmt2invoice_details(const tal_t *ctx,
dtl->paid_timestamp = db_column_u64(stmt, 8);
}
dtl->bolt11 = tal_strndup(dtl, db_column_blob(stmt, 9),
dtl->invstring = tal_strndup(dtl, db_column_blob(stmt, 9),
db_column_bytes(stmt, 9));
if (!db_column_is_null(stmt, 10))

2
wallet/statements_gettextgen.po

@ -1161,4 +1161,4 @@ msgstr ""
#: wallet/test/run-wallet.c:1378
msgid "INSERT INTO channels (id) VALUES (1);"
msgstr ""
# SHA256STAMP:edc18cc0be69eb519707d9442372246c466d08ec7ed12f24584be19ae9032d9b
# SHA256STAMP:f567e217e4f94d8fd86c0c8d6997931d891df4f8295517fa527b80a323b256a8

4
wallet/wallet.h

@ -722,8 +722,8 @@ struct invoice_details {
struct amount_msat received;
/* Set if state == PAID; time paid */
u64 paid_timestamp;
/* BOLT11 encoding for this invoice */
const char *bolt11;
/* BOLT11 or BOLT12 encoding for this invoice */
const char *invstring;
/* The description of the payment. */
char *description;

Loading…
Cancel
Save