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.

32 lines
742 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. // Alternatively, it may make sense to add types here and let
  9. // []byte be type 0x1 so we can have versioned txs if need be in the future.
  10. func (tx Tx) Hash() []byte {
  11. return merkle.SimpleHashFromBinary(tx)
  12. }
  13. type Txs []Tx
  14. func (txs Txs) Hash() []byte {
  15. // Recursive impl.
  16. // Copied from go-merkle to avoid allocations
  17. switch len(txs) {
  18. case 0:
  19. return nil
  20. case 1:
  21. return txs[0].Hash()
  22. default:
  23. left := Txs(txs[:(len(txs)+1)/2]).Hash()
  24. right := Txs(txs[(len(txs)+1)/2:]).Hash()
  25. return merkle.SimpleHashFromTwoHashes(left, right)
  26. }
  27. }