Skip to content

Commit 34c70da

Browse files
saraogiraj94claude
andcommitted
lnwallet+rpc: add label filter to GetTransactions/ListTransactionDetails
Adds an optional `label` string field to `GetTransactionsRequest` (proto field 6) so callers can filter chain transactions by label. - `WalletController.ListTransactionDetails` gains a `labelFilter string` parameter; when non-empty, only transactions whose `Label` field exactly matches are returned (client-side filter after the full fetch). - `rpcserver.GetTransactions` threads `req.Label` through to the wallet call. - `lncli listchaintxns` gains a `--label` flag. - All mocks and the integration-test harness are updated to pass the new parameter. - New integration test `testListTransactionDetailsLabelFilter` covers: exact match by label, no-filter returns all, and unknown label returns empty. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e8b7542 commit 34c70da

12 files changed

Lines changed: 2075 additions & 1531 deletions

File tree

cmd/commands/commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,6 +2288,12 @@ var listChainTxnsCommand = cli.Command{
22882288
"all transactions",
22892289
Value: 0,
22902290
},
2291+
cli.StringFlag{
2292+
Name: "label",
2293+
Usage: "an optional label to filter " +
2294+
"transactions by; only transactions with " +
2295+
"a matching label will be returned",
2296+
},
22912297
},
22922298
Description: `
22932299
List all transactions an address of the wallet was involved in.
@@ -2338,6 +2344,7 @@ func listChainTxns(ctx *cli.Context) error {
23382344
MaxTransactions: uint32(ctx.Uint64("max_transactions")),
23392345
StartHeight: startHeight,
23402346
EndHeight: endHeight,
2347+
Label: ctx.String("label"),
23412348
}
23422349

23432350
resp, err := client.GetTransactions(ctxc, req)

docs/release-notes/release-notes-0.22.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,16 @@
3232

3333
## RPC Additions
3434

35+
* [`GetTransactions`](https://github.com/lightningnetwork/lnd/pull/10806)
36+
now accepts an optional `label` field to filter returned transactions by
37+
their label. Only transactions whose label exactly matches the provided
38+
value are returned; omitting the field returns all transactions as before.
39+
3540
## lncli Additions
3641

42+
* `listchaintxns` now accepts an optional `--label` flag to filter returned
43+
transactions by their label.
44+
3745
# Improvements
3846

3947
## Functional Updates
@@ -71,3 +79,4 @@
7179

7280
* Boris Nagaev
7381
* Erick Cestari
82+
* saraogiraj94

lnrpc/lightning.pb.go

Lines changed: 1302 additions & 959 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lnrpc/lightning.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,9 @@ message GetTransactionsRequest {
856856
This value should be set to 0 to return all transactions.
857857
*/
858858
uint32 max_transactions = 5;
859+
860+
// An optional filter to only include transactions with a matching label.
861+
string label = 6;
859862
}
860863

861864
message TransactionDetails {

lnrpc/lightning.swagger.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,13 @@
28232823
"required": false,
28242824
"type": "integer",
28252825
"format": "int64"
2826+
},
2827+
{
2828+
"name": "label",
2829+
"description": "An optional filter to only include transactions with a matching label.",
2830+
"in": "query",
2831+
"required": false,
2832+
"type": "string"
28262833
}
28272834
],
28282835
"tags": [

lnrpc/lightning_grpc.pb.go

Lines changed: 580 additions & 554 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lntest/mock/walletcontroller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ func (w *WalletController) ListUnspentWitness(int32, int32,
187187

188188
// ListTransactionDetails currently returns dummy values.
189189
func (w *WalletController) ListTransactionDetails(int32, int32,
190-
string, uint32, uint32) ([]*lnwallet.TransactionDetail,
190+
string, string, uint32, uint32) ([]*lnwallet.TransactionDetail,
191191
uint64, uint64, error) {
192192

193193
return nil, 0, 0, nil

lnwallet/btcwallet/btcwallet.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ func unminedTransactionsToDetail(
14811481
//
14821482
// This is a part of the WalletController interface.
14831483
func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
1484-
accountFilter string, indexOffset uint32,
1484+
accountFilter string, labelFilter string, indexOffset uint32,
14851485
maxTransactions uint32) ([]*lnwallet.TransactionDetail, uint64, uint64,
14861486
error) {
14871487

@@ -1523,6 +1523,18 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
15231523
txDetails = append(txDetails, detail)
15241524
}
15251525

1526+
// If a label filter is specified, only include transactions whose label
1527+
// matches exactly.
1528+
if labelFilter != "" {
1529+
filtered := txDetails[:0]
1530+
for _, tx := range txDetails {
1531+
if tx.Label == labelFilter {
1532+
filtered = append(filtered, tx)
1533+
}
1534+
}
1535+
txDetails = filtered
1536+
}
1537+
15261538
// Return empty transaction list, if offset is more than all
15271539
// transactions.
15281540
if int(indexOffset) >= len(txDetails) {

lnwallet/interface.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,11 @@ type WalletController interface {
400400
// the tip of the chain until the start height (inclusive) and
401401
// unconfirmed transactions. The account parameter serves as a filter to
402402
// retrieve the transactions relevant to a specific account. When
403-
// empty, transactions of all wallet accounts are returned.
403+
// empty, transactions of all wallet accounts are returned. The label
404+
// parameter serves as an optional filter to retrieve only transactions
405+
// with a matching label. When empty, all transactions are returned.
404406
ListTransactionDetails(startHeight, endHeight int32,
405-
accountFilter string, indexOffset uint32,
407+
accountFilter string, labelFilter string, indexOffset uint32,
406408
maxTransactions uint32) ([]*TransactionDetail, uint64, uint64,
407409
error)
408410

lnwallet/mock.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ func (w *mockWalletController) ListUnspentWitness(int32, int32,
198198

199199
// ListTransactionDetails currently returns dummy values.
200200
func (w *mockWalletController) ListTransactionDetails(int32, int32,
201-
string, uint32, uint32) ([]*TransactionDetail, uint64, uint64, error) {
201+
string, string, uint32, uint32) ([]*TransactionDetail, uint64, uint64,
202+
error) {
202203

203204
return nil, 0, 0, nil
204205
}

0 commit comments

Comments
 (0)