mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
rpcserver: extract marshalNode
This commit is contained in:
parent
01e7f09dfb
commit
0663a92bff
1 changed files with 24 additions and 36 deletions
60
rpcserver.go
60
rpcserver.go
|
@ -5673,23 +5673,7 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
||||||
// within the graph), collating their current state into the RPC
|
// within the graph), collating their current state into the RPC
|
||||||
// response.
|
// response.
|
||||||
err := graph.ForEachNode(func(_ kvdb.RTx, node *channeldb.LightningNode) error {
|
err := graph.ForEachNode(func(_ kvdb.RTx, node *channeldb.LightningNode) error {
|
||||||
nodeAddrs := make([]*lnrpc.NodeAddress, 0)
|
lnNode := marshalNode(node)
|
||||||
for _, addr := range node.Addresses {
|
|
||||||
nodeAddr := &lnrpc.NodeAddress{
|
|
||||||
Network: addr.Network(),
|
|
||||||
Addr: addr.String(),
|
|
||||||
}
|
|
||||||
nodeAddrs = append(nodeAddrs, nodeAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
lnNode := &lnrpc.LightningNode{
|
|
||||||
LastUpdate: uint32(node.LastUpdate.Unix()),
|
|
||||||
PubKey: hex.EncodeToString(node.PubKeyBytes[:]),
|
|
||||||
Addresses: nodeAddrs,
|
|
||||||
Alias: node.Alias,
|
|
||||||
Color: routing.EncodeHexColor(node.Color),
|
|
||||||
Features: invoicesrpc.CreateRPCFeatures(node.Features),
|
|
||||||
}
|
|
||||||
|
|
||||||
resp.Nodes = append(resp.Nodes, lnNode)
|
resp.Nodes = append(resp.Nodes, lnNode)
|
||||||
|
|
||||||
|
@ -5927,32 +5911,36 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeAddrs := make([]*lnrpc.NodeAddress, 0)
|
|
||||||
for _, addr := range node.Addresses {
|
|
||||||
nodeAddr := &lnrpc.NodeAddress{
|
|
||||||
Network: addr.Network(),
|
|
||||||
Addr: addr.String(),
|
|
||||||
}
|
|
||||||
nodeAddrs = append(nodeAddrs, nodeAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
features := invoicesrpc.CreateRPCFeatures(node.Features)
|
|
||||||
|
|
||||||
return &lnrpc.NodeInfo{
|
return &lnrpc.NodeInfo{
|
||||||
Node: &lnrpc.LightningNode{
|
Node: marshalNode(node),
|
||||||
LastUpdate: uint32(node.LastUpdate.Unix()),
|
|
||||||
PubKey: in.PubKey,
|
|
||||||
Addresses: nodeAddrs,
|
|
||||||
Alias: node.Alias,
|
|
||||||
Color: routing.EncodeHexColor(node.Color),
|
|
||||||
Features: features,
|
|
||||||
},
|
|
||||||
NumChannels: numChannels,
|
NumChannels: numChannels,
|
||||||
TotalCapacity: int64(totalCapacity),
|
TotalCapacity: int64(totalCapacity),
|
||||||
Channels: channels,
|
Channels: channels,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func marshalNode(node *channeldb.LightningNode) *lnrpc.LightningNode {
|
||||||
|
nodeAddrs := make([]*lnrpc.NodeAddress, len(node.Addresses))
|
||||||
|
for i, addr := range node.Addresses {
|
||||||
|
nodeAddr := &lnrpc.NodeAddress{
|
||||||
|
Network: addr.Network(),
|
||||||
|
Addr: addr.String(),
|
||||||
|
}
|
||||||
|
nodeAddrs[i] = nodeAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
features := invoicesrpc.CreateRPCFeatures(node.Features)
|
||||||
|
|
||||||
|
return &lnrpc.LightningNode{
|
||||||
|
LastUpdate: uint32(node.LastUpdate.Unix()),
|
||||||
|
PubKey: hex.EncodeToString(node.PubKeyBytes[:]),
|
||||||
|
Addresses: nodeAddrs,
|
||||||
|
Alias: node.Alias,
|
||||||
|
Color: routing.EncodeHexColor(node.Color),
|
||||||
|
Features: features,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// QueryRoutes attempts to query the daemons' Channel Router for a possible
|
// QueryRoutes attempts to query the daemons' Channel Router for a possible
|
||||||
// route to a target destination capable of carrying a specific amount of
|
// route to a target destination capable of carrying a specific amount of
|
||||||
// satoshis within the route's flow. The returned route contains the full
|
// satoshis within the route's flow. The returned route contains the full
|
||||||
|
|
Loading…
Add table
Reference in a new issue