rpc: add gettransaction endpoint to walletrpc sub-server

This commit is contained in:
ErikEk
2023-01-18 13:29:09 +08:00
parent c32edbd732
commit f0bc6d804c
14 changed files with 1130 additions and 745 deletions

View File

@@ -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: `

View File

@@ -74,6 +74,7 @@ func walletCommands() []cli.Command {
listSweepsCommand,
labelTxCommand,
publishTxCommand,
getTxCommand,
releaseOutputCommand,
leaseOutputCommand,
listLeasesCommand,
@@ -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"`