OSDN Git Service

Use best block for default in /get-hash-rate (#1243)
authorHAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Mon, 13 Aug 2018 03:22:59 +0000 (11:22 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 13 Aug 2018 03:22:59 +0000 (11:22 +0800)
* Use best block for default in /get-hash-rate

* minor

api/block_retrieve.go
api/miner.go

index 77e0cb2..9b43b76 100644 (file)
@@ -182,10 +182,13 @@ type getHashRateResp struct {
 }
 
 func (a *API) getHashRate(ins BlockReq) Response {
-       if len(ins.BlockHash) != 32 && ins.BlockHeight == 0 {
-               err := errors.New("Request format error.")
+       if len(ins.BlockHash) != 32 && len(ins.BlockHash) != 0 {
+               err := errors.New("Block hash format error.")
                return NewErrorResponse(err)
        }
+       if ins.BlockHeight == 0 {
+               ins.BlockHeight = a.chain.BestBlockHeight()
+       }
 
        block, err := a.getBlockHelper(ins)
        if err != nil {
index 6c300e4..988456e 100644 (file)
@@ -18,7 +18,7 @@ type BlockHeaderJSON struct {
        Timestamp         uint64                 `json:"timestamp"`           // The time of the block in seconds.
        Nonce             uint64                 `json:"nonce"`               // Nonce used to generate the block.
        Bits              uint64                 `json:"bits"`                // Difficulty target for the block.
-       BlockCommitment   *types.BlockCommitment `json:"block_commitment"`    //Block commitment
+       BlockCommitment   *types.BlockCommitment `json:"block_commitment"`    // Block commitment
 }
 
 type CoinbaseArbitrary struct {