Commit 58cc8183 authored by suyanlong's avatar suyanlong

Add two api function

parent 278041a9
Pipeline #8428 failed with stages
...@@ -37,11 +37,30 @@ func (g *Server) sendTransaction(c *gin.Context) { ...@@ -37,11 +37,30 @@ func (g *Server) sendTransaction(c *gin.Context) {
} }
// TODO // TODO
c.JSON(http.StatusOK, res) c.JSON(http.StatusOK, res)
panic("implement me") panic("implement me")
} }
// GET 127.0.0.1:80/api/QueryOuterMeta/:did
func (g *Server) QueryOuterMeta(c *gin.Context) {
did := c.Param("did")
data := g.mg.AppChain(did).QueryOuterMeta()
c.JSON(http.StatusOK, data)
}
// GET 127.0.0.1:80/api/QueryIBTP/:did/:to/:id
func (g *Server) QueryIBTP(c *gin.Context) {
id := c.Param("id")
to := c.Param("to")
did := c.Param("did")
ib, err := g.mg.AppChain(did).QueryIBTP(to, id)
if err != nil {
c.JSON(http.StatusOK, NewError(http.StatusOK, http.StatusInternalServerError, err.Error()))
} else {
c.JSON(http.StatusOK, ib)
}
}
// GET 127.0.0.1:80/api/getTransaction/:hash // GET 127.0.0.1:80/api/getTransaction/:hash
func (g *Server) getTransaction(c *gin.Context) { func (g *Server) getTransaction(c *gin.Context) {
panic("implement me") panic("implement me")
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"gitlab.33.cn/link33/sidecar/cmd/sidecar/client" "gitlab.33.cn/link33/sidecar/cmd/sidecar/client"
"gitlab.33.cn/link33/sidecar/internal/appchain"
"gitlab.33.cn/link33/sidecar/internal/repo" "gitlab.33.cn/link33/sidecar/internal/repo"
"gitlab.33.cn/link33/sidecar/internal/router" "gitlab.33.cn/link33/sidecar/internal/router"
"gitlab.33.cn/link33/sidecar/model/pb" "gitlab.33.cn/link33/sidecar/model/pb"
...@@ -30,13 +31,14 @@ type Server struct { ...@@ -30,13 +31,14 @@ type Server struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
router router.Router router router.Router
mg *appchain.Manager
} }
type response struct { type response struct {
Data []byte `json:"data"` Data []byte `json:"data"`
} }
func NewServer(config *repo.Config, router router.Router, logger logrus.FieldLogger) *Server { func NewServer(config *repo.Config, router router.Router, mg *appchain.Manager, logger logrus.FieldLogger) *Server {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
// load the casbin model and policy from files, database is also supported. // load the casbin model and policy from files, database is also supported.
...@@ -59,12 +61,15 @@ func NewServer(config *repo.Config, router router.Router, logger logrus.FieldLog ...@@ -59,12 +61,15 @@ func NewServer(config *repo.Config, router router.Router, logger logrus.FieldLog
func (g *Server) Start() error { func (g *Server) Start() error {
g.engine.Use(gin.Recovery()) g.engine.Use(gin.Recovery())
v1 := g.engine.Group("/v1") v1 := g.engine.Group("/v1/api")
// g.engine.Use(gin.Recovery()) // g.engine.Use(gin.Recovery())
{ {
v1.POST(client.RegisterAppchainUrl, g.registerAppchain) v1.POST(client.RegisterAppchainUrl, g.registerAppchain)
v1.POST(client.UpdateAppchainUrl, g.updateAppchain) v1.POST(client.UpdateAppchainUrl, g.updateAppchain)
v1.GET(client.GetAppchainUrl, g.getAppchain) v1.GET(client.GetAppchainUrl, g.getAppchain)
v1.GET("/QueryOuterMeta/:did", g.QueryOuterMeta)
v1.GET("/QueryIBTP/:did/:to/:id", g.QueryIBTP)
} }
go func() { go func() {
......
...@@ -18,6 +18,8 @@ const ( ...@@ -18,6 +18,8 @@ const (
AuditAppchainUrl = "appchain/audit" AuditAppchainUrl = "appchain/audit"
GetAppchainUrl = "appchain/get" GetAppchainUrl = "appchain/get"
RegisterRuleUrl = "rule/register" RegisterRuleUrl = "rule/register"
QueryOuterMeta = "QueryOuterMeta"
QueryIBTP = "QueryIBTP"
) )
func httpGet(url string) ([]byte, error) { func httpGet(url string) ([]byte, error) {
......
...@@ -68,7 +68,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error) ...@@ -68,7 +68,7 @@ func NewSidecar(repoRoot string, config *repo.Config) (internal.Launcher, error)
r.Adds(managerPort.Ports()) r.Adds(managerPort.Ports())
tool.Asset(err) tool.Asset(err)
apiServer := api.NewServer(config, r, loggers.Logger(loggers.ApiServer)) apiServer := api.NewServer(config, r, managerPort, loggers.Logger(loggers.ApiServer))
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
return &App{ return &App{
storage: store, storage: store,
......
...@@ -47,11 +47,11 @@ func newAppchain(ctx context.Context, client plugins.Client, cryptor txcrypto.Cr ...@@ -47,11 +47,11 @@ func newAppchain(ctx context.Context, client plugins.Client, cryptor txcrypto.Cr
} }
} }
func newAppchains(ctx context.Context, clients []plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) []*appChain { func newAppchains(ctx context.Context, clients []plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) map[string]*appChain {
var ps []*appChain ps := make(map[string]*appChain)
for _, c := range clients { for _, c := range clients {
p := newAppchain(ctx, c, cryptor, logger) p := newAppchain(ctx, c, cryptor, logger)
ps = append(ps, p) ps[p.ID()] = p
} }
return ps return ps
......
...@@ -15,7 +15,7 @@ type Manager struct { ...@@ -15,7 +15,7 @@ type Manager struct {
ctx context.Context ctx context.Context
cancel context.CancelFunc cancel context.CancelFunc
g *tool.Group g *tool.Group
appChains []*appChain appChains map[string]*appChain
} }
func NewManager(clients []plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) *Manager { func NewManager(clients []plugins.Client, cryptor txcrypto.Cryptor, logger logrus.FieldLogger) *Manager {
...@@ -57,3 +57,7 @@ func (m *Manager) Ports() []port.Port { ...@@ -57,3 +57,7 @@ func (m *Manager) Ports() []port.Port {
} }
return ports return ports
} }
func (m *Manager) AppChain(id string) AppChain {
return m.appChains[id]
}
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