mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-19 21:31:04 +02:00
rpc+cli: add general ListAliases function to dump all aliases
This commit is contained in:
parent
48f270fe20
commit
aa576adecc
@ -399,6 +399,23 @@ func (m *Manager) RequestAlias() (lnwire.ShortChannelID, error) {
|
||||
return nextAlias, nil
|
||||
}
|
||||
|
||||
// ListAliases returns a carbon copy of baseToSet. This is used by the rpc
|
||||
// layer.
|
||||
func (m *Manager) ListAliases() map[lnwire.ShortChannelID][]lnwire.ShortChannelID {
|
||||
m.RLock()
|
||||
defer m.RUnlock()
|
||||
|
||||
baseCopy := make(map[lnwire.ShortChannelID][]lnwire.ShortChannelID)
|
||||
|
||||
for k, v := range m.baseToSet {
|
||||
setCopy := make([]lnwire.ShortChannelID, len(v))
|
||||
copy(setCopy, v)
|
||||
baseCopy[k] = setCopy
|
||||
}
|
||||
|
||||
return baseCopy
|
||||
}
|
||||
|
||||
// getNextScid is a utility function that returns the next SCID for a given
|
||||
// alias SCID. The BlockHeight ranges from [16000000, 16250000], the TxIndex
|
||||
// ranges from [1, 16777215], and the TxPosition ranges from [1, 65535].
|
||||
|
@ -1419,6 +1419,31 @@ var listChannelsCommand = cli.Command{
|
||||
Action: actionDecorator(listChannels),
|
||||
}
|
||||
|
||||
var listAliasesCommand = cli.Command{
|
||||
Name: "listaliases",
|
||||
Category: "Channels",
|
||||
Usage: "List all aliases.",
|
||||
Flags: []cli.Flag{},
|
||||
Action: actionDecorator(listaliases),
|
||||
}
|
||||
|
||||
func listaliases(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
client, cleanUp := getClient(ctx)
|
||||
defer cleanUp()
|
||||
|
||||
req := &lnrpc.ListAliasesRequest{}
|
||||
|
||||
resp, err := client.ListAliases(ctxc, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printRespJSON(resp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func listChannels(ctx *cli.Context) error {
|
||||
ctxc := getContext()
|
||||
client, cleanUp := getClient(ctx)
|
||||
|
@ -414,6 +414,7 @@ func main() {
|
||||
sendCustomCommand,
|
||||
subscribeCustomCommand,
|
||||
fishCompletionCommand,
|
||||
listAliasesCommand,
|
||||
}
|
||||
|
||||
// Add any extra commands determined by build flags.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2354,6 +2354,24 @@ func request_Lightning_SubscribeCustomMessages_0(ctx context.Context, marshaler
|
||||
|
||||
}
|
||||
|
||||
func request_Lightning_ListAliases_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListAliasesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.ListAliases(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Lightning_ListAliases_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ListAliasesRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.ListAliases(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterLightningHandlerServer registers the http handlers for service Lightning to "mux".
|
||||
// UnaryRPC :call LightningServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@ -3640,6 +3658,29 @@ func RegisterLightningHandlerServer(ctx context.Context, mux *runtime.ServeMux,
|
||||
return
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Lightning_ListAliases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/lnrpc.Lightning/ListAliases", runtime.WithHTTPPathPattern("/v1/aliases/list"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_Lightning_ListAliases_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_ListAliases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -4961,6 +5002,26 @@ func RegisterLightningHandlerClient(ctx context.Context, mux *runtime.ServeMux,
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Lightning_ListAliases_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/lnrpc.Lightning/ListAliases", runtime.WithHTTPPathPattern("/v1/aliases/list"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_Lightning_ListAliases_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_Lightning_ListAliases_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -5092,6 +5153,8 @@ var (
|
||||
pattern_Lightning_SendCustomMessage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "custommessage"}, ""))
|
||||
|
||||
pattern_Lightning_SubscribeCustomMessages_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "custommessage", "subscribe"}, ""))
|
||||
|
||||
pattern_Lightning_ListAliases_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "aliases", "list"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
@ -5222,4 +5285,6 @@ var (
|
||||
forward_Lightning_SendCustomMessage_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Lightning_SubscribeCustomMessages_0 = runtime.ForwardResponseStream
|
||||
|
||||
forward_Lightning_ListAliases_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
@ -1700,4 +1700,29 @@ func RegisterLightningJSONCallbacks(registry map[string]func(ctx context.Context
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
registry["lnrpc.Lightning.ListAliases"] = func(ctx context.Context,
|
||||
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
|
||||
|
||||
req := &ListAliasesRequest{}
|
||||
err := marshaler.Unmarshal([]byte(reqJSON), req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
client := NewLightningClient(conn)
|
||||
resp, err := client.ListAliases(ctx, req)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
|
||||
respBytes, err := marshaler.Marshal(resp)
|
||||
if err != nil {
|
||||
callback("", err)
|
||||
return
|
||||
}
|
||||
callback(string(respBytes), nil)
|
||||
}
|
||||
}
|
||||
|
@ -570,6 +570,13 @@ service Lightning {
|
||||
*/
|
||||
rpc SubscribeCustomMessages (SubscribeCustomMessagesRequest)
|
||||
returns (stream CustomMessage);
|
||||
|
||||
/* lncli: `listaliases`
|
||||
ListAliases returns the set of all aliases that have ever existed with
|
||||
their confirmed SCID (if it exists) and/or the base SCID (in the case of
|
||||
zero conf).
|
||||
*/
|
||||
rpc ListAliases (ListAliasesRequest) returns (ListAliasesResponse);
|
||||
}
|
||||
|
||||
message SubscribeCustomMessagesRequest {
|
||||
@ -1513,6 +1520,22 @@ message ListChannelsResponse {
|
||||
repeated Channel channels = 11;
|
||||
}
|
||||
|
||||
message AliasMap {
|
||||
/*
|
||||
For non-zero-conf channels, this is the confirmed SCID. Otherwise, this is
|
||||
the first assigned "base" alias.
|
||||
*/
|
||||
uint64 base_scid = 1;
|
||||
|
||||
// The set of all aliases stored for the base SCID.
|
||||
repeated uint64 aliases = 2;
|
||||
}
|
||||
message ListAliasesRequest {
|
||||
}
|
||||
message ListAliasesResponse {
|
||||
repeated AliasMap alias_maps = 1;
|
||||
}
|
||||
|
||||
enum Initiator {
|
||||
INITIATOR_UNKNOWN = 0;
|
||||
INITIATOR_LOCAL = 1;
|
||||
|
@ -16,6 +16,29 @@
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/v1/aliases/list": {
|
||||
"get": {
|
||||
"summary": "lncli: `listaliases`\nListAliases returns the set of all aliases that have ever existed with\ntheir confirmed SCID (if it exists) and/or the base SCID (in the case of\nzero conf).",
|
||||
"operationId": "Lightning_ListAliases",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/lnrpcListAliasesResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
"Lightning"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/balance/blockchain": {
|
||||
"get": {
|
||||
"summary": "lncli: `walletbalance`\nWalletBalance returns total unspent outputs(confirmed and unconfirmed), all\nconfirmed unspent outputs and all unconfirmed unspent outputs under control\nof the wallet.",
|
||||
@ -2951,6 +2974,24 @@
|
||||
"description": "- `p2wkh`: Pay to witness key hash (`WITNESS_PUBKEY_HASH` = 0)\n- `np2wkh`: Pay to nested witness key hash (`NESTED_PUBKEY_HASH` = 1)\n- `p2tr`: Pay to taproot pubkey (`TAPROOT_PUBKEY` = 4)",
|
||||
"title": "`AddressType` has to be one of:"
|
||||
},
|
||||
"lnrpcAliasMap": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"base_scid": {
|
||||
"type": "string",
|
||||
"format": "uint64",
|
||||
"description": "For non-zero-conf channels, this is the confirmed SCID. Otherwise, this is\nthe first assigned \"base\" alias."
|
||||
},
|
||||
"aliases": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
},
|
||||
"description": "The set of all aliases stored for the base SCID."
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcAmount": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -5017,6 +5058,17 @@
|
||||
},
|
||||
"description": "An individual vertex/node within the channel graph. A node is\nconnected to other nodes by one or more channel edges emanating from it. As the\ngraph is directed, a node will also have an incoming edge attached to it for\neach outgoing edge."
|
||||
},
|
||||
"lnrpcListAliasesResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alias_maps": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/lnrpcAliasMap"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"lnrpcListChannelsResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
@ -160,3 +160,5 @@ http:
|
||||
body: "*"
|
||||
- selector: lnrpc.Lightning.SubscribeCustomMessages
|
||||
get: "/v1/custommessage/subscribe"
|
||||
- selector: lnrpc.Lightning.ListAliases
|
||||
get: "/v1/aliases/list"
|
||||
|
@ -410,6 +410,11 @@ type LightningClient interface {
|
||||
//SubscribeCustomMessages subscribes to a stream of incoming custom peer
|
||||
//messages.
|
||||
SubscribeCustomMessages(ctx context.Context, in *SubscribeCustomMessagesRequest, opts ...grpc.CallOption) (Lightning_SubscribeCustomMessagesClient, error)
|
||||
// lncli: `listaliases`
|
||||
//ListAliases returns the set of all aliases that have ever existed with
|
||||
//their confirmed SCID (if it exists) and/or the base SCID (in the case of
|
||||
//zero conf).
|
||||
ListAliases(ctx context.Context, in *ListAliasesRequest, opts ...grpc.CallOption) (*ListAliasesResponse, error)
|
||||
}
|
||||
|
||||
type lightningClient struct {
|
||||
@ -1302,6 +1307,15 @@ func (x *lightningSubscribeCustomMessagesClient) Recv() (*CustomMessage, error)
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (c *lightningClient) ListAliases(ctx context.Context, in *ListAliasesRequest, opts ...grpc.CallOption) (*ListAliasesResponse, error) {
|
||||
out := new(ListAliasesResponse)
|
||||
err := c.cc.Invoke(ctx, "/lnrpc.Lightning/ListAliases", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// LightningServer is the server API for Lightning service.
|
||||
// All implementations must embed UnimplementedLightningServer
|
||||
// for forward compatibility
|
||||
@ -1698,6 +1712,11 @@ type LightningServer interface {
|
||||
//SubscribeCustomMessages subscribes to a stream of incoming custom peer
|
||||
//messages.
|
||||
SubscribeCustomMessages(*SubscribeCustomMessagesRequest, Lightning_SubscribeCustomMessagesServer) error
|
||||
// lncli: `listaliases`
|
||||
//ListAliases returns the set of all aliases that have ever existed with
|
||||
//their confirmed SCID (if it exists) and/or the base SCID (in the case of
|
||||
//zero conf).
|
||||
ListAliases(context.Context, *ListAliasesRequest) (*ListAliasesResponse, error)
|
||||
mustEmbedUnimplementedLightningServer()
|
||||
}
|
||||
|
||||
@ -1900,6 +1919,9 @@ func (UnimplementedLightningServer) SendCustomMessage(context.Context, *SendCust
|
||||
func (UnimplementedLightningServer) SubscribeCustomMessages(*SubscribeCustomMessagesRequest, Lightning_SubscribeCustomMessagesServer) error {
|
||||
return status.Errorf(codes.Unimplemented, "method SubscribeCustomMessages not implemented")
|
||||
}
|
||||
func (UnimplementedLightningServer) ListAliases(context.Context, *ListAliasesRequest) (*ListAliasesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListAliases not implemented")
|
||||
}
|
||||
func (UnimplementedLightningServer) mustEmbedUnimplementedLightningServer() {}
|
||||
|
||||
// UnsafeLightningServer may be embedded to opt out of forward compatibility for this service.
|
||||
@ -3142,6 +3164,24 @@ func (x *lightningSubscribeCustomMessagesServer) Send(m *CustomMessage) error {
|
||||
return x.ServerStream.SendMsg(m)
|
||||
}
|
||||
|
||||
func _Lightning_ListAliases_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListAliasesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(LightningServer).ListAliases(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/lnrpc.Lightning/ListAliases",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(LightningServer).ListAliases(ctx, req.(*ListAliasesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// Lightning_ServiceDesc is the grpc.ServiceDesc for Lightning service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@ -3357,6 +3397,10 @@ var Lightning_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "SendCustomMessage",
|
||||
Handler: _Lightning_SendCustomMessage_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListAliases",
|
||||
Handler: _Lightning_ListAliases_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
|
35
rpcserver.go
35
rpcserver.go
@ -576,6 +576,10 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
|
||||
Entity: "offchain",
|
||||
Action: "read",
|
||||
}},
|
||||
"/lnrpc.Lightning/ListAliases": {{
|
||||
Entity: "offchain",
|
||||
Action: "read",
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@ -7728,6 +7732,37 @@ func (r *rpcServer) SubscribeCustomMessages(req *lnrpc.SubscribeCustomMessagesRe
|
||||
}
|
||||
}
|
||||
|
||||
// ListAliases returns the set of all aliases we have ever allocated along with
|
||||
// their base SCID's and possibly a separate confirmed SCID in the case of
|
||||
// zero-conf.
|
||||
func (r *rpcServer) ListAliases(ctx context.Context,
|
||||
in *lnrpc.ListAliasesRequest) (*lnrpc.ListAliasesResponse, error) {
|
||||
|
||||
// Fetch the map of all aliases.
|
||||
mapAliases := r.server.aliasMgr.ListAliases()
|
||||
|
||||
// Fill out the response. This does not include the zero-conf confirmed
|
||||
// SCID. Doing so would require more database lookups and it can be
|
||||
// cross-referenced with the output of listchannels/closedchannels.
|
||||
resp := &lnrpc.ListAliasesResponse{
|
||||
AliasMaps: make([]*lnrpc.AliasMap, 0),
|
||||
}
|
||||
|
||||
for base, set := range mapAliases {
|
||||
rpcMap := &lnrpc.AliasMap{
|
||||
BaseScid: base.ToUint64(),
|
||||
}
|
||||
for _, alias := range set {
|
||||
rpcMap.Aliases = append(
|
||||
rpcMap.Aliases, alias.ToUint64(),
|
||||
)
|
||||
}
|
||||
resp.AliasMaps = append(resp.AliasMaps, rpcMap)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// rpcInitiator returns the correct lnrpc initiator for channels where we have
|
||||
// a record of the opening channel.
|
||||
func rpcInitiator(isInitiator bool) lnrpc.Initiator {
|
||||
|
Loading…
x
Reference in New Issue
Block a user