diff --git a/cmd/lncli/neutrino_active.go b/cmd/lncli/neutrino_active.go index 9df1360c3..f76d3b924 100644 --- a/cmd/lncli/neutrino_active.go +++ b/cmd/lncli/neutrino_active.go @@ -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, }, }, }