-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow.go
104 lines (98 loc) · 2.61 KB
/
follow.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"clout/display"
"clout/keys"
"clout/models"
"clout/network"
"clout/session"
"encoding/json"
"fmt"
"os"
"sort"
"time"
)
func HandleFollow() {
if len(os.Args) < 3 {
fmt.Println("missing username")
return
}
username := os.Args[2]
follower := session.LoggedInPub58()
followed := session.UsernameToPub58(username)
jsonString := network.CreateFollow(follower, followed)
var tx models.TxReady
json.Unmarshal([]byte(jsonString), &tx)
mnemonic := session.ReadLoggedInWords()
if mnemonic == "" {
return
}
_, priv := keys.ComputeKeysFromSeed(session.SeedBytes(mnemonic))
jsonString = network.SubmitTx(tx.TransactionHex, priv)
if jsonString != "" {
fmt.Println("Success.")
}
}
func HandleFollowing() {
pub58 := session.LoggedInPub58()
if len(os.Args) > 2 {
pub58 = os.Args[2]
LoopThruAllFollowing(pub58, "", 0)
return
}
RunFollowLogic(pub58, "")
}
func ListFollowers() {
pub58, username, _, _ := session.LoggedInAs()
RunFollowLogic(pub58, username)
}
func RunFollowLogic(pub58, username string) {
items := LoopThruAllFollowing(pub58, username, 0)
//fmt.Println("NumFollowers", pktpe.NumFollowers)
//fmt.Println("")
fields := []string{"username", "cap", "price"}
sizes := []int{20, 10, 10}
display.Header(sizes, fields...)
sort.SliceStable(items, func(i, j int) bool {
return items[i].CoinPriceBitCloutNanos < items[j].CoinPriceBitCloutNanos
})
for _, v := range items {
display.Row(sizes, v.Username, display.Float(v.MarketCap()),
display.OneE9(v.CoinPriceBitCloutNanos))
}
}
func GetNumFollowers(pub58, username string) int64 {
js := network.GetFollowsStateless(pub58, username, "")
var pktpe models.PublicKeyToProfileEntry
json.Unmarshal([]byte(js), &pktpe)
return pktpe.NumFollowers
}
func LoopThruAllFollowing(pub58, username string, limit int) []models.ProfileEntryResponse {
last := ""
js := network.GetFollowsStateless(pub58, username, last)
var pktpe models.PublicKeyToProfileEntry
json.Unmarshal([]byte(js), &pktpe)
NumFollowers := pktpe.NumFollowers
total := map[string]bool{}
bigList := []models.ProfileEntryResponse{}
fmt.Println("Getting all", pktpe.NumFollowers, "...")
for {
for key, v := range pktpe.PublicKeyToProfileEntry {
last = key
if total[v.Username] == false {
total[v.Username] = true
bigList = append(bigList, v)
}
}
if len(bigList) >= limit && limit != 0 {
break
}
if len(total) >= int(NumFollowers) {
break
}
fmt.Println("got", len(bigList), "out of", NumFollowers)
time.Sleep(time.Second * 1)
js := network.GetFollowsStateless(pub58, username, last)
json.Unmarshal([]byte(js), &pktpe)
}
return bigList
}