mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
wallet: Add function to retrieve the latest groupid for a payment
When doing things like `waitsendpay` without specifying the `groupid` we likely want to use the latest `groupid` we created, since that's the one in flight. This adds a function to quickly retrieve that.
This commit is contained in:
parent
db84b984e5
commit
0bb0d8a707
2 changed files with 26 additions and 0 deletions
|
@ -3018,6 +3018,23 @@ void wallet_payment_delete(struct wallet *wallet,
|
|||
db_exec_prepared_v2(take(stmt));
|
||||
}
|
||||
|
||||
u64 wallet_payment_get_groupid(struct wallet *wallet,
|
||||
const struct sha256 *payment_hash)
|
||||
{
|
||||
struct db_stmt *stmt;
|
||||
u64 groupid = 0;
|
||||
stmt = db_prepare_v2(
|
||||
wallet->db, SQL("SELECT MAX(groupid) FROM payments WHERE payment_hash = ?"));
|
||||
|
||||
db_bind_sha256(stmt, 0, payment_hash);
|
||||
db_query_prepared(stmt);
|
||||
if (db_step(stmt) && !db_column_is_null(stmt, 0)) {
|
||||
groupid = db_column_u64(stmt, 0);
|
||||
}
|
||||
tal_free(stmt);
|
||||
return groupid;
|
||||
}
|
||||
|
||||
void wallet_payment_delete_by_hash(struct wallet *wallet,
|
||||
const struct sha256 *payment_hash)
|
||||
{
|
||||
|
|
|
@ -1050,6 +1050,15 @@ wallet_payment_by_hash(const tal_t *ctx, struct wallet *wallet,
|
|||
const struct sha256 *payment_hash,
|
||||
u64 partid);
|
||||
|
||||
/**
|
||||
* Retrieve maximum groupid for a given payment_hash.
|
||||
*
|
||||
* Useful to either wait on the latest payment that was iniated with
|
||||
* the hash or start a new one by incrementing the groupid.
|
||||
*/
|
||||
u64 wallet_payment_get_groupid(struct wallet *wallet,
|
||||
const struct sha256 *payment_hash);
|
||||
|
||||
/**
|
||||
* wallet_payment_set_status - Update the status of the payment
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue