Commit d18111f6 authored by shajiaiming's avatar shajiaiming

主链信息

parent ef89831e
...@@ -237,3 +237,13 @@ func GetCoinsPlatform() ([]*Coin, error) { ...@@ -237,3 +237,13 @@ func GetCoinsPlatform() ([]*Coin, error) {
return coins, nil return coins, nil
} }
func GetCoinChains() ([]*Coin, error) {
var coins []*Coin
err := db.Select("chain").Where("chain <> ?", "").Group("chain").Find(&coins).Error
if err != nil && err != gorm.ErrRecordNotFound {
return nil, err
}
return coins, nil
}
package v1 package v1
import ( import (
"bwallet/pkg/app"
"bwallet/pkg/e"
"bwallet/pkg/errno" "bwallet/pkg/errno"
"bwallet/pkg/handler" "bwallet/pkg/handler"
"bwallet/pkg/util" "bwallet/pkg/util"
...@@ -12,6 +14,7 @@ import ( ...@@ -12,6 +14,7 @@ import (
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/astaxie/beego/validation" "github.com/astaxie/beego/validation"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
"strconv" "strconv"
"strings" "strings"
) )
...@@ -325,6 +328,28 @@ func GetCoinsPlatform(c *gin.Context) { ...@@ -325,6 +328,28 @@ func GetCoinsPlatform(c *gin.Context) {
} }
*/ */
func GetCoinChains(c *gin.Context) {
appG := app.Gin{c}
coinService := coin_service.Coin{}
coins, err := coinService.GetCoinChains()
if err != nil {
appG.Response(http.StatusInternalServerError, e.ERROR_GET_COIN_FAIL, nil)
return
}
data := make(map[string]interface{})
var items [] string
for _, value := range coins {
if "" != value.Chain {
items = append(items, value.Chain)
}
}
data["items"] = items
handler.SendResponse(c, nil, data)
}
func GetPrimaryChains(c *gin.Context) { func GetPrimaryChains(c *gin.Context) {
data := make(map[string]interface{}) data := make(map[string]interface{})
data["items"] = [] string{"BTC", "ETH", "BTY", "DCR"} data["items"] = [] string{"BTC", "ETH", "BTY", "DCR"}
......
...@@ -34,7 +34,7 @@ func InitRouter() *gin.Engine { ...@@ -34,7 +34,7 @@ func InitRouter() *gin.Engine {
api.GET("/coin", v1.GetCoin) api.GET("/coin", v1.GetCoin)
api.PUT("/coin", v1.EditCoin) api.PUT("/coin", v1.EditCoin)
api.DELETE("/coin", v1.DeleteCoin) api.DELETE("/coin", v1.DeleteCoin)
api.GET("/primary-chains", v1.GetPrimaryChains) api.GET("/primary-chains", v1.GetCoinChains)
api.GET("/types", v1.GetTypes) api.GET("/types", v1.GetTypes)
api.GET("/coin-relation", v1.GetWalletCoinRelationCoinRelations) api.GET("/coin-relation", v1.GetWalletCoinRelationCoinRelations)
......
...@@ -190,6 +190,17 @@ func (c *Coin) GetCoinsPlatform() ([]*models.Coin, error) { ...@@ -190,6 +190,17 @@ func (c *Coin) GetCoinsPlatform() ([]*models.Coin, error) {
return coins, nil return coins, nil
} }
func (c *Coin) GetCoinChains() ([]*models.Coin, error) {
var coins []*models.Coin
coins, err := models.GetCoinChains()
if err != nil {
return nil, err
}
return coins, nil
}
func (c *Coin) getMaps() (map[string]interface{}) { func (c *Coin) getMaps() (map[string]interface{}) {
maps := make(map[string]interface{}) maps := make(map[string]interface{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment