chainhash: Abstract hash logic to new package. (#729)

This is mostly a backport of some of the same modifications made in
Decred along with a few additional things cleaned up.  In particular,
this updates the code to make use of the new chainhash package.

Also, since this required API changes anyways and the hash algorithm is
no longer tied specifically to SHA, all other functions throughout the
code base which had "Sha" in their name have been changed to Hash so
they are not incorrectly implying the hash algorithm.

The following is an overview of the changes:

- Remove the wire.ShaHash type
- Update all references to wire.ShaHash to the new chainhash.Hash type
- Rename the following functions and update all references:
  - wire.BlockHeader.BlockSha -> BlockHash
  - wire.MsgBlock.BlockSha -> BlockHash
  - wire.MsgBlock.TxShas -> TxHashes
  - wire.MsgTx.TxSha -> TxHash
  - blockchain.ShaHashToBig -> HashToBig
  - peer.ShaFunc -> peer.HashFunc
- Rename all variables that included sha in their name to include hash
  instead
- Update for function name changes in other dependent packages such as
  btcutil
- Update copyright dates on all modified files
- Update glide.lock file to use the required version of btcutil
This commit is contained in:
Dave Collins
2016-08-08 14:04:33 -05:00
committed by GitHub
parent b6b1e55d1e
commit bd4e64d1d4
82 changed files with 916 additions and 1150 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2013-2015 The btcsuite developers
// Copyright (c) 2013-2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
@@ -13,6 +13,7 @@ import (
"hash"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
"github.com/btcsuite/fastsha256"
"github.com/btcsuite/golangcrypto/ripemd160"
@@ -1833,7 +1834,7 @@ func opcodeHash256(op *parsedOpcode, vm *Engine) error {
return err
}
vm.dstack.PushByteArray(wire.DoubleSha256(buf))
vm.dstack.PushByteArray(chainhash.DoubleHashB(buf))
return nil
}
@@ -1934,7 +1935,7 @@ func opcodeCheckSig(op *parsedOpcode, vm *Engine) error {
var valid bool
if vm.sigCache != nil {
var sigHash wire.ShaHash
var sigHash chainhash.Hash
copy(sigHash[:], hash)
valid = vm.sigCache.Exists(sigHash, signature, pubKey)
@@ -2148,7 +2149,7 @@ func opcodeCheckMultiSig(op *parsedOpcode, vm *Engine) error {
var valid bool
if vm.sigCache != nil {
var sigHash wire.ShaHash
var sigHash chainhash.Hash
copy(sigHash[:], hash)
valid = vm.sigCache.Exists(sigHash, parsedSig, parsedPubKey)