Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chain33_sdk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
harrylee2015
chain33_sdk
Commits
b76314a6
Commit
b76314a6
authored
Apr 19, 2018
by
lihailei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add comment routing.
parent
473996bd
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
67 additions
and
46 deletions
+67
-46
app.conf
conf/app.conf
+1
-1
block.go
controllers/block.go
+38
-25
peer.go
controllers/peer.go
+3
-3
tx.go
controllers/tx.go
+16
-6
models.go
models/models.go
+0
-0
router.go
routers/router.go
+9
-11
No files found.
conf/app.conf
View file @
b76314a6
...
...
@@ -2,6 +2,6 @@ appname = chain33_sdk
httpport
=
8080
runmode
=
dev
autorender
=
false
copyrequestbody
=
fals
e
copyrequestbody
=
tru
e
EnableDocs
=
true
jrpcAddr
=
"http://localhost:8801"
controllers/block.go
View file @
b76314a6
...
...
@@ -18,23 +18,24 @@ type BlockController struct {
// URLMapping ...
func
(
c
*
BlockController
)
URLMapping
()
{
//View last block header
c
.
Mapping
(
"getLastHeader"
,
c
.
g
etLastHeader
)
c
.
Mapping
(
"getLastHeader"
,
c
.
G
etLastHeader
)
//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
.
g
etBlockViewByHash
)
c
.
Mapping
(
"getBlockViewByHash"
,
c
.
G
etBlockViewByHash
)
//Get block headers between [start, end]
c
.
Mapping
(
"getBlockHeaders"
,
c
.
g
etBlockHeaders
)
c
.
Mapping
(
"getBlockHeaders"
,
c
.
G
etBlockHeaders
)
// Get block headers between [start, end]
c
.
Mapping
(
"getBlockList"
,
c
.
g
etBlockList
)
c
.
Mapping
(
"getBlockList"
,
c
.
G
etBlockList
)
}
//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
)
g
etBlockHeaders
()
{
func
(
c
*
BlockController
)
G
etBlockHeaders
()
{
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
)
g
etBlockList
()
{
func
(
c
*
BlockController
)
G
etBlockList
()
{
startH
,
errS
:=
strconv
.
ParseInt
(
c
.
Ctx
.
Request
.
Header
.
Get
(
"startH"
),
10
,
64
)
endH
,
errE
:=
strconv
.
ParseInt
(
c
.
Ctx
.
Request
.
Header
.
Get
(
"endH"
),
10
,
64
)
...
...
controllers/peer.go
View file @
b76314a6
...
...
@@ -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
...
...
controllers/tx.go
View file @
b76314a6
...
...
@@ -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
)
...
...
models/models.go
0 → 100644
View file @
b76314a6
This diff is collapsed.
Click to expand it.
routers/router.go
View file @
b76314a6
...
...
@@ -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{})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment