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.

73 lines
1.9 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. "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 the list of ResponseDeliverTx.
  22. func NewResults(responses []*abci.ResponseDeliverTx) ABCIResults {
  23. res := make(ABCIResults, len(responses))
  24. for i, d := range responses {
  25. res[i] = NewResultFromResponse(d)
  26. }
  27. return res
  28. }
  29. // NewResultFromResponse creates ABCIResult from ResponseDeliverTx.
  30. func NewResultFromResponse(response *abci.ResponseDeliverTx) ABCIResult {
  31. return ABCIResult{
  32. Code: response.Code,
  33. Data: response.Data,
  34. }
  35. }
  36. // Bytes serializes the ABCIResponse using wire
  37. func (a ABCIResults) Bytes() []byte {
  38. bz, err := cdc.MarshalBinary(a)
  39. if err != nil {
  40. panic(err)
  41. }
  42. return bz
  43. }
  44. // Hash returns a merkle hash of all results
  45. func (a ABCIResults) Hash() []byte {
  46. // NOTE: we copy the impl of the merkle tree for txs -
  47. // we should be consistent and either do it for both or not.
  48. return merkle.SimpleHashFromHashers(a.toHashers())
  49. }
  50. // ProveResult returns a merkle proof of one result from the set
  51. func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
  52. _, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
  53. return *proofs[i]
  54. }
  55. func (a ABCIResults) toHashers() []merkle.Hasher {
  56. l := len(a)
  57. hashers := make([]merkle.Hasher, l)
  58. for i := 0; i < l; i++ {
  59. hashers[i] = a[i]
  60. }
  61. return hashers
  62. }