Skip to content

Commit b05145f

Browse files
committed
chore: json key name
1 parent b2d6a04 commit b05145f

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

router/_RPC_api.gno

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// EXTERNAL API
21
package router
32

43
import (
@@ -11,32 +10,31 @@ import (
1110
"gno.land/p/demo/ufmt"
1211
)
1312

14-
type ApiQueryBase struct {
13+
type TokenPathPrice struct {
14+
Path string `json:"path"`
15+
Price bigint `json:"price"`
16+
}
17+
18+
type ResponseQueryBase struct {
1519
Height int64 `json:"height"`
1620
Timestamp int64 `json:"timestamp"`
1721
}
1822

1923
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"`
2426
}
2527

2628
func ApiGetRatiosFromBase() string {
27-
qb := ApiQueryBase{
29+
qb := ResponseQueryBase{
2830
Height: GetHeight(),
2931
Timestamp: GetTimestamp(),
3032
}
3133

3234
ratios := getRatiosFromBase(3)
3335
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,
4038
}
4139

4240
rr, err := json.Marshal(r)
@@ -47,7 +45,7 @@ func ApiGetRatiosFromBase() string {
4745
return string(rr)
4846
}
4947

50-
func getRatiosFromBase(maxHops int) []map[string]bigint {
48+
func getRatiosFromBase(maxHops int) []TokenPathPrice {
5149
tokenPrice := make(map[string]bigint, 0)
5250

5351
// BASE
@@ -92,9 +90,12 @@ func getRatiosFromBase(maxHops int) []map[string]bigint {
9290
// TOKEN ENDS
9391
}
9492

95-
var tokenPrices []map[string]bigint
93+
tokenPrices := []TokenPathPrice{}
9694
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+
})
9899
}
99100

100101
return tokenPrices
@@ -185,19 +186,19 @@ func makePoolPath(poolPath string, poolIndex int) string {
185186

186187
func poolPathWithFeeDivide(poolPath string) (string, string, int) {
187188
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))
189190

190191
feeInt, err := strconv.Atoi(poolPathSplit[2])
191192
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]))
193194
}
194195

195196
return poolPathSplit[0], poolPathSplit[1], feeInt
196197
}
197198

198199
func singlePoolPathWithFeeDivide(poolPath string) (string, string) {
199200
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))
201202

202203
return singlePoolPathSplit[0], singlePoolPathSplit[1]
203204
}

router/_TEST_router_api_getter_test.gno

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestPositionMint(t *testing.T) {
5151
func TestApiGetRatiosFromBase(t *testing.T) {
5252
jsonOutput := ApiGetRatiosFromBase()
5353
jsonStr := gjson.Parse(jsonOutput)
54-
jsonArr := jsonStr.Get("response.data").Array()
54+
jsonArr := jsonStr.Get("response").Array()
5555
shouldEQ(t, len(jsonArr), 4)
5656

5757
shouldEQ(t, jsonArr[0].String(), "{\"gno.land/r/demo/wugnot\":79228162514264337593543950336}") // 1

0 commit comments

Comments
 (0)