2015-11-02 07:39:53 -08:00
|
|
|
package types
|
|
|
|
|
2016-01-30 19:36:33 -08:00
|
|
|
import (
|
2018-01-14 18:37:59 -05:00
|
|
|
"bufio"
|
|
|
|
"encoding/binary"
|
2016-01-30 19:36:33 -08:00
|
|
|
"io"
|
2015-11-02 07:39:53 -08:00
|
|
|
|
2018-05-31 21:45:14 -04:00
|
|
|
"github.com/gogo/protobuf/proto"
|
2015-11-02 07:39:53 -08:00
|
|
|
)
|
|
|
|
|
2018-01-14 18:37:59 -05:00
|
|
|
const (
|
|
|
|
maxMsgSize = 104857600 // 100MB
|
|
|
|
)
|
|
|
|
|
|
|
|
// WriteMessage writes a varint length-delimited protobuf message.
|
2017-12-01 01:05:13 -05:00
|
|
|
func WriteMessage(msg proto.Message, w io.Writer) error {
|
|
|
|
bz, err := proto.Marshal(msg)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-03 02:39:34 -05:00
|
|
|
return encodeByteSlice(w, bz)
|
2017-12-01 01:05:13 -05:00
|
|
|
}
|
|
|
|
|
2018-01-14 18:37:59 -05:00
|
|
|
// ReadMessage reads a varint length-delimited protobuf message.
|
2017-12-01 01:05:13 -05:00
|
|
|
func ReadMessage(r io.Reader, msg proto.Message) error {
|
2018-01-14 18:37:59 -05:00
|
|
|
return readProtoMsg(r, msg, maxMsgSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func readProtoMsg(r io.Reader, msg proto.Message, maxSize int) error {
|
2018-05-31 21:45:14 -04:00
|
|
|
// binary.ReadVarint takes an io.ByteReader, eg. a bufio.Reader
|
2018-02-03 00:24:48 -05:00
|
|
|
reader, ok := r.(*bufio.Reader)
|
|
|
|
if !ok {
|
|
|
|
reader = bufio.NewReader(r)
|
|
|
|
}
|
2018-05-31 21:45:14 -04:00
|
|
|
length64, err := binary.ReadVarint(reader)
|
2017-12-01 01:05:13 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-01-14 18:37:59 -05:00
|
|
|
length := int(length64)
|
|
|
|
if length < 0 || length > maxSize {
|
|
|
|
return io.ErrShortBuffer
|
|
|
|
}
|
|
|
|
buf := make([]byte, length)
|
|
|
|
if _, err := io.ReadFull(reader, buf); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return proto.Unmarshal(buf, msg)
|
2017-12-01 01:05:13 -05:00
|
|
|
}
|
|
|
|
|
2018-02-03 02:39:34 -05:00
|
|
|
//-----------------------------------------------------------------------
|
2018-05-31 21:45:14 -04:00
|
|
|
// NOTE: we copied wire.EncodeByteSlice from go-wire rather than keep
|
|
|
|
// go-wire as a dep
|
2018-02-03 02:39:34 -05:00
|
|
|
|
|
|
|
func encodeByteSlice(w io.Writer, bz []byte) (err error) {
|
2018-05-31 21:45:14 -04:00
|
|
|
err = encodeVarint(w, int64(len(bz)))
|
2018-02-03 02:39:34 -05:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = w.Write(bz)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-05-31 21:45:14 -04:00
|
|
|
func encodeVarint(w io.Writer, i int64) (err error) {
|
2018-02-03 02:39:34 -05:00
|
|
|
var buf [10]byte
|
2018-05-31 21:45:14 -04:00
|
|
|
n := binary.PutVarint(buf[:], i)
|
2018-02-03 02:39:34 -05:00
|
|
|
_, err = w.Write(buf[0:n])
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-12-01 01:05:13 -05:00
|
|
|
//----------------------------------------
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToRequestEcho(message string) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2018-07-27 06:23:19 +04:00
|
|
|
Value: &Request_Echo{&RequestEcho{Message: message}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToRequestFlush() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 20:06:24 -04:00
|
|
|
Value: &Request_Flush{&RequestFlush{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2017-09-22 11:10:39 -04:00
|
|
|
func ToRequestInfo(req RequestInfo) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-09-22 11:10:39 -04:00
|
|
|
Value: &Request_Info{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToRequestSetOption(req RequestSetOption) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Request_SetOption{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
abci: Refactor CheckTx to notify of recheck (#3744)
As per #2127, this refactors the RequestCheckTx ProtoBuf struct to allow for a flag indicating whether a query is a recheck or not (and allows for possible future, more nuanced states).
In order to pass this extended information through to the ABCI app, the proxy.AppConnMempool (and, for consistency, the proxy.AppConnConsensus) interface seems to need to be refactored along with abcicli.Client.
And, as per this comment, I've made the following modification to the protobuf definition for the RequestCheckTx structure:
enum CheckTxType {
New = 0;
Recheck = 1;
}
message RequestCheckTx {
bytes tx = 1;
CheckTxType type = 2;
}
* Refactor ABCI CheckTx to notify of recheck
As per #2127, this refactors the `RequestCheckTx` ProtoBuf struct to allow for:
1. a flag indicating whether a query is a recheck or not (and allows for
possible future, more nuanced states)
2. an `additional_data` bytes array to provide information for those more
nuanced states.
In order to pass this extended information through to the ABCI app, the
`proxy.AppConnMempool` (and, for consistency, the
`proxy.AppConnConsensus`) interface seems to need to be refactored.
Commits:
* Fix linting issue
* Add CHANGELOG_PENDING entry
* Remove extraneous explicit initialization
* Update ABCI spec doc to include new CheckTx params
* Rename method param for consistency
* Rename CheckTxType enum values and remove additional_data param
2019-07-02 10:14:53 -04:00
|
|
|
func ToRequestDeliverTx(req RequestDeliverTx) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
abci: Refactor CheckTx to notify of recheck (#3744)
As per #2127, this refactors the RequestCheckTx ProtoBuf struct to allow for a flag indicating whether a query is a recheck or not (and allows for possible future, more nuanced states).
In order to pass this extended information through to the ABCI app, the proxy.AppConnMempool (and, for consistency, the proxy.AppConnConsensus) interface seems to need to be refactored along with abcicli.Client.
And, as per this comment, I've made the following modification to the protobuf definition for the RequestCheckTx structure:
enum CheckTxType {
New = 0;
Recheck = 1;
}
message RequestCheckTx {
bytes tx = 1;
CheckTxType type = 2;
}
* Refactor ABCI CheckTx to notify of recheck
As per #2127, this refactors the `RequestCheckTx` ProtoBuf struct to allow for:
1. a flag indicating whether a query is a recheck or not (and allows for
possible future, more nuanced states)
2. an `additional_data` bytes array to provide information for those more
nuanced states.
In order to pass this extended information through to the ABCI app, the
`proxy.AppConnMempool` (and, for consistency, the
`proxy.AppConnConsensus`) interface seems to need to be refactored.
Commits:
* Fix linting issue
* Add CHANGELOG_PENDING entry
* Remove extraneous explicit initialization
* Update ABCI spec doc to include new CheckTx params
* Rename method param for consistency
* Rename CheckTxType enum values and remove additional_data param
2019-07-02 10:14:53 -04:00
|
|
|
Value: &Request_DeliverTx{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
abci: Refactor CheckTx to notify of recheck (#3744)
As per #2127, this refactors the RequestCheckTx ProtoBuf struct to allow for a flag indicating whether a query is a recheck or not (and allows for possible future, more nuanced states).
In order to pass this extended information through to the ABCI app, the proxy.AppConnMempool (and, for consistency, the proxy.AppConnConsensus) interface seems to need to be refactored along with abcicli.Client.
And, as per this comment, I've made the following modification to the protobuf definition for the RequestCheckTx structure:
enum CheckTxType {
New = 0;
Recheck = 1;
}
message RequestCheckTx {
bytes tx = 1;
CheckTxType type = 2;
}
* Refactor ABCI CheckTx to notify of recheck
As per #2127, this refactors the `RequestCheckTx` ProtoBuf struct to allow for:
1. a flag indicating whether a query is a recheck or not (and allows for
possible future, more nuanced states)
2. an `additional_data` bytes array to provide information for those more
nuanced states.
In order to pass this extended information through to the ABCI app, the
`proxy.AppConnMempool` (and, for consistency, the
`proxy.AppConnConsensus`) interface seems to need to be refactored.
Commits:
* Fix linting issue
* Add CHANGELOG_PENDING entry
* Remove extraneous explicit initialization
* Update ABCI spec doc to include new CheckTx params
* Rename method param for consistency
* Rename CheckTxType enum values and remove additional_data param
2019-07-02 10:14:53 -04:00
|
|
|
func ToRequestCheckTx(req RequestCheckTx) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
abci: Refactor CheckTx to notify of recheck (#3744)
As per #2127, this refactors the RequestCheckTx ProtoBuf struct to allow for a flag indicating whether a query is a recheck or not (and allows for possible future, more nuanced states).
In order to pass this extended information through to the ABCI app, the proxy.AppConnMempool (and, for consistency, the proxy.AppConnConsensus) interface seems to need to be refactored along with abcicli.Client.
And, as per this comment, I've made the following modification to the protobuf definition for the RequestCheckTx structure:
enum CheckTxType {
New = 0;
Recheck = 1;
}
message RequestCheckTx {
bytes tx = 1;
CheckTxType type = 2;
}
* Refactor ABCI CheckTx to notify of recheck
As per #2127, this refactors the `RequestCheckTx` ProtoBuf struct to allow for:
1. a flag indicating whether a query is a recheck or not (and allows for
possible future, more nuanced states)
2. an `additional_data` bytes array to provide information for those more
nuanced states.
In order to pass this extended information through to the ABCI app, the
`proxy.AppConnMempool` (and, for consistency, the
`proxy.AppConnConsensus`) interface seems to need to be refactored.
Commits:
* Fix linting issue
* Add CHANGELOG_PENDING entry
* Remove extraneous explicit initialization
* Update ABCI spec doc to include new CheckTx params
* Rename method param for consistency
* Rename CheckTxType enum values and remove additional_data param
2019-07-02 10:14:53 -04:00
|
|
|
Value: &Request_CheckTx{&req},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToRequestCommit() *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2016-05-17 20:06:24 -04:00
|
|
|
Value: &Request_Commit{&RequestCommit{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2017-09-22 00:10:13 -04:00
|
|
|
func ToRequestQuery(req RequestQuery) *Request {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Request{
|
2017-09-22 00:10:13 -04:00
|
|
|
Value: &Request_Query{&req},
|
2017-01-10 15:49:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:10:13 -04:00
|
|
|
func ToRequestInitChain(req RequestInitChain) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2017-09-22 00:10:13 -04:00
|
|
|
Value: &Request_InitChain{&req},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:10:13 -04:00
|
|
|
func ToRequestBeginBlock(req RequestBeginBlock) *Request {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Request{
|
2017-09-22 00:10:13 -04:00
|
|
|
Value: &Request_BeginBlock{&req},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToRequestEndBlock(req RequestEndBlock) *Request {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Request{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Request_EndBlock{&req},
|
2016-03-05 19:18:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 07:39:53 -08:00
|
|
|
//----------------------------------------
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToResponseException(errStr string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2018-07-27 06:23:19 +04:00
|
|
|
Value: &Response_Exception{&ResponseException{Error: errStr}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToResponseEcho(message string) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2018-07-27 06:23:19 +04:00
|
|
|
Value: &Response_Echo{&ResponseEcho{Message: message}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-08 15:18:58 -08:00
|
|
|
}
|
|
|
|
|
2016-05-14 02:22:32 -04:00
|
|
|
func ToResponseFlush() *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2016-05-17 20:06:24 -04:00
|
|
|
Value: &Response_Flush{&ResponseFlush{}},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-09 16:29:45 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseInfo(res ResponseInfo) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_Info{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-27 10:14:46 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseSetOption(res ResponseSetOption) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_SetOption{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_DeliverTx{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseCheckTx(res ResponseCheckTx) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_CheckTx{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2015-11-02 07:39:53 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseCommit(res ResponseCommit) *Response {
|
2016-01-30 19:36:33 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_Commit{&res},
|
2016-01-30 19:36:33 -08:00
|
|
|
}
|
2016-01-18 14:37:42 -08:00
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseQuery(res ResponseQuery) *Response {
|
2017-01-10 15:49:26 +01:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_Query{&res},
|
2017-01-10 15:49:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseInitChain(res ResponseInitChain) *Response {
|
2016-03-05 19:18:34 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_InitChain{&res},
|
2016-03-05 19:18:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
|
2016-03-26 22:35:23 -07:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_BeginBlock{&res},
|
2016-03-26 22:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-27 19:04:21 +00:00
|
|
|
func ToResponseEndBlock(res ResponseEndBlock) *Response {
|
2016-02-28 19:19:29 -08:00
|
|
|
return &Response{
|
2017-11-27 19:04:21 +00:00
|
|
|
Value: &Response_EndBlock{&res},
|
2016-02-28 19:19:29 -08:00
|
|
|
}
|
|
|
|
}
|