OSDN Git Service

add list chains api (#389)
authoriczc <iczcalan@gmail.com>
Wed, 21 Aug 2019 09:02:24 +0000 (17:02 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 21 Aug 2019 09:02:24 +0000 (17:02 +0800)
* add list chains api

* adding json tag to chain struct

toolbar/federation/api/handler.go
toolbar/federation/api/server.go
toolbar/federation/database/orm/chain.go

index 8c7d6c3..d8f1445 100644 (file)
@@ -57,3 +57,12 @@ func (s *Server) ListCrosschainTxs(c *gin.Context, listTxsReq *listCrosschainTxs
 
        return ormTxs, nil
 }
 
        return ormTxs, nil
 }
+
+func (s *Server) ListChains(c *gin.Context) ([]*orm.Chain, error) {
+       var chains []*orm.Chain
+       if err := s.db.Find(&chains).Error; err != nil {
+               return nil, err
+       }
+
+       return chains, nil
+}
index b99adab..2aff662 100644 (file)
@@ -37,6 +37,7 @@ func (server *Server) setupRouter() {
 
        v1 := r.Group("/api/v1")
        v1.POST("/federation/list-crosschain-txs", handlerMiddleware(server.ListCrosschainTxs))
 
        v1 := r.Group("/api/v1")
        v1.POST("/federation/list-crosschain-txs", handlerMiddleware(server.ListCrosschainTxs))
+       v1.GET("/federation/list-chains", handlerMiddleware(server.ListChains))
 
        server.engine = r
 }
 
        server.engine = r
 }
index 31f6c11..afbdbe8 100644 (file)
@@ -5,10 +5,10 @@ import (
 )
 
 type Chain struct {
 )
 
 type Chain struct {
-       ID          uint64 `gorm:"primary_key"`
-       Name        string
-       BlockHeight uint64
-       BlockHash   string
-       CreatedAt   types.Timestamp
-       UpdatedAt   types.Timestamp
+       ID          uint64          `gorm:"primary_key" json:"-"`
+       Name        string          `json:"name"`
+       BlockHeight uint64          `json:"block_height"`
+       BlockHash   string          `json:"block_hash"`
+       CreatedAt   types.Timestamp `json:"-"`
+       UpdatedAt   types.Timestamp `json:"-"`
 }
 }