func printRTAsJSON(r *rt.RoutingTable) { type ChannelDesc struct { ID1 string `json:"lightning_id1"` ID2 string `json:"lightning_id2"` EdgeId string `json:"outpoint"` Capacity int64 `json:"capacity"` Weight float64 `json:"weight"` } var channels struct { Channels []ChannelDesc `json:"channels"` } channelsRaw := r.AllChannels() channels.Channels = make([]ChannelDesc, 0, len(channelsRaw)) for _, channelRaw := range channelsRaw { sourceHex := channelRaw.Id1.String() targetHex := channelRaw.Id2.String() channels.Channels = append(channels.Channels, ChannelDesc{ ID1: sourceHex, ID2: targetHex, EdgeId: channelRaw.EdgeID.String(), Weight: channelRaw.Info.Weight(), Capacity: channelRaw.Info.Capacity(), }, ) } printRespJson(channels) }
// Prints routing table in human readable table format func printRTAsTable(r *rt.RoutingTable, humanForm bool) { // Minimum length of data part to which name can be shortened var minLen int var tmpl string var lightningIdTree, edgeIdTree prefix_tree.PrefixTree if humanForm { tmpl = "%-10v %-10v %-10v %-10v %-10v\n" minLen = 6 } else { tmpl = "%-64v %-64v %-66v %-10v %-10v\n" minLen = 100 } fmt.Printf(tmpl, "ID1", "ID2", "Outpoint", "Capacity", "Weight") channels := r.AllChannels() if humanForm { // Generate prefix tree for shortcuts lightningIdTree = prefix_tree.NewPrefixTree() for _, node := range r.Nodes() { lightningIdTree.Add(node.String()) } edgeIdTree = prefix_tree.NewPrefixTree() for _, channel := range channels { edgeIdTree.Add(channel.EdgeID.String()) } } for _, channel := range channels { var source, target, edgeId string sourceHex := channel.Id1.String() targetHex := channel.Id2.String() edgeIdRaw := channel.EdgeID.String() if humanForm { source = getShortcut(lightningIdTree, sourceHex, minLen) target = getShortcut(lightningIdTree, targetHex, minLen) edgeId = getShortcut(edgeIdTree, edgeIdRaw, minLen) } else { source = sourceHex target = targetHex edgeId = edgeIdRaw } fmt.Printf(tmpl, source, target, edgeId, channel.Info.Cpt, channel.Info.Wgt) } }