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

Allocate own string for invoice description #1020

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lightningd/invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static void json_invoice(struct command *cmd,
jsmntok_t *msatoshi, *label, *desc, *exp;
u64 *msatoshi_val;
const char *label_val;
const char *desc_val;
struct json_result *response = new_json_result(cmd);
struct wallet *wallet = cmd->ld->wallet;
struct bolt11 *b11;
Expand Down Expand Up @@ -148,6 +149,10 @@ static void json_invoice(struct command *cmd,
INVOICE_MAX_LABEL_LEN);
return;
}
/* description */
desc_val = tal_strndup(cmd, buffer + desc->start,
desc->end - desc->start);
/* expiry */
if (exp && !json_tok_u64(buffer, exp, &expiry)) {
command_fail(cmd, "Expiry '%.*s' invalid seconds",
exp->end - exp->start,
Expand Down Expand Up @@ -177,8 +182,7 @@ static void json_invoice(struct command *cmd,
sha256(b11->description_hash, buffer + desc->start,
desc->end - desc->start);
} else
b11->description = tal_strndup(b11, buffer + desc->start,
desc->end - desc->start);
b11->description = tal_strdup(b11, desc_val);

/* FIXME: add private routes if necessary! */
b11enc = bolt11_encode(cmd, b11, false, hsm_sign_b11, cmd->ld);
Expand All @@ -191,7 +195,7 @@ static void json_invoice(struct command *cmd,
json_add_u64(response, "expires_at", invoice->expiry_time);
json_add_string(response, "bolt11", b11enc);
if (b11->description_hash)
json_add_string(response, "description", b11->description);
json_add_string(response, "description", desc_val);
json_object_end(response);

command_success(cmd, response);
Expand Down
5 changes: 5 additions & 0 deletions tests/test_lightningd.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,11 @@ def test_pay(self):
assert len(l1.rpc.listpayments(inv)['payments']) == 1
assert l1.rpc.listpayments(inv)['payments'][0]['payment_preimage'] == preimage['preimage']

# Check long descriptions
longdesc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce tortor massa, sodales sit amet felis eu, tempus ullamcorper ex. Duis fermentum odio finibus, pharetra justo et, faucibus sem. Integer ac iaculis felis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean euismod lobortis dapibus. Ut tellus neque, posuere non nunc vel, varius hendrerit erat. Sed quis tristique ex. Maecenas rutrum orci at lorem eleifend imperdiet. Cras pretium id nulla a placerat. Sed rutrum nisl vitae mauris elementum, ac dapibus nulla ultrices. Mauris nec odio consequat, ultrices magna euismod, porta urna. Aenean porttitor et enim luctus semper nullam. "
longinv = l2.rpc.invoice(12345, "longinv", longdesc)['bolt11']
l1.rpc.pay(longinv, description=longdesc)

def test_pay_optional_args(self):
l1,l2 = self.connect()

Expand Down