Skip to content

Commit a4c676b

Browse files
committed
feat: include token type to response
1 parent b500ad4 commit a4c676b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/handlers/token_handlers.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ type BalanceModel struct {
1717
TokenAddress string `json:"token_address" ch:"address"`
1818
TokenId string `json:"token_id" ch:"token_id"`
1919
Balance string `json:"balance" ch:"balance"`
20+
TokenType string `json:"token_type" ch:"token_type"`
2021
}
2122

2223
type HolderModel struct {
2324
HolderAddress string `json:"holder_address" ch:"owner"`
2425
TokenId string `json:"token_id" ch:"token_id"`
2526
Balance string `json:"balance" ch:"balance"`
27+
TokenType string `json:"token_type" ch:"token_type"`
2628
}
2729

2830
// @Summary Get token balances of an address by type
@@ -77,8 +79,8 @@ func GetTokenBalancesByType(c *gin.Context) {
7779
columns := []string{"address", "sum(balance) as balance"}
7880
groupBy := []string{"address"}
7981
if !strings.Contains(strings.Join(tokenTypes, ","), "erc20") {
80-
columns = []string{"address", "token_id", "sum(balance) as balance"}
81-
groupBy = []string{"address", "token_id"}
82+
columns = []string{"address", "token_id", "sum(balance) as balance", "token_type"}
83+
groupBy = []string{"address", "token_id", "token_type"}
8284
}
8385

8486
qf := storage.BalancesQueryFilter{
@@ -139,6 +141,7 @@ func serializeBalance(balance common.TokenBalance) BalanceModel {
139141
}
140142
return ""
141143
}(),
144+
TokenType: balance.TokenType,
142145
}
143146
}
144147

@@ -220,8 +223,8 @@ func GetTokenHoldersByType(c *gin.Context) {
220223
groupBy := []string{"owner"}
221224

222225
if !strings.Contains(strings.Join(tokenTypes, ","), "erc20") {
223-
columns = []string{"owner", "token_id", "sum(balance) as balance"}
224-
groupBy = []string{"owner", "token_id"}
226+
columns = []string{"owner", "token_id", "sum(balance) as balance", "token_type"}
227+
groupBy = []string{"owner", "token_id", "token_type"}
225228
}
226229

227230
tokenIds, err := getTokenIdsFromReq(c)
@@ -286,5 +289,6 @@ func serializeHolder(holder common.TokenBalance) HolderModel {
286289
}
287290
return ""
288291
}(),
292+
TokenType: holder.TokenType,
289293
}
290294
}

0 commit comments

Comments
 (0)