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.

170 lines
4.3 KiB

  1. package types
  2. import cmn "github.com/tendermint/tmlibs/common"
  3. // nondeterministic
  4. type ResultException struct {
  5. Error string `json:"error,omitempty"`
  6. }
  7. type ResultEcho struct {
  8. Message string `json:"message,omitempty"`
  9. }
  10. type ResultFlush struct {
  11. }
  12. type ResultInfo struct {
  13. Data string `json:"data,omitempty"`
  14. Version string `json:"version,omitempty"`
  15. LastBlockHeight int64 `json:"last_block_height,omitempty"`
  16. LastBlockAppHash []byte `json:"last_block_app_hash,omitempty"`
  17. }
  18. func FromResultInfo(res ResultInfo) ResponseInfo {
  19. return ResponseInfo(res)
  20. }
  21. type ResultSetOption struct {
  22. Code uint32 `json:"code,omitempty"`
  23. // bytes data = 2;
  24. Log string `json:"log,omitempty"`
  25. Info string `json:"info,omitempty"`
  26. }
  27. func FromResultSetOption(res ResultSetOption) ResponseSetOption {
  28. return ResponseSetOption(res)
  29. }
  30. type ResultInitChain struct {
  31. Validators []Validator `json:"validators"`
  32. }
  33. func FromResultInitChain(res ResultInitChain) ResponseInitChain {
  34. vals := valsToPointers(res.Validators)
  35. return ResponseInitChain{
  36. Validators: vals,
  37. }
  38. }
  39. type ResultQuery struct {
  40. Code uint32 `json:"code,omitempty"`
  41. // bytes data = 2; // use "value" instead.
  42. Log string `json:"log,omitempty"`
  43. Info string `json:"info,omitempty"`
  44. Index int64 `json:"index,omitempty"`
  45. Key []byte `json:"key,omitempty"`
  46. Value []byte `json:"value,omitempty"`
  47. Proof []byte `json:"proof,omitempty"`
  48. Height int64 `json:"height,omitempty"`
  49. }
  50. func FromResultQuery(res ResultQuery) ResponseQuery {
  51. return ResponseQuery(res)
  52. }
  53. type ResultBeginBlock struct {
  54. Tags []cmn.KVPair `json:"tags,omitempty"`
  55. }
  56. func FromResultBeginBlock(res ResultBeginBlock) ResponseBeginBlock {
  57. tags := tagsToPointers(res.Tags)
  58. return ResponseBeginBlock{
  59. Tags: tags,
  60. }
  61. }
  62. type ResultCheckTx struct {
  63. Code uint32 `json:"code,omitempty"`
  64. Data []byte `json:"data,omitempty"`
  65. Log string `json:"log,omitempty"`
  66. Info string `json:"info,omitempty"`
  67. GasWanted int64 `json:"gas_wanted,omitempty"`
  68. GasUsed int64 `json:"gas_used,omitempty"`
  69. Tags []cmn.KVPair `json:"tags,omitempty"`
  70. Fee cmn.KI64Pair `json:"fee"`
  71. }
  72. func FromResultCheckTx(res ResultCheckTx) ResponseCheckTx {
  73. tags := tagsToPointers(res.Tags)
  74. return ResponseCheckTx{
  75. Code: res.Code,
  76. Data: res.Data,
  77. Log: res.Log,
  78. Info: res.Info,
  79. GasWanted: res.GasWanted,
  80. GasUsed: res.GasUsed,
  81. Tags: tags,
  82. Fee: &res.Fee,
  83. }
  84. }
  85. type ResultDeliverTx struct {
  86. Code uint32 `json:"code,omitempty"`
  87. Data []byte `json:"data,omitempty"`
  88. Log string `json:"log,omitempty"`
  89. Info string `json:"info,omitempty"`
  90. GasWanted int64 `json:"gas_wanted,omitempty"`
  91. GasUsed int64 `json:"gas_used,omitempty"`
  92. Tags []cmn.KVPair `json:"tags,omitempty"`
  93. Fee cmn.KI64Pair `json:"fee"`
  94. }
  95. func FromResultDeliverTx(res ResultDeliverTx) ResponseDeliverTx {
  96. tags := tagsToPointers(res.Tags)
  97. return ResponseDeliverTx{
  98. Code: res.Code,
  99. Data: res.Data,
  100. Log: res.Log,
  101. Info: res.Info,
  102. GasWanted: res.GasWanted,
  103. GasUsed: res.GasUsed,
  104. Tags: tags,
  105. Fee: &res.Fee,
  106. }
  107. }
  108. type ResultEndBlock struct {
  109. ValidatorUpdates []Validator `json:"validator_updates"`
  110. ConsensusParamUpdates *ConsensusParams `json:"consensus_param_updates,omitempty"`
  111. Tags []cmn.KVPair `json:"tags,omitempty"`
  112. }
  113. func FromResultEndBlock(res ResultEndBlock) ResponseEndBlock {
  114. tags := tagsToPointers(res.Tags)
  115. vals := valsToPointers(res.ValidatorUpdates)
  116. return ResponseEndBlock{
  117. ValidatorUpdates: vals,
  118. ConsensusParamUpdates: res.ConsensusParamUpdates,
  119. Tags: tags,
  120. }
  121. }
  122. type ResultCommit struct {
  123. // reserve 1
  124. Data []byte `json:"data,omitempty"`
  125. }
  126. func FromResultCommit(res ResultCommit) ResponseCommit {
  127. return ResponseCommit(res)
  128. }
  129. //-------------------------------------------------------
  130. func tagsToPointers(tags []cmn.KVPair) []*cmn.KVPair {
  131. tagPtrs := make([]*cmn.KVPair, len(tags))
  132. for i := 0; i < len(tags); i++ {
  133. t := tags[i]
  134. tagPtrs[i] = &t
  135. }
  136. return tagPtrs
  137. }
  138. func valsToPointers(vals []Validator) []*Validator {
  139. valPtrs := make([]*Validator, len(vals))
  140. for i := 0; i < len(vals); i++ {
  141. v := vals[i]
  142. valPtrs[i] = &v
  143. }
  144. return valPtrs
  145. }