1- // EXTERNAL API
21package router
32
43import (
@@ -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
1923type 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
2628func 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
186187func 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
198199func 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}
0 commit comments