neutrinorpc: add getblockhash command

This commit is contained in:
ErikEk 2022-05-07 08:05:34 +02:00
parent 74023fe230
commit 2d58ecb183

View file

@ -6,6 +6,8 @@ package main
import (
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
"github.com/urfave/cli"
"strconv"
)
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
@ -261,6 +263,47 @@ func getCFilter(ctx *cli.Context) error {
return nil
}
var getBlockHashCommand = cli.Command{
Name: "getblockhash",
Usage: "Get a block hash.",
Category: "Neutrino",
Description: "Returns the header hash of a block at a given height.",
ArgsUsage: "height",
Action: actionDecorator(getBlockHash),
}
func getBlockHash(ctx *cli.Context) error {
ctxc := getContext()
args := ctx.Args()
// Display the command's help message if we do not have the expected
// number of arguments/flags.
if !args.Present() {
return cli.ShowCommandHelp(ctx, "getblockhash")
}
client, cleanUp := getNeutrinoKitClient(ctx)
defer cleanUp()
height, err := strconv.ParseInt(args.First(), 10, 32)
if err != nil {
return err
}
req := &neutrinorpc.GetBlockHashRequest{
Height: int32(height),
}
resp, err := client.GetBlockHash(ctxc, req)
if err != nil {
return err
}
printRespJSON(resp)
return nil
}
// neutrinoCommands will return the set of commands to enable for neutrinorpc
// builds.
func neutrinoCommands() []cli.Command {
@ -278,6 +321,7 @@ func neutrinoCommands() []cli.Command {
getBlockCommand,
getBlockHeaderCommand,
getCFilterCommand,
getBlockHashCommand,
},
},
}