"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
// 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 {
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)
}
}
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)))