1
- // EXTERNAL API
2
1
package router
3
2
4
3
import (
@@ -11,32 +10,31 @@ import (
11
10
"gno.land/p/demo/ufmt"
12
11
)
13
12
14
- type ApiQueryBase struct {
13
+ type TokenPathPrice struct {
14
+ Path string `json:"path"`
15
+ Price bigint `json:"price"`
16
+ }
17
+
18
+ type ResponseQueryBase struct {
15
19
Height int64 `json:"height"`
16
20
Timestamp int64 `json:"timestamp"`
17
21
}
18
22
19
23
type ResponseGetRatiosFromBase struct {
20
- Stat ApiQueryBase `json:"stat"`
21
- Response struct {
22
- Data []map[string]bigint `json:"data"`
23
- } `json:"response"`
24
+ Stat ResponseQueryBase `json:"stat"`
25
+ Response []TokenPathPrice `json:"response"`
24
26
}
25
27
26
28
func ApiGetRatiosFromBase() string {
27
- qb := ApiQueryBase {
29
+ qb := ResponseQueryBase {
28
30
Height: GetHeight(),
29
31
Timestamp: GetTimestamp(),
30
32
}
31
33
32
34
ratios := getRatiosFromBase(3)
33
35
r := ResponseGetRatiosFromBase{
34
- Stat: qb,
35
- Response: struct {
36
- Data []map[string]bigint `json:"data"`
37
- }{
38
- Data: ratios,
39
- },
36
+ Stat: qb,
37
+ Response: ratios,
40
38
}
41
39
42
40
rr, err := json.Marshal(r)
@@ -47,7 +45,7 @@ func ApiGetRatiosFromBase() string {
47
45
return string(rr)
48
46
}
49
47
50
- func getRatiosFromBase(maxHops int) []map[string]bigint {
48
+ func getRatiosFromBase(maxHops int) []TokenPathPrice {
51
49
tokenPrice := make(map[string]bigint, 0)
52
50
53
51
// BASE
@@ -92,9 +90,12 @@ func getRatiosFromBase(maxHops int) []map[string]bigint {
92
90
// TOKEN ENDS
93
91
}
94
92
95
- var tokenPrices []map[string]bigint
93
+ tokenPrices := []TokenPathPrice{}
96
94
for token, price := range tokenPrice {
97
- tokenPrices = append(tokenPrices, map[string]bigint{token: price})
95
+ tokenPrices = append(tokenPrices, TokenPathPrice{
96
+ Path: token,
97
+ Price: price,
98
+ })
98
99
}
99
100
100
101
return tokenPrices
@@ -185,19 +186,19 @@ func makePoolPath(poolPath string, poolIndex int) string {
185
186
186
187
func poolPathWithFeeDivide(poolPath string) (string, string, int) {
187
188
poolPathSplit := strings.Split(poolPath, ":")
188
- require(len(poolPathSplit) == 3, ufmt.Sprintf("[ROUTER] util .gno__poolPathWithFeeDivide() || len(poolPathSplit) != 3, poolPath: %s", poolPath))
189
+ require(len(poolPathSplit) == 3, ufmt.Sprintf("[ROUTER] _RPC_api .gno__poolPathWithFeeDivide() || len(poolPathSplit) != 3, poolPath: %s", poolPath))
189
190
190
191
feeInt, err := strconv.Atoi(poolPathSplit[2])
191
192
if err != nil {
192
- panic(ufmt.Sprintf("[ROUTER] util .gno__poolPathWithFeeDivide() || cannot convert fee(%s) to int", poolPathSplit[2]))
193
+ panic(ufmt.Sprintf("[ROUTER] _RPC_api .gno__poolPathWithFeeDivide() || cannot convert fee(%s) to int", poolPathSplit[2]))
193
194
}
194
195
195
196
return poolPathSplit[0], poolPathSplit[1], feeInt
196
197
}
197
198
198
199
func singlePoolPathWithFeeDivide(poolPath string) (string, string) {
199
200
singlePoolPathSplit := strings.Split(poolPath, ":")
200
- require(len(singlePoolPathSplit) == 2, ufmt.Sprintf("[ROUTER] util .gno__singlePoolPathWithFeeDivide || len(singlePoolPathSplit) != 2, poolPath: %s", poolPath))
201
+ require(len(singlePoolPathSplit) == 2, ufmt.Sprintf("[ROUTER] _RPC_api .gno__singlePoolPathWithFeeDivide || len(singlePoolPathSplit) != 2, poolPath: %s", poolPath))
201
202
202
203
return singlePoolPathSplit[0], singlePoolPathSplit[1]
203
204
}
0 commit comments