-
Notifications
You must be signed in to change notification settings - Fork 2
/
tview_models.go
72 lines (57 loc) · 1.21 KB
/
tview_models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package tview
import (
"fmt"
"sort"
"strings"
"github.com/adrianbrad/privatebtc"
"golang.org/x/exp/maps"
)
type mempoolTxDetailsOutputs map[string]float64
func (s mempoolTxDetailsOutputs) String() string {
ks := maps.Keys(s)
sort.Strings(ks)
var b strings.Builder
b.WriteString("\n")
for _, k := range ks {
b.WriteString(fmt.Sprintf("%s: %f\n", k, s[k]))
}
return b.String()
}
type mempoolTxDetails struct {
hash string
nodes map[int]struct{}
outputs mempoolTxDetailsOutputs
}
func (m mempoolTxDetails) String() string {
nodes := maps.Keys(m.nodes)
sort.Ints(nodes)
return fmt.Sprintf(
"Hash: %s\nNodes: %v\nOutputs: %v",
m.hash,
nodes,
m.outputs,
)
}
type nodeDetails struct {
id int
blockCount int
connected bool
balance privatebtc.Balance
addresses []string
mempoolTxs []string
}
func (n nodeDetails) String() string {
return fmt.Sprintf(
"ID: %d\nConnected: %t\n"+
"Block Count: %d\n"+
"Balance: T:[green]%.2f[-] P:%.2f I:%.2f \n"+
"Addresses:\n%s\n"+
"Mempool Transactions:\n%s",
n.id,
n.connected,
n.blockCount,
n.balance.Trusted, n.balance.Pending, n.balance.Immature,
strings.Join(n.addresses, "\n"),
strings.Join(n.mempoolTxs, "\n"),
)
}