From a5d2dbf219fa8ac56ebdaca38c3ff2633e2a7562 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 25 Jan 2017 18:27:27 -0800 Subject: [PATCH] cmd/lncli: remove Z prefix from vertexes in describegraph rendering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes the prior work around to display a prefix of the node’s public key as a vertex. It turns out that if you quote the string, the it will escape all characters enclosed. This allows us the drop the hacky “Z” prefix that we used before. --- cmd/lncli/commands.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 3b78bee8..1df1a6d0 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -824,6 +824,7 @@ func normalizeFunc(edges []*lnrpc.ChannelEdge, scaleFactor float64) func(int64) return func(x int64) float64 { y := math.Log2(float64(x)) + // TODO(roasbeef): results in min being zero return float64(y-min) / float64(max-min) * scaleFactor } } @@ -851,6 +852,12 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error { graphCanvas.SetName(graphName) graphCanvas.SetDir(false) + const numKeyChars = 10 + + truncateStr := func(k string, n uint) string { + return k[:n] + } + // For each node within the graph, we'll add a new vertex to the graph. for _, node := range graph.Nodes { // Rather than using the entire hex-encoded string, we'll only @@ -859,7 +866,8 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error { // non-integer. // // TODO(roasbeef): should be able to get around this? - nodeID := "Z" + node.PubKey[:10] + nodeID := fmt.Sprintf(`"%v"`, truncateStr(node.PubKey, numKeyChars)) + fmt.Println(nodeID) graphCanvas.AddNode(graphName, nodeID, gographviz.Attrs{}) } @@ -871,8 +879,8 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error { for _, edge := range graph.Edges { // Once again, we add a 'Z' prefix so we're compliant with the // dot grammar. - src := "Z" + edge.Node1Pub[:10] - dest := "Z" + edge.Node2Pub[:10] + src := fmt.Sprintf(`"%v"`, truncateStr(edge.Node1Pub, numKeyChars)) + dest := fmt.Sprintf(`"%v"`, truncateStr(edge.Node2Pub, numKeyChars)) // The weight for our edge will be the total capacity of the // channel, in BTC. @@ -883,7 +891,8 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error { // The label for each edge will simply be a truncated version // of it's channel ID. - edgeLabel := strconv.FormatUint(edge.ChannelId, 10)[:10] + chanIDStr := strconv.FormatUint(edge.ChannelId, 10) + edgeLabel := fmt.Sprintf(`"cid:%v"`, truncateStr(chanIDStr, 7)) // We'll also use a normalized version of the channels' // capacity in satoshis in order to modulate the "thickness" of @@ -891,6 +900,7 @@ func drawChannelGraph(graph *lnrpc.ChannelGraph) error { normalizedCapacity := normalize(edge.Capacity) edgeThickness := strconv.FormatFloat(normalizedCapacity, 'f', -1, 64) + // TODO(roasbeef): color code based on percentile capacity graphCanvas.AddEdge(src, dest, false, gographviz.Attrs{ "penwidth": edgeThickness, "weight": edgeWeight,