mod+cmd/lncli: use google.golang.org/protobuf package

This commit is contained in:
Oliver Gugger committed 2023-05-11 22:51:16 +02:00
1 parent fd9adaf6ce
commit f9436ec05d
11 files changed
+90 -61

No files matched your search

+2 -2
View File
@@ -10,11 +10,11 @@ import (
"strings"
"unicode"
"github.com/golang/protobuf/proto"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/urfave/cli"
"google.golang.org/protobuf/proto"
"gopkg.in/macaroon-bakery.v2/bakery"
"gopkg.in/macaroon.v2"
)
@@ -385,7 +385,7 @@ func printMacaroon(ctx *cli.Context) error {
return fmt.Errorf("unable to decode macaroon version: %v", err)
}
// Prepare everything to be printed in a more human readable format.
// Prepare everything to be printed in a more human-readable format.
content := &macaroonContent{
Version: uint16(mac.Version()),
Location: mac.Location(),
+4 -3
View File
@@ -17,7 +17,6 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/chainreg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
@@ -952,7 +951,7 @@ func sendToRoute(ctx *cli.Context) error {
// format.
var route *lnrpc.Route
routes := &lnrpc.QueryRoutesResponse{}
err = jsonpb.UnmarshalString(jsonRoutes, routes)
err = lnrpc.ProtoJSONUnmarshalOpts.Unmarshal([]byte(jsonRoutes), routes)
if err == nil {
if len(routes.Routes) == 0 {
return fmt.Errorf("no routes provided")
@@ -966,7 +965,9 @@ func sendToRoute(ctx *cli.Context) error {
route = routes.Routes[0]
} else {
routes := &routerrpc.BuildRouteResponse{}
err = jsonpb.UnmarshalString(jsonRoutes, routes)
err = lnrpc.ProtoJSONUnmarshalOpts.Unmarshal(
[]byte(jsonRoutes), routes,
)
if err != nil {
return fmt.Errorf("unable to unmarshal json string "+
"from incoming array of routes: %v", err)
+1 -2
View File
@@ -10,7 +10,6 @@ import (
"strconv"
"strings"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
@@ -720,7 +719,7 @@ func createWatchOnly(ctx *cli.Context) error {
}
jsonAccts := &walletrpc.ListAccountsResponse{}
err = jsonpb.Unmarshal(bytes.NewReader(jsonBytes), jsonAccts)
err = lnrpc.ProtoJSONUnmarshalOpts.Unmarshal(jsonBytes, jsonAccts)
if err != nil {
return fmt.Errorf("error parsing JSON: %v", err)
}
+4 -11
View File
@@ -5,6 +5,7 @@ import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"io"
@@ -17,9 +18,6 @@ import (
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/protobuf-hex-display/json"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightninglabs/protobuf-hex-display/proto"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/routing"
"github.com/lightningnetwork/lnd/routing/route"
@@ -27,6 +25,7 @@ import (
"github.com/urfave/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
// TODO(roasbeef): cli logic for supporting both positional and unix style
@@ -71,19 +70,13 @@ func printJSON(resp interface{}) {
}
func printRespJSON(resp proto.Message) {
jsonMarshaler := &jsonpb.Marshaler{
EmitDefaults: true,
OrigName: true,
Indent: " ",
}
jsonStr, err := jsonMarshaler.MarshalToString(resp)
jsonBytes, err := lnrpc.ProtoJSONMarshalOpts.Marshal(resp)
if err != nil {
fmt.Println("unable to decode response: ", err)
return
}
fmt.Println(jsonStr)
fmt.Printf("%s\n", jsonBytes)
}
// actionDecorator is used to add additional information and error handling
+3 -5
View File
@@ -4,11 +4,9 @@
package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/lncfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/devrpc"
@@ -43,14 +41,14 @@ func importGraph(ctx *cli.Context) error {
defer cleanUp()
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
jsonBytes, err := ioutil.ReadFile(jsonFile)
jsonBytes, err := os.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)
err = lnrpc.ProtoJSONUnmarshalOpts.Unmarshal(jsonBytes, jsonGraph)
if err != nil {
return fmt.Errorf("error parsing JSON: %v", err)
}