tendermint/types/tx.go

33 lines
742 B
Go
Raw Normal View History

package types
2014-06-05 02:34:45 -07:00
2016-03-12 10:01:08 -08:00
import (
"github.com/tendermint/go-merkle"
)
2015-11-01 11:34:08 -08:00
type Tx []byte
2016-03-12 10:01:08 -08:00
2016-06-27 17:43:09 -07:00
// NOTE: this is the hash of the go-wire encoded Tx.
// Tx has no types at this level, so just length-prefixed.
2016-07-12 11:58:16 -07:00
// Alternatively, it may make sense to add types here and let
// []byte be type 0x1 so we can have versioned txs if need be in the future.
2016-06-27 17:43:09 -07:00
func (tx Tx) Hash() []byte {
return merkle.SimpleHashFromBinary(tx)
}
2016-03-12 10:01:08 -08:00
type Txs []Tx
func (txs Txs) Hash() []byte {
// Recursive impl.
// Copied from go-merkle to avoid allocations
switch len(txs) {
case 0:
return nil
case 1:
2016-06-27 17:43:09 -07:00
return txs[0].Hash()
2016-03-12 10:01:08 -08:00
default:
left := Txs(txs[:(len(txs)+1)/2]).Hash()
right := Txs(txs[(len(txs)+1)/2:]).Hash()
return merkle.SimpleHashFromTwoHashes(left, right)
}
}