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-01-30 19:36:33 -08:00
|
|
|
func RequestEcho(message string) *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Echo,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: []byte(message),
|
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestFlush() *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Flush,
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestInfo() *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Info,
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestSetOption(key string, value string) *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_SetOption,
|
2016-01-30 19:36:33 -08:00
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestAppendTx(txBytes []byte) *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_AppendTx,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: txBytes,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestCheckTx(txBytes []byte) *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_CheckTx,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: txBytes,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-02-14 13:11:06 -08:00
|
|
|
func RequestCommit() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-02-14 13:11:06 -08:00
|
|
|
Type: MessageType_Commit,
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func RequestQuery(queryBytes []byte) *Request {
|
|
|
|
return &Request{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Query,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: queryBytes,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-03-05 19:18:34 -08:00
|
|
|
func RequestInitChain(validators []*Validator) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2016-03-05 19:18:34 -08:00
|
|
|
Type: MessageType_InitChain,
|
2016-02-28 19:19:29 -08:00
|
|
|
Validators: validators,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 22:35:23 -07:00
|
|
|
func RequestBeginBlock(height uint64) *Request {
|
|
|
|
return &Request{
|
|
|
|
Type: MessageType_BeginBlock,
|
|
|
|
Height: height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 17:57:47 -08:00
|
|
|
func RequestEndBlock(height uint64) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2016-03-06 17:57:47 -08:00
|
|
|
Type: MessageType_EndBlock,
|
2016-03-05 19:18:34 -08:00
|
|
|
Height: height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 07:39:53 -08:00
|
|
|
//----------------------------------------
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func ResponseException(errStr string) *Response {
|
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Exception,
|
2016-01-30 19:36:33 -08:00
|
|
|
Error: errStr,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func ResponseEcho(message string) *Response {
|
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Echo,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: []byte(message),
|
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func ResponseFlush() *Response {
|
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Flush,
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func ResponseInfo(info string) *Response {
|
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Info,
|
2016-01-30 19:36:33 -08:00
|
|
|
Data: []byte(info),
|
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
func ResponseSetOption(log string) *Response {
|
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_SetOption,
|
2016-01-30 19:36:33 -08:00
|
|
|
Log: log,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 02:50:29 -07:00
|
|
|
func ResponseAppendTx(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_AppendTx,
|
2016-01-31 20:39:43 -08:00
|
|
|
Code: code,
|
2016-03-23 02:50:29 -07:00
|
|
|
Data: data,
|
2016-01-30 19:36:33 -08:00
|
|
|
Log: log,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 02:50:29 -07:00
|
|
|
func ResponseCheckTx(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_CheckTx,
|
2016-01-31 20:39:43 -08:00
|
|
|
Code: code,
|
2016-03-23 02:50:29 -07:00
|
|
|
Data: data,
|
2016-01-30 19:36:33 -08:00
|
|
|
Log: log,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 02:50:29 -07:00
|
|
|
func ResponseCommit(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-02-14 13:11:06 -08:00
|
|
|
Type: MessageType_Commit,
|
2016-03-23 02:50:29 -07:00
|
|
|
Code: code,
|
|
|
|
Data: data,
|
2016-01-30 19:36:33 -08:00
|
|
|
Log: log,
|
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2016-03-23 02:50:29 -07:00
|
|
|
func ResponseQuery(code CodeType, data []byte, log string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-01-31 19:56:02 -08:00
|
|
|
Type: MessageType_Query,
|
2016-01-31 20:39:43 -08:00
|
|
|
Code: code,
|
2016-03-23 02:50:29 -07:00
|
|
|
Data: data,
|
2016-01-30 19:36:33 -08:00
|
|
|
Log: log,
|
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-03-05 19:18:34 -08:00
|
|
|
func ResponseInitChain() *Response {
|
|
|
|
return &Response{
|
|
|
|
Type: MessageType_InitChain,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-26 22:35:23 -07:00
|
|
|
func ResponseBeginBlock() *Response {
|
|
|
|
return &Response{
|
|
|
|
Type: MessageType_BeginBlock,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 19:18:34 -08:00
|
|
|
func ResponseEndBlock(validators []*Validator) *Response {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Response{
|
2016-03-05 19:18:34 -08:00
|
|
|
Type: MessageType_EndBlock,
|
2016-02-28 19:19:29 -08:00
|
|
|
Validators: validators,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|