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.

173 lines
3.5 KiB

9 years ago
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
9 years ago
9 years ago
  1. package types
  2. import (
  3. "io"
  4. "github.com/golang/protobuf/proto"
  5. wire "github.com/tendermint/go-wire"
  6. )
  7. func ToRequestEcho(message string) *Request {
  8. return &Request{
  9. Value: &Request_Echo{&RequestEcho{message}},
  10. }
  11. }
  12. func ToRequestFlush() *Request {
  13. return &Request{
  14. Value: &Request_Flush{&RequestFlush{}},
  15. }
  16. }
  17. func ToRequestInfo(req RequestInfo) *Request {
  18. return &Request{
  19. Value: &Request_Info{&req},
  20. }
  21. }
  22. func ToRequestSetOption(key string, value string) *Request {
  23. return &Request{
  24. Value: &Request_SetOption{&RequestSetOption{key, value}},
  25. }
  26. }
  27. func ToRequestDeliverTx(txBytes []byte) *Request {
  28. return &Request{
  29. Value: &Request_DeliverTx{&RequestDeliverTx{txBytes}},
  30. }
  31. }
  32. func ToRequestCheckTx(txBytes []byte) *Request {
  33. return &Request{
  34. Value: &Request_CheckTx{&RequestCheckTx{txBytes}},
  35. }
  36. }
  37. func ToRequestCommit() *Request {
  38. return &Request{
  39. Value: &Request_Commit{&RequestCommit{}},
  40. }
  41. }
  42. func ToRequestQuery(req RequestQuery) *Request {
  43. return &Request{
  44. Value: &Request_Query{&req},
  45. }
  46. }
  47. func ToRequestInitChain(req RequestInitChain) *Request {
  48. return &Request{
  49. Value: &Request_InitChain{&req},
  50. }
  51. }
  52. func ToRequestBeginBlock(req RequestBeginBlock) *Request {
  53. return &Request{
  54. Value: &Request_BeginBlock{&req},
  55. }
  56. }
  57. func ToRequestEndBlock(height uint64) *Request {
  58. return &Request{
  59. Value: &Request_EndBlock{&RequestEndBlock{height}},
  60. }
  61. }
  62. //----------------------------------------
  63. func ToResponseException(errStr string) *Response {
  64. return &Response{
  65. Value: &Response_Exception{&ResponseException{errStr}},
  66. }
  67. }
  68. func ToResponseEcho(message string) *Response {
  69. return &Response{
  70. Value: &Response_Echo{&ResponseEcho{message}},
  71. }
  72. }
  73. func ToResponseFlush() *Response {
  74. return &Response{
  75. Value: &Response_Flush{&ResponseFlush{}},
  76. }
  77. }
  78. func ToResponseInfo(resInfo ResponseInfo) *Response {
  79. return &Response{
  80. Value: &Response_Info{&resInfo},
  81. }
  82. }
  83. func ToResponseSetOption(log string) *Response {
  84. return &Response{
  85. Value: &Response_SetOption{&ResponseSetOption{log}},
  86. }
  87. }
  88. func ToResponseDeliverTx(code CodeType, data []byte, log string, tags []*KVPair) *Response {
  89. return &Response{
  90. Value: &Response_DeliverTx{&ResponseDeliverTx{code, data, log, tags}},
  91. }
  92. }
  93. func ToResponseCheckTx(code CodeType, data []byte, log string) *Response {
  94. return &Response{
  95. Value: &Response_CheckTx{&ResponseCheckTx{code, data, log}},
  96. }
  97. }
  98. func ToResponseCommit(code CodeType, data []byte, log string) *Response {
  99. return &Response{
  100. Value: &Response_Commit{&ResponseCommit{code, data, log}},
  101. }
  102. }
  103. func ToResponseQuery(resQuery ResponseQuery) *Response {
  104. return &Response{
  105. Value: &Response_Query{&resQuery},
  106. }
  107. }
  108. func ToResponseInitChain() *Response {
  109. return &Response{
  110. Value: &Response_InitChain{&ResponseInitChain{}},
  111. }
  112. }
  113. func ToResponseBeginBlock() *Response {
  114. return &Response{
  115. Value: &Response_BeginBlock{&ResponseBeginBlock{}},
  116. }
  117. }
  118. func ToResponseEndBlock(resEndBlock ResponseEndBlock) *Response {
  119. return &Response{
  120. Value: &Response_EndBlock{&resEndBlock},
  121. }
  122. }
  123. //----------------------------------------
  124. // Write proto message, length delimited
  125. func WriteMessage(msg proto.Message, w io.Writer) error {
  126. bz, err := proto.Marshal(msg)
  127. if err != nil {
  128. return err
  129. }
  130. var n int
  131. wire.WriteByteSlice(bz, w, &n, &err)
  132. return err
  133. }
  134. // Read proto message, length delimited
  135. func ReadMessage(r io.Reader, msg proto.Message) error {
  136. var n int
  137. var err error
  138. bz := wire.ReadByteSlice(r, 0, &n, &err)
  139. if err != nil {
  140. return err
  141. }
  142. err = proto.Unmarshal(bz, msg)
  143. return err
  144. }