Skip to content

Commit

Permalink
add defaultDenom&bech32Prefix to GetTokenAliases
Browse files Browse the repository at this point in the history
  • Loading branch information
tj327 committed Jan 6, 2024
1 parent 2787f37 commit 7e78347
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 65 deletions.
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Features:

* Implement QueryUndelegations endpoint
* Bump sekai version to v0.3.38
* Add DefaultDenom and Bech32Prefix to QueryKiraTokensAliases endpoint
* Bump sekai version to v0.3.40
10 changes: 6 additions & 4 deletions common/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func GetBlockNanoTime(rpcAddr string, height int64) (int64, error) {
}

// GetTokenAliases is a function to get token aliases
func GetTokenAliases(gwCosmosmux *runtime.ServeMux, r *http.Request) []types.TokenAlias {
func GetTokenAliases(gwCosmosmux *runtime.ServeMux, r *http.Request) ([]types.TokenAlias, string, string) {
// tokens, err := database.GetTokenAliases()
// if err == nil {
// return tokens
Expand All @@ -320,16 +320,18 @@ func GetTokenAliases(gwCosmosmux *runtime.ServeMux, r *http.Request) []types.Tok
r.Method = "GET"

// GetLogger().Info("[grpc-call] Entering grpc call: ", r.URL.Path)

recorder := httptest.NewRecorder()
gwCosmosmux.ServeHTTP(recorder, r)
resp := recorder.Result()

type TokenAliasesResponse struct {
Data []types.TokenAlias `json:"data"`
Data []types.TokenAlias `json:"data"`
DefaultDenom string `json:"defaultDenom"`
Bech32Prefix string `json:"bech32Prefix"`
}

result := TokenAliasesResponse{}

err := json.NewDecoder(resp.Body).Decode(&result)
if err != nil {
GetLogger().Error("[grpc-call] Unable to decode response: ", err)
Expand All @@ -341,7 +343,7 @@ func GetTokenAliases(gwCosmosmux *runtime.ServeMux, r *http.Request) []types.Tok
GetLogger().Error("[grpc-call] Unable to save response")
}

return result.Data
return result.Data, result.DefaultDenom, result.Bech32Prefix
}

// GetTokenSupply is a function to get token supply
Expand Down
4 changes: 2 additions & 2 deletions config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package config

const (
InterxVersion = "v0.4.41"
SekaiVersion = "v0.3.38"
CosmosVersion = "v0.47.5"
SekaiVersion = "v0.3.40"
CosmosVersion = "v0.47.6"

QueryDashboard = "/api/dashboard"

Expand Down
19 changes: 15 additions & 4 deletions gateway/kira/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,30 @@ func RegisterKiraTokensRoutes(r *mux.Router, gwCosmosmux *runtime.ServeMux, rpcA
}

func queryKiraTokensAliasesHandler(r *http.Request, gwCosmosmux *runtime.ServeMux) (interface{}, interface{}, int) {
type TokenAliasesResult struct {
type TokenAliasesData struct {
Decimals int64 `json:"decimals"`
Denoms []string `json:"denoms"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Icon string `json:"icon"`
Amount sdk.Int `json:"amount"`
}
type TokenAliasesResult struct {
Data []TokenAliasesData `json:"token_aliases_data"`
DefaultDenom string `json:"default_denom"`
Bech32Prefix string `json:"bech32_prefix"`
}

tokens := common.GetTokenAliases(gwCosmosmux, r.Clone(r.Context()))
tokens, defaultDenom, bech32Prefix := common.GetTokenAliases(gwCosmosmux, r.Clone(r.Context()))
tokensSupply := common.GetTokenSupply(gwCosmosmux, r.Clone(r.Context()))

result := make([]TokenAliasesResult, 0)
data := make([]TokenAliasesData, 0)
for _, token := range tokens {
flag := false
for _, denom := range token.Denoms {
for _, supply := range tokensSupply {
if denom == supply.Denom {
result = append(result, TokenAliasesResult{
data = append(data, TokenAliasesData{
Decimals: token.Decimals,
Denoms: token.Denoms,
Name: token.Name,
Expand All @@ -60,6 +65,12 @@ func queryKiraTokensAliasesHandler(r *http.Request, gwCosmosmux *runtime.ServeMu
}
}

result := TokenAliasesResult{
Data: data,
DefaultDenom: defaultDenom,
Bech32Prefix: bech32Prefix,
}

return result, nil, http.StatusOK
}

Expand Down
2 changes: 1 addition & 1 deletion gateway/rosetta/data/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func queryAccountBalanceHandler(r *http.Request, request types.InterxRequest, rp
var response dataapi.AccountBalanceResponse

balances := common.GetAccountBalances(gwCosmosmux, r.Clone(r.Context()), req.AccountIdentifier.Address)
tokens := common.GetTokenAliases(gwCosmosmux, r.Clone(r.Context()))
tokens, _, _ := common.GetTokenAliases(gwCosmosmux, r.Clone(r.Context()))

response.Balances = make([]rosetta.Amount, 0)
for _, balance := range balances {
Expand Down
34 changes: 17 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/btcsuite/btcd v0.22.1
github.com/cometbft/cometbft v0.37.2
github.com/cosmos/cosmos-proto v1.0.0-beta.2
github.com/cosmos/cosmos-sdk v0.47.5
github.com/cosmos/cosmos-sdk v0.47.6
github.com/cosmos/go-bip39 v1.0.0
github.com/ethereum/go-ethereum v1.10.21
github.com/gogo/protobuf v1.3.2
Expand All @@ -24,8 +24,8 @@ require (
github.com/stretchr/testify v1.8.4
github.com/tyler-smith/go-bip39 v1.0.2
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb
google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e
google.golang.org/grpc v1.57.0
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
)

Expand All @@ -35,7 +35,7 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/log v1.2.1 // indirect
cosmossdk.io/math v1.1.2 // indirect
cosmossdk.io/math v1.2.0 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand All @@ -61,8 +61,8 @@ require (
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.10 // indirect
github.com/cosmos/iavl v0.20.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.1 // indirect
github.com/cosmos/iavl v0.20.1 // indirect
github.com/cosmos/ledger-cosmos-go v0.12.4 // indirect
github.com/cosmos/rosetta-sdk-go v0.10.0 // indirect
github.com/creachadair/taskgroup v0.3.2 // indirect
github.com/danieljoos/wincred v1.1.2 // indirect
Expand All @@ -85,7 +85,7 @@ require (
github.com/go-stack/stack v1.8.0 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand All @@ -108,7 +108,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.3 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.7 // indirect
Expand Down Expand Up @@ -150,16 +150,16 @@ require (
github.com/tidwall/btree v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.0 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit 7e78347

Please sign in to comment.