minter 0.2.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +208 -278
  3. data/lib/ffi/{transaction → sign}/compile.rb +5 -3
  4. data/lib/ffi/sign/go.mod +5 -0
  5. data/lib/ffi/sign/go.sum +520 -0
  6. data/lib/ffi/sign/sign-darwin-10.6-amd64.dylib +0 -0
  7. data/lib/ffi/sign/sign-darwin-10.6-amd64.h +78 -0
  8. data/lib/ffi/sign/sign-linux-amd64.h +78 -0
  9. data/lib/ffi/sign/sign-linux-amd64.so +0 -0
  10. data/lib/ffi/sign/sign.go +84 -0
  11. data/lib/ffi/sign/sign_ffi.rb +12 -0
  12. data/lib/ffi/tx_hash/compile.rb +16 -0
  13. data/lib/ffi/tx_hash/go.mod +5 -0
  14. data/lib/ffi/tx_hash/go.sum +525 -0
  15. data/lib/ffi/tx_hash/tx-hash-darwin-10.6-amd64.dylib +0 -0
  16. data/lib/ffi/tx_hash/tx-hash-darwin-10.6-amd64.h +100 -0
  17. data/lib/ffi/tx_hash/tx-hash-linux-amd64.h +100 -0
  18. data/lib/ffi/tx_hash/tx-hash-linux-amd64.so +0 -0
  19. data/lib/ffi/tx_hash/tx_hash.go +618 -0
  20. data/lib/ffi/tx_hash/tx_hash_ffi.rb +25 -0
  21. data/lib/ffi/wallet/compile.rb +5 -3
  22. data/lib/ffi/wallet/go.mod +5 -0
  23. data/lib/ffi/wallet/go.sum +525 -0
  24. data/lib/ffi/wallet/wallet-darwin-10.6-amd64.dylib +0 -0
  25. data/lib/ffi/wallet/wallet-darwin-10.6-amd64.h +86 -0
  26. data/lib/ffi/wallet/wallet-linux-amd64.h +86 -0
  27. data/lib/ffi/wallet/wallet-linux-amd64.so +0 -0
  28. data/lib/ffi/wallet/wallet.go +50 -0
  29. data/lib/ffi/wallet/wallet_ffi.rb +1 -1
  30. data/lib/minter.rb +2 -1
  31. data/lib/minter/api/client.rb +4 -1
  32. data/lib/minter/api/connection.rb +6 -0
  33. data/lib/minter/api/resources/address_resource.rb +2 -6
  34. data/lib/minter/api/resources/block_resource.rb +2 -3
  35. data/lib/minter/api/resources/candidate_resource.rb +2 -2
  36. data/lib/minter/api/resources/coin_resource.rb +2 -2
  37. data/lib/minter/api/resources/estimate_resource.rb +1 -1
  38. data/lib/minter/api/resources/events_resource.rb +2 -3
  39. data/lib/minter/api/resources/max_gas_resource.rb +1 -1
  40. data/lib/minter/api/resources/nonce_resource.rb +3 -4
  41. data/lib/minter/api/resources/send_transaction_resource.rb +2 -3
  42. data/lib/minter/api/resources/transactions_resource.rb +2 -3
  43. data/lib/minter/transactions/buy_coin_tx.rb +0 -1
  44. data/lib/minter/transactions/create_coin_tx.rb +0 -1
  45. data/lib/minter/transactions/create_multisig_address_tx.rb +38 -0
  46. data/lib/minter/transactions/declare_candidacy_tx.rb +0 -2
  47. data/lib/minter/transactions/delegate_tx.rb +0 -1
  48. data/lib/minter/transactions/edit_candidate_tx.rb +4 -3
  49. data/lib/minter/transactions/multi_send_tx.rb +2 -3
  50. data/lib/minter/transactions/redeem_check_tx.rb +0 -1
  51. data/lib/minter/transactions/sell_all_coin_tx.rb +0 -1
  52. data/lib/minter/transactions/sell_coin_tx.rb +0 -1
  53. data/lib/minter/transactions/send_coin_tx.rb +0 -2
  54. data/lib/minter/transactions/set_candidate_off_tx.rb +0 -1
  55. data/lib/minter/transactions/set_candidate_on_tx.rb +0 -1
  56. data/lib/minter/transactions/signed_tx.rb +3 -3
  57. data/lib/minter/transactions/transaction.rb +34 -10
  58. data/lib/minter/transactions/unbond_tx.rb +0 -1
  59. data/lib/minter/version.rb +1 -1
  60. metadata +32 -8
  61. data/lib/ffi/transaction/transaction_ffi.rb +0 -93
