rpc+cli: add general ListAliases function to dump all aliases

This commit is contained in:
eugene
2022-07-14 13:51:48 -04:00
parent 48f270fe20
commit aa576adecc
11 changed files with 1574 additions and 1084 deletions

View File

@@ -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 {