From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Mon, 13 Aug 2018 03:22:59 +0000 (+0800) Subject: Use best block for default in /get-hash-rate (#1243) X-Git-Tag: v1.0.5~2^2~22 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=63f9ccd3444a3b227d508c82c5acd6655e9fa977;p=bytom%2Fbytom.git Use best block for default in /get-hash-rate (#1243) * Use best block for default in /get-hash-rate * minor --- diff --git a/api/block_retrieve.go b/api/block_retrieve.go index 77e0cb23..9b43b766 100644 --- a/api/block_retrieve.go +++ b/api/block_retrieve.go @@ -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 { diff --git a/api/miner.go b/api/miner.go index 6c300e48..988456ee 100644 --- a/api/miner.go +++ b/api/miner.go @@ -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 {