@@ -0,0 +1,100 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package mod */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h> /* for ptrdiff_t below */
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+
23
+
24
+ /* End of preamble from import "C" comments. */
25
+
26
+
27
+ /* Start of boilerplate cgo prologue. */
28
+ #line 1 "cgo-gcc-export-header-prolog"
29
+
30
+ #ifndef GO_CGO_PROLOGUE_H
31
+ #define GO_CGO_PROLOGUE_H
32
+
33
+ typedef signed char GoInt8;
34
+ typedef unsigned char GoUint8;
35
+ typedef short GoInt16;
36
+ typedef unsigned short GoUint16;
37
+ typedef int GoInt32;
38
+ typedef unsigned int GoUint32;
39
+ typedef long long GoInt64;
40
+ typedef unsigned long long GoUint64;
41
+ typedef GoInt64 GoInt;
42
+ typedef GoUint64 GoUint;
43
+ typedef __SIZE_TYPE__ GoUintptr;
44
+ typedef float GoFloat32;
45
+ typedef double GoFloat64;
46
+ typedef float _Complex GoComplex64;
47
+ typedef double _Complex GoComplex128;
48
+
49
+ /*
50
+ static assertion to make sure the file is being used on architecture
51
+ at least with matching size of GoInt.
52
+ */
53
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
54
+
55
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
56
+ typedef _GoString_ GoString;
57
+ #endif
58
+ typedef void *GoMap;
59
+ typedef void *GoChan;
60
+ typedef struct { void *t; void *v; } GoInterface;
61
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
62
+
63
+ #endif
64
+
65
+ /* End of boilerplate cgo prologue. */
66
+
67
+ #ifdef __cplusplus
68
+ extern "C" {
69
+ #endif
70
+
71
+
72
+ extern char* BuyCoinTx(char* p0);
73
+
74
+ extern char* CreateCoinTx(char* p0);
75
+
76
+ extern char* SendCoinTx(char* p0);
77
+
78
+ extern char* SellCoinTx(char* p0);
79
+
80
+ extern char* SellAllCoinTx(char* p0);
81
+
82
+ extern char* DeclareCandidacyTx(char* p0);
83
+
84
+ extern char* DelegateTx(char* p0);
85
+
86
+ extern char* UnbondTx(char* p0);
87
+
88
+ extern char* SetCandidateOffTx(char* p0);
89
+
90
+ extern char* SetCandidateOnTx(char* p0);
91
+
92
+ extern char* RedeemCheckTx(char* p0);
93
+
94
+ extern char* EditCandidateTx(char* p0);
95
+
96
+ extern char* MultiSendTx(char* p0);
97
+
98
+ #ifdef __cplusplus
99
+ }
100
+ #endif
@@ -0,0 +1,100 @@
1
+ /* Code generated by cmd/cgo; DO NOT EDIT. */
2
+
3
+ /* package mod */
4
+
5
+
6
+ #line 1 "cgo-builtin-export-prolog"
7
+
8
+ #include <stddef.h> /* for ptrdiff_t below */
9
+
10
+ #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
+ #define GO_CGO_EXPORT_PROLOGUE_H
12
+
13
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
14
+ typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
+ #endif
16
+
17
+ #endif
18
+
19
+ /* Start of preamble from import "C" comments. */
20
+
21
+
22
+
23
+
24
+ /* End of preamble from import "C" comments. */
25
+
26
+
27
+ /* Start of boilerplate cgo prologue. */
28
+ #line 1 "cgo-gcc-export-header-prolog"
29
+
30
+ #ifndef GO_CGO_PROLOGUE_H
31
+ #define GO_CGO_PROLOGUE_H
32
+
33
+ typedef signed char GoInt8;
34
+ typedef unsigned char GoUint8;
35
+ typedef short GoInt16;
36
+ typedef unsigned short GoUint16;
37
+ typedef int GoInt32;
38
+ typedef unsigned int GoUint32;
39
+ typedef long long GoInt64;
40
+ typedef unsigned long long GoUint64;
41
+ typedef GoInt64 GoInt;
42
+ typedef GoUint64 GoUint;
43
+ typedef __SIZE_TYPE__ GoUintptr;
44
+ typedef float GoFloat32;
45
+ typedef double GoFloat64;
46
+ typedef float _Complex GoComplex64;
47
+ typedef double _Complex GoComplex128;
48
+
49
+ /*
50
+ static assertion to make sure the file is being used on architecture
51
+ at least with matching size of GoInt.
52
+ */
53
+ typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
54
+
55
+ #ifndef GO_CGO_GOSTRING_TYPEDEF
56
+ typedef _GoString_ GoString;
57
+ #endif
58
+ typedef void *GoMap;
59
+ typedef void *GoChan;
60
+ typedef struct { void *t; void *v; } GoInterface;
61
+ typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
62
+
63
+ #endif
64
+
65
+ /* End of boilerplate cgo prologue. */
66
+
67
+ #ifdef __cplusplus
68
+ extern "C" {
69
+ #endif
70
+
71
+
72
+ extern char* BuyCoinTx(char* p0);
73
+
74
+ extern char* CreateCoinTx(char* p0);
75
+
76
+ extern char* SendCoinTx(char* p0);
77
+
78
+ extern char* SellCoinTx(char* p0);
79
+
80
+ extern char* SellAllCoinTx(char* p0);
81
+
82
+ extern char* DeclareCandidacyTx(char* p0);
83
+
84
+ extern char* DelegateTx(char* p0);
85
+
86
+ extern char* UnbondTx(char* p0);
87
+
88
+ extern char* SetCandidateOffTx(char* p0);
89
+
90
+ extern char* SetCandidateOnTx(char* p0);
91
+
92
+ extern char* RedeemCheckTx(char* p0);
93
+
94
+ extern char* EditCandidateTx(char* p0);
95
+
96
+ extern char* MultiSendTx(char* p0);
97
+
98
+ #ifdef __cplusplus
99
+ }
100
+ #endif
@@ -0,0 +1,618 @@
1
+ package main
2
+
3
+ import (
4
+ "C"
5
+ "encoding/json"
6
+ "github.com/MinterTeam/minter-go-sdk/v2/transaction"
7
+ "math/big"
8
+ )
9
+
10
+ type CommonParams struct {
11
+ SignatureType transaction.SignatureType
12
+ ChainId byte
13
+ Nonce uint64
14
+ GasPrice uint8
15
+ GasCoin uint64
16
+ }
17
+
18
+ //BuyCoinTx
19
+ type BuyCoinParams struct {
20
+ CoinToBuy uint64
21
+ ValueToBuy *big.Int
22
+ CoinToSell uint64
23
+ MaximumValueToSell *big.Int
24
+ CommonParams
25
+ }
26
+
27
+ //export BuyCoinTx
28
+ func BuyCoinTx(paramsJson *C.char) *C.char {
29
+ var params BuyCoinParams
30
+ jsonBytes := []byte(C.GoString(paramsJson))
31
+ err := json.Unmarshal(jsonBytes, &params)
32
+ if err != nil {
33
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
34
+ return C.CString(string(resultJson))
35
+ }
36
+
37
+ data := transaction.NewBuyCoinData().
38
+ SetCoinToBuy(params.CoinToBuy).
39
+ SetValueToBuy(params.ValueToBuy).
40
+ SetCoinToSell(params.CoinToSell).
41
+ SetMaximumValueToSell(params.MaximumValueToSell)
42
+
43
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
44
+ if err != nil {
45
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
46
+ return C.CString(string(resultJson))
47
+ }
48
+
49
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
50
+
51
+ encode, err := tx.Encode()
52
+ if err != nil {
53
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
54
+ return C.CString(string(resultJson))
55
+ }
56
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
57
+ return C.CString(string(resultJson))
58
+ }
59
+
60
+ // CreateCoinTX
61
+ type CreateCoinParams struct {
62
+ Name string
63
+ Symbol string
64
+ InitialAmount *big.Int
65
+ InitialReserve *big.Int
66
+ ReserveRation uint32
67
+ MaxSupply *big.Int
68
+ CommonParams
69
+ }
70
+
71
+ //export CreateCoinTx
72
+ func CreateCoinTx(paramsJson *C.char) *C.char {
73
+ var params CreateCoinParams
74
+ jsonBytes := []byte(C.GoString(paramsJson))
75
+ err := json.Unmarshal(jsonBytes, &params)
76
+ if err != nil {
77
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
78
+ return C.CString(string(resultJson))
79
+ }
80
+
81
+ data := transaction.NewCreateCoinData().
82
+ SetName(params.Name).
83
+ SetSymbol(params.Symbol).
84
+ SetInitialAmount(params.InitialAmount).
85
+ SetInitialReserve(params.InitialReserve).
86
+ SetConstantReserveRatio(params.ReserveRation).
87
+ SetMaxSupply(params.MaxSupply)
88
+
89
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
90
+ if err != nil {
91
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
92
+ return C.CString(string(resultJson))
93
+ }
94
+
95
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
96
+
97
+ encode, err := tx.Encode()
98
+ if err != nil {
99
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
100
+ return C.CString(string(resultJson))
101
+ }
102
+
103
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
104
+ return C.CString(string(resultJson))
105
+ }
106
+
107
+ // SendCoinTx
108
+ type SendCoinParams struct {
109
+ AddressTo string
110
+ Value *big.Int
111
+ Coin uint64
112
+ CommonParams
113
+ }
114
+
115
+ //export SendCoinTx
116
+ func SendCoinTx(paramsJson *C.char) *C.char {
117
+ var params SendCoinParams
118
+ jsonBytes := []byte(C.GoString(paramsJson))
119
+ err := json.Unmarshal(jsonBytes, &params)
120
+ if err != nil {
121
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
122
+ return C.CString(string(resultJson))
123
+ }
124
+
125
+ data, err := transaction.NewSendData().SetCoin(params.Coin).SetValue(params.Value).SetTo(params.AddressTo)
126
+ if err != nil {
127
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
128
+ return C.CString(string(resultJson))
129
+ }
130
+
131
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
132
+ if err != nil {
133
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
134
+ return C.CString(string(resultJson))
135
+ }
136
+
137
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
138
+
139
+ encode, err := tx.Encode()
140
+ if err != nil {
141
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
142
+ return C.CString(string(resultJson))
143
+ }
144
+
145
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
146
+ return C.CString(string(resultJson))
147
+ }
148
+
149
+ type SellCoinParams struct {
150
+ CoinToSell uint32
151
+ ValueToSell *big.Int
152
+ CoinToBuy uint32
153
+ MinimumValueToBuy *big.Int
154
+ CommonParams
155
+ }
156
+
157
+ //export SellCoinTx
158
+ func SellCoinTx(paramsJson *C.char) *C.char {
159
+ var params SellCoinParams
160
+ jsonBytes := []byte(C.GoString(paramsJson))
161
+ err := json.Unmarshal(jsonBytes, &params)
162
+ if err != nil {
163
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
164
+ return C.CString(string(resultJson))
165
+ }
166
+
167
+ data := transaction.NewSellCoinData().
168
+ SetCoinToSell(params.CoinToSell).
169
+ SetValueToSell(params.ValueToSell).
170
+ SetCoinToBuy(params.CoinToBuy).
171
+ SetMinimumValueToBuy(params.MinimumValueToBuy)
172
+
173
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
174
+ if err != nil {
175
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
176
+ return C.CString(string(resultJson))
177
+ }
178
+
179
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
180
+
181
+ encode, err := tx.Encode()
182
+ if err != nil {
183
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
184
+ return C.CString(string(resultJson))
185
+ }
186
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
187
+ return C.CString(string(resultJson))
188
+ }
189
+
190
+ type SellAllCoinParams struct {
191
+ CoinToSell uint64
192
+ CoinToBuy uint64
193
+ ValueToBuy *big.Int
194
+ MinimumValueToBuy *big.Int
195
+ CommonParams
196
+ }
197
+
198
+ //export SellAllCoinTx
199
+ func SellAllCoinTx(paramsJson *C.char) *C.char {
200
+ var params SellAllCoinParams
201
+ jsonBytes := []byte(C.GoString(paramsJson))
202
+ err := json.Unmarshal(jsonBytes, &params)
203
+ if err != nil {
204
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
205
+ return C.CString(string(resultJson))
206
+ }
207
+
208
+ data := transaction.NewSellAllCoinData().
209
+ SetCoinToSell(params.CoinToSell).
210
+ SetCoinToBuy(params.CoinToBuy).
211
+ SetMinimumValueToBuy(params.MinimumValueToBuy)
212
+
213
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
214
+ if err != nil {
215
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
216
+ return C.CString(string(resultJson))
217
+ }
218
+
219
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
220
+
221
+ encode, err := tx.Encode()
222
+ if err != nil {
223
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
224
+ return C.CString(string(resultJson))
225
+ }
226
+
227
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
228
+ return C.CString(string(resultJson))
229
+ }
230
+
231
+ type DeclareCandidacyParams struct {
232
+ Address string
233
+ PubKey string
234
+ Commission uint32
235
+ Coin uint64
236
+ Stake *big.Int
237
+ CommonParams
238
+ }
239
+
240
+ //export DeclareCandidacyTx
241
+ func DeclareCandidacyTx(paramsJson *C.char) *C.char {
242
+ var params DeclareCandidacyParams
243
+ jsonBytes := []byte(C.GoString(paramsJson))
244
+ err := json.Unmarshal(jsonBytes, &params)
245
+
246
+ data, err := transaction.NewDeclareCandidacyData().
247
+ MustSetPubKey(params.PubKey).
248
+ SetCommission(params.Commission).
249
+ SetCoin(params.Coin).
250
+ SetStake(params.Stake).
251
+ SetAddress(params.Address)
252
+ if err != nil {
253
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
254
+ return C.CString(string(resultJson))
255
+ }
256
+
257
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
258
+ if err != nil {
259
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
260
+ return C.CString(string(resultJson))
261
+ }
262
+
263
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
264
+
265
+ encode, err := tx.Encode()
266
+ if err != nil {
267
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
268
+ return C.CString(string(resultJson))
269
+ }
270
+
271
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
272
+ return C.CString(string(resultJson))
273
+ }
274
+
275
+ type DelegateParams struct {
276
+ PubKey string
277
+ Coin uint64
278
+ Value *big.Int
279
+ CommonParams
280
+ }
281
+
282
+ //export DelegateTx
283
+ func DelegateTx(paramsJson *C.char) *C.char {
284
+ var params DelegateParams
285
+ jsonBytes := []byte(C.GoString(paramsJson))
286
+ err := json.Unmarshal(jsonBytes, &params)
287
+ if err != nil {
288
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
289
+ return C.CString(string(resultJson))
290
+ }
291
+
292
+ data := transaction.NewDelegateData().
293
+ MustSetPubKey(params.PubKey).
294
+ SetCoin(params.Coin).
295
+ SetValue(params.Value)
296
+
297
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
298
+ if err != nil {
299
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
300
+ return C.CString(string(resultJson))
301
+ }
302
+
303
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
304
+
305
+ encode, err := tx.Encode()
306
+ if err != nil {
307
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
308
+ return C.CString(string(resultJson))
309
+ }
310
+
311
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
312
+ return C.CString(string(resultJson))
313
+ }
314
+
315
+ type UnbondParams struct {
316
+ PubKey string
317
+ Coin uint64
318
+ Value *big.Int
319
+ CommonParams
320
+ }
321
+
322
+ //export UnbondTx
323
+ func UnbondTx(paramsJson *C.char) *C.char {
324
+ var params UnbondParams
325
+ jsonBytes := []byte(C.GoString(paramsJson))
326
+ err := json.Unmarshal(jsonBytes, &params)
327
+ if err != nil {
328
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
329
+ return C.CString(string(resultJson))
330
+ }
331
+
332
+ data := transaction.NewUnbondData().
333
+ MustSetPubKey(params.PubKey).
334
+ SetCoin(params.Coin).
335
+ SetValue(params.Value)
336
+
337
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
338
+ if err != nil {
339
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
340
+ return C.CString(string(resultJson))
341
+ }
342
+
343
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
344
+
345
+ encode, err := tx.Encode()
346
+ if err != nil {
347
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
348
+ return C.CString(string(resultJson))
349
+ }
350
+
351
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
352
+ return C.CString(string(resultJson))
353
+ }
354
+
355
+ type SetCandidateParams struct {
356
+ PubKey string
357
+ CommonParams
358
+ }
359
+
360
+ //export SetCandidateOffTx
361
+ func SetCandidateOffTx(paramsJson *C.char) *C.char {
362
+ var params SetCandidateParams
363
+ jsonBytes := []byte(C.GoString(paramsJson))
364
+ err := json.Unmarshal(jsonBytes, &params)
365
+ if err != nil {
366
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
367
+ return C.CString(string(resultJson))
368
+ }
369
+
370
+ data := transaction.NewSetCandidateOffData().
371
+ MustSetPubKey(params.PubKey)
372
+
373
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
374
+ if err != nil {
375
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
376
+ return C.CString(string(resultJson))
377
+ }
378
+
379
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
380
+
381
+ encode, err := tx.Encode()
382
+ if err != nil {
383
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
384
+ return C.CString(string(resultJson))
385
+ }
386
+
387
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
388
+ return C.CString(string(resultJson))
389
+ }
390
+
391
+ //export SetCandidateOnTx
392
+ func SetCandidateOnTx(paramsJson *C.char) *C.char {
393
+ var params SetCandidateParams
394
+ jsonBytes := []byte(C.GoString(paramsJson))
395
+ err := json.Unmarshal(jsonBytes, &params)
396
+ if err != nil {
397
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
398
+ return C.CString(string(resultJson))
399
+ }
400
+
401
+ data := transaction.NewSetCandidateOnData().
402
+ MustSetPubKey(params.PubKey)
403
+
404
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
405
+ if err != nil {
406
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
407
+ return C.CString(string(resultJson))
408
+ }
409
+
410
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
411
+
412
+ encode, err := tx.Encode()
413
+ if err != nil {
414
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
415
+ return C.CString(string(resultJson))
416
+ }
417
+
418
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
419
+ return C.CString(string(resultJson))
420
+ }
421
+
422
+ type RedeemCheckParams struct {
423
+ Check string
424
+ Proof string
425
+ CommonParams
426
+ }
427
+
428
+ //export RedeemCheckTx
429
+ func RedeemCheckTx(paramsJson *C.char) *C.char {
430
+ var params RedeemCheckParams
431
+ jsonBytes := []byte(C.GoString(paramsJson))
432
+ err := json.Unmarshal(jsonBytes, &params)
433
+ if err != nil {
434
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
435
+ return C.CString(string(resultJson))
436
+ }
437
+
438
+ data := transaction.NewRedeemCheckData().
439
+ MustSetProof(params.Proof).
440
+ MustSetRawCheck(params.Check)
441
+
442
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
443
+ if err != nil {
444
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
445
+ return C.CString(string(resultJson))
446
+ }
447
+
448
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
449
+
450
+ encode, err := tx.Encode()
451
+ if err != nil {
452
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
453
+ return C.CString(string(resultJson))
454
+ }
455
+
456
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
457
+ return C.CString(string(resultJson))
458
+ }
459
+
460
+ type EditCandidateParams struct {
461
+ PubKey string
462
+ RewardAddress string
463
+ OwnerAddress string
464
+ ControlAddress string
465
+ CommonParams
466
+ }
467
+
468
+ //export EditCandidateTx
469
+ func EditCandidateTx(paramsJson *C.char) *C.char {
470
+ var params EditCandidateParams
471
+ jsonBytes := []byte(C.GoString(paramsJson))
472
+ err := json.Unmarshal(jsonBytes, &params)
473
+ if err != nil {
474
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
475
+ return C.CString(string(resultJson))
476
+ }
477
+
478
+ data := transaction.NewEditCandidateData().
479
+ MustSetPubKey(params.PubKey).
480
+ MustSetOwnerAddress(params.OwnerAddress).
481
+ MustSetRewardAddress(params.RewardAddress).
482
+ MustSetControlAddress(params.ControlAddress)
483
+
484
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
485
+ if err != nil {
486
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
487
+ return C.CString(string(resultJson))
488
+ }
489
+
490
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
491
+
492
+ encode, err := tx.Encode()
493
+ if err != nil {
494
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
495
+ return C.CString(string(resultJson))
496
+ }
497
+
498
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
499
+ return C.CString(string(resultJson))
500
+ }
501
+
502
+ type MultiSendItem struct {
503
+ AddressTo string
504
+ CoinID uint64
505
+ Value *big.Int
506
+ }
507
+
508
+ type MultiSendParams struct {
509
+ Items []MultiSendItem
510
+ CommonParams
511
+ }
512
+
513
+ //export MultiSendTx
514
+ func MultiSendTx(paramsJson *C.char) *C.char {
515
+ var params MultiSendParams
516
+ jsonBytes := []byte(C.GoString(paramsJson))
517
+ err := json.Unmarshal(jsonBytes, &params)
518
+ if err != nil {
519
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
520
+ return C.CString(string(resultJson))
521
+ }
522
+
523
+ data := transaction.NewMultisendData()
524
+
525
+ for _, item := range params.Items {
526
+ data.AddItem(
527
+ transaction.NewSendData().
528
+ SetCoin(item.CoinID).
529
+ SetValue(item.Value).
530
+ MustSetTo(item.AddressTo),
531
+ )
532
+ }
533
+ tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
534
+ if err != nil {
535
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
536
+ return C.CString(string(resultJson))
537
+ }
538
+ tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
539
+
540
+ encode, err := tx.Encode()
541
+ if err != nil {
542
+ resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
543
+ return C.CString(string(resultJson))
544
+ }
545
+
546
+ resultJson, _ := json.Marshal(map[string]string{"success": "true", "tx_hash": encode})
547
+ return C.CString(string(resultJson))
548
+ }
549
+
550
+ type MultisigAddressItem struct {
551
+ Address string
552
+ Weight uint32
553
+ }
554
+
555
+ type MultisigAddressParams struct {
556
+ Addresses []MultisigAddressItem
557
+ Threshold uint
558
+ CommonParams
559
+ }
560
+
561
+ ////export CreateMultisigAddressTx
562
+ //func CreateMultisigAddressTx(paramsJson *C.char) *C.char {
563
+ // var params MultisigAddressParams
564
+ // jsonBytes := []byte(C.GoString(paramsJson))
565
+ // err := json.Unmarshal(jsonBytes, &params)
566
+ // if err != nil {
567
+ // resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
568
+ // return C.CString(string(resultJson))
569
+ // }
570
+ //
571
+ // data := transaction.NewCreateMultisigData()
572
+ //
573
+ // for _, address := range params.Addresses {
574
+ // data.MustAddSigData(address.Address, address.Weight)
575
+ // }
576
+ // tx, err := transaction.NewBuilder(transaction.ChainID(params.ChainId)).NewTransaction(data)
577
+ // if err != nil {
578
+ // resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
579
+ // return C.CString(string(resultJson))
580
+ // }
581
+ // tx.SetNonce(params.Nonce).SetGasPrice(params.GasPrice).SetGasCoin(params.GasCoin).SetSignatureType(params.SignatureType)
582
+ //
583
+ // encode, err := tx.Encode()
584
+ // if err != nil {
585
+ // resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
586
+ // return C.CString(string(resultJson))
587
+ // }
588
+ //
589
+ // result := map[string]string{
590
+ // "success": "true",
591
+ // "tx_hash": encode,
592
+ // "multisig_address": data.AddressString(),
593
+ // }
594
+ // resultJson, _ := json.Marshal(result)
595
+ // return C.CString(string(resultJson))
596
+ //}
597
+ //
598
+ ////export GetMultisigAddress
599
+ //func GetMultisigAddress(paramsJson *C.char) *C.char {
600
+ // var params MultisigAddressParams
601
+ // jsonBytes := []byte(C.GoString(paramsJson))
602
+ // err := json.Unmarshal(jsonBytes, &params)
603
+ // if err != nil {
604
+ // resultJson, _ := json.Marshal(map[string]string{"success": "false", "error": err.Error()})
605
+ // return C.CString(string(resultJson))
606
+ // }
607
+ //
608
+ // data := transaction.NewCreateMultisigData()
609
+ //
610
+ // for _, address := range params.Addresses {
611
+ // data.MustAddSigData(address.Address, address.Weight)
612
+ // }
613
+ //
614
+ // resultJson, _ := json.Marshal(map[string]string{"success": "true", "multisig_address": data.AddressString()})
615
+ // return C.CString(string(resultJson))
616
+ //}
617
+
618
+ func main() {}