OSDN Git Service

update doc (#1807)
[bytom/bytom.git] / api / block_retrieve.go
index d0f8fae..37642e2 100644 (file)
@@ -5,12 +5,12 @@ import (
 
        "gopkg.in/fatih/set.v0"
 
-       "github.com/bytom/blockchain/query"
-       "github.com/bytom/consensus/difficulty"
-       chainjson "github.com/bytom/encoding/json"
-       "github.com/bytom/errors"
-       "github.com/bytom/protocol/bc"
-       "github.com/bytom/protocol/bc/types"
+       "github.com/bytom/bytom/blockchain/query"
+       "github.com/bytom/bytom/consensus/difficulty"
+       chainjson "github.com/bytom/bytom/encoding/json"
+       "github.com/bytom/bytom/errors"
+       "github.com/bytom/bytom/protocol/bc"
+       "github.com/bytom/bytom/protocol/bc/types"
 )
 
 // return best block hash
@@ -124,7 +124,8 @@ func (a *API) getBlock(ins BlockReq) Response {
 
 // GetRawBlockResp is resp struct for getRawBlock API
 type GetRawBlockResp struct {
-       RawBlock *types.Block `json:"raw_block"`
+       RawBlock          *types.Block          `json:"raw_block"`
+       TransactionStatus *bc.TransactionStatus `json:"transaction_status"`
 }
 
 func (a *API) getRawBlock(ins BlockReq) Response {
@@ -133,7 +134,16 @@ func (a *API) getRawBlock(ins BlockReq) Response {
                return NewErrorResponse(err)
        }
 
-       resp := GetRawBlockResp{RawBlock: block}
+       blockHash := block.Hash()
+       txStatus, err := a.chain.GetTransactionStatus(&blockHash)
+       if err != nil {
+               return NewErrorResponse(err)
+       }
+
+       resp := GetRawBlockResp{
+               RawBlock:          block,
+               TransactionStatus: txStatus,
+       }
        return NewSuccessResponse(resp)
 }
 
@@ -222,6 +232,9 @@ func (a *API) getHashRate(ins BlockReq) Response {
        }
 
        diffTime := block.Timestamp - preBlock.Timestamp
+       if preBlock.Timestamp >= block.Timestamp {
+               diffTime = 1
+       }
        hashCount := difficulty.CalcWork(block.Bits)
        hashRate := new(big.Int).Div(hashCount, big.NewInt(int64(diffTime)))