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.

70 lines
1.7 KiB

7 years ago
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/tendermint/abci/types"
  4. cmn "github.com/tendermint/tmlibs/common"
  5. "github.com/tendermint/tmlibs/merkle"
  6. )
  7. //-----------------------------------------------------------------------------
  8. // ABCIResult is the deterministic component of a ResponseDeliverTx.
  9. // TODO: add Tags
  10. type ABCIResult struct {
  11. Code uint32 `json:"code"`
  12. Data cmn.HexBytes `json:"data"`
  13. }
  14. // Hash returns the canonical hash of the ABCIResult
  15. func (a ABCIResult) Hash() []byte {
  16. bz := aminoHash(a)
  17. return bz
  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 wire
  36. func (a ABCIResults) Bytes() []byte {
  37. bz, err := cdc.MarshalBinary(a)
  38. if err != nil {
  39. panic(err)
  40. }
  41. return bz
  42. }
  43. // Hash returns a merkle hash of all results
  44. func (a ABCIResults) Hash() []byte {
  45. return merkle.SimpleHashFromHashers(a.toHashers())
  46. }
  47. // ProveResult returns a merkle proof of one result from the set
  48. func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
  49. _, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
  50. return *proofs[i]
  51. }
  52. func (a ABCIResults) toHashers() []merkle.Hasher {
  53. l := len(a)
  54. hashers := make([]merkle.Hasher, l)
  55. for i := 0; i < l; i++ {
  56. hashers[i] = a[i]
  57. }
  58. return hashers
  59. }