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.

250 lines
5.2 KiB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. package types
  2. import (
  3. "io"
  4. "github.com/gogo/protobuf/proto"
  5. "github.com/tendermint/tendermint/internal/libs/protoio"
  6. )
  7. const (
  8. maxMsgSize = 104857600 // 100MB
  9. )
  10. // WriteMessage writes a varint length-delimited protobuf message.
  11. func WriteMessage(msg proto.Message, w io.Writer) error {
  12. protoWriter := protoio.NewDelimitedWriter(w)
  13. _, err := protoWriter.WriteMsg(msg)
  14. return err
  15. }
  16. // ReadMessage reads a varint length-delimited protobuf message.
  17. func ReadMessage(r io.Reader, msg proto.Message) error {
  18. _, err := protoio.NewDelimitedReader(r, maxMsgSize).ReadMsg(msg)
  19. return err
  20. }
  21. //----------------------------------------
  22. func ToRequestEcho(message string) *Request {
  23. return &Request{
  24. Value: &Request_Echo{&RequestEcho{Message: message}},
  25. }
  26. }
  27. func ToRequestFlush() *Request {
  28. return &Request{
  29. Value: &Request_Flush{&RequestFlush{}},
  30. }
  31. }
  32. func ToRequestInfo(req RequestInfo) *Request {
  33. return &Request{
  34. Value: &Request_Info{&req},
  35. }
  36. }
  37. func ToRequestDeliverTx(req RequestDeliverTx) *Request {
  38. return &Request{
  39. Value: &Request_DeliverTx{&req},
  40. }
  41. }
  42. func ToRequestCheckTx(req RequestCheckTx) *Request {
  43. return &Request{
  44. Value: &Request_CheckTx{&req},
  45. }
  46. }
  47. func ToRequestCommit() *Request {
  48. return &Request{
  49. Value: &Request_Commit{&RequestCommit{}},
  50. }
  51. }
  52. func ToRequestQuery(req RequestQuery) *Request {
  53. return &Request{
  54. Value: &Request_Query{&req},
  55. }
  56. }
  57. func ToRequestInitChain(req RequestInitChain) *Request {
  58. return &Request{
  59. Value: &Request_InitChain{&req},
  60. }
  61. }
  62. func ToRequestBeginBlock(req RequestBeginBlock) *Request {
  63. return &Request{
  64. Value: &Request_BeginBlock{&req},
  65. }
  66. }
  67. func ToRequestEndBlock(req RequestEndBlock) *Request {
  68. return &Request{
  69. Value: &Request_EndBlock{&req},
  70. }
  71. }
  72. func ToRequestListSnapshots(req RequestListSnapshots) *Request {
  73. return &Request{
  74. Value: &Request_ListSnapshots{&req},
  75. }
  76. }
  77. func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request {
  78. return &Request{
  79. Value: &Request_OfferSnapshot{&req},
  80. }
  81. }
  82. func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request {
  83. return &Request{
  84. Value: &Request_LoadSnapshotChunk{&req},
  85. }
  86. }
  87. func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
  88. return &Request{
  89. Value: &Request_ApplySnapshotChunk{&req},
  90. }
  91. }
  92. func ToRequestExtendVote(req RequestExtendVote) *Request {
  93. return &Request{
  94. Value: &Request_ExtendVote{&req},
  95. }
  96. }
  97. func ToRequestVerifyVoteExtension(req RequestVerifyVoteExtension) *Request {
  98. return &Request{
  99. Value: &Request_VerifyVoteExtension{&req},
  100. }
  101. }
  102. func ToRequestPrepareProposal(req RequestPrepareProposal) *Request {
  103. return &Request{
  104. Value: &Request_PrepareProposal{&req},
  105. }
  106. }
  107. func ToRequestProcessProposal(req RequestProcessProposal) *Request {
  108. return &Request{
  109. Value: &Request_ProcessProposal{&req},
  110. }
  111. }
  112. //----------------------------------------
  113. func ToResponseException(errStr string) *Response {
  114. return &Response{
  115. Value: &Response_Exception{&ResponseException{Error: errStr}},
  116. }
  117. }
  118. func ToResponseEcho(message string) *Response {
  119. return &Response{
  120. Value: &Response_Echo{&ResponseEcho{Message: message}},
  121. }
  122. }
  123. func ToResponseFlush() *Response {
  124. return &Response{
  125. Value: &Response_Flush{&ResponseFlush{}},
  126. }
  127. }
  128. func ToResponseInfo(res ResponseInfo) *Response {
  129. return &Response{
  130. Value: &Response_Info{&res},
  131. }
  132. }
  133. func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
  134. return &Response{
  135. Value: &Response_DeliverTx{&res},
  136. }
  137. }
  138. func ToResponseCheckTx(res ResponseCheckTx) *Response {
  139. return &Response{
  140. Value: &Response_CheckTx{&res},
  141. }
  142. }
  143. func ToResponseCommit(res ResponseCommit) *Response {
  144. return &Response{
  145. Value: &Response_Commit{&res},
  146. }
  147. }
  148. func ToResponseQuery(res ResponseQuery) *Response {
  149. return &Response{
  150. Value: &Response_Query{&res},
  151. }
  152. }
  153. func ToResponseInitChain(res ResponseInitChain) *Response {
  154. return &Response{
  155. Value: &Response_InitChain{&res},
  156. }
  157. }
  158. func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
  159. return &Response{
  160. Value: &Response_BeginBlock{&res},
  161. }
  162. }
  163. func ToResponseEndBlock(res ResponseEndBlock) *Response {
  164. return &Response{
  165. Value: &Response_EndBlock{&res},
  166. }
  167. }
  168. func ToResponseListSnapshots(res ResponseListSnapshots) *Response {
  169. return &Response{
  170. Value: &Response_ListSnapshots{&res},
  171. }
  172. }
  173. func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response {
  174. return &Response{
  175. Value: &Response_OfferSnapshot{&res},
  176. }
  177. }
  178. func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response {
  179. return &Response{
  180. Value: &Response_LoadSnapshotChunk{&res},
  181. }
  182. }
  183. func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
  184. return &Response{
  185. Value: &Response_ApplySnapshotChunk{&res},
  186. }
  187. }
  188. func ToResponseExtendVote(res ResponseExtendVote) *Response {
  189. return &Response{
  190. Value: &Response_ExtendVote{&res},
  191. }
  192. }
  193. func ToResponseVerifyVoteExtension(res ResponseVerifyVoteExtension) *Response {
  194. return &Response{
  195. Value: &Response_VerifyVoteExtension{&res},
  196. }
  197. }
  198. func ToResponsePrepareProposal(res ResponsePrepareProposal) *Response {
  199. return &Response{
  200. Value: &Response_PrepareProposal{&res},
  201. }
  202. }
  203. func ToResponseProcessProposal(res ResponseProcessProposal) *Response {
  204. return &Response{
  205. Value: &Response_ProcessProposal{&res},
  206. }
  207. }