You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
657 B

  1. package types
  2. import (
  3. "github.com/tendermint/go-merkle"
  4. )
  5. type Tx []byte
  6. // NOTE: this is the hash of the go-wire encoded Tx.
  7. // Tx has no types at this level, so just length-prefixed.
  8. // Maybe it should just be the hash of the bytes tho?
  9. func (tx Tx) Hash() []byte {
  10. return merkle.SimpleHashFromBinary(tx)
  11. }
  12. type Txs []Tx
  13. func (txs Txs) Hash() []byte {
  14. // Recursive impl.
  15. // Copied from go-merkle to avoid allocations
  16. switch len(txs) {
  17. case 0:
  18. return nil
  19. case 1:
  20. return txs[0].Hash()
  21. default:
  22. left := Txs(txs[:(len(txs)+1)/2]).Hash()
  23. right := Txs(txs[(len(txs)+1)/2:]).Hash()
  24. return merkle.SimpleHashFromTwoHashes(left, right)
  25. }
  26. }