mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +01:00
Merge pull request #3647 from cfromknecht/hex-jsonpb
build+lncli: default to hex encoding for byte slices
This commit is contained in:
commit
72a49d486a
12 changed files with 716 additions and 889 deletions
|
@ -88,7 +88,7 @@ func buildRoute(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(route)
|
||||
printRespJSON(route)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
|
||||
|
||||
|
@ -31,34 +30,7 @@ func queryMissionControl(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
type displayPairHistory struct {
|
||||
NodeFrom, NodeTo string
|
||||
SuccessTime, FailTime int64
|
||||
FailAmtSat, FailAmtMsat int64
|
||||
SuccessAmtSat, SuccessAmtMsat int64
|
||||
}
|
||||
|
||||
displayResp := struct {
|
||||
Pairs []displayPairHistory
|
||||
}{}
|
||||
|
||||
for _, n := range snapshot.Pairs {
|
||||
displayResp.Pairs = append(
|
||||
displayResp.Pairs,
|
||||
displayPairHistory{
|
||||
NodeFrom: hex.EncodeToString(n.NodeFrom),
|
||||
NodeTo: hex.EncodeToString(n.NodeTo),
|
||||
FailTime: n.History.FailTime,
|
||||
SuccessTime: n.History.SuccessTime,
|
||||
FailAmtSat: n.History.FailAmtSat,
|
||||
FailAmtMsat: n.History.FailAmtMsat,
|
||||
SuccessAmtSat: n.History.SuccessAmtSat,
|
||||
SuccessAmtMsat: n.History.SuccessAmtMsat,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
printJSON(displayResp)
|
||||
printRespJSON(snapshot)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -20,8 +19,9 @@ import (
|
|||
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/golang/protobuf/jsonpb"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"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/lnrpc/routerrpc"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
|
@ -1938,53 +1938,7 @@ func getInfo(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
chains := make([]chain, len(resp.Chains))
|
||||
for i, c := range resp.Chains {
|
||||
chains[i] = chain{
|
||||
Chain: c.Chain,
|
||||
Network: c.Network,
|
||||
}
|
||||
}
|
||||
|
||||
// We print a struct that mimics the proto definition of GetInfoResponse
|
||||
// but has a better ordering for the same list of fields.
|
||||
printJSON(struct {
|
||||
Version string `json:"version"`
|
||||
IdentityPubkey string `json:"identity_pubkey"`
|
||||
Alias string `json:"alias"`
|
||||
Color string `json:"color"`
|
||||
NumPendingChannels uint32 `json:"num_pending_channels"`
|
||||
NumActiveChannels uint32 `json:"num_active_channels"`
|
||||
NumInactiveChannels uint32 `json:"num_inactive_channels"`
|
||||
NumPeers uint32 `json:"num_peers"`
|
||||
BlockHeight uint32 `json:"block_height"`
|
||||
BlockHash string `json:"block_hash"`
|
||||
BestHeaderTimestamp int64 `json:"best_header_timestamp"`
|
||||
SyncedToChain bool `json:"synced_to_chain"`
|
||||
SyncedToGraph bool `json:"synced_to_graph"`
|
||||
Testnet bool `json:"testnet"`
|
||||
Chains []chain `json:"chains"`
|
||||
Uris []string `json:"uris"`
|
||||
Features map[uint32]*lnrpc.Feature `json:"features"`
|
||||
}{
|
||||
Version: resp.Version,
|
||||
IdentityPubkey: resp.IdentityPubkey,
|
||||
Alias: resp.Alias,
|
||||
Color: resp.Color,
|
||||
NumPendingChannels: resp.NumPendingChannels,
|
||||
NumActiveChannels: resp.NumActiveChannels,
|
||||
NumInactiveChannels: resp.NumInactiveChannels,
|
||||
NumPeers: resp.NumPeers,
|
||||
BlockHeight: resp.BlockHeight,
|
||||
BlockHash: resp.BlockHash,
|
||||
BestHeaderTimestamp: resp.BestHeaderTimestamp,
|
||||
SyncedToChain: resp.SyncedToChain,
|
||||
SyncedToGraph: resp.SyncedToGraph,
|
||||
Testnet: resp.Testnet,
|
||||
Chains: chains,
|
||||
Uris: resp.Uris,
|
||||
Features: resp.Features,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -2427,15 +2381,7 @@ func sendPaymentRequest(ctx *cli.Context, req *lnrpc.SendRequest) error {
|
|||
|
||||
paymentStream.CloseSend()
|
||||
|
||||
printJSON(struct {
|
||||
E string `json:"payment_error"`
|
||||
P string `json:"payment_preimage"`
|
||||
R *lnrpc.Route `json:"payment_route"`
|
||||
}{
|
||||
E: resp.PaymentError,
|
||||
P: hex.EncodeToString(resp.PaymentPreimage),
|
||||
R: resp.PaymentRoute,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
// If we get a payment error back, we pass an error
|
||||
// up to main which eventually calls fatal() and returns
|
||||
|
@ -2637,15 +2583,7 @@ func sendToRouteRequest(ctx *cli.Context, req *lnrpc.SendToRouteRequest) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
E string `json:"payment_error"`
|
||||
P string `json:"payment_preimage"`
|
||||
R *lnrpc.Route `json:"payment_route"`
|
||||
}{
|
||||
E: resp.PaymentError,
|
||||
P: hex.EncodeToString(resp.PaymentPreimage),
|
||||
R: resp.PaymentRoute,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -2762,15 +2700,7 @@ func addInvoice(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
RHash string `json:"r_hash"`
|
||||
PayReq string `json:"pay_req"`
|
||||
AddIndex uint64 `json:"add_index"`
|
||||
}{
|
||||
RHash: hex.EncodeToString(resp.RHash),
|
||||
PayReq: resp.PaymentRequest,
|
||||
AddIndex: resp.AddIndex,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -3856,14 +3786,11 @@ func exportChanBackup(ctx *cli.Context) error {
|
|||
|
||||
printJSON(struct {
|
||||
ChanPoint string `json:"chan_point"`
|
||||
ChanBackup string `json:"chan_backup"`
|
||||
ChanBackup []byte `json:"chan_backup"`
|
||||
}{
|
||||
ChanPoint: chanPoint.String(),
|
||||
ChanBackup: hex.EncodeToString(
|
||||
chanBackup.ChanBackup,
|
||||
),
|
||||
},
|
||||
)
|
||||
ChanPoint: chanPoint.String(),
|
||||
ChanBackup: chanBackup.ChanBackup,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -3901,16 +3828,8 @@ func exportChanBackup(ctx *cli.Context) error {
|
|||
}.String())
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
ChanPoints []string `json:"chan_points"`
|
||||
MultiChanBackup string `json:"multi_chan_backup"`
|
||||
}{
|
||||
ChanPoints: chanPoints,
|
||||
MultiChanBackup: hex.EncodeToString(
|
||||
chanBackup.MultiChanBackup.MultiChanBackup,
|
||||
),
|
||||
},
|
||||
)
|
||||
printRespJSON(chanBackup)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ func settleInvoice(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(resp)
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ func cancelInvoice(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(resp)
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
|
||||
"github.com/urfave/cli"
|
||||
|
@ -51,15 +50,7 @@ func towerInfo(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(struct {
|
||||
Pubkey string `json:"pubkey"`
|
||||
Listeners []string `json:"listeners"`
|
||||
URIs []string `json:"uris"`
|
||||
}{
|
||||
Pubkey: hex.EncodeToString(resp.Pubkey),
|
||||
Listeners: resp.Listeners,
|
||||
URIs: resp.Uris,
|
||||
})
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -170,16 +170,8 @@ func listTowers(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
var listTowersResp = struct {
|
||||
Towers []*Tower `json:"towers"`
|
||||
}{
|
||||
Towers: make([]*Tower, len(resp.Towers)),
|
||||
}
|
||||
for i, tower := range resp.Towers {
|
||||
listTowersResp.Towers[i] = NewTowerFromProto(tower)
|
||||
}
|
||||
printRespJSON(resp)
|
||||
|
||||
printJSON(listTowersResp)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -224,7 +216,7 @@ func getTower(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
printJSON(NewTowerFromProto(resp))
|
||||
printRespJSON(resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
|
||||
)
|
||||
|
||||
// TowerSession encompasses information about a tower session.
|
||||
type TowerSession struct {
|
||||
NumBackups uint32 `json:"num_backups"`
|
||||
NumPendingBackups uint32 `json:"num_pending_backups"`
|
||||
MaxBackups uint32 `json:"max_backups"`
|
||||
SweepSatPerByte uint32 `json:"sweep_sat_per_byte"`
|
||||
}
|
||||
|
||||
// NewTowerSessionsFromProto converts a set of tower sessions from their RPC
|
||||
// type to a CLI-friendly type.
|
||||
func NewTowerSessionsFromProto(sessions []*wtclientrpc.TowerSession) []*TowerSession {
|
||||
towerSessions := make([]*TowerSession, 0, len(sessions))
|
||||
for _, session := range sessions {
|
||||
towerSessions = append(towerSessions, &TowerSession{
|
||||
NumBackups: session.NumBackups,
|
||||
NumPendingBackups: session.NumPendingBackups,
|
||||
MaxBackups: session.MaxBackups,
|
||||
SweepSatPerByte: session.SweepSatPerByte,
|
||||
})
|
||||
}
|
||||
return towerSessions
|
||||
}
|
||||
|
||||
// Tower encompasses information about a registered watchtower.
|
||||
type Tower struct {
|
||||
PubKey string `json:"pubkey"`
|
||||
Addresses []string `json:"addresses"`
|
||||
ActiveSessionCandidate bool `json:"active_session_candidate"`
|
||||
NumSessions uint32 `json:"num_sessions"`
|
||||
Sessions []*TowerSession `json:"sessions"`
|
||||
}
|
||||
|
||||
// NewTowerFromProto converts a tower from its RPC type to a CLI-friendly type.
|
||||
func NewTowerFromProto(tower *wtclientrpc.Tower) *Tower {
|
||||
return &Tower{
|
||||
PubKey: hex.EncodeToString(tower.Pubkey),
|
||||
Addresses: tower.Addresses,
|
||||
ActiveSessionCandidate: tower.ActiveSessionCandidate,
|
||||
NumSessions: tower.NumSessions,
|
||||
Sessions: NewTowerSessionsFromProto(tower.Sessions),
|
||||
}
|
||||
}
|
1
go.mod
1
go.mod
|
@ -34,6 +34,7 @@ require (
|
|||
github.com/juju/version v0.0.0-20180108022336-b64dbd566305 // indirect
|
||||
github.com/kkdai/bstream v0.0.0-20181106074824-b3251f7901ec
|
||||
github.com/lightninglabs/neutrino v0.11.0
|
||||
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d
|
||||
github.com/lightningnetwork/lightning-onion v0.0.0-20191214001659-f34e9dc1651d
|
||||
github.com/lightningnetwork/lnd/cert v1.0.0
|
||||
github.com/lightningnetwork/lnd/queue v1.0.2
|
||||
|
|
2
go.sum
2
go.sum
|
@ -134,6 +134,8 @@ github.com/lightninglabs/neutrino v0.11.0 h1:lPpYFCtsfJX2W5zI4pWycPmbbBdr7zU+Baf
|
|||
github.com/lightninglabs/neutrino v0.11.0/go.mod h1:CuhF0iuzg9Sp2HO6ZgXgayviFTn1QHdSTJlMncK80wg=
|
||||
github.com/lightningnetwork/lightning-onion v0.0.0-20191214001659-f34e9dc1651d h1:U50MHOOeL6gR3Ee/l0eMvZMpmRo+ydzmlQuIruCyCsA=
|
||||
github.com/lightningnetwork/lightning-onion v0.0.0-20191214001659-f34e9dc1651d/go.mod h1:rigfi6Af/KqsF7Za0hOgcyq2PNH4AN70AaMRxcJkff4=
|
||||
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d h1:QWD/5MPnaZfUVP7P8wLa4M8Td2DI7XXHXt2vhVtUgGI=
|
||||
github.com/lightninglabs/protobuf-hex-display v1.3.3-0.20191212020323-b444784ce75d/go.mod h1:KDb67YMzoh4eudnzClmvs2FbiLG9vxISmLApUkCa4uI=
|
||||
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796 h1:sjOGyegMIhvgfq5oaue6Td+hxZuf3tDC8lAPrFldqFw=
|
||||
github.com/ltcsuite/ltcd v0.0.0-20190101042124-f37f8bf35796/go.mod h1:3p7ZTf9V1sNPI5H8P3NkTFF4LuwMdPl2DodF60qAKqY=
|
||||
github.com/ltcsuite/ltcutil v0.0.0-20181217130922-17f3b04680b6/go.mod h1:8Vg/LTOO0KYa/vlHWJ6XZAevPQThGH5sufO0Hrou/lA=
|
||||
|
|
1288
lnrpc/rpc.pb.go
1288
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load diff
|
@ -1505,18 +1505,27 @@ message GetInfoRequest {
|
|||
}
|
||||
message GetInfoResponse {
|
||||
|
||||
/// The version of the LND software that the node is running.
|
||||
string version = 14 [ json_name = "version" ];
|
||||
|
||||
/// The identity pubkey of the current node.
|
||||
string identity_pubkey = 1 [json_name = "identity_pubkey"];
|
||||
|
||||
/// If applicable, the alias of the current node, e.g. "bob"
|
||||
string alias = 2 [json_name = "alias"];
|
||||
|
||||
/// The color of the current node in hex code format
|
||||
string color = 17 [json_name = "color"];
|
||||
|
||||
/// Number of pending channels
|
||||
uint32 num_pending_channels = 3 [json_name = "num_pending_channels"];
|
||||
|
||||
/// Number of active channels
|
||||
uint32 num_active_channels = 4 [json_name = "num_active_channels"];
|
||||
|
||||
/// Number of inactive channels
|
||||
uint32 num_inactive_channels = 15 [json_name = "num_inactive_channels"];
|
||||
|
||||
/// Number of peers
|
||||
uint32 num_peers = 5 [json_name = "num_peers"];
|
||||
|
||||
|
@ -1526,9 +1535,15 @@ message GetInfoResponse {
|
|||
/// The node's current view of the hash of the best block
|
||||
string block_hash = 8 [json_name = "block_hash"];
|
||||
|
||||
/// Timestamp of the block best known to the wallet
|
||||
int64 best_header_timestamp = 13 [ json_name = "best_header_timestamp" ];
|
||||
|
||||
/// Whether the wallet's view is synced to the main chain
|
||||
bool synced_to_chain = 9 [json_name = "synced_to_chain"];
|
||||
|
||||
// Whether we consider ourselves synced with the public channel graph.
|
||||
bool synced_to_graph = 18 [json_name = "synced_to_graph"];
|
||||
|
||||
/**
|
||||
Whether the current node is connected to testnet. This field is
|
||||
deprecated and the network field should be used instead
|
||||
|
@ -1537,26 +1552,11 @@ message GetInfoResponse {
|
|||
|
||||
reserved 11;
|
||||
|
||||
/// The URIs of the current node.
|
||||
repeated string uris = 12 [json_name = "uris"];
|
||||
|
||||
/// Timestamp of the block best known to the wallet
|
||||
int64 best_header_timestamp = 13 [ json_name = "best_header_timestamp" ];
|
||||
|
||||
/// The version of the LND software that the node is running.
|
||||
string version = 14 [ json_name = "version" ];
|
||||
|
||||
/// Number of inactive channels
|
||||
uint32 num_inactive_channels = 15 [json_name = "num_inactive_channels"];
|
||||
|
||||
/// A list of active chains the node is connected to
|
||||
repeated Chain chains = 16 [json_name = "chains"];
|
||||
|
||||
/// The color of the current node in hex code format
|
||||
string color = 17 [json_name = "color"];
|
||||
|
||||
// Whether we consider ourselves synced with the public channel graph.
|
||||
bool synced_to_graph = 18 [json_name = "synced_to_graph"];
|
||||
/// The URIs of the current node.
|
||||
repeated string uris = 12 [json_name = "uris"];
|
||||
|
||||
/*
|
||||
Features that our node has advertised in our init message, node
|
||||
|
|
|
@ -2453,6 +2453,10 @@
|
|||
"lnrpcGetInfoResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {
|
||||
"type": "string",
|
||||
"description": "/ The version of the LND software that the node is running."
|
||||
},
|
||||
"identity_pubkey": {
|
||||
"type": "string",
|
||||
"description": "/ The identity pubkey of the current node."
|
||||
|
@ -2461,6 +2465,10 @@
|
|||
"type": "string",
|
||||
"title": "/ If applicable, the alias of the current node, e.g. \"bob\""
|
||||
},
|
||||
"color": {
|
||||
"type": "string",
|
||||
"title": "/ The color of the current node in hex code format"
|
||||
},
|
||||
"num_pending_channels": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
|
@ -2471,6 +2479,11 @@
|
|||
"format": "int64",
|
||||
"title": "/ Number of active channels"
|
||||
},
|
||||
"num_inactive_channels": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"title": "/ Number of inactive channels"
|
||||
},
|
||||
"num_peers": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
|
@ -2485,36 +2498,25 @@
|
|||
"type": "string",
|
||||
"title": "/ The node's current view of the hash of the best block"
|
||||
},
|
||||
"synced_to_chain": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"title": "/ Whether the wallet's view is synced to the main chain"
|
||||
},
|
||||
"testnet": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"title": "* \nWhether the current node is connected to testnet. This field is \ndeprecated and the network field should be used instead"
|
||||
},
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "/ The URIs of the current node."
|
||||
},
|
||||
"best_header_timestamp": {
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"title": "/ Timestamp of the block best known to the wallet"
|
||||
},
|
||||
"version": {
|
||||
"type": "string",
|
||||
"description": "/ The version of the LND software that the node is running."
|
||||
"synced_to_chain": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"title": "/ Whether the wallet's view is synced to the main chain"
|
||||
},
|
||||
"num_inactive_channels": {
|
||||
"type": "integer",
|
||||
"format": "int64",
|
||||
"title": "/ Number of inactive channels"
|
||||
"synced_to_graph": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"description": "Whether we consider ourselves synced with the public channel graph."
|
||||
},
|
||||
"testnet": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"title": "* \nWhether the current node is connected to testnet. This field is \ndeprecated and the network field should be used instead"
|
||||
},
|
||||
"chains": {
|
||||
"type": "array",
|
||||
|
@ -2523,14 +2525,12 @@
|
|||
},
|
||||
"title": "/ A list of active chains the node is connected to"
|
||||
},
|
||||
"color": {
|
||||
"type": "string",
|
||||
"title": "/ The color of the current node in hex code format"
|
||||
},
|
||||
"synced_to_graph": {
|
||||
"type": "boolean",
|
||||
"format": "boolean",
|
||||
"description": "Whether we consider ourselves synced with the public channel graph."
|
||||
"uris": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": "/ The URIs of the current node."
|
||||
},
|
||||
"features": {
|
||||
"type": "object",
|
||||
|
|
Loading…
Add table
Reference in a new issue