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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
392 additions
and
46 deletions
+392
-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
+325
-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
package
models
import
(
"fmt"
"strconv"
jsonrpc
"gitlab.33.cn/chain33/chain33/rpc"
"gitlab.33.cn/chain33/chain33/types"
)
type
AccountsResult
struct
{
Wallets
[]
*
WalletResult
`json:"wallets"`
}
type
WalletResult
struct
{
Acc
*
AccountResult
`json:"acc,omitempty"`
Label
string
`json:"label,omitempty"`
}
type
AccountResult
struct
{
Currency
int32
`json:"currency,omitempty"`
Balance
string
`json:"balance,omitempty"`
Frozen
string
`json:"frozen,omitempty"`
Addr
string
`json:"addr,omitempty"`
}
type
TokenAccountResult
struct
{
Token
string
`json:"Token,omitempty"`
Currency
int32
`json:"currency,omitempty"`
Balance
string
`json:"balance,omitempty"`
Frozen
string
`json:"frozen,omitempty"`
Addr
string
`json:"addr,omitempty"`
}
type
TxListResult
struct
{
Txs
[]
*
TxResult
`json:"txs"`
}
type
TxResult
struct
{
Execer
string
`json:"execer"`
Payload
interface
{}
`json:"payload"`
RawPayload
string
`json:"rawpayload"`
Signature
*
jsonrpc
.
Signature
`json:"signature"`
Fee
string
`json:"fee"`
Expire
int64
`json:"expire"`
Nonce
int64
`json:"nonce"`
To
string
`json:"to"`
Amount
string
`json:"amount,omitempty"`
From
string
`json:"from,omitempty"`
}
type
ReceiptData
struct
{
Ty
int32
`json:"ty"`
TyName
string
`json:"tyname"`
Logs
[]
*
ReceiptLog
`json:"logs"`
}
type
ReceiptLog
struct
{
Ty
int32
`json:"ty"`
TyName
string
`json:"tyname"`
Log
interface
{}
`json:"log"`
RawLog
string
`json:"rawlog"`
}
type
ReceiptAccountTransfer
struct
{
Prev
*
AccountResult
`protobuf:"bytes,1,opt,name=prev" json:"prev,omitempty"`
Current
*
AccountResult
`protobuf:"bytes,2,opt,name=current" json:"current,omitempty"`
}
type
ReceiptExecAccountTransfer
struct
{
ExecAddr
string
`protobuf:"bytes,1,opt,name=execAddr" json:"execAddr,omitempty"`
Prev
*
AccountResult
`protobuf:"bytes,2,opt,name=prev" json:"prev,omitempty"`
Current
*
AccountResult
`protobuf:"bytes,3,opt,name=current" json:"current,omitempty"`
}
type
TxDetailResult
struct
{
Tx
*
TxResult
`json:"tx"`
Receipt
*
ReceiptData
`json:"receipt"`
Proofs
[]
string
`json:"proofs,omitempty"`
Height
int64
`json:"height"`
Index
int64
`json:"index"`
Blocktime
int64
`json:"blocktime"`
Amount
string
`json:"amount"`
Fromaddr
string
`json:"fromaddr"`
ActionName
string
`json:"actionname"`
}
type
TxDetailsResult
struct
{
Txs
[]
*
TxDetailResult
`json:"txs"`
}
type
BlockResult
struct
{
Version
int64
`json:"version"`
ParentHash
string
`json:"parenthash"`
TxHash
string
`json:"txhash"`
StateHash
string
`json:"statehash"`
Height
int64
`json:"height"`
BlockTime
int64
`json:"blocktime"`
Txs
[]
*
TxResult
`json:"txs"`
}
type
BlockDetailResult
struct
{
Block
*
BlockResult
`json:"block"`
Receipts
[]
*
ReceiptData
`json:"receipts"`
}
type
BlockDetailsResult
struct
{
Items
[]
*
BlockDetailResult
`json:"items"`
}
type
WalletTxDetailsResult
struct
{
TxDetails
[]
*
WalletTxDetailResult
`json:"txDetails"`
}
type
WalletTxDetailResult
struct
{
Tx
*
TxResult
`json:"tx"`
Receipt
*
ReceiptData
`json:"receipt"`
Height
int64
`json:"height"`
Index
int64
`json:"index"`
Blocktime
int64
`json:"blocktime"`
Amount
string
`json:"amount"`
Fromaddr
string
`json:"fromaddr"`
Txhash
string
`json:"txhash"`
ActionName
string
`json:"actionname"`
}
type
AddrOverviewResult
struct
{
Reciver
string
`json:"reciver"`
Balance
string
`json:"balance"`
TxCount
int64
`json:"txCount"`
}
type
SellOrder2Show
struct
{
Tokensymbol
string
`json:"tokensymbol"`
Seller
string
`json:"address"`
Amountperboardlot
string
`json:"amountperboardlot"`
Minboardlot
int64
`json:"minboardlot"`
Priceperboardlot
string
`json:"priceperboardlot"`
Totalboardlot
int64
`json:"totalboardlot"`
Soldboardlot
int64
`json:"soldboardlot"`
Starttime
int64
`json:"starttime"`
Stoptime
int64
`json:"stoptime"`
Crowdfund
bool
`json:"crowdfund"`
SellID
string
`json:"sellid"`
Status
string
`json:"status"`
Height
int64
`json:"height"`
}
type
ReqAddr
struct
{
Addr
string
`json:"addr,omitempty"`
Flag
int32
`json:"flag,omitempty"`
Count
int32
`json:"count,omitempty"`
Direction
int32
`json:"direction,omitempty"`
Height
int64
`json:"height,omitempty"`
Index
int64
`json:"index,omitempty"`
}
func
decodeTransaction
(
tx
*
jsonrpc
.
Transaction
)
*
TxResult
{
feeResult
:=
strconv
.
FormatFloat
(
float64
(
tx
.
Fee
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
amountResult
:=
""
if
tx
.
Amount
!=
0
{
amountResult
=
strconv
.
FormatFloat
(
float64
(
tx
.
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
}
result
:=
&
TxResult
{
Execer
:
tx
.
Execer
,
Payload
:
tx
.
Payload
,
RawPayload
:
tx
.
RawPayload
,
Signature
:
tx
.
Signature
,
Fee
:
feeResult
,
Expire
:
tx
.
Expire
,
Nonce
:
tx
.
Nonce
,
To
:
tx
.
To
,
}
payloacValue
:=
tx
.
Payload
.
(
map
[
string
]
interface
{})[
"Value"
]
.
(
map
[
string
]
interface
{})
for
_
,
e
:=
range
[
4
]
string
{
"Transfer"
,
"Withdraw"
,
"Genesis"
,
"Hlock"
}
{
if
_
,
ok
:=
payloacValue
[
e
];
ok
{
if
amtValue
,
ok
:=
result
.
Payload
.
(
map
[
string
]
interface
{})[
"Value"
]
.
(
map
[
string
]
interface
{})[
e
]
.
(
map
[
string
]
interface
{})[
"amount"
];
ok
{
amt
:=
amtValue
.
(
float64
)
/
float64
(
types
.
Coin
)
amtResult
:=
strconv
.
FormatFloat
(
amt
,
'f'
,
4
,
64
)
result
.
Payload
.
(
map
[
string
]
interface
{})[
"Value"
]
.
(
map
[
string
]
interface
{})[
e
]
.
(
map
[
string
]
interface
{})[
"amount"
]
=
amtResult
break
}
}
}
if
_
,
ok
:=
payloacValue
[
"Miner"
];
ok
{
if
rwdValue
,
ok
:=
result
.
Payload
.
(
map
[
string
]
interface
{})[
"Value"
]
.
(
map
[
string
]
interface
{})[
"Miner"
]
.
(
map
[
string
]
interface
{})[
"reward"
];
ok
{
rwd
:=
rwdValue
.
(
float64
)
/
float64
(
types
.
Coin
)
rwdResult
:=
strconv
.
FormatFloat
(
rwd
,
'f'
,
4
,
64
)
result
.
Payload
.
(
map
[
string
]
interface
{})[
"Value"
]
.
(
map
[
string
]
interface
{})[
"Miner"
]
.
(
map
[
string
]
interface
{})[
"reward"
]
=
rwdResult
}
}
if
tx
.
Amount
!=
0
{
result
.
Amount
=
amountResult
}
if
tx
.
From
!=
""
{
result
.
From
=
tx
.
From
}
return
result
}
func
decodeAccount
(
acc
*
types
.
Account
,
precision
int64
)
*
AccountResult
{
balanceResult
:=
strconv
.
FormatFloat
(
float64
(
acc
.
GetBalance
())
/
float64
(
precision
),
'f'
,
4
,
64
)
frozenResult
:=
strconv
.
FormatFloat
(
float64
(
acc
.
GetFrozen
())
/
float64
(
precision
),
'f'
,
4
,
64
)
accResult
:=
&
AccountResult
{
Addr
:
acc
.
GetAddr
(),
Currency
:
acc
.
GetCurrency
(),
Balance
:
balanceResult
,
Frozen
:
frozenResult
,
}
return
accResult
}
func
constructAccFromLog
(
l
*
jsonrpc
.
ReceiptLogResult
,
key
string
)
*
types
.
Account
{
var
cur
int32
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
key
]
.
(
map
[
string
]
interface
{})[
"currency"
];
ok
{
cur
=
int32
(
tmp
.
(
float32
))
}
var
bal
int64
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
key
]
.
(
map
[
string
]
interface
{})[
"balance"
];
ok
{
bal
=
int64
(
tmp
.
(
float64
))
}
var
fro
int64
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
key
]
.
(
map
[
string
]
interface
{})[
"frozen"
];
ok
{
fro
=
int64
(
tmp
.
(
float64
))
}
var
ad
string
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
key
]
.
(
map
[
string
]
interface
{})[
"addr"
];
ok
{
ad
=
tmp
.
(
string
)
}
return
&
types
.
Account
{
Currency
:
cur
,
Balance
:
bal
,
Frozen
:
fro
,
Addr
:
ad
,
}
}
func
decodeLog
(
rlog
jsonrpc
.
ReceiptDataResult
)
*
ReceiptData
{
rd
:=
&
ReceiptData
{
Ty
:
rlog
.
Ty
,
TyName
:
rlog
.
TyName
}
for
_
,
l
:=
range
rlog
.
Logs
{
rl
:=
&
ReceiptLog
{
Ty
:
l
.
Ty
,
TyName
:
l
.
TyName
,
RawLog
:
l
.
RawLog
}
switch
l
.
Ty
{
//case 1, 4, 111, 112, 113, 114:
case
types
.
TyLogErr
,
types
.
TyLogGenesis
,
types
.
TyLogNewTicket
,
types
.
TyLogCloseTicket
,
types
.
TyLogMinerTicket
,
types
.
TyLogTicketBind
,
types
.
TyLogPreCreateToken
,
types
.
TyLogFinishCreateToken
,
types
.
TyLogRevokeCreateToken
,
types
.
TyLogTradeSell
,
types
.
TyLogTradeBuy
,
types
.
TyLogTradeRevoke
:
rl
.
Log
=
l
.
Log
//case 2, 3, 5, 11:
case
types
.
TyLogFee
,
types
.
TyLogTransfer
,
types
.
TyLogDeposit
,
types
.
TyLogGenesisTransfer
,
types
.
TyLogTokenTransfer
,
types
.
TyLogTokenDeposit
:
rl
.
Log
=
&
ReceiptAccountTransfer
{
Prev
:
decodeAccount
(
constructAccFromLog
(
l
,
"prev"
),
types
.
Coin
),
Current
:
decodeAccount
(
constructAccFromLog
(
l
,
"current"
),
types
.
Coin
),
}
//case 6, 7, 8, 9, 10, 12:
case
types
.
TyLogExecTransfer
,
types
.
TyLogExecWithdraw
,
types
.
TyLogExecDeposit
,
types
.
TyLogExecFrozen
,
types
.
TyLogExecActive
,
types
.
TyLogGenesisDeposit
:
var
execaddr
string
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
"execaddr"
]
.
(
string
);
ok
{
execaddr
=
tmp
}
rl
.
Log
=
&
ReceiptExecAccountTransfer
{
ExecAddr
:
execaddr
,
Prev
:
decodeAccount
(
constructAccFromLog
(
l
,
"prev"
),
types
.
Coin
),
Current
:
decodeAccount
(
constructAccFromLog
(
l
,
"current"
),
types
.
Coin
),
}
case
types
.
TyLogTokenExecTransfer
,
types
.
TyLogTokenExecWithdraw
,
types
.
TyLogTokenExecDeposit
,
types
.
TyLogTokenExecFrozen
,
types
.
TyLogTokenExecActive
,
types
.
TyLogTokenGenesisTransfer
,
types
.
TyLogTokenGenesisDeposit
:
var
execaddr
string
if
tmp
,
ok
:=
l
.
Log
.
(
map
[
string
]
interface
{})[
"execaddr"
]
.
(
string
);
ok
{
execaddr
=
tmp
}
rl
.
Log
=
&
ReceiptExecAccountTransfer
{
ExecAddr
:
execaddr
,
Prev
:
decodeAccount
(
constructAccFromLog
(
l
,
"prev"
),
types
.
TokenPrecision
),
Current
:
decodeAccount
(
constructAccFromLog
(
l
,
"current"
),
types
.
TokenPrecision
),
}
default
:
fmt
.
Printf
(
"---The log with vlaue:%d is not decoded --------------------
\n
"
,
l
.
Ty
)
return
nil
}
rd
.
Logs
=
append
(
rd
.
Logs
,
rl
)
}
return
rd
}
func
ParseBlockDetail
(
res
interface
{})
(
interface
{},
error
)
{
var
result
BlockDetailsResult
for
_
,
vItem
:=
range
res
.
(
*
jsonrpc
.
BlockDetails
)
.
Items
{
b
:=
&
BlockResult
{
Version
:
vItem
.
Block
.
Version
,
ParentHash
:
vItem
.
Block
.
ParentHash
,
TxHash
:
vItem
.
Block
.
TxHash
,
StateHash
:
vItem
.
Block
.
StateHash
,
Height
:
vItem
.
Block
.
Height
,
BlockTime
:
vItem
.
Block
.
BlockTime
,
}
for
_
,
vTx
:=
range
vItem
.
Block
.
Txs
{
b
.
Txs
=
append
(
b
.
Txs
,
decodeTransaction
(
vTx
))
}
var
rpt
[]
*
ReceiptData
for
_
,
vR
:=
range
vItem
.
Receipts
{
rpt
=
append
(
rpt
,
decodeLog
(
*
vR
))
}
bd
:=
&
BlockDetailResult
{
Block
:
b
,
Receipts
:
rpt
}
result
.
Items
=
append
(
result
.
Items
,
bd
)
}
return
result
,
nil
}
func
ParseQueryTxRes
(
arg
interface
{})
(
interface
{},
error
)
{
res
:=
arg
.
(
*
jsonrpc
.
TransactionDetail
)
amountResult
:=
strconv
.
FormatFloat
(
float64
(
res
.
Amount
)
/
float64
(
types
.
Coin
),
'f'
,
4
,
64
)
result
:=
TxDetailResult
{
Tx
:
decodeTransaction
(
res
.
Tx
),
Receipt
:
decodeLog
(
*
(
res
.
Receipt
)),
Proofs
:
res
.
Proofs
,
Height
:
res
.
Height
,
Index
:
res
.
Index
,
Blocktime
:
res
.
Blocktime
,
Amount
:
amountResult
,
Fromaddr
:
res
.
Fromaddr
,
ActionName
:
res
.
ActionName
,
}
return
result
,
nil
}
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