From aa1ca5c9ea5577e3a09fb56e5dfd4b3c02a6b0b9 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 25 Nov 2019 14:32:28 +0100 Subject: [PATCH] json-rpc: Only show the amount_msat field if we know it in payments If we initiated the payment using an externally generated onion we don't know what the final hop gets, or even who it is, so we don't display the amount in these cases. I chose to show `null` instead in order not to break dependees that rely on the value being there. --- lightningd/pay.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lightningd/pay.c b/lightningd/pay.c index 38e325fe5264..dc3c9a6c7be4 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -83,8 +83,15 @@ void json_add_payment_fields(struct json_stream *response, if (t->destination != NULL) json_add_node_id(response, "destination", t->destination); - json_add_amount_msat_compat(response, t->msatoshi, - "msatoshi", "amount_msat"); + /* If we have a 0 amount delivered at the remote end we simply don't + * know since the onion was generated externally. */ + if (amount_msat_greater(t->msatoshi, AMOUNT_MSAT(0))) + json_add_amount_msat_compat(response, t->msatoshi, "msatoshi", + "amount_msat"); + else + json_add_null(response, "amount_msat"); + + json_add_amount_msat_compat(response, t->msatoshi_sent, "msatoshi_sent", "amount_sent_msat"); json_add_u64(response, "created_at", t->timestamp);