2015-11-02 07:39:53 -08:00
|
|
|
package types
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
import (
|
|
|
|
"io"
|
2015-11-02 07:39:53 -08:00
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
"github.com/golang/protobuf/proto"
|
|
|
|
"github.com/tendermint/go-wire"
|
2015-11-02 07:39:53 -08:00
|
|
|
)
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestEcho(message string) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_Echo{&RequestEcho{message}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestFlush() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_Flush{&RequestFlush{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestInfo() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_Info{&RequestInfo{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestSetOption(key string, value string) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_SetOption{&RequestSetOption{key, value}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-01-12 12:27:08 -08:00
|
|
|
func ToRequestDeliverTx(txBytes []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-01-12 12:27:08 -08:00
|
|
|
Value: &Request_DeliverTx{&RequestDeliverTx{txBytes}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestCheckTx(txBytes []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_CheckTx{&RequestCheckTx{txBytes}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestCommit() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_Commit{&RequestCommit{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2017-01-23 23:42:09 -08:00
|
|
|
func ToRequestQuery(reqQuery RequestQuery) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-01-23 23:42:09 -08:00
|
|
|
Value: &Request_Query{&reqQuery},
|
2017-01-10 06:49:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:51:48 -07:00
|
|
|
func ToRequestInitChain(reqInitChain RequestInitChain) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2017-09-18 12:51:48 -07:00
|
|
|
Value: &Request_InitChain{&reqInitChain},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:51:48 -07:00
|
|
|
func ToRequestBeginBlock(reqBeginBlock RequestBeginBlock) *Request {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Request{
|
2017-09-18 12:51:48 -07:00
|
|
|
Value: &Request_BeginBlock{&reqBeginBlock},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestEndBlock(height uint64) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Request_EndBlock{&RequestEndBlock{height}},
|
2016-03-05 19:18:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 07:39:53 -08:00
|
|
|
//----------------------------------------
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseException(errStr string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_Exception{&ResponseException{errStr}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseEcho(message string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_Echo{&ResponseEcho{message}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseFlush() *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_Flush{&ResponseFlush{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2016-12-26 17:44:36 -08:00
|
|
|
func ToResponseInfo(resInfo ResponseInfo) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-01-12 12:18:38 -08:00
|
|
|
Value: &Response_Info{&resInfo},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseSetOption(log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_SetOption{&ResponseSetOption{log}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-01-12 12:27:08 -08:00
|
|
|
func ToResponseDeliverTx(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-01-12 12:27:08 -08:00
|
|
|
Value: &Response_DeliverTx{&ResponseDeliverTx{code, data, log}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseCheckTx(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_CheckTx{&ResponseCheckTx{code, data, log}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseCommit(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_Commit{&ResponseCommit{code, data, log}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2017-01-23 23:42:09 -08:00
|
|
|
func ToResponseQuery(resQuery ResponseQuery) *Response {
|
2017-01-10 06:49:26 -08:00
|
|
|
return &Response{
|
2017-01-23 23:42:09 -08:00
|
|
|
Value: &Response_Query{&resQuery},
|
2017-01-10 06:49:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseInitChain() *Response {
|
2016-03-05 19:18:34 -08:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_InitChain{&ResponseInitChain{}},
|
2016-03-05 19:18:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseBeginBlock() *Response {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Response{
|
2016-05-17 17:06:24 -07:00
|
|
|
Value: &Response_BeginBlock{&ResponseBeginBlock{}},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 22:12:32 -08:00
|
|
|
func ToResponseEndBlock(resEndBlock ResponseEndBlock) *Response {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Response{
|
2017-01-12 12:18:38 -08:00
|
|
|
Value: &Response_EndBlock{&resEndBlock},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
//----------------------------------------
|
2015-11-02 07:39:53 -08:00
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
// Write proto message, length delimited
|
|
|
|
func WriteMessage(msg proto.Message, w io.Writer) error {
|
|
|
|
bz, err := proto.Marshal(msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var n int
|
|
|
|
wire.WriteByteSlice(bz, w, &n, &err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read proto message, length delimited
|
|
|
|
func ReadMessage(r io.Reader, msg proto.Message) error {
|
|
|
|
var n int
|
|
|
|
var err error
|
|
|
|
bz := wire.ReadByteSlice(r, 0, &n, &err)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = proto.Unmarshal(bz, msg)
|
|
|
|
return err
|
|
|
|
}
|