mirror of
https://github.com/aljazceru/breez-lnd.git
synced 2025-12-18 14:44:22 +01:00
cmd/lncli: add --peer flag to list channels
This commit adds a flag to listchannels that filters by remote pubkey.
This commit is contained in:
@@ -1990,6 +1990,12 @@ var listChannelsCommand = cli.Command{
|
|||||||
Name: "private_only",
|
Name: "private_only",
|
||||||
Usage: "only list channels which are currently private",
|
Usage: "only list channels which are currently private",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "peer",
|
||||||
|
Usage: "(optional) only display channels with a " +
|
||||||
|
"particular peer, accepts 66-byte, " +
|
||||||
|
"hex-encoded pubkeys",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: actionDecorator(listChannels),
|
Action: actionDecorator(listChannels),
|
||||||
}
|
}
|
||||||
@@ -1999,11 +2005,26 @@ func listChannels(ctx *cli.Context) error {
|
|||||||
client, cleanUp := getClient(ctx)
|
client, cleanUp := getClient(ctx)
|
||||||
defer cleanUp()
|
defer cleanUp()
|
||||||
|
|
||||||
|
peer := ctx.String("peer")
|
||||||
|
|
||||||
|
// If the user requested channels with a particular key, parse the
|
||||||
|
// provided pubkey.
|
||||||
|
var peerKey []byte
|
||||||
|
if len(peer) > 0 {
|
||||||
|
pk, err := route.NewVertexFromStr(peer)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid --peer pubkey: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
peerKey = pk[:]
|
||||||
|
}
|
||||||
|
|
||||||
req := &lnrpc.ListChannelsRequest{
|
req := &lnrpc.ListChannelsRequest{
|
||||||
ActiveOnly: ctx.Bool("active_only"),
|
ActiveOnly: ctx.Bool("active_only"),
|
||||||
InactiveOnly: ctx.Bool("inactive_only"),
|
InactiveOnly: ctx.Bool("inactive_only"),
|
||||||
PublicOnly: ctx.Bool("public_only"),
|
PublicOnly: ctx.Bool("public_only"),
|
||||||
PrivateOnly: ctx.Bool("private_only"),
|
PrivateOnly: ctx.Bool("private_only"),
|
||||||
|
Peer: peerKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.ListChannels(ctxb, req)
|
resp, err := client.ListChannels(ctxb, req)
|
||||||
@@ -2011,8 +2032,6 @@ func listChannels(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): defer close the client for the all
|
|
||||||
|
|
||||||
printRespJSON(resp)
|
printRespJSON(resp)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
1264
lnrpc/rpc.pb.go
1264
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@@ -1385,6 +1385,12 @@ message ListChannelsRequest {
|
|||||||
bool inactive_only = 2;
|
bool inactive_only = 2;
|
||||||
bool public_only = 3;
|
bool public_only = 3;
|
||||||
bool private_only = 4;
|
bool private_only = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Filters the response for channels with a target peer's pubkey. If peer is
|
||||||
|
empty, all channels will be returned.
|
||||||
|
*/
|
||||||
|
bytes peer = 5;
|
||||||
}
|
}
|
||||||
message ListChannelsResponse {
|
message ListChannelsResponse {
|
||||||
/// The list of active channels
|
/// The list of active channels
|
||||||
|
|||||||
@@ -116,6 +116,14 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"format": "boolean"
|
"format": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "peer",
|
||||||
|
"description": "*\nFilters the response for channels with a target peer's pubkey. If peer is\nempty, all channels will be returned.",
|
||||||
|
"in": "query",
|
||||||
|
"required": false,
|
||||||
|
"type": "string",
|
||||||
|
"format": "byte"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
12
rpcserver.go
12
rpcserver.go
@@ -2948,6 +2948,11 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
|||||||
"`private_only` can be set, but not both")
|
"`private_only` can be set, but not both")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(in.Peer) > 0 && len(in.Peer) != 33 {
|
||||||
|
_, err := route.NewVertexFromBytes(in.Peer)
|
||||||
|
return nil, fmt.Errorf("invalid `peer` key: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
resp := &lnrpc.ListChannelsResponse{}
|
resp := &lnrpc.ListChannelsResponse{}
|
||||||
|
|
||||||
graph := r.server.chanDB.ChannelGraph()
|
graph := r.server.chanDB.ChannelGraph()
|
||||||
@@ -2962,8 +2967,15 @@ func (r *rpcServer) ListChannels(ctx context.Context,
|
|||||||
|
|
||||||
for _, dbChannel := range dbChannels {
|
for _, dbChannel := range dbChannels {
|
||||||
nodePub := dbChannel.IdentityPub
|
nodePub := dbChannel.IdentityPub
|
||||||
|
nodePubBytes := nodePub.SerializeCompressed()
|
||||||
chanPoint := dbChannel.FundingOutpoint
|
chanPoint := dbChannel.FundingOutpoint
|
||||||
|
|
||||||
|
// If the caller requested channels for a target node, skip any
|
||||||
|
// that don't match the provided pubkey.
|
||||||
|
if len(in.Peer) > 0 && !bytes.Equal(nodePubBytes, in.Peer) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var peerOnline bool
|
var peerOnline bool
|
||||||
if _, err := r.server.FindPeer(nodePub); err == nil {
|
if _, err := r.server.FindPeer(nodePub); err == nil {
|
||||||
peerOnline = true
|
peerOnline = true
|
||||||
|
|||||||
Reference in New Issue
Block a user