-
Notifications
You must be signed in to change notification settings - Fork 1
/
meta_api.go
70 lines (64 loc) · 1.95 KB
/
meta_api.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
package metax
import (
"context"
"fmt"
"net/http"
)
type MetaAPIResponse struct {
Log string `json:"log"`
Flag int `json:"flag"`
Total int `json:"total"`
ListAPI []MetaAPIInfo `json:"listApis"`
}
type MetaAPIInfo struct {
/// need to filter non contractAdress
ContractAddress string `json:"contractAddress"`
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Version int `json:"version"`
Method string `json:"method"`
MethodType string `json:"methodType"`
APIType string `json:"apiType"`
MetaTxLimitStatus int `json:"metaTxLimitStatus"`
MetaTxLimit MetaTxLimit `json:"metaTxLimit"`
}
type MetaTxLimit struct {
Type int `json:"type"`
Value float32 `json:"value"`
DurationValue int `json:"durationValue"`
Day string `json:"day"`
LimitStartTime int64 `json:"limitStartTime"`
LimitDurationInMs int64 `json:"limitDurationInMs"`
}
func (b *Bcnmy) GetMetaAPI(ctx context.Context) (*MetaAPIResponse, error) {
responseCh := make(chan interface{}, 1)
errorCh := make(chan error)
defer close(errorCh)
defer close(responseCh)
req, err := http.NewRequest(http.MethodGet, MetaAPIURL, nil)
if err != nil {
b.logger.WithError(err).Error("MetaAPI NewRequest failed")
return nil, err
}
req.Header.Set("Content-Type", "application/json; charset=utf-8")
req.Header.Set("x-api-key", b.apiKey)
var resp MetaAPIResponse
b.asyncHttpx(req, &resp, errorCh, responseCh)
select {
case ret := <-responseCh:
resp, ok := ret.(*MetaAPIResponse)
if !ok {
return nil, fmt.Errorf("MetaAPI failed")
}
if resp.Flag != 143 {
err := fmt.Errorf("%v", resp)
b.logger.WithError(err).Error(resp.Log)
return nil, err
}
return resp, nil
case err := <-errorCh:
b.logger.Error(err.Error())
return nil, err
}
}