Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip]: add get transaction rpc #7378

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1788,6 +1788,11 @@ var listChainTxnsCommand = cli.Command{
"until the chain tip, including unconfirmed, " +
"set this value to -1",
},
cli.StringSliceFlag{
Name: "tx_hash",
Usage: "the transaction hash to search for. Can be set " +
"multiple times in the same command.",
},
},
Description: `
List all transactions an address of the wallet was involved in.
Expand Down Expand Up @@ -1818,6 +1823,9 @@ func listChainTxns(ctx *cli.Context) error {
if ctx.IsSet("end_height") {
req.EndHeight = int32(ctx.Int64("end_height"))
}
if ctx.IsSet("tx_hash") {
req.TxHashList = ctx.StringSlice("tx_hash")
}

resp, err := client.GetTransactions(ctxc, req)
if err != nil {
Expand Down
5,515 changes: 2,763 additions & 2,752 deletions lnrpc/lightning.pb.go

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ message GetTransactionsRequest {

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

// A filter for searching specific transactions.
repeated string tx_hash_list = 4;
}

message TransactionDetails {
Expand Down
22 changes: 22 additions & 0 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2504,6 +2504,17 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "tx_hash_list",
"description": "A filter for searching specific transactions.",
"in": "query",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
}
],
"tags": [
Expand Down Expand Up @@ -2674,6 +2685,17 @@
"in": "query",
"required": false,
"type": "string"
},
{
"name": "tx_hash_list",
"description": "A filter for searching specific transactions.",
"in": "query",
"required": false,
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "multi"
}
],
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion lnrpc/walletrpc/walletkit_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
// the wallet is still tracking. Sweeps are currently always swept to
// the default wallet account.
transactions, err := w.cfg.Wallet.ListTransactionDetails(
0, btcwallet.UnconfirmedHeight, lnwallet.DefaultAccountName,
0, btcwallet.UnconfirmedHeight, nil, lnwallet.DefaultAccountName,
)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion lntest/mock/walletcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (w *WalletController) ListUnspentWitness(int32, int32,
}

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

return nil, nil
Expand Down
4 changes: 3 additions & 1 deletion lnwallet/btcwallet/btcwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,13 +1384,15 @@ func unminedTransactionsToDetail(
//
// This is a part of the WalletController interface.
func (b *BtcWallet) ListTransactionDetails(startHeight, endHeight int32,
accountFilter string) ([]*lnwallet.TransactionDetail, error) {
txHashList []string, accountFilter string) ([]*lnwallet.TransactionDetail, error) {

// Grab the best block the wallet knows of, we'll use this to calculate
// # of confirmations shortly below.
bestBlock := b.wallet.Manager.SyncedTo()
currentHeight := bestBlock.Height

// TODO: handle 'tx_hash_list' parameter here

// We'll attempt to find all transactions from start to end height.
start := base.NewBlockIdentifierFromHeight(startHeight)
stop := base.NewBlockIdentifierFromHeight(endHeight)
Expand Down
2 changes: 1 addition & 1 deletion lnwallet/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ type WalletController interface {
// unconfirmed transactions. The account parameter serves as a filter to
// retrieve the transactions relevant to a specific account. When
// empty, transactions of all wallet accounts are returned.
ListTransactionDetails(startHeight, endHeight int32,
ListTransactionDetails(startHeight, endHeight int32, txHashList []string,
accountFilter string) ([]*TransactionDetail, error)

// LockOutpoint marks an outpoint as locked meaning it will no longer
Expand Down
10 changes: 5 additions & 5 deletions lnwallet/test/test_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,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(0, btcwallet.UnconfirmedHeight, "")
txs, err := w.ListTransactionDetails(0, btcwallet.UnconfirmedHeight, nil, "")
require.NoError(t, err, "unable to retrieve transactions")
for _, tx := range txs {
if tx.Hash != txHash {
Expand Down Expand Up @@ -1129,7 +1129,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
err = waitForWalletSync(miner, alice)
require.NoError(t, err, "Couldn't sync Alice's wallet")
txDetails, err := alice.ListTransactionDetails(
startHeight, chainTip, "",
startHeight, chainTip, nil, "",
)
require.NoError(t, err, "unable to fetch tx details")

Expand Down Expand Up @@ -1238,7 +1238,7 @@ func testListTransactionDetails(miner *rpctest.Harness,
// with a confirmation height of 0, indicating that it has not been
// mined yet.
txDetails, err = alice.ListTransactionDetails(
chainTip, btcwallet.UnconfirmedHeight, "",
chainTip, btcwallet.UnconfirmedHeight, nil, "",
)
require.NoError(t, err, "unable to fetch tx details")
var mempoolTxFound bool
Expand Down Expand Up @@ -1290,7 +1290,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(chainTip, chainTip, "")
txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, nil, "")
require.NoError(t, err, "unable to fetch tx details")
var burnTxFound bool
for _, txDetail := range txDetails {
Expand Down Expand Up @@ -1331,7 +1331,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(chainTip, chainTip, "")
txDetails, err = alice.ListTransactionDetails(chainTip, chainTip, nil, "")
require.NoError(t, err, "unexpected error")
if len(txDetails) != 0 {
t.Fatalf("expected 0 transactions, got: %v", len(txDetails))
Expand Down
7 changes: 6 additions & 1 deletion rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5714,8 +5714,13 @@ func (r *rpcServer) GetTransactions(ctx context.Context,
endHeight = req.EndHeight
}

var txHashList []string
if len(req.TxHashList) != 0 {
txHashList = req.TxHashList
}

transactions, err := r.server.cc.Wallet.ListTransactionDetails(
req.StartHeight, endHeight, req.Account,
req.StartHeight, endHeight, txHashList, req.Account,
)
if err != nil {
return nil, err
Expand Down