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"
|
2017-11-09 13:52:52 -08:00
|
|
|
wire "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
|
|
|
}
|
|
|
|
|
2017-09-22 08:10:39 -07:00
|
|
|
func ToRequestInfo(req RequestInfo) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-09-22 08:10:39 -07:00
|
|
|
Value: &Request_Info{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToRequestSetOption(req RequestSetOption) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Request_SetOption{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToRequestDeliverTx(tx []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Request_DeliverTx{&RequestDeliverTx{tx}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToRequestCheckTx(tx []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Request_CheckTx{&RequestCheckTx{tx}},
|
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-09-21 21:10:13 -07:00
|
|
|
func ToRequestQuery(req RequestQuery) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-09-21 21:10:13 -07:00
|
|
|
Value: &Request_Query{&req},
|
2017-01-10 06:49:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 21:10:13 -07:00
|
|
|
func ToRequestInitChain(req RequestInitChain) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2017-09-21 21:10:13 -07:00
|
|
|
Value: &Request_InitChain{&req},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-21 21:10:13 -07:00
|
|
|
func ToRequestBeginBlock(req RequestBeginBlock) *Request {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Request{
|
2017-09-21 21:10:13 -07:00
|
|
|
Value: &Request_BeginBlock{&req},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToRequestEndBlock(req RequestEndBlock) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Request_EndBlock{&req},
|
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
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseInfo(res ResponseInfo) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_Info{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseSetOption(res ResponseSetOption) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_SetOption{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_DeliverTx{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseCheckTx(res ResponseCheckTx) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_CheckTx{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseCommit(res ResponseCommit) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_Commit{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseQuery(res ResponseQuery) *Response {
|
2017-01-10 06:49:26 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_Query{&res},
|
2017-01-10 06:49:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseInitChain(res ResponseInitChain) *Response {
|
2016-03-05 19:18:34 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_InitChain{&res},
|
2016-03-05 19:18:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_BeginBlock{&res},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 11:04:21 -08:00
|
|
|
func ToResponseEndBlock(res ResponseEndBlock) *Response {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Response{
|
2017-11-27 11:04:21 -08:00
|
|
|
Value: &Response_EndBlock{&res},
|
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
|
|
|
|
}
|