From 173810759883fc2b54c2fe2761ceb98ad5987541 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Mon, 23 Jul 2018 14:37:05 +0200 Subject: [PATCH] json-rpc: Add description argument to `sendpay` --- contrib/pylightning/lightning/lightning.py | 5 ++-- lightningd/pay.c | 30 +++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/contrib/pylightning/lightning/lightning.py b/contrib/pylightning/lightning/lightning.py index bb3c5a8ca..1891c1d28 100644 --- a/contrib/pylightning/lightning/lightning.py +++ b/contrib/pylightning/lightning/lightning.py @@ -275,13 +275,14 @@ class LightningRpc(UnixDomainSocketRpc): """ return self.call("getinfo") - def sendpay(self, route, payment_hash): + def sendpay(self, route, payment_hash, description=""): """ Send along {route} in return for preimage of {payment_hash} """ payload = { "route": route, - "payment_hash": payment_hash + "payment_hash": payment_hash, + "description": description, } return self.call("sendpay", payload) diff --git a/lightningd/pay.c b/lightningd/pay.c index db93876b7..cef13e5c8 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -918,17 +918,20 @@ static void json_sendpay_on_resolve(const struct sendpay_result* r, static void json_sendpay(struct command *cmd, const char *buffer, const jsmntok_t *params) { - const jsmntok_t *routetok, *rhashtok; + const jsmntok_t *routetok, *rhashtok, *desctok; const jsmntok_t *t, *end; size_t n_hops; struct sha256 rhash; struct route_hop *route; u64 *msatoshi; + const struct json_escaped *desc; + const char *description; if (!param(cmd, buffer, params, p_req("route", json_tok_tok, &routetok), p_req("payment_hash", json_tok_tok, &rhashtok), p_opt("msatoshi", json_tok_u64, &msatoshi), + p_opt_tok("description", &desctok), NULL)) return; @@ -1025,10 +1028,31 @@ static void json_sendpay(struct command *cmd, } } - /* FIXME(cdecker): Add a description parameter to sendpay */ + if (desctok) { + desc = json_tok_escaped_string(cmd, buffer, desctok); + if (!desc) { + command_fail(cmd, JSONRPC2_INVALID_PARAMS, + "description '%.*s' not a string", + desctok->end - desctok->start, + buffer + desctok->start); + return; + } + description = json_escaped_unescape(cmd, desc); + if (description == NULL) { + command_fail( + cmd, JSONRPC2_INVALID_PARAMS, + "description '%.*s' not a valid escaped string", + desctok->end - desctok->start, + buffer + desctok->start); + return; + } + } else { + description = NULL; + } + if (send_payment(cmd, cmd->ld, &rhash, route, msatoshi ? *msatoshi : route[n_hops-1].amount, - NULL, + description, &json_sendpay_on_resolve, cmd)) command_still_pending(cmd); }