• R/O
  • HTTP
  • SSH
  • HTTPS

vapor: Commit

Golang implemented sidechain for Bytom


Commit MetaInfo

Revision2d31faaf45b7ec5179ec0b21cfd9e3541041cba7 (tree)
Time2019-08-21 18:02:24
Authoriczc <iczcalan@gmai...>
CommiterPaladz

Log Message

add list chains api (#389)

* add list chains api

* adding json tag to chain struct

Change Summary

Incremental Difference

--- a/toolbar/federation/api/handler.go
+++ b/toolbar/federation/api/handler.go
@@ -57,3 +57,12 @@ func (s *Server) ListCrosschainTxs(c *gin.Context, listTxsReq *listCrosschainTxs
5757
5858 return ormTxs, nil
5959 }
60+
61+func (s *Server) ListChains(c *gin.Context) ([]*orm.Chain, error) {
62+ var chains []*orm.Chain
63+ if err := s.db.Find(&chains).Error; err != nil {
64+ return nil, err
65+ }
66+
67+ return chains, nil
68+}
--- a/toolbar/federation/api/server.go
+++ b/toolbar/federation/api/server.go
@@ -37,6 +37,7 @@ func (server *Server) setupRouter() {
3737
3838 v1 := r.Group("/api/v1")
3939 v1.POST("/federation/list-crosschain-txs", handlerMiddleware(server.ListCrosschainTxs))
40+ v1.GET("/federation/list-chains", handlerMiddleware(server.ListChains))
4041
4142 server.engine = r
4243 }
--- a/toolbar/federation/database/orm/chain.go
+++ b/toolbar/federation/database/orm/chain.go
@@ -5,10 +5,10 @@ import (
55 )
66
77 type Chain struct {
8- ID uint64 `gorm:"primary_key"`
9- Name string
10- BlockHeight uint64
11- BlockHash string
12- CreatedAt types.Timestamp
13- UpdatedAt types.Timestamp
8+ ID uint64 `gorm:"primary_key" json:"-"`
9+ Name string `json:"name"`
10+ BlockHeight uint64 `json:"block_height"`
11+ BlockHash string `json:"block_hash"`
12+ CreatedAt types.Timestamp `json:"-"`
13+ UpdatedAt types.Timestamp `json:"-"`
1414 }
Show on old repository browser