wallet: Load and value completed_at timestamp from DB

This commit is contained in:
Christian Decker 2022-06-09 18:36:00 +02:00
parent daeec66bd7
commit cb3ee0ac2e
20 changed files with 343 additions and 325 deletions

View file

@ -666,6 +666,7 @@
"ListPays.pays[].amount_sent_msat": 9,
"ListPays.pays[].bolt11": 6,
"ListPays.pays[].bolt12": 7,
"ListPays.pays[].completed_at": 12,
"ListPays.pays[].created_at": 4,
"ListPays.pays[].description": 11,
"ListPays.pays[].destination": 3,
@ -940,6 +941,7 @@
"SendPay.amount_sent_msat": 8,
"SendPay.bolt11": 11,
"SendPay.bolt12": 12,
"SendPay.completed_at": 15,
"SendPay.created_at": 7,
"SendPay.destination": 6,
"SendPay.groupid": 2,
@ -1080,6 +1082,7 @@
"WaitSendPay.amount_sent_msat": 8,
"WaitSendPay.bolt11": 11,
"WaitSendPay.bolt12": 12,
"WaitSendPay.completed_at": 14,
"WaitSendPay.created_at": 7,
"WaitSendPay.destination": 6,
"WaitSendPay.groupid": 2,

View file

@ -324,6 +324,7 @@ message SendpayResponse {
optional Amount amount_msat = 5;
optional bytes destination = 6;
uint64 created_at = 7;
optional uint64 completed_at = 15;
Amount amount_sent_msat = 8;
optional string label = 9;
optional uint64 partid = 10;
@ -918,6 +919,7 @@ message WaitsendpayResponse {
optional Amount amount_msat = 5;
optional bytes destination = 6;
uint64 created_at = 7;
optional double completed_at = 14;
Amount amount_sent_msat = 8;
optional string label = 9;
optional uint64 partid = 10;
@ -1263,6 +1265,7 @@ message ListpaysPays {
ListpaysPaysStatus status = 2;
optional bytes destination = 3;
uint64 created_at = 4;
optional uint64 completed_at = 12;
optional string label = 5;
optional string bolt11 = 6;
optional string description = 11;

View file

@ -232,6 +232,7 @@ impl From<&responses::SendpayResponse> for pb::SendpayResponse {
amount_msat: c.amount_msat.map(|f| f.into()), // Rule #2 for type msat?
destination: c.destination.as_ref().map(|v| v.to_vec()), // Rule #2 for type pubkey?
created_at: c.created_at.clone(), // Rule #2 for type u64
completed_at: c.completed_at.clone(), // Rule #2 for type u64?
amount_sent_msat: Some(c.amount_sent_msat.into()), // Rule #2 for type msat
label: c.label.clone(), // Rule #2 for type string?
partid: c.partid.clone(), // Rule #2 for type u64?
@ -683,6 +684,7 @@ impl From<&responses::WaitsendpayResponse> for pb::WaitsendpayResponse {
amount_msat: c.amount_msat.map(|f| f.into()), // Rule #2 for type msat?
destination: c.destination.as_ref().map(|v| v.to_vec()), // Rule #2 for type pubkey?
created_at: c.created_at.clone(), // Rule #2 for type u64
completed_at: c.completed_at.clone(), // Rule #2 for type number?
amount_sent_msat: Some(c.amount_sent_msat.into()), // Rule #2 for type msat
label: c.label.clone(), // Rule #2 for type string?
partid: c.partid.clone(), // Rule #2 for type u64?
@ -924,6 +926,7 @@ impl From<&responses::ListpaysPays> for pb::ListpaysPays {
status: c.status as i32,
destination: c.destination.as_ref().map(|v| v.to_vec()), // Rule #2 for type pubkey?
created_at: c.created_at.clone(), // Rule #2 for type u64
completed_at: c.completed_at.clone(), // Rule #2 for type u64?
label: c.label.clone(), // Rule #2 for type string?
bolt11: c.bolt11.clone(), // Rule #2 for type string?
description: c.description.clone(), // Rule #2 for type string?

View file

@ -1409,6 +1409,8 @@ pub mod responses {
pub destination: Option<Pubkey>,
#[serde(alias = "created_at")]
pub created_at: u64,
#[serde(alias = "completed_at", skip_serializing_if = "Option::is_none")]
pub completed_at: Option<u64>,
#[serde(alias = "amount_sent_msat")]
pub amount_sent_msat: Amount,
#[serde(alias = "label", skip_serializing_if = "Option::is_none")]
@ -2327,6 +2329,8 @@ pub mod responses {
pub destination: Option<Pubkey>,
#[serde(alias = "created_at")]
pub created_at: u64,
#[serde(alias = "completed_at", skip_serializing_if = "Option::is_none")]
pub completed_at: Option<f64>,
#[serde(alias = "amount_sent_msat")]
pub amount_sent_msat: Amount,
#[serde(alias = "label", skip_serializing_if = "Option::is_none")]
@ -2725,6 +2729,8 @@ pub mod responses {
pub destination: Option<Pubkey>,
#[serde(alias = "created_at")]
pub created_at: u64,
#[serde(alias = "completed_at", skip_serializing_if = "Option::is_none")]
pub completed_at: Option<u64>,
#[serde(alias = "label", skip_serializing_if = "Option::is_none")]
pub label: Option<String>,
#[serde(alias = "bolt11", skip_serializing_if = "Option::is_none")]

View file

@ -241,6 +241,7 @@ def sendpay2py(m):
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"destination": hexlify(m.destination), # PrimitiveField in generate_composite
"created_at": m.created_at, # PrimitiveField in generate_composite
"completed_at": m.completed_at, # PrimitiveField in generate_composite
"amount_sent_msat": amount2msat(m.amount_sent_msat), # PrimitiveField in generate_composite
"label": m.label, # PrimitiveField in generate_composite
"partid": m.partid, # PrimitiveField in generate_composite
@ -606,6 +607,7 @@ def waitsendpay2py(m):
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"destination": hexlify(m.destination), # PrimitiveField in generate_composite
"created_at": m.created_at, # PrimitiveField in generate_composite
"completed_at": m.completed_at, # PrimitiveField in generate_composite
"amount_sent_msat": amount2msat(m.amount_sent_msat), # PrimitiveField in generate_composite
"label": m.label, # PrimitiveField in generate_composite
"partid": m.partid, # PrimitiveField in generate_composite
@ -823,12 +825,13 @@ def listpays_pays2py(m):
"status": str(m.status), # EnumField in generate_composite
"destination": hexlify(m.destination), # PrimitiveField in generate_composite
"created_at": m.created_at, # PrimitiveField in generate_composite
"completed_at": m.completed_at, # PrimitiveField in generate_composite
"label": m.label, # PrimitiveField in generate_composite
"bolt11": m.bolt11, # PrimitiveField in generate_composite
"description": m.description, # PrimitiveField in generate_composite
"bolt12": m.bolt12, # PrimitiveField in generate_composite
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"amount_sent_msat": amount2msat(m.amount_sent_msat), # PrimitiveField in generate_composite
"preimage": hexlify(m.preimage), # PrimitiveField in generate_composite
"number_of_parts": m.number_of_parts, # PrimitiveField in generate_composite
"erroronion": hexlify(m.erroronion), # PrimitiveField in generate_composite
})

File diff suppressed because one or more lines are too long

View file

@ -46,6 +46,7 @@ On success, an object containing **payments** is returned. It is an array of ob
- **partid** (u64, optional): unique ID within this (multi-part) payment
- **destination** (pubkey, optional): the final destination of the payment if known
- **amount\_msat** (msat, optional): the amount the destination received, if known
- **completed\_at** (u64, optional): the UNIX timestamp showing when this payment was completed
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **payment\_preimage** (hex, optional): proof of payment (always 64 characters)
- **label** (string, optional): the label, if given to sendpay
@ -102,4 +103,4 @@ RESOURCES
---------
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:08dbf42e6d4bd63f9b6e7a45112b348c84d6192d3ff3087e5e02b4a4788e5605)
[comment]: # ( SHA256STAMP:1ce2241eeae759ed5566342fb7810e62fa2c618f2465314f17376ebe9b6d24f8)

View file

@ -23,16 +23,12 @@ On success, an object containing **pays** is returned. It is an array of object
- **status** (string): status of the payment (one of "pending", "failed", "complete")
- **created\_at** (u64): the UNIX timestamp showing when this payment was initiated
- **destination** (pubkey, optional): the final destination of the payment if known
- **completed\_at** (u64, optional): the UNIX timestamp showing when this payment was completed
- **label** (string, optional): the label, if given to sendpay
- **bolt11** (string, optional): the bolt11 string (if pay supplied one)
- **description** (string, optional): the description matching the bolt11 description hash (if pay supplied one)
- **bolt12** (string, optional): the bolt12 string (if supplied for pay: **experimental-offers** only).
If **status** is "pending" or "complete":
- **amount\_sent\_msat** (msat): the amount we actually sent, including fees
- **amount\_msat** (msat, optional): the amount the destination received, if known
If **status** is "complete":
- **preimage** (hex): proof of payment (always 64 characters)
@ -61,4 +57,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:64fd1d2a8673b2a4189623aa42d44384061ff66ba7c8918af40baf92ac29a889)
[comment]: # ( SHA256STAMP:1175415c0f9398e1087d68dd75266bf894249053a4e57f16b8ee16cf5ffa414f)

View file

@ -64,4 +64,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:2cd3f5a0d494ea4aaef6eb5ea9ff467da14198c0fa4d9fee6b45e72568a2d481)
[comment]: # ( SHA256STAMP:68af9f1edf2ddc78a7daad1bb72aa773b82c5103b0ba706ef83de36a11cabe26)

View file

@ -76,6 +76,7 @@ On success, an object is returned, containing:
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **amount\_msat** (msat, optional): The amount delivered to destination (if known)
- **destination** (pubkey, optional): the final destination of the payment if known
- **completed\_at** (u64, optional): the UNIX timestamp showing when this payment was completed
- **label** (string, optional): the *label*, if given to sendpay
- **partid** (u64, optional): the *partid*, if given to sendpay
- **bolt11** (string, optional): the bolt11 string (if supplied)
@ -142,4 +143,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:4878733d02711f919c49740652a3723fbcc78a0cd865b71385db965c878d2b77)
[comment]: # ( SHA256STAMP:c129f537b1af8a5dc767a25a72be419634cb21ebc26a9e6b9bb091db8db7e6ca)

View file

@ -43,6 +43,7 @@ On success, an object is returned, containing:
- **groupid** (u64, optional): Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash
- **amount\_msat** (msat, optional): The amount delivered to destination (if known)
- **destination** (pubkey, optional): the final destination of the payment if known
- **completed\_at** (number, optional): the UNIX timestamp showing when this payment was completed
- **label** (string, optional): the label, if given to sendpay
- **partid** (u64, optional): the *partid*, if given to sendpay
- **bolt11** (string, optional): the bolt11 string (if pay supplied one)
@ -103,4 +104,4 @@ RESOURCES
Main web site: <https://github.com/ElementsProject/lightning>
[comment]: # ( SHA256STAMP:b87ddb42fd2b1182ef11101f0298be2e4de9b942fd3b8b4b169d1bdc849f48a8)
[comment]: # ( SHA256STAMP:f4dbe3ecc88a294f7bb983a2f2b8e9613e440e4564580e51dd30fc83ba218a91)

View file

@ -64,6 +64,10 @@
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"completed_at": {
"type": "u64",
"description": "the UNIX timestamp showing when this payment was completed"
},
"groupid": {
"type": "u64",
"description": "Grouping key to disambiguate multiple attempts to pay an invoice or the same payment_hash"

View file

@ -40,6 +40,10 @@
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"completed_at": {
"type": "u64",
"description": "the UNIX timestamp showing when this payment was completed"
},
"label": {
"type": "string",
"description": "the label, if given to sendpay"
@ -58,45 +62,6 @@
}
},
"allOf": [
{
"if": {
"properties": {
"status": {
"type": "string",
"enum": [
"pending",
"complete"
]
}
}
},
"then": {
"additionalProperties": false,
"required": [
"amount_sent_msat"
],
"properties": {
"payment_hash": {},
"status": {},
"destination": {},
"created_at": {},
"label": {},
"bolt11": {},
"description": {},
"bolt12": {},
"preimage": {},
"number_of_parts": {},
"amount_msat": {
"type": "msat",
"description": "the amount the destination received, if known"
},
"amount_sent_msat": {
"type": "msat",
"description": "the amount we actually sent, including fees"
}
}
}
},
{
"if": {
"properties": {
@ -111,6 +76,7 @@
"then": {
"additionalProperties": false,
"required": [
"amount_sent_msat",
"preimage"
],
"properties": {
@ -118,6 +84,7 @@
"status": {},
"destination": {},
"created_at": {},
"completed_at": {},
"label": {},
"bolt11": {},
"description": {},
@ -150,7 +117,9 @@
},
"then": {
"additionalProperties": false,
"required": [],
"required": [
"amount_sent_msat"
],
"properties": {
"payment_hash": {},
"status": {},

View file

@ -108,6 +108,7 @@
"amount_msat": {},
"destination": {},
"created_at": {},
"completed_at": {},
"msatoshi_sent": {},
"amount_sent_msat": {},
"label": {},
@ -147,6 +148,7 @@
"amount_msat": {},
"destination": {},
"created_at": {},
"completed_at": {},
"msatoshi_sent": {},
"amount_sent_msat": {},
"label": {},

View file

@ -47,6 +47,10 @@
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"completed_at": {
"type": "u64",
"description": "the UNIX timestamp showing when this payment was completed"
},
"msatoshi_sent": {
"deprecated": true
},
@ -97,6 +101,7 @@
"amount_msat": {},
"destination": {},
"created_at": {},
"completed_at": {},
"msatoshi_sent": {},
"amount_sent_msat": {},
"label": {},
@ -137,6 +142,7 @@
"amount_msat": {},
"destination": {},
"created_at": {},
"completed_at": {},
"msatoshi_sent": {},
"amount_sent_msat": {},
"label": {},

View file

@ -46,6 +46,10 @@
"type": "u64",
"description": "the UNIX timestamp showing when this payment was initiated"
},
"completed_at": {
"type": "number",
"description": "the UNIX timestamp showing when this payment was completed"
},
"msatoshi_sent": {
"deprecated": true
},
@ -96,6 +100,7 @@
"amount_msat": {},
"destination": {},
"created_at": {},
"completed_at": {},
"msatoshi_sent": {},
"amount_sent_msat": {},
"label": {},

View file

@ -128,7 +128,9 @@ void json_add_payment_fields(struct json_stream *response,
json_add_amount_msat_compat(response, t->msatoshi_sent,
"msatoshi_sent", "amount_sent_msat");
json_add_u64(response, "created_at", t->timestamp);
json_add_u32(response, "created_at", t->timestamp);
if (t->completed_at)
json_add_u32(response, "completed_at", *t->completed_at);
switch (t->status) {
case PAYMENT_PENDING:
@ -1101,6 +1103,8 @@ send_payment_core(struct lightningd *ld,
payment->route_nodes = tal_steal(payment, route_nodes);
payment->route_channels = tal_steal(payment, route_channels);
payment->failonion = NULL;
payment->completed_at = NULL;
if (label != NULL)
payment->label = tal_strdup(payment, label);
else

View file

@ -3948,6 +3948,7 @@ def test_bolt11_null_after_pay(node_factory, bitcoind):
assert(pays[0]["bolt11"] == invl1)
assert('amount_msat' in pays[0] and pays[0]['amount_msat'] == amt)
assert('created_at' in pays[0])
assert('completed_at' in pays[0])
def test_mpp_presplit_routehint_conflict(node_factory, bitcoind):

View file

@ -3260,6 +3260,12 @@ static struct wallet_payment *wallet_stmt2payment(const tal_t *ctx,
} else
payment->local_offer_id = NULL;
if (!db_col_is_null(stmt, "completed_at")) {
payment->completed_at = tal(payment, u32);
*payment->completed_at = db_col_int(stmt, "completed_at");
} else
payment->completed_at = NULL;
payment->groupid = db_col_u64(stmt, "groupid");
return payment;
@ -3298,6 +3304,7 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
", partid"
", local_offer_id"
", groupid"
", completed_at"
" FROM payments"
" WHERE payment_hash = ?"
" AND partid = ? AND groupid=?"));
@ -3535,6 +3542,7 @@ wallet_payment_list(const tal_t *ctx,
", partid"
", local_offer_id"
", groupid"
", completed_at"
" FROM payments"
" WHERE"
" (payment_hash = ? OR 1=?) AND"
@ -3602,6 +3610,7 @@ wallet_payments_by_offer(const tal_t *ctx,
", partid"
", local_offer_id"
", groupid"
", completed_at"
" FROM payments"
" WHERE local_offer_id = ?;"));
db_bind_sha256(stmt, 0, local_offer_id);

View file

@ -334,6 +334,7 @@ struct wallet_payment {
struct list_node list;
u64 id;
u32 timestamp;
u32 *completed_at;
/* The combination of these three fields is unique: */
struct sha256 payment_hash;