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.

42 lines
1.0 KiB

  1. package types
  2. import (
  3. abci "github.com/tendermint/abci/types"
  4. "github.com/tendermint/go-merkle"
  5. )
  6. type Tx []byte
  7. // NOTE: this is the hash of the go-wire encoded Tx.
  8. // Tx has no types at this level, so just length-prefixed.
  9. // Alternatively, it may make sense to add types here and let
  10. // []byte be type 0x1 so we can have versioned txs if need be in the future.
  11. func (tx Tx) Hash() []byte {
  12. return merkle.SimpleHashFromBinary(tx)
  13. }
  14. type Txs []Tx
  15. func (txs Txs) Hash() []byte {
  16. // Recursive impl.
  17. // Copied from go-merkle to avoid allocations
  18. switch len(txs) {
  19. case 0:
  20. return nil
  21. case 1:
  22. return txs[0].Hash()
  23. default:
  24. left := Txs(txs[:(len(txs)+1)/2]).Hash()
  25. right := Txs(txs[(len(txs)+1)/2:]).Hash()
  26. return merkle.SimpleHashFromTwoHashes(left, right)
  27. }
  28. }
  29. // TxResult contains results of executing the transaction.
  30. //
  31. // One usage is indexing transaction results.
  32. type TxResult struct {
  33. Height uint64 `json:"height"`
  34. Index uint32 `json:"index"`
  35. DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
  36. }