mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
Merge pull request #2312 from xsb/color-node-update
rpc: add node color to NodeUpdate and GetInfo
This commit is contained in:
commit
6cd71b7f7a
7 changed files with 560 additions and 489 deletions
|
@ -1840,6 +1840,7 @@ func getInfo(ctx *cli.Context) error {
|
|||
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"`
|
||||
|
@ -1855,6 +1856,7 @@ func getInfo(ctx *cli.Context) error {
|
|||
Version: resp.Version,
|
||||
IdentityPubkey: resp.IdentityPubkey,
|
||||
Alias: resp.Alias,
|
||||
Color: resp.Color,
|
||||
NumPendingChannels: resp.NumPendingChannels,
|
||||
NumActiveChannels: resp.NumActiveChannels,
|
||||
NumInactiveChannels: resp.NumInactiveChannels,
|
||||
|
|
987
lnrpc/rpc.pb.go
987
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load diff
|
@ -1329,6 +1329,9 @@ message GetInfoResponse {
|
|||
|
||||
/// 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"];
|
||||
}
|
||||
|
||||
message Chain {
|
||||
|
@ -1854,6 +1857,7 @@ message NodeUpdate {
|
|||
string identity_key = 2;
|
||||
bytes global_features = 3;
|
||||
string alias = 4;
|
||||
string color = 5;
|
||||
}
|
||||
message ChannelEdgeUpdate {
|
||||
/**
|
||||
|
|
|
@ -2158,6 +2158,10 @@
|
|||
"$ref": "#/definitions/lnrpcChain"
|
||||
},
|
||||
"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"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -2639,6 +2643,9 @@
|
|||
},
|
||||
"alias": {
|
||||
"type": "string"
|
||||
},
|
||||
"color": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -2,6 +2,7 @@ package routing
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"image/color"
|
||||
"net"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
@ -246,6 +247,9 @@ type NetworkNodeUpdate struct {
|
|||
|
||||
// Alias is the alias or nick name of the node.
|
||||
Alias string
|
||||
|
||||
// Color is the node's color in hex code format.
|
||||
Color string
|
||||
}
|
||||
|
||||
// ChannelEdgeUpdate is an update for a new channel within the ChannelGraph.
|
||||
|
@ -321,6 +325,7 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
|
|||
Addresses: m.Addresses,
|
||||
IdentityKey: pubKey,
|
||||
Alias: m.Alias,
|
||||
Color: EncodeHexColor(m.Color),
|
||||
}
|
||||
nodeUpdate.IdentityKey.Curve = nil
|
||||
|
||||
|
@ -388,3 +393,8 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
|
|||
"unknown message type %T", msg)
|
||||
}
|
||||
}
|
||||
|
||||
// EncodeHexColor takes a color and returns it in hex code format.
|
||||
func EncodeHexColor(color color.RGBA) string {
|
||||
return fmt.Sprintf("#%02x%02x%02x", color.R, color.G, color.B)
|
||||
}
|
||||
|
|
|
@ -628,6 +628,10 @@ func TestNodeUpdateNotification(t *testing.T) {
|
|||
t.Fatalf("node alias doesn't match: expected %v, got %v",
|
||||
ann.Alias, nodeUpdate.Alias)
|
||||
}
|
||||
if nodeUpdate.Color != EncodeHexColor(ann.Color) {
|
||||
t.Fatalf("node color doesn't match: expected %v, got %v",
|
||||
EncodeHexColor(ann.Color), nodeUpdate.Color)
|
||||
}
|
||||
}
|
||||
|
||||
// Create lookup map for notifications we are intending to receive. Entries
|
||||
|
@ -926,3 +930,30 @@ func TestChannelCloseNotification(t *testing.T) {
|
|||
t.Fatal("notification not sent")
|
||||
}
|
||||
}
|
||||
|
||||
// TestEncodeHexColor tests that the string used to represent a node color is
|
||||
// correctly encoded.
|
||||
func TestEncodeHexColor(t *testing.T) {
|
||||
var colorTestCases = []struct {
|
||||
R uint8
|
||||
G uint8
|
||||
B uint8
|
||||
encoded string
|
||||
isValid bool
|
||||
}{
|
||||
{0, 0, 0, "#000000", true},
|
||||
{255, 255, 255, "#ffffff", true},
|
||||
{255, 117, 215, "#ff75d7", true},
|
||||
{0, 0, 0, "000000", false},
|
||||
{1, 2, 3, "", false},
|
||||
{1, 2, 3, "#", false},
|
||||
}
|
||||
|
||||
for _, tc := range colorTestCases {
|
||||
encoded := EncodeHexColor(color.RGBA{tc.R, tc.G, tc.B, 0})
|
||||
if (encoded == tc.encoded) != tc.isValid {
|
||||
t.Fatalf("incorrect color encoding, "+
|
||||
"want: %v, got: %v", tc.encoded, encoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2002,6 +2002,7 @@ func (r *rpcServer) GetInfo(ctx context.Context,
|
|||
Chains: activeChains,
|
||||
Uris: uris,
|
||||
Alias: nodeAnn.Alias.String(),
|
||||
Color: routing.EncodeHexColor(nodeAnn.RGBColor),
|
||||
BestHeaderTimestamp: int64(bestHeaderTimestamp),
|
||||
Version: build.Version(),
|
||||
}, nil
|
||||
|
@ -3677,13 +3678,12 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||
nodeAddrs = append(nodeAddrs, nodeAddr)
|
||||
}
|
||||
|
||||
nodeColor := fmt.Sprintf("#%02x%02x%02x", node.Color.R, node.Color.G, node.Color.B)
|
||||
resp.Nodes = append(resp.Nodes, &lnrpc.LightningNode{
|
||||
LastUpdate: uint32(node.LastUpdate.Unix()),
|
||||
PubKey: hex.EncodeToString(node.PubKeyBytes[:]),
|
||||
Addresses: nodeAddrs,
|
||||
Alias: node.Alias,
|
||||
Color: nodeColor,
|
||||
Color: routing.EncodeHexColor(node.Color),
|
||||
})
|
||||
|
||||
return nil
|
||||
|
@ -3841,14 +3841,13 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||
}
|
||||
// TODO(roasbeef): list channels as well?
|
||||
|
||||
nodeColor := fmt.Sprintf("#%02x%02x%02x", node.Color.R, node.Color.G, node.Color.B)
|
||||
return &lnrpc.NodeInfo{
|
||||
Node: &lnrpc.LightningNode{
|
||||
LastUpdate: uint32(node.LastUpdate.Unix()),
|
||||
PubKey: in.PubKey,
|
||||
Addresses: nodeAddrs,
|
||||
Alias: node.Alias,
|
||||
Color: nodeColor,
|
||||
Color: routing.EncodeHexColor(node.Color),
|
||||
},
|
||||
NumChannels: numChannels,
|
||||
TotalCapacity: int64(totalCapacity),
|
||||
|
@ -4078,6 +4077,7 @@ func marshallTopologyChange(topChange *routing.TopologyChange) *lnrpc.GraphTopol
|
|||
IdentityKey: encodeKey(nodeUpdate.IdentityKey),
|
||||
GlobalFeatures: nodeUpdate.GlobalFeatures,
|
||||
Alias: nodeUpdate.Alias,
|
||||
Color: nodeUpdate.Color,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue