Skip to content

Commit

Permalink
Merge pull request #7654 from ErikEk/listchaintxns-add-txhash
Browse files Browse the repository at this point in the history
rpc: add gettx command to walletrpc
  • Loading branch information
guggero authored Dec 11, 2023
2 parents c32edbd + c8a7a3d commit 0ec9ac7
Show file tree
Hide file tree
Showing 18 changed files with 1,187 additions and 766 deletions.
6 changes: 3 additions & 3 deletions cmd/lncli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1853,9 +1853,9 @@ var listChainTxnsCommand = cli.Command{
cli.Int64Flag{
Name: "end_height",
Usage: "the block height until which to list " +
"transactions, inclusive, to get transactions " +
"until the chain tip, including unconfirmed, " +
"set this value to -1",
"transactions, inclusive, to get " +
"transactions until the chain tip, including " +
"unconfirmed, set this value to -1",
},
},
Description: `
Expand Down
38 changes: 38 additions & 0 deletions cmd/lncli/walletrpc_active.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func walletCommands() []cli.Command {
listSweepsCommand,
labelTxCommand,
publishTxCommand,
getTxCommand,
releaseOutputCommand,
leaseOutputCommand,
listLeasesCommand,
Expand Down Expand Up @@ -561,6 +562,43 @@ func publishTransaction(ctx *cli.Context) error {
return nil
}

var getTxCommand = cli.Command{
Name: "gettx",
Usage: "Returns details of a transaction.",
ArgsUsage: "txid",
Description: `
Query the transaction using the given transaction id and return its
details. An error is returned if the transaction is not found.
`,
Action: actionDecorator(getTransaction),
}

func getTransaction(ctx *cli.Context) error {
ctxc := getContext()

// Display the command's help message if we do not have the expected
// number of arguments/flags.
if ctx.NArg() != 1 {
return cli.ShowCommandHelp(ctx, "gettx")
}

walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp()

req := &walletrpc.GetTransactionRequest{
Txid: ctx.Args().First(),
}

res, err := walletClient.GetTransaction(ctxc, req)
if err != nil {
return err
}

printRespJSON(res)

return nil
}

// utxoLease contains JSON annotations for a lease on an unspent output.
type utxoLease struct {
ID string `json:"id"`
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.18.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
status, `StatusInitiated`, to explicitly report its current state. Before
running this new version, please make sure to upgrade your client application
to include this new status so it can understand the RPC response properly.

* Adds a new rpc endpoint gettx to the walletrpc sub-server to [fetch
transaction details](https://github.com/lightningnetwork/lnd/pull/7654).

## lncli Additions

Expand Down Expand Up @@ -175,6 +178,7 @@
* Andras Banki-Horvath
* Carla Kirk-Cohen
* Elle Mouton
* ErikEk
* Keagan McClelland
* Marcos Fernandez Perez
* Matt Morehouse
Expand Down
32 changes: 11 additions & 21 deletions itest/lnd_misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,32 +829,22 @@ func testSweepAllCoins(ht *lntest.HarnessTest) {
// assertTxLabel is a helper function which finds a target tx in our
// set of transactions and checks that it has the desired label.
assertTxLabel := func(targetTx, label string) error {
// List all transactions relevant to our wallet, and find the
// tx so that we can check the correct label has been set.
txResp := ainz.RPC.GetTransactions(nil)

var target *lnrpc.Transaction

// First we need to find the target tx.
for _, txn := range txResp.Transactions {
if txn.TxHash == targetTx {
target = txn
break
}
}

// If we cannot find it, return an error.
if target == nil {
return fmt.Errorf("target tx %v not found", targetTx)
}
// Get the transaction from our wallet so that we can check
// that the correct label has been set.
txResp := ainz.RPC.GetTransaction(
&walletrpc.GetTransactionRequest{
Txid: targetTx,
},
)
require.NotNilf(ht, txResp, "target tx %v not found", targetTx)

// Otherwise, check the labels are matched.
if target.Label == label {
// Make sure the labels match.
if txResp.Label == label {
return nil
}

return fmt.Errorf("labels not match, want: "+
"%v, got %v", label, target.Label)
"%v, got %v", label, txResp.Label)
}

// waitTxLabel waits until the desired tx label is found or timeout.
Expand Down
Loading

0 comments on commit 0ec9ac7

Please sign in to comment.