neutrinorpc: add getblockhash command
This commit is contained in:
1 parent
74023fe230
commit
2d58ecb183
1 file changed
+44
@@ -6,6 +6,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
"github.com/lightningnetwork/lnd/lnrpc/neutrinorpc"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
|
func getNeutrinoKitClient(ctx *cli.Context) (neutrinorpc.NeutrinoKitClient, func()) {
|
||||||
@@ -261,6 +263,47 @@ func getCFilter(ctx *cli.Context) error {
|
|||||||
return nil
|
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
|
// neutrinoCommands will return the set of commands to enable for neutrinorpc
|
||||||
// builds.
|
// builds.
|
||||||
func neutrinoCommands() []cli.Command {
|
func neutrinoCommands() []cli.Command {
|
||||||
@@ -278,6 +321,7 @@ func neutrinoCommands() []cli.Command {
|
|||||||
getBlockCommand,
|
getBlockCommand,
|
||||||
getBlockHeaderCommand,
|
getBlockHeaderCommand,
|
||||||
getCFilterCommand,
|
getCFilterCommand,
|
||||||
|
getBlockHashCommand,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user