-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.go
122 lines (102 loc) · 2.12 KB
/
tools.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
package main
import (
"encoding/json"
"log"
"strconv"
"github.com/valyala/fasthttp"
)
type Response struct {
STATUS bool
DESCR string
}
type BalanceResponse struct {
STATUS bool
BALANCE string
}
type SimpleTransaction struct {
TT string
SENDER string
RECEIVER string
TTOKEN string
CTOKEN string
TST string
SIGNATURE string
}
type SimpleTransactionForVerify struct {
TT string
SENDER string
RECEIVER string
TTOKEN string
CTOKEN string
TST string
}
type HelloTransaction struct {
TT string
SENDER string
SIGNATURE string
}
type HelloTransactionForVerify struct {
TT string
SENDER string
}
type StatisticsResponse struct {
TCOUNT string
LTPS string
BHEIGHT string
LTPB string
TPD string
VMAP []string
UPD string
}
type redisError interface {
Err() error
}
func isRedisError(err redisError) bool {
//
return err.Err() != nil
}
func makeResponse(status bool,
description string,
statusCode int,
ctx *fasthttp.RequestCtx) {
//
response := Response{status, description}
jsResponse, _ := json.Marshal(response)
ctx.SetContentType("application/json")
ctx.SetStatusCode(statusCode)
ctx.SetBody(jsResponse)
log.Println(statusCode, description, string(jsResponse))
}
func makeBalanceResponse(status bool,
balance string,
statusCode int,
ctx *fasthttp.RequestCtx) {
//
response := BalanceResponse{status, balance}
jsResponse, _ := json.Marshal(response)
ctx.SetContentType("application/json")
ctx.SetStatusCode(statusCode)
ctx.SetBody(jsResponse)
}
func makeStatisticsResponse(status bool,
tranCount int64,
ltps int64,
blockHeight int64,
ltpb int64,
tpd float64,
upd int64,
statusCode int,
ctx *fasthttp.RequestCtx) {
//
response := StatisticsResponse{strconv.FormatInt(tranCount, 10),
strconv.FormatInt(ltps, 10),
strconv.FormatInt(blockHeight, 10),
strconv.FormatInt(ltpb, 10),
strconv.FormatFloat(tpd, 'f', 8, 64),
[]string{"50.11", "8.68"},
strconv.FormatInt(upd, 10)}
jsResponse, _ := json.Marshal(response)
ctx.SetContentType("application/json")
ctx.SetStatusCode(statusCode)
ctx.SetBody(jsResponse)
}