@@ -24,10 +24,15 @@ import (
2424 "gopkg.in/ini.v1"
2525)
2626
27+ const (
28+ maxAmntMn = 5 // количество мастернод
29+ )
30+
2731var (
2832 CoinMinter string // Основная монета Minter
2933 MnAddress string
30- MnPublicKey string
34+ MnPublicKey [maxAmntMn ]string
35+ MnPrc [maxAmntMn ]int
3136 AccAddress string
3237 AccPrivateKey string
3338 TimeOut int64 // Время в мин. обновления статуса
@@ -130,89 +135,97 @@ func getBalance(usrAddr string) float32 {
130135// делегирование
131136func delegate () {
132137 valueBuy := getBalance (AccAddress )
133- validatorKey := types .Hex2Bytes (strings .TrimLeft (MnPublicKey , "Mp" ))
134-
135138 fmt .Println ("valueBuy=" , valueBuy )
136-
137139 // 1MNT на прозапас
138140 if valueBuy < float32 (MinAmnt + 1 ) {
139141 fmt .Printf ("Меньше %dMNT+1" , MinAmnt )
140142 return
141143 }
142144
143- privKey , err := crypto .HexToECDSA (AccPrivateKey )
144- if err != nil {
145- panic (err )
146- }
145+ fullDelegCoin := float64 (valueBuy - 1.0 ) // 1MNT на комиссию
147146
148- var mntV types.CoinSymbol
149- copy (mntV [:], []byte (CoinMinter ))
150-
151- mng18 := big .NewInt (1000000000000000 ) // убрал 000 (3-нуля)
152- mng000 := big .NewFloat (1000 ) // вот тут 000 (3-нуля)
153- amnt := big .NewFloat (float64 (valueBuy - 1.0 )) // 1MNT на комиссию
154- fmt .Println ("amnt=" , amnt .String ())
155- mnFl := big .NewFloat (0 ).Mul (amnt , mng000 )
156- fmt .Println ("mnFl=" , mnFl .String ())
157- amntInt_000 , _ := mnFl .Int64 ()
158- var amntBInt big.Int
159- amntBInt1 := amntBInt .Mul (big .NewInt (amntInt_000 ), mng18 )
160- fmt .Println ("amntBInt1=" , amntBInt1 .String ())
161-
162- buyC := tr.DelegateData {}
163- buyC .PubKey = validatorKey
164- buyC .Coin = mntV
165- buyC .Stake = amntBInt1
166-
167- trn := tr.Transaction {}
168- trn .Type = tr .TypeDelegate // делегирование
169- trn .Data , _ = rlp .EncodeToBytes (buyC )
170- trn .Nonce = uint64 (getNonce (AccAddress ) + 1 )
171- trn .GasCoin = mntV
172- trn .SignatureType = tr .SigTypeSingle
173-
174- err = trn .Sign (privKey )
175- if err != nil {
176- panic (err )
177- }
147+ for i := 0 ; i < maxAmntMn ; i ++ {
148+ if MnPublicKey [i ] == "" || MnPrc [i ] <= 0 {
149+ continue
150+ }
151+ fmt .Printf ("###########\n #### %d ####\n ###########\n " , i + 1 )
178152
179- bts , err := trn .Serialize ()
180- if err != nil {
181- panic (err )
182- }
183- str := hex .EncodeToString (bts )
153+ validatorKey := types .Hex2Bytes (strings .TrimLeft (MnPublicKey [i ], "Mp" ))
184154
185- message := map [string ]interface {}{
186- "transaction" : str ,
187- }
188- bytesRepresentation , err := json .Marshal (message )
189- if err != nil {
190- panic (err )
191- }
155+ privKey , err := crypto .HexToECDSA (AccPrivateKey )
156+ if err != nil {
157+ panic (err )
158+ }
159+
160+ var mntV types.CoinSymbol
161+ copy (mntV [:], []byte (CoinMinter ))
162+
163+ mng18 := big .NewInt (1000000000000000 ) // убрал 000 (3-нуля)
164+ mng000 := big .NewFloat (1000 ) // вот тут 000 (3-нуля)
165+ amnt := big .NewFloat (fullDelegCoin * float64 (MnPrc [i ]) / 100 ) // в процентном соотношение
166+ fmt .Println ("amnt=" , amnt .String ())
167+ mnFl := big .NewFloat (0 ).Mul (amnt , mng000 )
168+ fmt .Println ("mnFl=" , mnFl .String ())
169+ amntInt_000 , _ := mnFl .Int64 ()
170+ var amntBInt big.Int
171+ amntBInt1 := amntBInt .Mul (big .NewInt (amntInt_000 ), mng18 )
172+ fmt .Println ("amntBInt1=" , amntBInt1 .String ())
173+
174+ buyC := tr.DelegateData {}
175+ buyC .PubKey = validatorKey
176+ buyC .Coin = mntV
177+ buyC .Stake = amntBInt1
178+
179+ trn := tr.Transaction {}
180+ trn .Type = tr .TypeDelegate // делегирование
181+ trn .Data , _ = rlp .EncodeToBytes (buyC )
182+ trn .Nonce = uint64 (getNonce (AccAddress ) + 1 )
183+ trn .GasCoin = mntV
184+ trn .SignatureType = tr .SigTypeSingle
185+
186+ err = trn .Sign (privKey )
187+ if err != nil {
188+ panic (err )
189+ }
190+
191+ bts , err := trn .Serialize ()
192+ if err != nil {
193+ panic (err )
194+ }
195+ str := hex .EncodeToString (bts )
192196
193- fmt .Println ("TRANSACTION:" , bytes .NewBuffer (bytesRepresentation ))
197+ message := map [string ]interface {}{
198+ "transaction" : str ,
199+ }
200+ bytesRepresentation , err := json .Marshal (message )
201+ if err != nil {
202+ panic (err )
203+ }
194204
195- urlTx := fmt .Sprintf ("%s/api/sendTransaction" , MnAddress )
196- resp , err := http .Post (urlTx , "application/json" , bytes .NewBuffer (bytesRepresentation ))
205+ fmt .Println ("TRANSACTION:" , bytes .NewBuffer (bytesRepresentation ))
197206
198- if err != nil {
199- panic (err )
200- }
201- defer resp .Body .Close ()
202- fmt .Printf ("RESP: %#v\n " , resp )
207+ urlTx := fmt .Sprintf ("%s/api/sendTransaction" , MnAddress )
208+ resp , err := http .Post (urlTx , "application/json" , bytes .NewBuffer (bytesRepresentation ))
203209
204- body , err := ioutil .ReadAll (resp .Body )
205- if err != nil {
206- panic (err )
207- }
210+ if err != nil {
211+ panic (err )
212+ }
213+ defer resp .Body .Close ()
214+ fmt .Printf ("RESP: %#v\n " , resp )
208215
209- var data send_transaction
210- json .Unmarshal (body , & data )
216+ body , err := ioutil .ReadAll (resp .Body )
217+ if err != nil {
218+ panic (err )
219+ }
211220
212- if data .Code == 0 {
213- fmt .Println ("HASH:" , data .Result .Hash )
214- } else {
215- fmt .Println ("ERROR:" , data .Code , data .Log )
221+ var data send_transaction
222+ json .Unmarshal (body , & data )
223+
224+ if data .Code == 0 {
225+ fmt .Println ("HASH:" , data .Result .Hash )
226+ } else {
227+ fmt .Println ("ERROR:" , data .Code , data .Log )
228+ }
216229 }
217230}
218231
@@ -237,7 +250,15 @@ func main() {
237250
238251 secMN := cfg .Section ("masternode" )
239252 MnAddress = secMN .Key ("ADDRESS" ).String ()
240- MnPublicKey = secMN .Key ("PUBLICKEY" ).String ()
253+ for i := 0 ; i < maxAmntMn ; i ++ {
254+ MnPublicKey [i ] = secMN .Key (fmt .Sprintf ("PUBLICKEY_%d" , (i + 1 ))).String ()
255+ iAmntPrc , err := strconv .Atoi (secMN .Key (fmt .Sprintf ("PRC_%d" , (i + 1 ))).String ())
256+ if err != nil {
257+ fmt .Println (err )
258+ iAmntPrc = 0
259+ }
260+ MnPrc [i ] = iAmntPrc
261+ }
241262
242263 accMN := cfg .Section ("account" )
243264 AccAddress = accMN .Key ("ADDRESS" ).String () // Адрес аккаунта
0 commit comments