multi: return txns first and last indices
In this commit we introduce first and last indices for the tranasctions returned which can be used to seek for further transactions in a pagination style. Signed-off-by: Abdullahi Yunus <abdoollahikbk@gmail.com>
This commit is contained in:
1 parent
cd1df4ac34
commit
762d01536b
13 files changed
+3135
-3044
No files matched your search
@@ -1555,7 +1555,8 @@ func unminedTransactionsToDetail(
|
||||
// This is a part of the WalletController interface.
|
||||
func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
||||
accountFilter string, indexOffset uint32,
|
||||
maxTransactons uint32) ([]*lnwallet.TransactionDetail, error) {
|
||||
maxTransactions uint32) ([]*lnwallet.TransactionDetail, uint64, uint64,
|
||||
error) {
|
||||
|
||||
// Grab the best block the wallet knows of, we'll use this to calculate
|
||||
// # of confirmations shortly below.
|
||||
@@ -1567,7 +1568,7 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
||||
stop := base.NewBlockIdentifierFromHeight(endHeight)
|
||||
txns, err := b.wallet.GetTransactions(start, stop, accountFilter, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
txDetails := make([]*lnwallet.TransactionDetail, 0,
|
||||
@@ -1581,7 +1582,7 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
||||
currentHeight, blockPackage, b.netParams,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
txDetails = append(txDetails, details...)
|
||||
@@ -1589,7 +1590,7 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
||||
for _, tx := range txns.UnminedTransactions {
|
||||
detail, err := unminedTransactionsToDetail(tx, b.netParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
txDetails = append(txDetails, detail)
|
||||
@@ -1598,19 +1599,29 @@ func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
|
||||
// Return empty transaction list, if offset is more than all
|
||||
// transactions.
|
||||
if int(indexOffset) >= len(txDetails) {
|
||||
return []*lnwallet.TransactionDetail{}, nil
|
||||
txDetails = []*lnwallet.TransactionDetail{}
|
||||
|
||||
return txDetails, 0, 0, nil
|
||||
}
|
||||
|
||||
if maxTransactons == 0 {
|
||||
return txDetails[indexOffset:], nil
|
||||
end := indexOffset + maxTransactions
|
||||
|
||||
// If maxTransactions is set to 0, then we'll return all transactions
|
||||
// starting from the offset.
|
||||
if maxTransactions == 0 {
|
||||
end = uint32(len(txDetails))
|
||||
txDetails = txDetails[indexOffset:end]
|
||||
|
||||
return txDetails, uint64(indexOffset), uint64(end - 1), nil
|
||||
}
|
||||
|
||||
end := indexOffset + maxTransactons
|
||||
if int(end) > len(txDetails) {
|
||||
if end > uint32(len(txDetails)) {
|
||||
end = uint32(len(txDetails))
|
||||
}
|
||||
|
||||
return txDetails[indexOffset:end], nil
|
||||
txDetails = txDetails[indexOffset:end]
|
||||
|
||||
return txDetails, uint64(indexOffset), uint64(end - 1), nil
|
||||
}
|
||||
|
||||
// txSubscriptionClient encapsulates the transaction notification client from
|
||||
|
||||
@@ -403,7 +403,8 @@ type WalletController interface {
|
||||
// empty, transactions of all wallet accounts are returned.
|
||||
ListTransactionDetails(startHeight, endHeight int32,
|
||||
accountFilter string, indexOffset uint32,
|
||||
maxTransactions uint32) ([]*TransactionDetail, error)
|
||||
maxTransactions uint32) ([]*TransactionDetail, uint64, uint64,
|
||||
error)
|
||||
|
||||
// LeaseOutput locks an output to the given ID, preventing it from being
|
||||
// available for any future coin selection attempts. The absolute time
|
||||
|
||||
+2
-2
@@ -198,9 +198,9 @@ func (w *mockWalletController) ListUnspentWitness(int32, int32,
|
||||
|
||||
// ListTransactionDetails currently returns dummy values.
|
||||
func (w *mockWalletController) ListTransactionDetails(int32, int32,
|
||||
string, uint32, uint32) ([]*TransactionDetail, error) {
|
||||
string, uint32, uint32) ([]*TransactionDetail, uint64, uint64, error) {
|
||||
|
||||
return nil, nil
|
||||
return nil, 0, 0, nil
|
||||
}
|
||||
|
||||
// LeaseOutput returns the current time and a nil error.
|
||||
|
||||
@@ -199,7 +199,7 @@ func assertTxInWallet(t *testing.T, w *lnwallet.LightningWallet,
|
||||
// We'll fetch all of our transaction and go through each one until
|
||||
// finding the expected transaction with its expected confirmation
|
||||
// status.
|
||||
txs, err := w.ListTransactionDetails(
|
||||
txs, _, _, err := w.ListTransactionDetails(
|
||||
0, btcwallet.UnconfirmedHeight, "", 0, 1000,
|
||||
)
|
||||
require.NoError(t, err, "unable to retrieve transactions")
|
||||
@@ -1103,7 +1103,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// should be confirmed.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
txDetails, err := alice.ListTransactionDetails(
|
||||
txDetails, _, _, err := alice.ListTransactionDetails(
|
||||
startHeight, chainTip, "", 0, 1000,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
@@ -1215,7 +1215,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// unconfirmed transactions. The transaction above should be included
|
||||
// with a confirmation height of 0, indicating that it has not been
|
||||
// mined yet.
|
||||
txDetails, err = alice.ListTransactionDetails(
|
||||
txDetails, _, _, err = alice.ListTransactionDetails(
|
||||
chainTip, btcwallet.UnconfirmedHeight, "", 0, 1000,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
@@ -1268,7 +1268,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
// transactions from the last block.
|
||||
err = waitForWalletSync(miner, alice)
|
||||
require.NoError(t, err, "Couldn't sync Alice's wallet")
|
||||
txDetails, err = alice.ListTransactionDetails(
|
||||
txDetails, _, _, err = alice.ListTransactionDetails(
|
||||
chainTip, chainTip, "", 0, 1000,
|
||||
)
|
||||
require.NoError(t, err, "unable to fetch tx details")
|
||||
@@ -1311,7 +1311,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
|
||||
|
||||
// Query for transactions only in the latest block. We do not expect
|
||||
// any transactions to be returned.
|
||||
txDetails, err = alice.ListTransactionDetails(
|
||||
txDetails, _, _, err = alice.ListTransactionDetails(
|
||||
chainTip, chainTip, "", 0, 1000,
|
||||
)
|
||||
require.NoError(t, err, "unexpected error")
|
||||
|
||||
Reference in new issue
Block a user