Commit b76314a6 authored by lihailei's avatar lihailei

Add comment routing.

parent 473996bd
......@@ -2,6 +2,6 @@ appname = chain33_sdk
httpport = 8080
runmode = dev
autorender = false
copyrequestbody = false
copyrequestbody = true
EnableDocs = true
jrpcAddr="http://localhost:8801"
......@@ -18,23 +18,24 @@ type BlockController struct {
// URLMapping ...
func (c *BlockController) URLMapping() {
//View last block header
c.Mapping("getLastHeader", c.getLastHeader)
c.Mapping("getLastHeader", c.GetLastHeader)
//Get hash of block at height
c.Mapping("getBlockHashByHeight", c.getBlockHash)
c.Mapping("getBlockHashByHeight", c.GetBlockHashByHeight)
//View block info by block hash
c.Mapping("getBlockViewByHash", c.getBlockViewByHash)
c.Mapping("getBlockViewByHash", c.GetBlockViewByHash)
//Get block headers between [start, end]
c.Mapping("getBlockHeaders", c.getBlockHeaders)
c.Mapping("getBlockHeaders", c.GetBlockHeaders)
// Get block headers between [start, end]
c.Mapping("getBlockList", c.getBlockList)
c.Mapping("getBlockList", c.GetBlockList)
}
//getLastHeader...
//@Title getLastHeader
//@Description getLastHeader
//@Success 200 {block}
//@Failure 403 :
//@router [get]
func (c *BlockController) getLastHeader() {
//@Success 200 执行成功,返回block信息
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /getLastHeader [get]
func (c *BlockController) GetLastHeader() {
var res jsonrpc.Header
ctx := NewRpcCtx(GetJrpcURL(), "Chain33.GetLastHeader", nil, &res)
data, err := ctx.ReplyData()
......@@ -45,13 +46,15 @@ func (c *BlockController) getLastHeader() {
c.Ctx.ResponseWriter.Write(data)
}
}
//getLastHeader...
//@Title getLastHeader
//@Description getLastHeader
//@Success 200 {block}
//@Failure 400,403:
//getBlockHashByHeight...
//@Title getBlockHashByHeight
//@Description getBlockHashByHeight
//@Param height query int false "height"
//@Success 200 执行成功返回blockhash
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /getBlockHashByHeight [get]
func (c *BlockController) getBlockHash() {
func (c *BlockController) GetBlockHashByHeight() {
var res jsonrpc.ReplyHash
height := c.Ctx.Request.Header.Get("height")
h, err := strconv.ParseInt(height, 10, 64)
......@@ -74,10 +77,12 @@ func (c *BlockController) getBlockHash() {
//getblockViewByHash...
//@Title getblockViewByHash
//@Description getblockViewByHash
//@Success 200 {blockView}
//@Failure 400,403 :
//@router /getblockViewByHash [get]
func (c *BlockController) getBlockViewByHash() {
//@Success 200 执行成功返回blockView
//@Param blockHash query string "blockHash"
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /getBlockViewByHash [get]
func (c *BlockController) GetBlockViewByHash() {
blockHash := c.Ctx.Request.Header.Get("blockHash")
if blockHash == "" {
c.Ctx.ResponseWriter.WriteHeader(400)
......@@ -99,10 +104,14 @@ func (c *BlockController) getBlockViewByHash() {
//getblockHeaders...
//@Title getblockHeaders
//@Description getblockHeaders
//@Success 200 {blockHeader}
//@Failure 400,403 :
//@Param startH query int false "startH"
//@Param endH query int false "endH"
//@Param detail query bool false "detail"
//@Success 200 执行成功,返回blockHeader
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /getBlockHeaders [get]
func (c *BlockController) getBlockHeaders() {
func (c *BlockController) GetBlockHeaders() {
startH, errS := strconv.ParseInt(c.Ctx.Request.Header.Get("startH"), 10, 64)
endH, errE := strconv.ParseInt(c.Ctx.Request.Header.Get("endH"), 10, 64)
isDetail, errD := strconv.ParseBool(c.Ctx.Request.Header.Get("detail"))
......@@ -128,10 +137,14 @@ func (c *BlockController) getBlockHeaders() {
//getblockList...
//@Title getblockList
//@Description getblockList
//@Success 200 {blockList}
//@Failure 400,403 :
//@Param startH query int false "startH"
//@Param endH query int false "endH"
//@Param detail query bool false "detail"
//@Success 200 执行成功,返回blockList
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /getBlockList [get]
func (c *BlockController) getBlockList() {
func (c *BlockController) GetBlockList() {
startH, errS := strconv.ParseInt(c.Ctx.Request.Header.Get("startH"), 10, 64)
endH, errE := strconv.ParseInt(c.Ctx.Request.Header.Get("endH"), 10, 64)
......
......@@ -16,11 +16,11 @@ func (c *PeerController) URLMapping() {
c.Mapping("getPeers", c.GetPeers)
}
//GetOne ...
//@Title GetPeers
//@Description get Peers
//@Success 200 {object} models.Peer
//@Failure 403 :
//@Success 200 执行成功,返回节点信息
//@Failure 403 Forbidden禁止执行
//@router /getPeers [get]
func (c *PeerController) GetPeers() {
var res jsonrpc.PeerList
......
......@@ -24,9 +24,12 @@ func (c *TxController) URLMapping() {
}
//queryTxByHash...
//@Title queryTxByHash
//@Param hash query string false "hash"
//@Param isRawHex query bool false "isRawHex"
//@Description queryTxByHash
//@Success 200 {TX}
//@Failure 400,403 :
//@Success 200 执行成功,返回交易信息
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
//@router /queryTxByHash [get]
func (c *TxController) QueryTxByHash() {
hash := c.Ctx.Request.Header.Get("hash")
......@@ -52,10 +55,17 @@ func (c *TxController) QueryTxByHash() {
//queryTxByAddr...
//@Title queryTxByAddr
//@Description queryTxByAddr
//@Success 200 {TX}
//@Failure 400,403 :
//@router /queryTxByAddr [get]
//@Description queryTxByAddr 把参数以json格式,送给body体进行传入
//@Param Addr query string false "addr"
//@Param Flag query bool false "flag"
//@Param Count query int false "count"
//@Param Direction query string false direction"
//@Param Height query int false "height"
//@Param Index query int false "index"
//@Success 200 执行成功返回交易信息
//@Failure 403 Forbidden禁止执行
//@Failure 400 传入参数有误
// @router /queryTxByAddr [get]
func (c *TxController) QueryTxByAddr() {
var params types.ReqAddr
body,_:= ioutil.ReadAll(c.Ctx.Request.Body)
......
This diff is collapsed.
......@@ -11,7 +11,7 @@ import (
"gitlab.33.cn/lihailei/chain33_sdk/controllers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
//"github.com/astaxie/beego/context"
)
func init() {
......@@ -32,15 +32,13 @@ func init() {
),
),
)
ns.Filter("before", func(ctx *context.Context) {
//_, ok := ctx.Input.Session("uid").(int)
//if !ok && ctx.Request.RequestURI != "/login" {
// ctx.Redirect(302, "/login")
// }
ctx.Request.Header.Set("privateKey", "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944")
})
//ns.Filter("before", func(ctx *context.Context) {
// //_, ok := ctx.Input.Session("uid").(int)
// //if !ok && ctx.Request.RequestURI != "/login" {
// // ctx.Redirect(302, "/login")
// // }
// ctx.Request.Header.Set("privateKey", "CC38546E9E659D15E6B4893F0AB32A06D103931A8230B0BDE71459D2B27D6944")
//})
beego.AddNamespace(ns)
//beego.Router("/v1/peer",&controllers.PeerController{},)
//beego.Router("/v1/block",&controllers.BlockController{})
//beego.Router("/v1/tx",&controllers.TxController{})
//beego.Include(&controllers.PeerController{},&controllers.BlockController{},&controllers.TxController{})
}
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