Browse Source

Use consistent names for timestamps.

Old fields still there, just deprecated.

Invoice commands:
	paid_timestamp -> paid_at
	expiry_time -> expires_at

decodepay:
	timestamp -> created_at

getlog:
	creation_time -> created_at

listpayments:
	timestamp -> created_at

Suggested-by: @shesek
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
parent
commit
8797159825
  1. 31
      lightningd/invoice.c
  2. 4
      lightningd/jsonrpc.c
  3. 7
      lightningd/pay.c
  4. 26
      tests/test_lightningd.py

31
lightningd/invoice.c

@ -45,10 +45,15 @@ static void json_add_invoice(struct json_result *response,
json_add_u64(response, "pay_index", inv->pay_index);
json_add_u64(response, "msatoshi_received",
inv->msatoshi_received);
json_add_u64(response, "paid_timestamp",
inv->paid_timestamp);
if (deprecated_apis)
json_add_u64(response, "paid_timestamp",
inv->paid_timestamp);
json_add_u64(response, "paid_at", inv->paid_timestamp);
}
json_add_u64(response, "expiry_time", inv->expiry_time);
if (deprecated_apis)
json_add_u64(response, "expiry_time", inv->expiry_time);
json_add_u64(response, "expires_at", inv->expiry_time);
json_object_end(response);
}
@ -178,7 +183,9 @@ static void json_invoice(struct command *cmd,
json_object_start(response, NULL);
json_add_hex(response, "payment_hash",
&invoice->rhash, sizeof(invoice->rhash));
json_add_u64(response, "expiry_time", invoice->expiry_time);
if (deprecated_apis)
json_add_u64(response, "expiry_time", invoice->expiry_time);
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);
@ -191,7 +198,7 @@ static const struct json_command invoice_command = {
"invoice",
json_invoice,
"Create invoice for {msatoshi} with {label} and {description} with optional {expiry} seconds (default 1 hour)",
"Returns the {payment_hash}, {expiry_time} and {bolt11} on success, and {description} if too large for {bolt11}. "
"Returns the {payment_hash}, {expires_at} and {bolt11} on success, and {description} if too large for {bolt11}. "
};
AUTODATA(json_command, &invoice_command);
@ -252,7 +259,7 @@ static const struct json_command listinvoice_command = {
"listinvoice",
json_listinvoice,
"(DEPRECATED) Show invoice {label} (or all, if no {label}))",
"Returns an array of {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} (if paid) and {expiry_time} on success. ",
"Returns an array of {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} (if paid) and {expires_time} on success. ",
.deprecated = true
};
AUTODATA(json_command, &listinvoice_command);
@ -267,7 +274,7 @@ static const struct json_command listinvoices_command = {
"listinvoices",
json_listinvoices,
"Show invoice {label} (or all, if no {label}))",
"Returns an array of {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} (if paid) and {expiry_time} on success. ",
"Returns an array of {label}, {payment_hash}, {msatoshi} (if set), {status}, {pay_index} (if paid) and {expires_at} on success. ",
};
AUTODATA(json_command, &listinvoices_command);
@ -326,7 +333,7 @@ static const struct json_command delinvoice_command = {
"delinvoice",
json_delinvoice,
"Delete unpaid invoice {label} with {status}",
"Returns {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} (if paid) and {expiry_time} on success. "
"Returns {label}, {payment_hash}, {msatoshi} (if set), {status}, {pay_index} (if paid) and {expires_at} on success. "
};
AUTODATA(json_command, &delinvoice_command);
@ -369,7 +376,7 @@ static const struct json_command waitanyinvoice_command = {
"waitanyinvoice",
json_waitanyinvoice,
"Wait for the next invoice to be paid, after {lastpay_index} (if supplied)))",
"Returns {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} and {expiry_time} on success. "
"Returns {label}, {payment_hash}, {msatoshi} (if set), {status}, {pay_index} and {expires_at} on success. "
};
AUTODATA(json_command, &waitanyinvoice_command);
@ -414,7 +421,7 @@ static const struct json_command waitinvoice_command = {
"waitinvoice",
json_waitinvoice,
"Wait for an incoming payment matching the invoice with {label}",
"Returns {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} and {expiry_time} on success"
"Returns {label}, {payment_hash}, {msatoshi} (if set), {complete}, {pay_index} and {expires_at} on success"
};
AUTODATA(json_command, &waitinvoice_command);
@ -454,7 +461,9 @@ static void json_decodepay(struct command *cmd,
json_object_start(response, NULL);
json_add_string(response, "currency", b11->chain->bip173_name);
json_add_u64(response, "timestamp", b11->timestamp);
if (deprecated_apis)
json_add_u64(response, "timestamp", b11->timestamp);
json_add_u64(response, "created_at", b11->timestamp);
json_add_u64(response, "expiry", b11->expiry);
json_add_pubkey(response, "payee", &b11->receiver_id);
if (b11->msatoshi)

4
lightningd/jsonrpc.c

@ -175,7 +175,9 @@ static void json_getlog(struct command *cmd,
info.response = new_json_result(cmd);
json_object_start(info.response, NULL);
json_add_time(info.response, "creation_time", log_init_time(lr)->ts);
if (deprecated_apis)
json_add_time(info.response, "creation_time", log_init_time(lr)->ts);
json_add_time(info.response, "created_at", log_init_time(lr)->ts);
json_add_num(info.response, "bytes_used", (unsigned int)log_used(lr));
json_add_num(info.response, "bytes_max", (unsigned int)log_max_mem(lr));
json_array_start(info.response, "log");

7
lightningd/pay.c

@ -12,6 +12,7 @@
#include <lightningd/jsonrpc.h>
#include <lightningd/lightningd.h>
#include <lightningd/log.h>
#include <lightningd/options.h>
#include <lightningd/peer_control.h>
#include <lightningd/peer_htlcs.h>
#include <lightningd/subd.h>
@ -494,7 +495,9 @@ static void json_listpayments(struct command *cmd, const char *buffer,
json_add_hex(response, "payment_hash", &t->payment_hash, sizeof(t->payment_hash));
json_add_pubkey(response, "destination", &t->destination);
json_add_u64(response, "msatoshi", t->msatoshi);
json_add_u64(response, "timestamp", t->timestamp);
if (deprecated_apis)
json_add_u64(response, "timestamp", t->timestamp);
json_add_u64(response, "created_at", t->timestamp);
switch (t->status) {
case PAYMENT_PENDING:
@ -523,6 +526,6 @@ static const struct json_command listpayments_command = {
"listpayments",
json_listpayments,
"Get a list of outgoing payments",
"Returns a list of payments with {payment_hash}, {destination}, {msatoshi}, {timestamp} and {status} (and {payment_preimage} if {status} is 'complete')"
"Returns a list of payments with {payment_hash}, {destination}, {msatoshi}, {created_at} and {status} (and {payment_preimage} if {status} is 'complete')"
};
AUTODATA(json_command, &listpayments_command);

26
tests/test_lightningd.py

@ -332,8 +332,8 @@ class LightningDTests(BaseLightningDTests):
after = int(time.time())
b11 = l1.rpc.decodepay(inv['bolt11'])
assert b11['currency'] == 'tb'
assert b11['timestamp'] >= before
assert b11['timestamp'] <= after
assert b11['created_at'] >= before
assert b11['created_at'] <= after
assert b11['payment_hash'] == inv['payment_hash']
assert b11['description'] == 'description'
assert b11['expiry'] == 3600
@ -367,7 +367,7 @@ class LightningDTests(BaseLightningDTests):
time.sleep(2)
self.assertRaises(ValueError, l1.rpc.pay, inv)
assert l2.rpc.listinvoices('test_pay')['invoices'][0]['status'] == 'expired'
assert l2.rpc.listinvoices('test_pay')['invoices'][0]['expiry_time'] < time.time()
assert l2.rpc.listinvoices('test_pay')['invoices'][0]['expires_at'] < time.time()
# Try deleting it.
self.assertRaisesRegex(ValueError,
@ -440,7 +440,7 @@ class LightningDTests(BaseLightningDTests):
# * `0lkg3c`: Bech32 checksum
b11 = l1.rpc.decodepay('lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdpl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d73gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ecky03ylcqca784w')
assert b11['currency'] == 'bc'
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['description'] == 'Please consider supporting this project'
assert b11['expiry'] == 3600
@ -468,7 +468,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc2500u1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdq5xysxxatsyp3k7enxv4jsxqzpuaztrnwngzn3kdzw5hydlzf03qdgm2hdq27cqv3agm2awhz5se903vruatfhq77w3ls4evs3ch9zw97j25emudupq63nyw24cg27h2rspfj9srp')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 2500 * 10**11 // 1000000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['description'] == '1 cup coffee'
assert b11['expiry'] == 60
@ -493,7 +493,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqscc6gd6ql3jrc5yzme8v4ntcewwz5cnw92tz0pc8qcuufvq7khhr8wpald05e92xw006sq94mg8v2ndf4sefvf9sygkshp5zfem29trqq2yxxz7', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -517,7 +517,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lntb20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfpp3x9et2e20v6pu37c5d9vax37wxq72un98kmzzhznpurw9sgl2v0nklu2g4d0keph5t7tj9tcqd8rexnd07ux4uv2cjvcqwaxgj7v4uwn5wmypjd5n69z2xm3xgksg28nwht7f6zspwp3f9t', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'tb'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -547,7 +547,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc20m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqsfpp3qjmp7lwpagxun9pygexvgpjdc4jdj85fr9yq20q82gphp2nflc7jtzrcazrra7wwgzxqc8u7754cdlpfrmccae92qgzqvzq2ps8pqqqqqqpqqqqq9qqqvpeuqafqxu92d8lr6fvg0r5gv0heeeqgcrqlnm6jhphu9y00rrhy4grqszsvpcgpy9qqqqqqgqqqqq7qqzqj9n4evl6mr5aj9f58zp6fyjzup6ywn3x6sk8akg5v4tgn2q8g4fhx05wf6juaxu9760yp46454gpg5mtzgerlzezqcqvjnhjh8z3g2qqdhhwkj', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -588,7 +588,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfppj3a24vwu6r8ejrss3axul8rxldph2q7z9kmrgvr7xlaqm47apw3d48zm203kzcq357a4ls9al2ea73r8jcceyjtya6fu5wzzpe50zrge6ulk4nvjcpxlekvmxl6qcs9j3tz0469gq5g658y', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -613,7 +613,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfppqw508d6qejxtdg4y5r3zarvary0c5xw7kepvrhrm9s57hejg0p662ur5j5cr03890fa7k2pypgttmh4897d3raaq85a293e9jpuqwl0rnfuwzam7yr8e690nd2ypcq9hlkdwdvycqa0qza8', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -638,7 +638,7 @@ class LightningDTests(BaseLightningDTests):
b11 = l1.rpc.decodepay('lnbc20m1pvjluezhp58yjmdan79s6qqdhdzgynm4zwqd5d7xmw5fk98klysy043l2ahrqspp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqfp4qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q28j0v3rwgy9pvjnd48ee2pl8xrpxysd5g44td63g6xcjcu003j3qe8878hluqlvl3km8rm92f5stamd3jw763n3hck0ct7p8wwj463cql26ava', 'One piece of chocolate cake, one icecream cone, one pickle, one slice of swiss cheese, one slice of salami, one lollypop, one piece of cherry pie, one sausage, one cupcake, and one slice of watermelon')
assert b11['currency'] == 'bc'
assert b11['msatoshi'] == 20 * 10**11 // 1000
assert b11['timestamp'] == 1496314658
assert b11['created_at'] == 1496314658
assert b11['payment_hash'] == '0001020304050607080900010203040506070809000102030405060708090102'
assert b11['expiry'] == 3600
assert b11['payee'] == '03e7156ae33b0a208d0744199163177e909e80176e55d97a2f221ede0f934dd9ad'
@ -786,8 +786,8 @@ class LightningDTests(BaseLightningDTests):
invoice = l2.rpc.listinvoices('test_pay')['invoices'][0]
assert invoice['status'] == 'paid'
assert invoice['paid_timestamp'] >= before
assert invoice['paid_timestamp'] <= after
assert invoice['paid_at'] >= before
assert invoice['paid_at'] <= after
# Repeat payments are NOPs (if valid): we can hand null.
l1.rpc.pay(inv, None)

Loading…
Cancel
Save