mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
lncli: add (dev only) importgraph
This commit is contained in:
parent
d059f78b4d
commit
996be217b9
3 changed files with 76 additions and 0 deletions
64
cmd/lncli/devrpc_active.go
Normal file
64
cmd/lncli/devrpc_active.go
Normal file
|
@ -0,0 +1,64 @@
|
|||
//go:build dev
|
||||
// +build dev
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
|
||||
"github.com/lightningnetwork/lnd/lncfg"
|
||||
"github.com/lightningnetwork/lnd/lnrpc"
|
||||
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// devCommands will return the set of commands to enable for devrpc builds.
|
||||
func devCommands() []cli.Command {
|
||||
return []cli.Command{
|
||||
{
|
||||
Name: "importgraph",
|
||||
Category: "Development",
|
||||
Description: "Imports graph from describegraph JSON",
|
||||
Usage: "Import the network graph.",
|
||||
ArgsUsage: "graph-json-file",
|
||||
Action: actionDecorator(importGraph),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func getDevClient(ctx *cli.Context) (devrpc.DevClient, func()) {
|
||||
conn := getClientConn(ctx, false)
|
||||
cleanUp := func() {
|
||||
conn.Close()
|
||||
}
|
||||
return devrpc.NewDevClient(conn), cleanUp
|
||||
}
|
||||
|
||||
func importGraph(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
client, cleanUp := getDevClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
|
||||
jsonBytes, err := ioutil.ReadFile(jsonFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading JSON from file %v: %v",
|
||||
jsonFile, err)
|
||||
}
|
||||
|
||||
jsonGraph := &lnrpc.ChannelGraph{}
|
||||
err = jsonpb.Unmarshal(bytes.NewReader(jsonBytes), jsonGraph)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error parsing JSON: %v", err)
|
||||
}
|
||||
res, err := client.ImportGraph(ctxc, jsonGraph)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(res)
|
||||
return nil
|
||||
}
|
11
cmd/lncli/devrpc_default.go
Normal file
11
cmd/lncli/devrpc_default.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
//go:build !dev
|
||||
// +build !dev
|
||||
|
||||
package main
|
||||
|
||||
import "github.com/urfave/cli"
|
||||
|
||||
// devCommands will return nil for non-devrpc builds.
|
||||
func devCommands() []cli.Command {
|
||||
return nil
|
||||
}
|
|
@ -400,6 +400,7 @@ func main() {
|
|||
app.Commands = append(app.Commands, walletCommands()...)
|
||||
app.Commands = append(app.Commands, watchtowerCommands()...)
|
||||
app.Commands = append(app.Commands, wtclientCommands()...)
|
||||
app.Commands = append(app.Commands, devCommands()...)
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
fatal(err)
|
||||
|
|
Loading…
Add table
Reference in a new issue