From a6f1f7c81175ba09f5ed9573c555edfb59aa5c0a Mon Sep 17 00:00:00 2001 From: Jonas Bostoen Date: Fri, 5 May 2023 14:47:02 +0200 Subject: [PATCH] feat: trace transaction command --- fmt.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 fmt.go diff --git a/fmt.go b/fmt.go new file mode 100644 index 0000000..c6bc7c5 --- /dev/null +++ b/fmt.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "strings" + + "github.com/chainbound/cbctl/api" +) + +func printTransactionTrace(trace []*api.TraceEntry, showSource bool) { + if showSource { + fmt.Printf("Timestamp\tNode ID\t\t\tRegion\t\t\tObservation Type\tSource\n") + } else { + fmt.Printf("Timestamp\tNode ID\t\t\tRegion\t\t\tObservation Type\n") + + } + for _, entry := range trace { + chunks := strings.Split(entry.NodeID, "-")[:3] + id := strings.Join(chunks, "-") + if showSource { + fmt.Printf("[%d]\t%s\t(%s)\t\t%s\t\t\t%s\n", entry.Timestamp/1000, id, entry.Region, entry.ObservationType, entry.Source) + } else { + fmt.Printf("[%d]\t%s\t(%s)\t\t%s\n", entry.Timestamp/1000, id, entry.Region, entry.ObservationType) + } + } +}