-
Notifications
You must be signed in to change notification settings - Fork 9
/
util.go
108 lines (92 loc) · 3.02 KB
/
util.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
package commands
import (
stdjson "encoding/json"
"os"
"time"
jww "github.com/spf13/jwalterweatherman"
"github.com/bytom/vapor/crypto/ed25519/chainkd"
"github.com/bytom/vapor/encoding/json"
chainjson "github.com/bytom/vapor/encoding/json"
"github.com/bytom/vapor/util"
)
// accountIns is used for account related request.
type accountIns struct {
RootXPubs []chainkd.XPub `json:"root_xpubs"`
Quorum int `json:"quorum"`
Alias string `json:"alias"`
AccessToken string `json:"access_token"`
}
// assetIns is used for asset related request.
type assetIns struct {
RootXPubs []chainkd.XPub `json:"root_xpubs"`
Quorum int `json:"quorum"`
Alias string `json:"alias"`
Definition map[string]interface{} `json:"definition"`
IssuanceProgram chainjson.HexBytes `json:"issuance_program"`
AccessToken string `json:"access_token"`
}
type requestQuery struct {
Filter string `json:"filter,omitempty"`
FilterParams []interface{} `json:"filter_params,omitempty"`
SumBy []string `json:"sum_by,omitempty"`
PageSize int `json:"page_size"`
AscLongPoll bool `json:"ascending_with_long_poll,omitempty"`
Timeout json.Duration `json:"timeout"`
After string `json:"after"`
StartTimeMS uint64 `json:"start_time,omitempty"`
EndTimeMS uint64 `json:"end_time,omitempty"`
TimestampMS uint64 `json:"timestamp,omitempty"`
Type string `json:"type"`
Aliases []string `json:"aliases,omitempty"`
}
// txFeed
type txFeed struct {
Alias string `json:"alias"`
Filter string `json:"filter,omitempty"`
}
type respArrayTxFeed struct {
Status string `json:"status,omitempty"`
Msg string `json:"msg,omitempty"`
Data []*txFeed `json:"data,omitempty"`
}
type respTxFeed struct {
Status string `json:"status,omitempty"`
Msg string `json:"msg,omitempty"`
Data txFeed `json:"data,omitempty"`
}
type accessToken struct {
ID string `json:"id,omitempty"`
Token string `json:"token,omitempty"`
Type string `json:"type,omitempty"`
Secret string `json:"secret,omitempty"`
Created time.Time `json:"created_at,omitempty"`
}
func printJSON(data interface{}) {
dataMap, ok := data.(map[string]interface{})
if ok != true {
jww.ERROR.Println("invalid type assertion")
os.Exit(util.ErrLocalParse)
}
rawData, err := stdjson.MarshalIndent(dataMap, "", " ")
if err != nil {
jww.ERROR.Println(err)
os.Exit(util.ErrLocalParse)
}
jww.FEEDBACK.Println(string(rawData))
}
func printJSONList(data interface{}) {
dataList, ok := data.([]interface{})
if ok != true {
jww.ERROR.Println("invalid type assertion")
os.Exit(util.ErrLocalParse)
}
for idx, item := range dataList {
jww.FEEDBACK.Println(idx, ":")
rawData, err := stdjson.MarshalIndent(item, "", " ")
if err != nil {
jww.ERROR.Println(err)
os.Exit(util.ErrLocalParse)
}
jww.FEEDBACK.Println(string(rawData))
}
}