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-14 00:09:47 -07:00
|
|
|
Requests: &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-13 23:22:32 -07:00
|
|
|
Requests: &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-13 23:22:32 -07:00
|
|
|
Requests: &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-13 23:22:32 -07:00
|
|
|
Requests: &Request_SetOption{&RequestSetOption{key, value}},
|
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 ToRequestAppendTx(txBytes []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-13 23:22:32 -07:00
|
|
|
Requests: &Request_AppendTx{&RequestAppendTx{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-13 23:22:32 -07:00
|
|
|
Requests: &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-13 23:22:32 -07:00
|
|
|
Requests: &Request_Commit{&RequestCommit{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestQuery(queryBytes []byte) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-13 23:22:32 -07:00
|
|
|
Requests: &Request_Query{&RequestQuery{queryBytes}},
|
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 ToRequestInitChain(validators []*Validator) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2016-05-13 23:22:32 -07:00
|
|
|
Requests: &Request_InitChain{&RequestInitChain{validators}},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToRequestBeginBlock(height uint64) *Request {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Request{
|
2016-05-13 23:22:32 -07:00
|
|
|
Requests: &Request_BeginBlock{&RequestBeginBlock{height}},
|
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-13 23:22:32 -07:00
|
|
|
Requests: &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-13 23:22:32 -07:00
|
|
|
Responses: &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-13 23:22:32 -07:00
|
|
|
Responses: &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-13 23:22:32 -07:00
|
|
|
Responses: &Response_Flush{&ResponseFlush{}},
|
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 ToResponseInfo(info string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-13 23:22:32 -07:00
|
|
|
Responses: &Response_Info{&ResponseInfo{info}},
|
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-13 23:22:32 -07:00
|
|
|
Responses: &Response_SetOption{&ResponseSetOption{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 ToResponseAppendTx(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-13 23:22:32 -07:00
|
|
|
Responses: &Response_AppendTx{&ResponseAppendTx{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-13 23:22:32 -07:00
|
|
|
Responses: &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-13 23:22:32 -07:00
|
|
|
Responses: &Response_Commit{&ResponseCommit{code, data, log}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseQuery(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-13 23:22:32 -07:00
|
|
|
Responses: &Response_Query{&ResponseQuery{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 ToResponseInitChain() *Response {
|
2016-03-05 19:18:34 -08:00
|
|
|
return &Response{
|
2016-05-13 23:22:32 -07:00
|
|
|
Responses: &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-13 23:22:32 -07:00
|
|
|
Responses: &Response_BeginBlock{&ResponseBeginBlock{}},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:22:32 -07:00
|
|
|
func ToResponseEndBlock(validators []*Validator) *Response {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Response{
|
2016-05-13 23:22:32 -07:00
|
|
|
Responses: &Response_EndBlock{&ResponseEndBlock{validators}},
|
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
|
|
|
|
}
|