-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_wallet.go
256 lines (237 loc) · 8.12 KB
/
client_wallet.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
package bbrpc
// Addnewtemplate https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#addnewtemplate
func (c *Client) Addnewtemplate(p AddnewtemplateParam) (*string, error) {
// TODO p should be a struct or pointer to struct
m := map[string]interface{}{
"type": p.TemplateType(),
p.ParamName(): p,
}
resp, err := c.sendCmd("addnewtemplate", m)
if err != nil {
return nil, err
}
var templateAddress string
err = futureParse(resp, &templateAddress)
return &templateAddress, err
}
// Createtransaction https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#createtransaction
func (c *Client) Createtransaction(cmd CmdCreatetransaction) (*string, error) {
resp, err := c.sendCmd("createtransaction", cmd)
if err != nil {
return nil, err
}
var txdata string
err = futureParse(resp, &txdata)
return &txdata, err
}
// Exportkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#exportkey
func (c *Client) Exportkey(pubkey string) (string, error) {
resp, err := c.sendCmd("exportkey", struct {
Pubkey string `json:"pubkey"`
}{pubkey})
if err != nil {
return "", err
}
var key string
err = futureParse(resp, &key)
return key, err
}
// Getbalance https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getbalance
func (c *Client) Getbalance(fork *string, address *string) ([]BalanceInfo, error) {
if address != nil && *address == "" {
address = nil
}
resp, err := c.sendCmd("getbalance", struct {
Fork *string `json:"fork,omitempty"`
Address *string `json:"address,omitempty"`
}{Fork: fork, Address: address})
if err != nil {
return nil, err
}
var data []BalanceInfo
err = futureParse(resp, &data)
return data, err
}
// Getnewkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#getnewkey
func (c *Client) Getnewkey(passphrase string) (string, error) {
resp, err := c.sendCmd("getnewkey", struct {
Passphrase string `json:"passphrase"`
}{Passphrase: passphrase})
if err != nil {
return "", nil
}
var pubkey string
err = futureParse(resp, &pubkey)
return pubkey, err
}
// Gettransaction https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#gettransaction
func (c *Client) Gettransaction(txid string, serialized *bool) (*TransactionDetail, error) {
resp, err := c.sendCmd("gettransaction", struct {
Txid string `json:"txid"`
Serialized *bool `json:"serialized,omitempty"`
}{Txid: txid, Serialized: serialized})
if err != nil {
return nil, err
}
var detail TransactionDetail
err = futureParse(resp, &detail)
return &detail, err
}
// Importkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#importkey
func (c *Client) Importkey(pubkey string, syncTx *bool) (string, error) {
resp, err := c.sendCmd("importkey", struct {
Pubkey string `json:"pubkey"`
Synctx *bool `json:"synctx,omitempty"`
}{pubkey, syncTx})
if err != nil {
return "", err
}
var key string
err = futureParse(resp, &key)
return key, err
}
// Importprivkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#importprivkey
func (c *Client) Importprivkey(privkey, passphrase string, syncTx *bool) (*string, error) {
resp, err := c.sendCmd("importprivkey", struct {
Privkey string `json:"privkey"`
Passphrase string `json:"passphrase"`
Synctx *bool `json:"synctx,omitempty"`
}{Privkey: privkey, Passphrase: passphrase, Synctx: syncTx})
if err != nil {
return nil, err
}
var pubkey string
err = futureParse(resp, &pubkey)
return &pubkey, err
}
// Importtemplate https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#importtemplate
func (c *Client) Importtemplate(data string) (*string, error) {
resp, err := c.sendCmd("importtemplate", struct {
Data string `json:"data"`
}{data})
if err != nil {
return nil, err
}
var address string
err = futureParse(resp, &address)
return &address, err
}
// Importpubkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#importpubkey
func (c *Client) Importpubkey(pubkey string) (*string, error) {
resp, err := c.sendCmd("importpubkey", struct {
Pubkey string `json:"pubkey"`
}{pubkey})
if err != nil {
return nil, err
}
var address string
err = futureParse(resp, &address)
return &address, err
}
// Listaddress https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#listaddress
func (c *Client) Listaddress() ([]AddressData, error) {
resp, err := c.sendCmd("listaddress", nil)
if err != nil {
return nil, err
}
var data []AddressData
err = futureParse(resp, &data)
return data, err
}
// Listkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#listkey
func (c *Client) Listkey() ([]PubkeyInfo, error) {
resp, err := c.sendCmd("listkey", nil)
if err != nil {
return nil, err
}
var data []PubkeyInfo
err = futureParse(resp, &data)
return data, err
}
// Listtransaction https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#listtransaction
func (c *Client) Listtransaction(count *uint, offset *int) ([]Transaction, error) {
resp, err := c.sendCmd("listtransaction", struct {
Count *uint `json:"count,omitempty"`
Offset *int `json:"offset,omitempty"`
}{Count: count, Offset: offset})
if err != nil {
return nil, err
}
var data []Transaction
err = futureParse(resp, &data)
return data, err
}
// CmdSendfrom .
type CmdSendfrom struct {
From string `json:"from"` //(string, required) from address
To string `json:"to"` //(string, required) to address
Amount float64 `json:"amount"` //(double, required) amount
Txfee *float64 `json:"txfee,omitempty"` //(double, optional) transaction fee
Fork *string `json:"fork,omitempty"` //(string, optional) fork hash
Data *string `json:"data,omitempty"` //(string, optional) output data
SignM *string `json:"sign_m,omitempty"` //(string, optional) exchange sign m
SignS *string `json:"sign_s,omitempty"` //(string, optional) exchange sign s
Sendtodata *string `json:"sendtodata,omitempty"` //(string, optional) If the 'to' address of transaction is a template, this option allows to save the template hex data. The hex data is equal output of RPC 'exporttemplate'
Type *uint `json:"type,omitempty"` //(uint, optional, default=0) 0: common token tx, 2: defi relation tx
}
// Sendfrom https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#sendfrom
func (c *Client) Sendfrom(cmd CmdSendfrom) (*string, error) {
resp, err := c.sendCmd("sendfrom", &cmd)
if err != nil {
return nil, err
}
var txid string
err = futureParse(resp, &txid)
return &txid, err
}
// Signtransaction https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#signtransaction
func (c *Client) Signtransaction(txdata string) (*SigntransactionResult, error) {
resp, err := c.sendCmd("signtransaction", struct {
Txdata string `json:"txdata"`
}{Txdata: txdata})
if err != nil {
return nil, err
}
var ret SigntransactionResult
err = futureParse(resp, &ret)
return &ret, err
}
// Signrawtransactionwithwallet https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#signrawtransactionwithwallet
func (c *Client) Signrawtransactionwithwallet(addrIn, txdata string) (*SigntransactionResult, error) {
resp, err := c.sendCmd("signrawtransactionwithwallet", struct {
Txdata string `json:"txdata"`
AddrIn string `json:"addrIn"`
}{Txdata: txdata, AddrIn: addrIn})
if err != nil {
return nil, err
}
var ret SigntransactionResult
err = futureParse(resp, &ret)
return &ret, err
}
// Validateaddress https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#validateaddress
func (c *Client) Validateaddress(addr string) (*AddressInfo, error) {
resp, err := c.sendCmd("validateaddress", struct {
Address string `json:"address"`
}{Address: addr})
if err != nil {
return nil, err
}
var info AddressInfo
err = futureParse(resp, &info)
return &info, err
}
// Unlockkey https://github.com/bigbangcore/BigBang/wiki/JSON-RPC#unlockkey
func (c *Client) Unlockkey(pubkey, passphrase string, timeout *int64) (*string, error) {
resp, err := c.sendCmd("unlockkey", struct {
Pubkey string `json:"pubkey"`
Passphrase string `json:"passphrase"`
Timeout *int64 `json:"timeout,omitempty"`
}{Pubkey: pubkey, Passphrase: passphrase, Timeout: timeout})
if err != nil {
return nil, err
}
var result string
err = futureParse(resp, &result)
return &result, err
}