This repository has been archived by the owner on Sep 3, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
arkgo-gui.go
274 lines (231 loc) · 7.01 KB
/
arkgo-gui.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package main
import (
"bufio"
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"regexp"
"runtime"
"sync"
log "github.com/sirupsen/logrus"
"github.com/kristjank/ark-go/arkcoin"
"github.com/kristjank/ark-go/core"
"github.com/fatih/color"
"github.com/spf13/viper"
"github.com/asdine/storm"
)
var arkclient = core.NewArkClient(nil)
var reader = bufio.NewReader(os.Stdin)
var arkpooldb *storm.DB
var wg sync.WaitGroup
func initLogger() {
// Log as JSON instead of the default ASCII formatter.
//log.SetFormatter(&log.JSONFormatter{})
// You could set this to any `io.Writer` such as a file
file, err := os.OpenFile("log/arkgo-pool.log", os.O_CREATE|os.O_WRONLY, 0666)
if err == nil {
log.SetOutput(io.MultiWriter(file))
} else {
log.Error("Failed to log to file, using default stderr")
}
}
func initializeBoltClient() {
var err error
arkpooldb, err = storm.Open(viper.GetString("client.dbfilename"))
if err != nil {
log.Panic(err.Error())
}
log.Println("DB Opened at:", arkpooldb.Path)
//defer arkpooldb.Close()
}
func readAccountData() (string, string) {
fmt.Println("\nEnter account passphrase")
fmt.Print("-->")
pass1, _ := reader.ReadString('\n')
re := regexp.MustCompile("\r?\n")
pass1 = re.ReplaceAllString(pass1, "")
pass2 := ""
key := arkcoin.NewPrivateKeyFromPassword(pass1, arkcoin.ActiveCoinConfig)
accountResp, _, _ := arkclient.GetAccount(core.AccountQueryParams{Address: key.PublicKey.Address()})
deleResp, _, _ := arkclient.GetDelegate(core.DelegateQueryParams{PublicKey: string(key.PublicKey.Serialize())})
if !accountResp.Success {
log.Info("Error getting account data for delegate: " + deleResp.SingleDelegate.Username + "[" + key.PublicKey.Address() + "]")
return "error", ""
}
if accountResp.Account.SecondSignature == 1 {
fmt.Println("\nEnter second account passphrase for delegate: " + deleResp.SingleDelegate.Username + "[" + key.PublicKey.Address() + "]")
fmt.Print("-->")
pass2, _ = reader.ReadString('\n')
re := regexp.MustCompile("\r?\n")
pass2 = re.ReplaceAllString(pass2, "")
}
return pass1, pass2
}
func loadConfig() {
viper.SetConfigName("config") // name of config file (without extension)
viper.AddConfigPath("settings") // path to look for the config file in
viper.AddConfigPath(".") // optionally look for config in the working directory
err := viper.ReadInConfig() // Find and read the config file
if err != nil {
log.Info("No productive config found - loading sample")
// try to load sample config
viper.SetConfigName("sample.config")
viper.AddConfigPath("settings")
err := viper.ReadInConfig()
if err != nil { // Handle errors reading the config file
log.Info("No configuration file loaded - using defaults")
}
}
viper.SetDefault("delegate.address", "")
viper.SetDefault("delegate.pubkey", "")
viper.SetDefault("delegate.Daddress", "")
viper.SetDefault("delegate.Dpubkey", "")
viper.SetDefault("voters.shareRatio", 0.0)
viper.SetDefault("voters.txdescription", "share tx by ark-go")
viper.SetDefault("voters.fidelity", true)
viper.SetDefault("voters.fidelityLimit", 24)
viper.SetDefault("voters.minamount", 0.0)
viper.SetDefault("voters.deductTxFees", true)
viper.SetDefault("costs.address", "")
viper.SetDefault("costs.shareRatio", 0.0)
viper.SetDefault("costs.txdescription", "cost tx by ark-go")
viper.SetDefault("costs.Daddress", "")
viper.SetDefault("reserve.address", "")
viper.SetDefault("reserve.shareRatio", 0.0)
viper.SetDefault("reserve.txdescription", "reserve tx by ark-go")
viper.SetDefault("reserve.Daddress", "")
viper.SetDefault("personal.address", "")
viper.SetDefault("personal.shareRatio", 0.0)
viper.SetDefault("personal.txdescription", "personal tx by ark-go")
viper.SetDefault("personal.Daddress", "")
viper.SetDefault("client.network", "DEVNET")
viper.SetDefault("client.dbFilename", "payment.db")
}
//////////////////////////////////////////////////////////////////////////////
//GUI RELATED STUFF
func pause() {
color.Set(color.FgHiYellow)
fmt.Println("")
fmt.Print("Press 'ENTER' key to continue... ")
//bufio.NewReader(os.Stdin).ReadBytes('\n')
reader.ReadString('\n')
}
func clearScreen() {
cmd := exec.Command("clear")
if runtime.GOOS == "windows" {
cmd = exec.Command("cmd", "/c", "cls")
}
cmd.Stdout = os.Stdout
cmd.Run()
}
func printNetworkInfo() {
color.Set(color.FgHiCyan)
if core.EnvironmentParams.Network.Type == core.MAINNET {
fmt.Println("Connected to MAINNET on peer:", core.BaseURL)
}
if core.EnvironmentParams.Network.Type == core.DEVNET {
fmt.Println("Connected to DEVNET on peer:", core.BaseURL)
}
}
func printBanner() {
color.Set(color.FgHiGreen)
dat, _ := ioutil.ReadFile("settings/banner.txt")
fmt.Print(string(dat))
}
func printMenu() {
log.Info("--------- MAIN MENU ----------------")
clearScreen()
printBanner()
printNetworkInfo()
color.Set(color.FgHiYellow)
fmt.Println("")
fmt.Println("\t1-Display contributors")
fmt.Println("\t2-Send reward payments")
fmt.Println("\t3-Switch network")
fmt.Println("\t4-Link account")
fmt.Println("\t5-Send bonus payments N/A currently")
fmt.Println("\t6-List history payments")
fmt.Println("\t0-Exit")
fmt.Println("")
fmt.Print("\tSelect option [1-9]:")
color.Unset()
}
func main() {
// Load configration and defaults
loadConfig()
initLogger()
log.Info("Ark-golang client starting")
log.Info("ArkApiClient connected, active peer: ", arkclient.GetActivePeer())
initializeBoltClient()
//switch to preset network
if viper.GetString("client.network") == "DEVNET" {
arkclient = arkclient.SetActiveConfiguration(core.DEVNET)
}
//SILENT MODE CHECKING AND AUTOMATION RUNNING
modeSilentPtr := flag.Bool("silent", false, "Is silent mode")
//autoPayment := flag.Bool("autopay", true, "Process auto payment")
flag.Parse()
log.Info(flag.Args())
if *modeSilentPtr {
log.Info("Silent Mode active")
log.Info("Starting to send payments")
SendPayments(true)
log.Info("Waiting for threads to complete")
color.Unset()
wg.Wait()
log.Info("Exiting silent mode and arkgopool")
os.Exit(1985)
}
var choice = 1
for choice != 0 {
//pause()
printMenu()
//fmt.Scan(&choice)
fmt.Fscan(reader, &choice)
reader.ReadString('\n')
switch choice {
case 1:
clearScreen()
color.Set(color.FgMagenta)
DisplayCalculatedVoteRatio()
color.Unset()
case 2:
clearScreen()
color.Set(color.FgHiGreen)
SendPayments(false)
wg.Wait()
color.Unset()
case 3:
if core.EnvironmentParams.Network.Type == core.MAINNET {
arkclient = arkclient.SetActiveConfiguration(core.DEVNET)
} else {
arkclient = arkclient.SetActiveConfiguration(core.MAINNET)
}
case 4:
clearScreen()
save(readAccountData())
color.Set(color.FgHiGreen)
log.Info("Account succesfully linked")
fmt.Println("Account succesfully linked")
pause()
color.Unset()
case 5:
clearScreen()
color.Set(color.FgHiGreen)
//SendBonus()
color.Unset()
case 6:
clearScreen()
color.Set(color.FgHiGreen)
listPaymentsDB()
pause()
//listPaymentsDetailsFromDB()
//pause()
color.Unset()
}
}
color.Unset()
}