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.

54 lines
1.4 KiB

  1. package types
  2. import (
  3. abci "github.com/tendermint/tendermint/abci/types"
  4. "github.com/tendermint/tendermint/crypto/merkle"
  5. )
  6. // ABCIResults wraps the deliver tx results to return a proof.
  7. type ABCIResults []*abci.ResponseDeliverTx
  8. // NewResults strips non-deterministic fields from ResponseDeliverTx responses
  9. // and returns ABCIResults.
  10. func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults {
  11. res := make(ABCIResults, len(responses))
  12. for i, d := range responses {
  13. res[i] = deterministicResponseDeliverTx(d)
  14. }
  15. return res
  16. }
  17. // Hash returns a merkle hash of all results.
  18. func (a ABCIResults) Hash() []byte {
  19. return merkle.HashFromByteSlices(a.toByteSlices())
  20. }
  21. // ProveResult returns a merkle proof of one result from the set
  22. func (a ABCIResults) ProveResult(i int) merkle.Proof {
  23. _, proofs := merkle.ProofsFromByteSlices(a.toByteSlices())
  24. return *proofs[i]
  25. }
  26. func (a ABCIResults) toByteSlices() [][]byte {
  27. l := len(a)
  28. bzs := make([][]byte, l)
  29. for i := 0; i < l; i++ {
  30. bz, err := a[i].Marshal()
  31. if err != nil {
  32. panic(err)
  33. }
  34. bzs[i] = bz
  35. }
  36. return bzs
  37. }
  38. // deterministicResponseDeliverTx strips non-deterministic fields from
  39. // ResponseDeliverTx and returns another ResponseDeliverTx.
  40. func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.ResponseDeliverTx {
  41. return &abci.ResponseDeliverTx{
  42. Code: response.Code,
  43. Data: response.Data,
  44. GasWanted: response.GasWanted,
  45. GasUsed: response.GasUsed,
  46. }
  47. }