25 lines
441 B
Go
Raw Normal View History

package types
2014-06-05 02:34:45 -07:00
2016-03-12 13:01:08 -05:00
import (
"github.com/tendermint/go-merkle"
)
2015-11-01 11:34:08 -08:00
type Tx []byte
2016-03-12 13:01:08 -05: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-04-26 22:17:13 -04:00
return merkle.SimpleHashFromBinary(txs[0])
2016-03-12 13:01:08 -05:00
default:
left := Txs(txs[:(len(txs)+1)/2]).Hash()
right := Txs(txs[(len(txs)+1)/2:]).Hash()
return merkle.SimpleHashFromTwoHashes(left, right)
}
}