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.

66 lines
1.6 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. package types
  2. import (
  3. abci "github.com/tendermint/abci/types"
  4. wire "github.com/tendermint/go-wire"
  5. cmn "github.com/tendermint/tmlibs/common"
  6. "github.com/tendermint/tmlibs/merkle"
  7. )
  8. //-----------------------------------------------------------------------------
  9. // ABCIResult is the deterministic component of a ResponseDeliverTx.
  10. // TODO: add Tags
  11. type ABCIResult struct {
  12. Code uint32 `json:"code"`
  13. Data cmn.HexBytes `json:"data"`
  14. }
  15. // Hash returns the canonical hash of the ABCIResult
  16. func (a ABCIResult) Hash() []byte {
  17. return wire.BinaryRipemd160(a)
  18. }
  19. // ABCIResults wraps the deliver tx results to return a proof
  20. type ABCIResults []ABCIResult
  21. // NewResults creates ABCIResults from ResponseDeliverTx
  22. func NewResults(del []*abci.ResponseDeliverTx) ABCIResults {
  23. res := make(ABCIResults, len(del))
  24. for i, d := range del {
  25. res[i] = NewResultFromResponse(d)
  26. }
  27. return res
  28. }
  29. func NewResultFromResponse(response *abci.ResponseDeliverTx) ABCIResult {
  30. return ABCIResult{
  31. Code: response.Code,
  32. Data: response.Data,
  33. }
  34. }
  35. // Bytes serializes the ABCIResponse using go-wire
  36. func (a ABCIResults) Bytes() []byte {
  37. return wire.BinaryBytes(a)
  38. }
  39. // Hash returns a merkle hash of all results
  40. func (a ABCIResults) Hash() []byte {
  41. return merkle.SimpleHashFromHashers(a.toHashers())
  42. }
  43. // ProveResult returns a merkle proof of one result from the set
  44. func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
  45. _, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
  46. return *proofs[i]
  47. }
  48. func (a ABCIResults) toHashers() []merkle.Hasher {
  49. l := len(a)
  50. hashers := make([]merkle.Hasher, l)
  51. for i := 0; i < l; i++ {
  52. hashers[i] = a[i]
  53. }
  54. return hashers
  55. }