Skip to content

Commit

Permalink
Merge pull request lightningnetwork#8998 from Abdulkbk/trx-pagination
Browse files Browse the repository at this point in the history
pagination: add pagination to wallet transactions
  • Loading branch information
guggero authored Nov 22, 2024
2 parents 38ec1a1 + 1c6790b commit 94f7ed4
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 37 deletions.
19 changes: 18 additions & 1 deletion cmd/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,20 @@ var listChainTxnsCommand = cli.Command{
"transactions until the chain tip, including " +
"unconfirmed, set this value to -1",
},
cli.UintFlag{
Name: "index_offset",
Usage: "the index of a transaction that will be " +
"used in a query to determine which " +
"transaction should be returned in the " +
"response",
},
cli.IntFlag{
Name: "max_transactions",
Usage: "(optional) the max number of transactions to " +
"return; leave at default of 0 to return " +
"all transactions",
Value: 0,
},
},
Description: `
List all transactions an address of the wallet was involved in.
Expand All @@ -2096,7 +2110,10 @@ func listChainTxns(ctx *cli.Context) error {
client, cleanUp := getClient(ctx)
defer cleanUp()

req := &lnrpc.GetTransactionsRequest{}
req := &lnrpc.GetTransactionsRequest{
IndexOffset: uint32(ctx.Uint64("index_offset")),
MaxTransactions: uint32(ctx.Uint64("max_transactions")),
}

if ctx.IsSet("start_height") {
req.StartHeight = int32(ctx.Int64("start_height"))
Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@

# New Features
## Functional Enhancements
* [Add ability](https://github.com/lightningnetwork/lnd/pull/8998) to paginate
wallet transactions.
## RPC Additions

* [Add a new rpc endpoint](https://github.com/lightningnetwork/lnd/pull/8843)
Expand Down Expand Up @@ -196,6 +198,7 @@ The underlying functionality between those two options remain the same.

# Contributors (Alphabetical Order)

* Abdullahi Yunus
* Animesh Bilthare
* Boris Nagaev
* CharlieZKSmith
Expand Down
69 changes: 59 additions & 10 deletions lnrpc/lightning.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,35 @@ message GetTransactionsRequest {

// An optional filter to only include transactions relevant to an account.
string account = 3;

/*
The index of a transaction that will be used in a query to determine which
transaction should be returned in the response.
*/
uint32 index_offset = 4;

/*
The maximal number of transactions returned in the response to this query.
This value should be set to 0 to return all transactions.
*/
uint32 max_transactions = 5;
}

message TransactionDetails {
// The list of transactions relevant to the wallet.
repeated Transaction transactions = 1;

/*
The index of the last item in the set of returned transactions. This can be
used to seek further, pagination style.
*/
uint64 last_index = 2;

/*
The index of the last item in the set of returned transactions. This can be
used to seek backwards, pagination style.
*/
uint64 first_index = 3;
}

message FeeLimit {
Expand Down
42 changes: 42 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2591,6 +2591,22 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "index_offset",
"description": "The index of a transaction that will be used in a query to determine which\ntransaction should be returned in the response.",
"in": "query",
"required": false,
"type": "integer",
"format": "int64"
},
{
"name": "max_transactions",
"description": "The maximal number of transactions returned in the response to this query.\nThis value should be set to 0 to return all transactions.",
"in": "query",
"required": false,
"type": "integer",
"format": "int64"
}
],
"tags": [
Expand Down Expand Up @@ -2774,6 +2790,22 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "index_offset",
"description": "The index of a transaction that will be used in a query to determine which\ntransaction should be returned in the response.",
"in": "query",
"required": false,
"type": "integer",
"format": "int64"
},
{
"name": "max_transactions",
"description": "The maximal number of transactions returned in the response to this query.\nThis value should be set to 0 to return all transactions.",
"in": "query",
"required": false,
"type": "integer",
"format": "int64"
}
],
"tags": [
Expand Down Expand Up @@ -7492,6 +7524,16 @@
"$ref": "#/definitions/lnrpcTransaction"
},
"description": "The list of transactions relevant to the wallet."
},
"last_index": {
"type": "string",
"format": "uint64",
"description": "The index of the last item in the set of returned transactions. This can be\nused to seek further, pagination style."
},
"first_index": {
"type": "string",
"format": "uint64",
"description": "The index of the last item in the set of returned transactions. This can be\nused to seek backwards, pagination style."
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion lnrpc/rpc_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,13 @@ func RPCTransaction(tx *lnwallet.TransactionDetail) *Transaction {
}

// RPCTransactionDetails returns a set of rpc transaction details.
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail) *TransactionDetails {
func RPCTransactionDetails(txns []*lnwallet.TransactionDetail, firstIdx,
lastIdx uint64) *TransactionDetails {

txDetails := &TransactionDetails{
Transactions: make([]*Transaction, len(txns)),
FirstIndex: firstIdx,
LastIndex: lastIdx,
}

for i, tx := range txns {
Expand Down
10 changes: 10 additions & 0 deletions lnrpc/walletrpc/walletkit.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,16 @@
"$ref": "#/definitions/lnrpcTransaction"
},
"description": "The list of transactions relevant to the wallet."
},
"last_index": {
"type": "string",
"format": "uint64",
"description": "The index of the last item in the set of returned transactions. This can be\nused to seek further, pagination style."
},
"first_index": {
"type": "string",
"format": "uint64",
"description": "The index of the last item in the set of returned transactions. This can be\nused to seek backwards, pagination style."
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1376,9 +1376,9 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
// can match our list of sweeps against the list of transactions that
// the wallet is still tracking. Sweeps are currently always swept to
// the default wallet account.
transactions, err := w.cfg.Wallet.ListTransactionDetails(
txns, firstIdx, lastIdx, err := w.cfg.Wallet.ListTransactionDetails(
in.StartHeight, btcwallet.UnconfirmedHeight,
lnwallet.DefaultAccountName,
lnwallet.DefaultAccountName, 0, 0,
)
if err != nil {
return nil, err
Expand All @@ -1389,7 +1389,7 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
txDetails []*lnwallet.TransactionDetail
)

for _, tx := range transactions {
for _, tx := range txns {
_, ok := sweepTxns[tx.Hash.String()]
if !ok {
continue
Expand All @@ -1408,7 +1408,7 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
return &ListSweepsResponse{
Sweeps: &ListSweepsResponse_TransactionDetails{
TransactionDetails: lnrpc.RPCTransactionDetails(
txDetails,
txDetails, firstIdx, lastIdx,
),
},
}, nil
Expand Down
5 changes: 3 additions & 2 deletions lntest/mock/walletcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ func (w *WalletController) ListUnspentWitness(int32, int32,

// ListTransactionDetails currently returns dummy values.
func (w *WalletController) ListTransactionDetails(int32, int32,
string) ([]*lnwallet.TransactionDetail, error) {
string, uint32, uint32) ([]*lnwallet.TransactionDetail,
uint64, uint64, error) {

return nil, nil
return nil, 0, 0, nil
}

// LeaseOutput returns the current time and a nil error.
Expand Down
Loading

0 comments on commit 94f7ed4

Please sign in to comment.