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

rpc: add gettx command to walletrpc #7654

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
guggero marked this conversation as resolved.
Show resolved Hide resolved
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(
guggero marked this conversation as resolved.
Show resolved Hide resolved
&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