Skip to content

Commit

Permalink
lightningd: don't print out notification msat fields as strings.
Browse files Browse the repository at this point in the history
Reported-by: Shahana Farooqui
Changelog-Fixed: JSON-RPC: Plugin notification `msat` fields in `invoice_payment` and `invoice_created` hooks now a number, not a string with "msat" suffix.
Changelog-Fixed: JSON-RPC: Plugin hook `payment` `msat` field is now a number, not a string with "msat" suffix.
  • Loading branch information
rustyrussell authored and ShahanaFarooqui committed Nov 21, 2023
1 parent 8796536 commit d7ddde3
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion common/json_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void json_add_amount_msat(struct json_stream *result,
const char *msatfieldname,
struct amount_msat msat)
{
assert(strends(msatfieldname, "_msat"));
assert(strends(msatfieldname, "_msat") || streq(msatfieldname, "msat"));
json_add_u64(result, msatfieldname, msat.millisatoshis); /* Raw: low-level helper */
}

Expand Down
4 changes: 1 addition & 3 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ invoice_payment_serialize(struct invoice_payment_hook_payload *payload,
json_object_start(stream, "payment");
json_add_escaped_string(stream, "label", payload->label);
json_add_preimage(stream, "preimage", &payload->preimage);
json_add_string(stream, "msat",
type_to_string(tmpctx, struct amount_msat,
&payload->msat));
json_add_amount_msat(stream, "msat", payload->msat);

if (payload->ld->developer && payload->set)
invoice_payment_add_tlvs(stream, payload->set);
Expand Down
7 changes: 2 additions & 5 deletions lightningd/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ static void invoice_payment_notification_serialize(struct json_stream *stream,
const struct bitcoin_outpoint *outpoint)
{
json_object_start(stream, "invoice_payment");
json_add_string(stream, "msat",
type_to_string(tmpctx, struct amount_msat, &amount));
json_add_amount_msat(stream, "msat", amount);
json_add_hex(stream, "preimage", &preimage, sizeof(preimage));
if (outpoint)
json_add_outpoint(stream, "outpoint", outpoint);
Expand Down Expand Up @@ -201,9 +200,7 @@ static void invoice_creation_notification_serialize(struct json_stream *stream,
{
json_object_start(stream, "invoice_creation");
if (amount != NULL)
json_add_string(
stream, "msat",
type_to_string(tmpctx, struct amount_msat, amount));
json_add_amount_msat(stream, "msat", *amount);

json_add_hex(stream, "preimage", &preimage, sizeof(preimage));
json_add_escaped_string(stream, "label", label);
Expand Down
1 change: 0 additions & 1 deletion tests/test_clnrest.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ def test_clnrest_websocket_rune_no_listnotifications(node_factory):
assert len([n for n in notifications if n.find('invoice_creation') > 0]) == 0


@pytest.mark.xfail(strict=True)
def test_clnrest_numeric_msat_notification(node_factory):
"""Test that msat fields are integers in notifications also."""
# start a node with clnrest
Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ def test_invoice_payment_notification(node_factory):
l1.dev_pay(inv1['bolt11'], dev_use_shadow=False)

l2.daemon.wait_for_log(r"Received invoice_payment event for label {},"
" preimage {}, and amount of {}msat"
" preimage {}, and amount of {}"
.format(label, preimage, msats))


Expand All @@ -1286,7 +1286,7 @@ def test_invoice_creation_notification(node_factory):
l2.rpc.invoice(msats, label, 'description', preimage=preimage)

l2.daemon.wait_for_log(r"Received invoice_creation event for label {},"
" preimage {}, and amount of {}msat"
" preimage {}, and amount of {}"
.format(label, preimage, msats))


Expand Down

0 comments on commit d7ddde3

Please sign in to comment.