diff --git a/lightningd/offer.c b/lightningd/offer.c index 4cb99370740b..d6a8f6a27665 100644 --- a/lightningd/offer.c +++ b/lightningd/offer.c @@ -236,7 +236,7 @@ static struct command_result *prev_payment(struct command *cmd, bool prev_paid = false; assert(!invreq->payer_info); - payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL); + payments = wallet_payment_list(cmd, cmd->ld->wallet, NULL, NULL); for (size_t i = 0; i < tal_count(payments); i++) { const struct tlv_invoice *inv; diff --git a/lightningd/pay.c b/lightningd/pay.c index f792d268cd4b..da17474b40c3 100644 --- a/lightningd/pay.c +++ b/lightningd/pay.c @@ -869,7 +869,7 @@ send_payment_core(struct lightningd *ld, bool have_complete = false; /* Now, do we already have one or more payments? */ - payments = wallet_payment_list(tmpctx, ld->wallet, rhash); + payments = wallet_payment_list(tmpctx, ld->wallet, rhash, NULL); for (size_t i = 0; i < tal_count(payments); i++) { log_debug(ld->log, "Payment %zu/%zu: %s %s", i, tal_count(payments), @@ -1525,12 +1525,13 @@ static struct command_result *json_listsendpays(struct command *cmd, const struct wallet_payment **payments; struct json_stream *response; struct sha256 *rhash; - const char *invstring; + const char *invstring, *status; if (!param(cmd, buffer, params, /* FIXME: parameter should be invstring now */ p_opt("bolt11", param_string, &invstring), p_opt("payment_hash", param_sha256, &rhash), + p_opt("status", param_string, &status), NULL)) return command_param_failed(); @@ -1562,7 +1563,7 @@ static struct command_result *json_listsendpays(struct command *cmd, } } - payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash); + payments = wallet_payment_list(cmd, cmd->ld->wallet, rhash, NULL); response = json_stream_success(cmd); @@ -1615,7 +1616,7 @@ static struct command_result *json_delpay(struct command *cmd, payment_status_to_string(status)); } - payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash); + payments = wallet_payment_list(cmd, cmd->ld->wallet, payment_hash, NULL); if (tal_count(payments) == 0) return command_fail(cmd, PAY_NO_SUCH_PAYMENT, "Unknown payment with payment_hash: %s", diff --git a/plugins/pay.c b/plugins/pay.c index 95d09ba84bf3..80c237280e26 100644 --- a/plugins/pay.c +++ b/plugins/pay.c @@ -1905,7 +1905,7 @@ static struct command_result *json_listpays(struct command *cmd, const char *buf, const jsmntok_t *params) { - const char *invstring; + const char *invstring, *status; struct sha256 *payment_hash; struct out_req *req; @@ -1914,6 +1914,7 @@ static struct command_result *json_listpays(struct command *cmd, /* FIXME: parameter should be invstring now */ p_opt("bolt11", param_string, &invstring), p_opt("payment_hash", param_sha256, &payment_hash), + p_opt("status", param_string, &status), NULL)) return command_param_failed(); @@ -1926,6 +1927,9 @@ static struct command_result *json_listpays(struct command *cmd, if (payment_hash) json_add_sha256(req->js, "payment_hash", payment_hash); + if(status) + json_add_string(req->js, "status", status); + return send_outreq(cmd->plugin, req); } diff --git a/wallet/db_postgres_sqlgen.c b/wallet/db_postgres_sqlgen.c index e85d5929d387..daa9923ae67c 100644 --- a/wallet/db_postgres_sqlgen.c +++ b/wallet/db_postgres_sqlgen.c @@ -1616,6 +1616,12 @@ struct db_query db_postgres_queries[] = { .placeholders = 1, .readonly = true, }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE status = ? ORDER BY id;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE status = $1 ORDER BY id;", + .placeholders = 1, + .readonly = true, + }, { .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;", .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;", @@ -1918,10 +1924,10 @@ struct db_query db_postgres_queries[] = { }, }; -#define DB_POSTGRES_QUERY_COUNT 318 +#define DB_POSTGRES_QUERY_COUNT 319 #endif /* HAVE_POSTGRES */ #endif /* LIGHTNINGD_WALLET_GEN_DB_POSTGRES */ -// SHA256STAMP:dbbcb7d784e7b3d6c7b27c2ff976dcc39335fdc26fbf095b65116488007799f7 +// SHA256STAMP:f7ebcea1bd78308227ed94ab39f4015337f73acc84fd5a7c4ad35c0be0624852 diff --git a/wallet/db_sqlite3_sqlgen.c b/wallet/db_sqlite3_sqlgen.c index 5b6eb8fa06d6..40ef14e3bdca 100644 --- a/wallet/db_sqlite3_sqlgen.c +++ b/wallet/db_sqlite3_sqlgen.c @@ -1616,6 +1616,12 @@ struct db_query db_sqlite3_queries[] = { .placeholders = 1, .readonly = true, }, + { + .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE status = ? ORDER BY id;", + .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE status = ? ORDER BY id;", + .placeholders = 1, + .readonly = true, + }, { .name = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;", .query = "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;", @@ -1918,10 +1924,10 @@ struct db_query db_sqlite3_queries[] = { }, }; -#define DB_SQLITE3_QUERY_COUNT 318 +#define DB_SQLITE3_QUERY_COUNT 319 #endif /* HAVE_SQLITE3 */ #endif /* LIGHTNINGD_WALLET_GEN_DB_SQLITE3 */ -// SHA256STAMP:dbbcb7d784e7b3d6c7b27c2ff976dcc39335fdc26fbf095b65116488007799f7 +// SHA256STAMP:f7ebcea1bd78308227ed94ab39f4015337f73acc84fd5a7c4ad35c0be0624852 diff --git a/wallet/statements_gettextgen.po b/wallet/statements_gettextgen.po index 030daf2061c8..8ec71958c963 100644 --- a/wallet/statements_gettextgen.po +++ b/wallet/statements_gettextgen.po @@ -1066,191 +1066,195 @@ msgstr "" msgid "UPDATE payments SET failonionreply=? , faildestperm=? , failindex=? , failcode=? , failnode=? , failchannel=? , failupdate=? , faildetail=? , faildirection=? WHERE payment_hash=? AND partid=?;" msgstr "" -#: wallet/wallet.c:3165 +#: wallet/wallet.c:3166 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE payment_hash = ? ORDER BY id;" msgstr "" -#: wallet/wallet.c:3188 +#: wallet/wallet.c:3192 +msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE status = ? ORDER BY id;" +msgstr "" + +#: wallet/wallet.c:3215 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments ORDER BY id;" msgstr "" -#: wallet/wallet.c:3239 +#: wallet/wallet.c:3266 msgid "SELECT id, status, destination, msatoshi, payment_hash, timestamp, payment_preimage, path_secrets, route_nodes, route_channels, msatoshi_sent, description, bolt11, failonionreply, total_msat, partid, local_offer_id FROM payments WHERE local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:3284 +#: wallet/wallet.c:3311 msgid "DELETE FROM htlc_sigs WHERE channelid = ?" msgstr "" -#: wallet/wallet.c:3291 +#: wallet/wallet.c:3318 msgid "INSERT INTO htlc_sigs (channelid, signature) VALUES (?, ?)" msgstr "" -#: wallet/wallet.c:3303 +#: wallet/wallet.c:3330 msgid "SELECT blobval FROM vars WHERE name='genesis_hash'" msgstr "" -#: wallet/wallet.c:3327 +#: wallet/wallet.c:3354 msgid "INSERT INTO vars (name, blobval) VALUES ('genesis_hash', ?);" msgstr "" -#: wallet/wallet.c:3345 +#: wallet/wallet.c:3372 msgid "SELECT txid, outnum FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3357 +#: wallet/wallet.c:3384 msgid "DELETE FROM utxoset WHERE spendheight < ?" msgstr "" -#: wallet/wallet.c:3365 wallet/wallet.c:3479 +#: wallet/wallet.c:3392 wallet/wallet.c:3506 msgid "INSERT INTO blocks (height, hash, prev_hash) VALUES (?, ?, ?);" msgstr "" -#: wallet/wallet.c:3384 +#: wallet/wallet.c:3411 msgid "DELETE FROM blocks WHERE hash = ?" msgstr "" -#: wallet/wallet.c:3390 +#: wallet/wallet.c:3417 msgid "SELECT * FROM blocks WHERE height >= ?;" msgstr "" -#: wallet/wallet.c:3399 +#: wallet/wallet.c:3426 msgid "DELETE FROM blocks WHERE height > ?" msgstr "" -#: wallet/wallet.c:3411 +#: wallet/wallet.c:3438 msgid "UPDATE outputs SET spend_height = ?, status = ? WHERE prev_out_tx = ? AND prev_out_index = ?" msgstr "" -#: wallet/wallet.c:3429 +#: wallet/wallet.c:3456 msgid "UPDATE utxoset SET spendheight = ? WHERE txid = ? AND outnum = ?" msgstr "" -#: wallet/wallet.c:3452 wallet/wallet.c:3490 +#: wallet/wallet.c:3479 wallet/wallet.c:3517 msgid "INSERT INTO utxoset ( txid, outnum, blockheight, spendheight, txindex, scriptpubkey, satoshis) VALUES(?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3516 +#: wallet/wallet.c:3543 msgid "SELECT height FROM blocks WHERE height = ?" msgstr "" -#: wallet/wallet.c:3529 +#: wallet/wallet.c:3556 msgid "SELECT txid, spendheight, scriptpubkey, satoshis FROM utxoset WHERE blockheight = ? AND txindex = ? AND outnum = ? AND spendheight IS NULL" msgstr "" -#: wallet/wallet.c:3571 +#: wallet/wallet.c:3598 msgid "SELECT blockheight, txindex, outnum FROM utxoset WHERE spendheight = ?" msgstr "" -#: wallet/wallet.c:3602 wallet/wallet.c:3762 +#: wallet/wallet.c:3629 wallet/wallet.c:3789 msgid "SELECT blockheight FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3612 +#: wallet/wallet.c:3639 msgid "INSERT INTO transactions ( id, blockheight, txindex, rawtx) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3633 +#: wallet/wallet.c:3660 msgid "UPDATE transactions SET blockheight = ?, txindex = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3650 +#: wallet/wallet.c:3677 msgid "INSERT INTO transaction_annotations (txid, idx, location, type, channel) VALUES (?, ?, ?, ?, ?) ON CONFLICT(txid,idx) DO NOTHING;" msgstr "" -#: wallet/wallet.c:3682 +#: wallet/wallet.c:3709 msgid "SELECT type, channel_id FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3698 +#: wallet/wallet.c:3725 msgid "UPDATE transactions SET type = ?, channel_id = ? WHERE id = ?" msgstr "" -#: wallet/wallet.c:3717 +#: wallet/wallet.c:3744 msgid "SELECT type FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3740 +#: wallet/wallet.c:3767 msgid "SELECT rawtx FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3786 +#: wallet/wallet.c:3813 msgid "SELECT blockheight, txindex FROM transactions WHERE id=?" msgstr "" -#: wallet/wallet.c:3814 +#: wallet/wallet.c:3841 msgid "SELECT id FROM transactions WHERE blockheight=?" msgstr "" -#: wallet/wallet.c:3833 +#: wallet/wallet.c:3860 msgid "INSERT INTO channeltxs ( channel_id, type, transaction_id, input_num, blockheight) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:3857 +#: wallet/wallet.c:3884 msgid "SELECT DISTINCT(channel_id) FROM channeltxs WHERE type = ?;" msgstr "" -#: wallet/wallet.c:3878 +#: wallet/wallet.c:3905 msgid "SELECT c.type, c.blockheight, t.rawtx, c.input_num, c.blockheight - t.blockheight + 1 AS depth, t.id as txid FROM channeltxs c JOIN transactions t ON t.id = c.transaction_id WHERE c.channel_id = ? ORDER BY c.id ASC;" msgstr "" -#: wallet/wallet.c:3923 +#: wallet/wallet.c:3950 msgid "UPDATE forwarded_payments SET in_msatoshi=?, out_msatoshi=?, state=?, resolved_time=?, failcode=? WHERE in_htlc_id=?" msgstr "" -#: wallet/wallet.c:3981 +#: wallet/wallet.c:4008 msgid "INSERT INTO forwarded_payments ( in_htlc_id, out_htlc_id, in_channel_scid, out_channel_scid, in_msatoshi, out_msatoshi, state, received_time, resolved_time, failcode) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4040 +#: wallet/wallet.c:4067 msgid "SELECT CAST(COALESCE(SUM(in_msatoshi - out_msatoshi), 0) AS BIGINT)FROM forwarded_payments WHERE state = ?;" msgstr "" -#: wallet/wallet.c:4089 +#: wallet/wallet.c:4116 msgid "SELECT f.state, in_msatoshi, out_msatoshi, hin.payment_hash as payment_hash, in_channel_scid, out_channel_scid, f.received_time, f.resolved_time, f.failcode FROM forwarded_payments f LEFT JOIN channel_htlcs hin ON (f.in_htlc_id = hin.id) WHERE (1 = ? OR f.state = ?) AND (1 = ? OR f.in_channel_scid = ?) AND (1 = ? OR f.out_channel_scid = ?)" msgstr "" -#: wallet/wallet.c:4211 +#: wallet/wallet.c:4238 msgid "SELECT t.id, t.rawtx, t.blockheight, t.txindex, t.type as txtype, c2.short_channel_id as txchan, a.location, a.idx as ann_idx, a.type as annotation_type, c.short_channel_id FROM transactions t LEFT JOIN transaction_annotations a ON (a.txid = t.id) LEFT JOIN channels c ON (a.channel = c.id) LEFT JOIN channels c2 ON (t.channel_id = c2.id) ORDER BY t.blockheight, t.txindex ASC" msgstr "" -#: wallet/wallet.c:4305 +#: wallet/wallet.c:4332 msgid "INSERT INTO penalty_bases ( channel_id, commitnum, txid, outnum, amount) VALUES (?, ?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4330 +#: wallet/wallet.c:4357 msgid "SELECT commitnum, txid, outnum, amount FROM penalty_bases WHERE channel_id = ?" msgstr "" -#: wallet/wallet.c:4354 +#: wallet/wallet.c:4381 msgid "DELETE FROM penalty_bases WHERE channel_id = ? AND commitnum = ?" msgstr "" -#: wallet/wallet.c:4372 +#: wallet/wallet.c:4399 msgid "SELECT 1 FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4385 +#: wallet/wallet.c:4412 msgid "INSERT INTO offers ( offer_id, bolt12, label, status) VALUES (?, ?, ?, ?);" msgstr "" -#: wallet/wallet.c:4412 +#: wallet/wallet.c:4439 msgid "SELECT bolt12, label, status FROM offers WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4440 +#: wallet/wallet.c:4467 msgid "SELECT offer_id FROM offers;" msgstr "" -#: wallet/wallet.c:4466 +#: wallet/wallet.c:4493 msgid "UPDATE offers SET status=? WHERE offer_id = ?;" msgstr "" -#: wallet/wallet.c:4477 +#: wallet/wallet.c:4504 msgid "UPDATE invoices SET state=? WHERE state=? AND local_offer_id = ?;" msgstr "" -#: wallet/wallet.c:4505 +#: wallet/wallet.c:4532 msgid "SELECT status FROM offers WHERE offer_id = ?;" msgstr "" @@ -1269,4 +1273,4 @@ msgstr "" #: wallet/test/run-wallet.c:1653 msgid "INSERT INTO channels (id) VALUES (1);" msgstr "" -# SHA256STAMP:e3c8d5cac8615668f0c9f37ebf6edff3b18833bafdf9643c2203b2a4ab654b7c +# SHA256STAMP:a9e9f879b603c01558d2303ef4d982a49384e8e50047612095d79753e0722caa diff --git a/wallet/wallet.c b/wallet/wallet.c index d53652fece4c..d413c29453dd 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -3152,7 +3152,8 @@ void wallet_payment_set_failinfo(struct wallet *wallet, const struct wallet_payment ** wallet_payment_list(const tal_t *ctx, struct wallet *wallet, - const struct sha256 *payment_hash) + const struct sha256 *payment_hash, + enum wallet_payment_status *status) { const struct wallet_payment **payments; struct db_stmt *stmt; @@ -3184,6 +3185,32 @@ wallet_payment_list(const tal_t *ctx, " WHERE payment_hash = ?" " ORDER BY id;")); db_bind_sha256(stmt, 0, payment_hash); + } else if (status) { + // TODO(vincenzopalazzo): Missing the filter options are both not null + // A possible solution is divided the string in two part (pre-where and post-where) and + // use a small if else to set the remain string, with this method we can have small code. + stmt = db_prepare_v2(wallet->db, SQL("SELECT" + " id" + ", status" + ", destination" + ", msatoshi" + ", payment_hash" + ", timestamp" + ", payment_preimage" + ", path_secrets" + ", route_nodes" + ", route_channels" + ", msatoshi_sent" + ", description" + ", bolt11" + ", failonionreply" + ", total_msat" + ", partid" + ", local_offer_id" + " FROM payments" + " WHERE status = ?" + " ORDER BY id;")); + db_bind_int(stmt, 0, wallet_payment_status_in_db(*status)); } else { stmt = db_prepare_v2(wallet->db, SQL("SELECT" " id" diff --git a/wallet/wallet.h b/wallet/wallet.h index d8b399385477..acf688ee34cd 100644 --- a/wallet/wallet.h +++ b/wallet/wallet.h @@ -1114,10 +1114,12 @@ void wallet_payment_set_failinfo(struct wallet *wallet, * wallet_payment_list - Retrieve a list of payments * * payment_hash: optional filter for only this payment hash. + * status: option filtering for all the payment with the specified status. */ const struct wallet_payment **wallet_payment_list(const tal_t *ctx, struct wallet *wallet, - const struct sha256 *payment_hash); + const struct sha256 *payment_hash, + enum wallet_payment_status *status); /** * wallet_payments_by_offer - Retrieve a list of payments for this local_offer_id @@ -1280,7 +1282,7 @@ struct channeltx *wallet_channeltxs_get(struct wallet *w, const tal_t *ctx, */ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in, const struct short_channel_id *scid_out, - const struct htlc_out *out, + const struct htlc_out *out, enum forward_status state, enum onion_wire failcode);