-
Notifications
You must be signed in to change notification settings - Fork 1
/
v3_query.go
209 lines (187 loc) · 6.3 KB
/
v3_query.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
package gosdk
import (
"github.com/axengine/httpc"
"github.com/pkg/errors"
"strconv"
)
// V3GetLedgers 查询所有账本(区块)
func (cli *APIClient) V3GetLedgers(cursor, limit int64, order string) ([]V3Ledger, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Result []V3Ledger `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/ledgers").Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New("get ledgers error")
}
return resp.Result, nil
}
// V3GetLedger 指定高度查询账本(区块)
func (cli *APIClient) V3GetLedger(height int64) (*V3Ledger, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Result []V3Ledger `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/ledgers/" + strconv.FormatInt(height, 10)).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New("get ledgers error")
}
if len(resp.Result) > 0 {
return &resp.Result[0], nil
}
return nil, nil
}
// V3GetTransactions 查询所有交易
func (cli *APIClient) V3GetTransactions(cursor, limit int64, order string) ([]V3Transaction, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Transaction `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/transactions").Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
return resp.Result, nil
}
// V3GetTransaction 指定hash查交易
func (cli *APIClient) V3GetTransaction(tx string) (*V3Transaction, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Transaction `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/transactions/" + tx).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
if len(resp.Result) == 0 {
return nil, nil
}
return &resp.Result[0], nil
}
// V3GetPayments 查询所有转账记录
// symbol:币种,例如OLO,大写,为空时查询所有币种的转账记录
func (cli *APIClient) V3GetPayments(symbol string, cursor, limit int64, order string) ([]V3Payment, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Payment `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/payments").Query("symbol", symbol).Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
return resp.Result, nil
}
// V1GetTxPayments 指定交易hash查payment
func (cli *APIClient) V3GetTxPayments(tx string, cursor, limit int64, order string) ([]V3Payment, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Payment `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/transactions/"+tx+"/payments").Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
return resp.Result, nil
}
// V3GetAccountPayments 指定账户查payment,账户可以是地址,也可以是公钥
func (cli *APIClient) V3GetAccountPayments(address string, cursor, limit int64, order string) ([]V3Payment, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Payment `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/accounts/"+address+"/payments").Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
return resp.Result, nil
}
// V3GetAccountTransactions 指定账户查payment
func (cli *APIClient) V3GetAccountTransactions(address string, cursor, limit int64, order string) ([]V3Transaction, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Transaction `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/accounts/"+address+"/transactions").Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
return resp.Result, nil
}
// V3GetLedgerTransactions 指定高度查tx
func (cli *APIClient) V3GetLedgerTransactions(height int64, cursor, limit int64, order string) ([]V3Transaction, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Transaction `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/ledgers/"+strconv.FormatUint(uint64(height), 10)+"/transactions").
Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
if len(resp.Result) == 0 {
return nil, nil
}
return resp.Result, nil
}
// V3GetLedgerPayments 指定高度查账本
func (cli *APIClient) V3GetLedgerPayments(height int64, cursor, limit int64, order string) ([]V3Payment, error) {
resp := struct {
IsSuccess bool `json:"isSuccess"`
Message string `json:"message"`
Result []V3Payment `json:"result"`
}{}
err := httpc.New(cli.addr).Path("/v3/ledgers/"+strconv.FormatUint(uint64(height), 10)+"/payments").
Query("cursor", strconv.FormatInt(cursor, 10)).
Query("limit", strconv.FormatInt(limit, 10)).Query("order", order).Get(&resp)
if err != nil {
return nil, err
}
if !resp.IsSuccess {
return nil, errors.New(resp.Message)
}
if len(resp.Result) == 0 {
return nil, nil
}
return resp.Result, nil
}