net.CurrentBlock = bcr.blockKeeper.chainHeight
net.HighestBlock = bcr.blockKeeper.maxPeerHeight
- return resWrapper(net)
+ return NewSuccessResponse(net)
}
// return best block hash
func (bcr *BlockchainReactor) getBestBlockHash() Response {
blockHash := map[string]string{"blockHash": bcr.chain.BestBlockHash().String()}
- return resWrapper(blockHash)
+ return NewSuccessResponse(blockHash)
}
// return block header by hash
hash := bc.Hash{}
if err := hash.UnmarshalText([]byte(strHash)); err != nil {
log.WithField("error", err).Error("Error occurs when transforming string hash to hash struct")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
block, err := bcr.chain.GetBlockByHash(&hash)
if err != nil {
log.WithField("error", err).Error("Fail to get block by hash")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
bcBlock := legacy.MapBlock(block)
- return resWrapper(bcBlock.BlockHeader)
+ return NewSuccessResponse(bcBlock.BlockHeader)
}
// TxJSON is used for getting block by hash.
hash := bc.Hash{}
if err := hash.UnmarshalText([]byte(strHash)); err != nil {
log.WithField("error", err).Error("Error occurs when transforming string hash to hash struct")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
legacyBlock, err := bcr.chain.GetBlockByHash(&hash)
if err != nil {
log.WithField("error", err).Error("Fail to get block by hash")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
bcBlock := legacy.MapBlock(legacyBlock)
block.Transactions = append(block.Transactions, txJSON)
}
- return resWrapper(block)
+ return NewSuccessResponse(block)
}
// return block by height
legacyBlock, err := bcr.chain.GetBlockByHeight(height)
if err != nil {
log.WithField("error", err).Error("Fail to get block by hash")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
bcBlock := legacy.MapBlock(legacyBlock)
res.Transactions = append(res.Transactions, txJSON)
}
- return resWrapper(res)
+ return NewSuccessResponse(res)
}
// return block transactions count by hash
hash := bc.Hash{}
if err := hash.UnmarshalText([]byte(strHash)); err != nil {
log.WithField("error", err).Error("Error occurs when transforming string hash to hash struct")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
legacyBlock, err := bcr.chain.GetBlockByHash(&hash)
if err != nil {
log.WithField("error", err).Error("Fail to get block by hash")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
count := map[string]int{"count": len(legacyBlock.Transactions)}
- return resWrapper(count)
+ return NewSuccessResponse(count)
}
// return block transactions count by height
legacyBlock, err := bcr.chain.GetBlockByHeight(height)
if err != nil {
log.WithField("error", err).Error("Fail to get block by hash")
- return resWrapper(nil, err)
+ return NewErrorResponse(err)
}
count := map[string]int{"count": len(legacyBlock.Transactions)}
- return resWrapper(count)
+ return NewSuccessResponse(count)
}
// return block height
func (bcr *BlockchainReactor) blockHeight() Response {
blockHeight := map[string]uint64{"blockHeight": bcr.chain.Height()}
- return resWrapper(blockHeight)
+ return NewSuccessResponse(blockHeight)
}
// return is in mining or not
func (bcr *BlockchainReactor) isMining() Response {
IsMining := map[string]bool{"isMining": bcr.mining.IsMining()}
- return resWrapper(IsMining)
+ return NewSuccessResponse(IsMining)
}
// return gasRate
func (bcr *BlockchainReactor) gasRate() Response {
gasrate := map[string]int64{"gasRate": validation.GasRate}
- return resWrapper(gasrate)
-}
-
-// wrapper json for response
-func resWrapper(data interface{}, errWrapper ...error) Response {
- var response Response
-
- if errWrapper != nil {
- response = Response{Status: FAIL, Msg: errWrapper[0].Error()}
- } else {
- response = Response{Status: SUCCESS, Data: data}
- }
-
- return response
+ return NewSuccessResponse(gasrate)
}