From 507a4eb5cc39ffff4caa484e7a387b187b7a0d75 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 27 Dec 2016 15:45:10 -0800 Subject: [PATCH] cmd/lncli: add support for the net channel graph related commands This commit adds support for the newly added channel graph related commands: describegraph, getchaninfo, getnodeinfo, queryroute, and finally getnetworkinfo. --- cmd/lncli/commands.go | 123 +++++++++++++++++++++++++++++++++++++++++- cmd/lncli/main.go | 8 ++- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 3d1bf871..89e76b1d 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -777,6 +777,127 @@ func listPayments(ctx *cli.Context) error { } printRespJson(payments) - + return nil +} + +var GetChanInfoCommand = cli.Command{ + Name: "getchaninfo", + Usage: "getchaninfo --chand_id=[8_byte_channel_id]", + Description: "prints out the latest authenticated state for a " + + "particular channel", + Flags: []cli.Flag{ + cli.IntFlag{ + Name: "chan_id", + Usage: "the 8-byte compact channel ID to query for", + }, + }, + Action: getChanInfo, +} + +func getChanInfo(ctx *cli.Context) error { + ctxb := context.Background() + client := getClient(ctx) + + req := &lnrpc.ChanInfoRequest{ + ChanId: uint64(ctx.Int("chan_id")), + } + + chanInfo, err := client.GetChanInfo(ctxb, req) + if err != nil { + return err + } + + printRespJson(chanInfo) + return nil +} + +var GetNodeInfoCommand = cli.Command{ + Name: "getnodeinfo", + Usage: "getnodeinfo --pub_key=[33_byte_serialized_pub_lky]", + Description: "prints out the latest authenticated node state for an " + + "advertised node", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "pub_key", + Usage: "the 33-byte hex-encoded compressed public of the target " + + "node", + }, + }, + Action: getNodeInfo, +} + +func getNodeInfo(ctx *cli.Context) error { + ctxb := context.Background() + client := getClient(ctx) + + req := &lnrpc.NodeInfoRequest{ + PubKey: ctx.String("pub_key"), + } + + nodeInfo, err := client.GetNodeInfo(ctxb, req) + if err != nil { + return err + } + + printRespJson(nodeInfo) + return nil +} + +var QueryRouteCommand = cli.Command{ + Name: "queryroute", + Usage: "queryroute --dest=[dest_pub_key] --amt=[amt_to_send_in_satoshis]", + Description: "queries the channel router for a potential path to the destination that has sufficient flow for the amount including fees", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "dest", + Usage: "the 33-byte hex-encoded public key for the payment " + + "destination", + }, + cli.IntFlag{ + Name: "amt", + Usage: "the amount to send expressed in satoshis", + }, + }, + Action: queryRoute, +} + +func queryRoute(ctx *cli.Context) error { + ctxb := context.Background() + client := getClient(ctx) + + req := &lnrpc.RouteRequest{ + PubKey: ctx.String("dest"), + Amt: int64(ctx.Int("amt")), + } + + route, err := client.QueryRoute(ctxb, req) + if err != nil { + return err + } + + printRespJson(route) + return nil +} + +var GetNetworkInfoCommand = cli.Command{ + Name: "getnetworkinfo", + Usage: "getnetworkinfo", + Description: "returns a set of statistics pertaining to the known channel " + + "graph", + Action: getNetworkInfo, +} + +func getNetworkInfo(ctx *cli.Context) error { + ctxb := context.Background() + client := getClient(ctx) + + req := &lnrpc.NetworkInfoRequest{} + + netInfo, err := client.GetNetworkInfo(ctxb, req) + if err != nil { + return err + } + + printRespJson(netInfo) return nil } diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index b1bdd6a0..875de57f 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -39,7 +39,7 @@ func main() { app := cli.NewApp() app.Name = "lncli" app.Version = "0.1" - app.Usage = "control plane for your LN daemon" + app.Usage = "control plane for your Lightning Network Daemon (lnd)" app.Flags = []cli.Flag{ cli.StringFlag{ Name: "rpcserver", @@ -63,9 +63,13 @@ func main() { AddInvoiceCommand, LookupInvoiceCommand, ListInvoicesCommand, - DescribeGraphCommand, ListChannelsCommand, ListPaymentsCommand, + DescribeGraphCommand, + GetChanInfoCommand, + GetNodeInfoCommand, + QueryRouteCommand, + GetNetworkInfoCommand, } if err := app.Run(os.Args); err != nil {