-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
199 lines (187 loc) · 6.91 KB
/
main.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
package main
import (
"fmt"
"github.com/ci123chain/ci123chain/pkg/abci/types"
sdk "github.com/ci123chain/ci123chain/sdk/broadcast"
sSDK "github.com/ci123chain/ci123chain/sdk/staking"
)
var (
async bool
isIBC bool
create bool
delegate bool
redelegate bool
undelegate bool
online bool
requestURL = "http://ciChain:3030/tx/broadcast"
// requestURL = "http://ciChain:3030/tx/broadcast_async"
from = "0x3F43E75Aaba2c2fD6E227C10C6E7DC125A93DE3c"
amount = types.NewChainCoin(types.NewInt(200))
gas uint64 = 20000
nonce uint64 = 0
pri = "2b452434ac4f7cf9c5d61d62f23834f34e851fb6efdb8d4a8c6e214a8bc93d70"
proxy = "lb"
minSelfDelegation int64 = 2
validatorAddress = "0xB6727FCbC60A03A6689AEE6E5fBC83a7FDc9beBf"
validatorSrcAddress = ""
validatorDstAddress = ""
delegatorAddress = "0xB6727FCbC60A03A6689AEE6E5fBC83a7FDc9beBf"
rate int64 = 1.000000000000000000
maxRate int64 = 1.000000000000000000
maxChangeRate int64 = 1.000000000000000000
moniker = "first"
identity = "identity"
website = "website"
securityContact = "security"
details = "details"
publicKey = "7b0a2274797065223a202274656e6465726d696e742f5075624b6579536563703235366b31222c0a2276616c7565223a20224138485a776b6442307544497150594536783530394d304a654c56585a2b70613172343279706e4630316e36220a7d"
//"validatorAddress": "0xB6727FCbC60A03A6689AEE6E5fBC83a7FDc9beBf"
//"address": "B6727FCBC60A03A6689AEE6E5FBC83A7FDC9BEBF"
//{
//"types": "tendermint/PubKeySecp256k1",
//"value": "A8HZwkdB0uDIqPYE6x509M0JeLVXZ+pa1r42ypnF01n6"
//}
onlineGas = "20000"
onlineNonce = ""
onlineAmount = "2"
delegateURL = "http://ciChain:3030/staking/delegate"
redelegateURL = "http://ciChain:3030/staking/redelegate"
undelegateURL = "http://ciChain:3030/staking/undelegate"
)
func main() {
async = false
isIBC = false
delegate = false
redelegate = false
undelegate = false
create = true
online = false
froms := types.HexToAddress(from)
validatorAddresss := types.HexToAddress(validatorAddress)
delegatorAddresss := types.HexToAddress(delegatorAddress)
validatorSrcAddresss := types.HexToAddress(validatorSrcAddress)
validatorDstAddresss := types.HexToAddress(validatorDstAddress)
if create {
fmt.Println("---------------添加验证者离线签名交易----------------------")
tx, err := SignCreateValidatorTx(froms, amount, pri, minSelfDelegation, validatorAddresss, delegatorAddresss, rate, maxRate,
maxChangeRate, moniker, identity, website, securityContact, details, publicKey)
if err != nil {
fmt.Println("签名失败,参数错误")
fmt.Println(err)
return
}
fmt.Print("---签名的交易:---")
fmt.Print(tx)
if async == false {
fmt.Println("---同步广播交易,等待交易结果:---")
b, _, err := sdk.SendTransaction(tx, async, isIBC, requestURL)
if err != nil {
fmt.Println("交易失败")
fmt.Println(err)
return
}
fmt.Print("---交易结果:---")
fmt.Println(string(b))
}else {
fmt.Println("---异步广播交易,无返回结果---")
_, _, _ =sdk.SendTransaction(tx, async, isIBC, requestURL)
}
fmt.Println("---------------添加验证者离线签名交易完成----------------------")
}
if delegate {
if online {
fmt.Println("---------------抵押在线签名交易----------------------")
sSDK.HttpDelegateTx(from, onlineGas, onlineNonce, onlineAmount, pri, validatorAddress, delegatorAddress,proxy, delegateURL)
fmt.Println("---------------抵押在线签名交易完成----------------------")
}else {
fmt.Println("---------------抵押离线签名交易----------------------")
delegateTx, err := SignDelegateTx(froms, gas, nonce, amount, pri, validatorAddresss, delegatorAddresss)
if err != nil {
fmt.Println("签名失败,参数错误")
fmt.Println(err)
return
}
fmt.Print("---签名的交易:---")
fmt.Print(delegateTx)
if async == false {
fmt.Println("---同步广播交易,等待交易结果:---")
b, _, err := sdk.SendTransaction(delegateTx, async, isIBC, requestURL)
if err != nil {
fmt.Println("交易失败")
fmt.Println(err)
return
}
fmt.Print("---交易结果:---")
fmt.Println(string(b))
}else {
fmt.Println("---异步广播交易,无返回结果---")
_, _, _ =sdk.SendTransaction(delegateTx, async, isIBC, requestURL)
}
fmt.Println("---------------抵押离线签名交易完成----------------------")
}
}
if redelegate {
if online {
fmt.Println("---------------重新抵押在线签名交易----------------------")
sSDK.HttpRedelegateTx(from, onlineGas, onlineNonce, onlineAmount, pri, validatorSrcAddress, validatorDstAddress, delegatorAddress,proxy, redelegateURL)
fmt.Println("---------------重新抵押在线签名交易完成----------------------")
}else {
fmt.Println("---------------重新抵押离线签名交易----------------------")
redelegateTx, err := SignRelegateTx(froms, gas, nonce, amount, pri, validatorSrcAddresss, validatorDstAddresss, delegatorAddresss)
if err != nil {
fmt.Println("签名失败,参数错误")
fmt.Println(err)
return
}
fmt.Print("---签名的交易:---")
fmt.Print(redelegateTx)
if async == false {
fmt.Println("---同步广播交易,等待交易结果:---")
b, _, err := sdk.SendTransaction(redelegateTx, async, isIBC, requestURL)
if err != nil {
fmt.Println("交易失败")
fmt.Println(err)
return
}
fmt.Print("---交易结果:---")
fmt.Println(string(b))
}else {
fmt.Println("---异步广播交易,无返回结果---")
_, _, _ =sdk.SendTransaction(redelegateTx, async, isIBC, requestURL)
}
fmt.Println("---------------重新抵押离线签名交易完成----------------------")
}
}
if undelegate {
if online {
fmt.Println("---------------解除抵押在线签名交易----------------------")
sSDK.HttpUndelegateTx(from, onlineGas, onlineNonce, onlineAmount, pri, validatorAddress, delegatorAddress,proxy, undelegateURL)
fmt.Println("---------------解除抵押在线签名交易完成----------------------")
}else {
fmt.Println("---------------解除抵押离线签名交易----------------------")
undelegateTx, err := SignUndelegate(froms, gas, nonce, amount, pri, validatorAddresss, delegatorAddresss)
if err != nil {
fmt.Println("签名失败,参数错误")
fmt.Println(err)
return
}
fmt.Print("---签名的交易:---")
fmt.Print(undelegateTx)
if async == false {
fmt.Println("---同步广播交易,等待交易结果:---")
b, _, err := sdk.SendTransaction(undelegateTx, async, isIBC, requestURL)
if err != nil {
fmt.Println("交易失败")
fmt.Println(err)
return
}
fmt.Print("---交易结果:---")
fmt.Println(string(b))
}else {
fmt.Println("---异步广播交易,无返回结果---")
_, _, _ =sdk.SendTransaction(undelegateTx, async, isIBC, requestURL)
}
fmt.Println("---------------解除抵押离线签名交易完成----------------------")
}
}
}