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.

72 lines
1.8 KiB

6 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. "github.com/tendermint/tendermint/crypto/merkle"
  5. cmn "github.com/tendermint/tendermint/libs/common"
  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. // NOTE: we copy the impl of the merkle tree for txs -
  46. // we should be consistent and either do it for both or not.
  47. return merkle.SimpleHashFromHashers(a.toHashers())
  48. }
  49. // ProveResult returns a merkle proof of one result from the set
  50. func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
  51. _, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
  52. return *proofs[i]
  53. }
  54. func (a ABCIResults) toHashers() []merkle.Hasher {
  55. l := len(a)
  56. hashers := make([]merkle.Hasher, l)
  57. for i := 0; i < l; i++ {
  58. hashers[i] = a[i]
  59. }
  60. return hashers
  61. }