mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-03 18:22:25 +02:00
chainrpc+lncli: expose GetBlockHeader + add to CLI
This commit is contained in:
@@ -25,6 +25,7 @@ func chainCommands() []cli.Command {
|
||||
getBlockCommand,
|
||||
getBestBlockCommand,
|
||||
getBlockHashCommand,
|
||||
getBlockHeaderCommand,
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -113,6 +114,45 @@ func getBlock(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var getBlockHeaderCommand = cli.Command{
|
||||
Name: "getblockheader",
|
||||
Usage: "Get a block header.",
|
||||
Category: "On-chain",
|
||||
Description: "Returns a block header with a particular block hash.",
|
||||
ArgsUsage: "hash",
|
||||
Action: actionDecorator(getBlockHeader),
|
||||
}
|
||||
|
||||
func getBlockHeader(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, "getblockheader")
|
||||
}
|
||||
|
||||
blockHash, err := chainhash.NewHashFromStr(args.First())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := &chainrpc.GetBlockHeaderRequest{BlockHash: blockHash[:]}
|
||||
|
||||
client, cleanUp := getChainClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
resp, err := client.GetBlockHeader(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var getBestBlockCommand = cli.Command{
|
||||
Name: "getbestblock",
|
||||
Category: "On-chain",
|
||||
|
@@ -155,16 +155,16 @@ func isBanned(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var getBlockHeaderCommand = cli.Command{
|
||||
var getBlockHeaderNeutrinoCommand = cli.Command{
|
||||
Name: "getblockheader",
|
||||
Usage: "Get a block header.",
|
||||
Category: "Neutrino",
|
||||
Description: "Returns a block header with a particular block hash.",
|
||||
ArgsUsage: "hash",
|
||||
Action: actionDecorator(getBlockHeader),
|
||||
Action: actionDecorator(getBlockHeaderNeutrino),
|
||||
}
|
||||
|
||||
func getBlockHeader(ctx *cli.Context) error {
|
||||
func getBlockHeaderNeutrino(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
args := ctx.Args()
|
||||
|
||||
@@ -239,7 +239,7 @@ func neutrinoCommands() []cli.Command {
|
||||
addPeerCommand,
|
||||
disconnectPeerCommand,
|
||||
isBannedCommand,
|
||||
getBlockHeaderCommand,
|
||||
getBlockHeaderNeutrinoCommand,
|
||||
getCFilterCommand,
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user