-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_stake.go
305 lines (238 loc) · 7.42 KB
/
query_stake.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
package main
import (
"fmt"
"github.com/truechain/ups/cmd/utils"
"github.com/truechain/ups/common"
"github.com/truechain/ups/core/types"
"gopkg.in/urfave/cli.v1"
"math/big"
)
var AppendCommand = cli.Command{
Name: "append",
Usage: "Append validator deposit staking count",
Action: utils.MigrateFlags(AppendImpawn),
Flags: ImpawnFlags,
}
func AppendImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
value := trueToWei(ctx, false)
input := packInput("append", value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, nil, priKey, input)
getResult(conn, txHash, true, false)
return nil
}
var UpdateFeeCommand = cli.Command{
Name: "updatefee",
Usage: "Update delegate fee will take effect in next epoch",
Action: utils.MigrateFlags(UpdateFeeImpawn),
Flags: ImpawnFlags,
}
func UpdateFeeImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
fee = ctx.GlobalUint64(FeeFlag.Name)
checkFee(new(big.Int).SetUint64(fee))
fmt.Println("Fee", fee)
input := packInput("setFee", new(big.Int).SetUint64(fee))
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, false)
return nil
}
var UpdatePKCommand = cli.Command{
Name: "updatepk",
Usage: "Update staking pk will take effect in next epoch",
Action: utils.MigrateFlags(UpdatePKImpawn),
Flags: ImpawnFlags,
}
func UpdatePKImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
pubkey, pk, _ := getPubKey(ctx, conn)
fmt.Println(" Pubkey ", pubkey)
input := packInput("setPubkey", pk)
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, false)
return nil
}
var cancelCommand = cli.Command{
Name: "cancel",
Usage: "Call this staking will cancelled at the next epoch",
Action: utils.MigrateFlags(cancelImpawn),
Flags: ImpawnFlags,
}
func cancelImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
value := trueToWei(ctx, false)
input := packInput("cancel", value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, false)
return nil
}
var withdrawCommand = cli.Command{
Name: "withdraw",
Usage: "Call this will instant receive your deposit money",
Action: utils.MigrateFlags(withdrawImpawn),
Flags: ImpawnFlags,
}
func withdrawImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
PrintBalance(conn, from)
value := trueToWei(ctx, false)
input := packInput("withdraw", value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, false)
PrintBalance(conn, from)
return nil
}
var queryStakingCommand = cli.Command{
Name: "querystaking",
Usage: "Query staking info, can cancel info and can withdraw info",
Action: utils.MigrateFlags(queryStakingImpawn),
Flags: append(ImpawnFlags, AddressFlag),
}
func queryStakingImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
queryStakingInfo(conn, true, false)
return nil
}
var queryRewardCommand = cli.Command{
Name: "queryreward",
Usage: "Query reward info, contain deposit and delegate reward",
Action: utils.MigrateFlags(queryRewardImpawn),
Flags: append(ImpawnFlags, AddressFlag),
}
func queryRewardImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
PrintBalance(conn, from)
start := false
snailNumber := uint64(0)
if ctx.GlobalIsSet(SnailNumberFlag.Name) {
snailNumber = ctx.GlobalUint64(SnailNumberFlag.Name)
start = true
}
queryRewardInfo(conn, snailNumber, start)
return nil
}
var sendCommand = cli.Command{
Name: "send",
Usage: "Send general transaction",
Action: utils.MigrateFlags(sendTX),
Flags: append(ImpawnFlags, AddressFlag),
}
func sendTX(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
PrintBalance(conn, from)
address := ctx.GlobalString(AddressFlag.Name)
if !common.IsHexAddress(address) {
printError("Must input correct address")
}
value := trueToWei(ctx, false)
txHash := sendContractTransaction(conn, from, common.HexToAddress(address), value, priKey, nil)
getResult(conn, txHash, false, false)
return nil
}
var depositDCommand = cli.Command{
Name: "deposit",
Usage: "Deposit staking on a validator address",
Action: utils.MigrateFlags(delegateImpawn),
Flags: append(ImpawnFlags, AddressFlag),
}
var cancelDCommand = cli.Command{
Name: "cancel",
Usage: "Call this staking will cancelled delegate at the next epoch",
Action: utils.MigrateFlags(cancelDImpawn),
Flags: append(ImpawnFlags, AddressFlag),
}
var withdrawDCommand = cli.Command{
Name: "withdraw",
Usage: "Call this will instant receive your deposit money",
Action: utils.MigrateFlags(withdrawDImpawn),
Flags: append(ImpawnFlags, AddressFlag),
}
var delegateCommand = cli.Command{
Name: "delegate",
Usage: "Delegate staking on a validator address",
Subcommands: []cli.Command{
depositDCommand,
cancelDCommand,
withdrawDCommand,
},
}
func delegateImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
PrintBalance(conn, from)
value := trueToWei(ctx, false)
address := ctx.GlobalString(AddressFlag.Name)
if !common.IsHexAddress(address) {
printError("Must input correct address")
}
holder = common.HexToAddress(address)
input := packInput("delegate", holder, value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, nil, priKey, input)
getResult(conn, txHash, true, true)
return nil
}
func cancelDImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
value := trueToWei(ctx, false)
address := ctx.GlobalString(AddressFlag.Name)
if !common.IsHexAddress(address) {
printError("Must input correct address")
}
holder = common.HexToAddress(address)
input := packInput("undelegate", holder, value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, true)
return nil
}
func withdrawDImpawn(ctx *cli.Context) error {
loadPrivate(ctx)
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
PrintBalance(conn, from)
value := trueToWei(ctx, false)
address := ctx.GlobalString(AddressFlag.Name)
if !common.IsHexAddress(address) {
printError("Must input correct address")
}
holder = common.HexToAddress(address)
input := packInput("withdrawDelegate", holder, value)
txHash := sendContractTransaction(conn, from, types.StakingAddress, new(big.Int).SetInt64(0), priKey, input)
getResult(conn, txHash, true, true)
PrintBalance(conn, from)
return nil
}
var queryTxCommand = cli.Command{
Name: "querytx",
Usage: "Query tx hash, get transaction result",
Action: utils.MigrateFlags(queryTxImpawn),
Flags: append(ImpawnFlags, TxHashFlag),
}
func queryTxImpawn(ctx *cli.Context) error {
conn, url := dialConn(ctx)
printBaseInfo(conn, url)
txhash := ctx.GlobalString(TxHashFlag.Name)
if txhash == "" {
printError("Must input tx hash")
}
queryTx(conn, common.HexToHash(txhash), false, true, false)
return nil
}