-
Notifications
You must be signed in to change notification settings - Fork 3
/
txSellAllCoin.go
95 lines (76 loc) · 1.84 KB
/
txSellAllCoin.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
package mintersdk
import (
"encoding/hex"
tr "github.com/MinterTeam/minter-go-node/core/transaction"
"github.com/MinterTeam/minter-go-node/core/types"
)
// Структура данных для Продажи всех монет
type TxSellAllCoinData struct {
CoinToSell string
CoinToBuy string
// Other
Payload string
// Gas
GasCoin string
GasPrice int64
}
func (c *SDK) TxSellAllCoinRLP(t *TxSellAllCoinData) (string, error) {
coinBuy := getStrCoin(t.CoinToBuy)
coinSell := getStrCoin(t.CoinToSell)
coinGas := getStrCoin(t.GasCoin)
valueGas := uint32(t.GasPrice)
privateKey, err := h2ECDSA(c.AccPrivateKey)
if err != nil {
return "", err
}
data := tr.SellAllCoinData{
CoinToSell: coinSell,
CoinToBuy: coinBuy,
}
encodedData, err := serializeData(data)
if err != nil {
return "", err
}
_, nowNonce, err := c.GetAddress(c.AccAddress)
if err != nil {
return "", err
}
var _ChainID types.ChainID
if c.ChainMainnet {
_ChainID = types.ChainMainnet
} else {
_ChainID = types.ChainTestnet
}
tx := tr.Transaction{
Nonce: uint64(nowNonce + 1),
ChainID: _ChainID,
GasPrice: valueGas,
GasCoin: coinGas,
Type: tr.TypeSellAllCoin,
Data: encodedData,
Payload: []byte(t.Payload),
SignatureType: tr.SigTypeSingle,
}
if err := tx.Sign(privateKey); err != nil {
return "", err
}
encodedTx, err := tx.Serialize()
if err != nil {
return "", err
}
strTxRPL := hex.EncodeToString(encodedTx)
strRlpEnc := string(strTxRPL)
return strRlpEnc, err
}
// Транзакция - Продажи всех монет
func (c *SDK) TxSellAllCoin(t *TxSellAllCoinData) (string, error) {
strRlpEnc, err := c.TxSellAllCoinRLP(t)
if err != nil {
return "", err
}
resHash, err := c.SetTransaction(strRlpEnc)
if err != nil {
return "", err
}
return resHash, nil
}