github.com/badrootd/nibiru-cometbft@v0.37.5-0.20240307173500-2a75559eee9b/abci/types/messages.go (about)

     1  package types
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/badrootd/nibiru-cometbft/libs/protoio"
     7  	"github.com/cosmos/gogoproto/proto"
     8  )
     9  
    10  const (
    11  	maxMsgSize = 104857600 // 100MB
    12  )
    13  
    14  // WriteMessage writes a varint length-delimited protobuf message.
    15  func WriteMessage(msg proto.Message, w io.Writer) error {
    16  	protoWriter := protoio.NewDelimitedWriter(w)
    17  	_, err := protoWriter.WriteMsg(msg)
    18  	if err != nil {
    19  		return err
    20  	}
    21  
    22  	return nil
    23  }
    24  
    25  // ReadMessage reads a varint length-delimited protobuf message.
    26  func ReadMessage(r io.Reader, msg proto.Message) error {
    27  	_, err := protoio.NewDelimitedReader(r, maxMsgSize).ReadMsg(msg)
    28  	return err
    29  }
    30  
    31  //----------------------------------------
    32  
    33  func ToRequestEcho(message string) *Request {
    34  	return &Request{
    35  		Value: &Request_Echo{&RequestEcho{Message: message}},
    36  	}
    37  }
    38  
    39  func ToRequestFlush() *Request {
    40  	return &Request{
    41  		Value: &Request_Flush{&RequestFlush{}},
    42  	}
    43  }
    44  
    45  func ToRequestInfo(req RequestInfo) *Request {
    46  	return &Request{
    47  		Value: &Request_Info{&req},
    48  	}
    49  }
    50  
    51  func ToRequestDeliverTx(req RequestDeliverTx) *Request {
    52  	return &Request{
    53  		Value: &Request_DeliverTx{&req},
    54  	}
    55  }
    56  
    57  func ToRequestCheckTx(req RequestCheckTx) *Request {
    58  	return &Request{
    59  		Value: &Request_CheckTx{&req},
    60  	}
    61  }
    62  
    63  func ToRequestCommit() *Request {
    64  	return &Request{
    65  		Value: &Request_Commit{&RequestCommit{}},
    66  	}
    67  }
    68  
    69  func ToRequestQuery(req RequestQuery) *Request {
    70  	return &Request{
    71  		Value: &Request_Query{&req},
    72  	}
    73  }
    74  
    75  func ToRequestInitChain(req RequestInitChain) *Request {
    76  	return &Request{
    77  		Value: &Request_InitChain{&req},
    78  	}
    79  }
    80  
    81  func ToRequestBeginBlock(req RequestBeginBlock) *Request {
    82  	return &Request{
    83  		Value: &Request_BeginBlock{&req},
    84  	}
    85  }
    86  
    87  func ToRequestEndBlock(req RequestEndBlock) *Request {
    88  	return &Request{
    89  		Value: &Request_EndBlock{&req},
    90  	}
    91  }
    92  
    93  func ToRequestListSnapshots(req RequestListSnapshots) *Request {
    94  	return &Request{
    95  		Value: &Request_ListSnapshots{&req},
    96  	}
    97  }
    98  
    99  func ToRequestOfferSnapshot(req RequestOfferSnapshot) *Request {
   100  	return &Request{
   101  		Value: &Request_OfferSnapshot{&req},
   102  	}
   103  }
   104  
   105  func ToRequestLoadSnapshotChunk(req RequestLoadSnapshotChunk) *Request {
   106  	return &Request{
   107  		Value: &Request_LoadSnapshotChunk{&req},
   108  	}
   109  }
   110  
   111  func ToRequestApplySnapshotChunk(req RequestApplySnapshotChunk) *Request {
   112  	return &Request{
   113  		Value: &Request_ApplySnapshotChunk{&req},
   114  	}
   115  }
   116  
   117  func ToRequestPrepareProposal(req RequestPrepareProposal) *Request {
   118  	return &Request{
   119  		Value: &Request_PrepareProposal{&req},
   120  	}
   121  }
   122  
   123  func ToRequestProcessProposal(req RequestProcessProposal) *Request {
   124  	return &Request{
   125  		Value: &Request_ProcessProposal{&req},
   126  	}
   127  }
   128  
   129  //----------------------------------------
   130  
   131  func ToResponseException(errStr string) *Response {
   132  	return &Response{
   133  		Value: &Response_Exception{&ResponseException{Error: errStr}},
   134  	}
   135  }
   136  
   137  func ToResponseEcho(message string) *Response {
   138  	return &Response{
   139  		Value: &Response_Echo{&ResponseEcho{Message: message}},
   140  	}
   141  }
   142  
   143  func ToResponseFlush() *Response {
   144  	return &Response{
   145  		Value: &Response_Flush{&ResponseFlush{}},
   146  	}
   147  }
   148  
   149  func ToResponseInfo(res ResponseInfo) *Response {
   150  	return &Response{
   151  		Value: &Response_Info{&res},
   152  	}
   153  }
   154  
   155  func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
   156  	return &Response{
   157  		Value: &Response_DeliverTx{&res},
   158  	}
   159  }
   160  
   161  func ToResponseCheckTx(res ResponseCheckTx) *Response {
   162  	return &Response{
   163  		Value: &Response_CheckTx{&res},
   164  	}
   165  }
   166  
   167  func ToResponseCommit(res ResponseCommit) *Response {
   168  	return &Response{
   169  		Value: &Response_Commit{&res},
   170  	}
   171  }
   172  
   173  func ToResponseQuery(res ResponseQuery) *Response {
   174  	return &Response{
   175  		Value: &Response_Query{&res},
   176  	}
   177  }
   178  
   179  func ToResponseInitChain(res ResponseInitChain) *Response {
   180  	return &Response{
   181  		Value: &Response_InitChain{&res},
   182  	}
   183  }
   184  
   185  func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
   186  	return &Response{
   187  		Value: &Response_BeginBlock{&res},
   188  	}
   189  }
   190  
   191  func ToResponseEndBlock(res ResponseEndBlock) *Response {
   192  	return &Response{
   193  		Value: &Response_EndBlock{&res},
   194  	}
   195  }
   196  
   197  func ToResponseListSnapshots(res ResponseListSnapshots) *Response {
   198  	return &Response{
   199  		Value: &Response_ListSnapshots{&res},
   200  	}
   201  }
   202  
   203  func ToResponseOfferSnapshot(res ResponseOfferSnapshot) *Response {
   204  	return &Response{
   205  		Value: &Response_OfferSnapshot{&res},
   206  	}
   207  }
   208  
   209  func ToResponseLoadSnapshotChunk(res ResponseLoadSnapshotChunk) *Response {
   210  	return &Response{
   211  		Value: &Response_LoadSnapshotChunk{&res},
   212  	}
   213  }
   214  
   215  func ToResponseApplySnapshotChunk(res ResponseApplySnapshotChunk) *Response {
   216  	return &Response{
   217  		Value: &Response_ApplySnapshotChunk{&res},
   218  	}
   219  }
   220  
   221  func ToResponsePrepareProposal(res ResponsePrepareProposal) *Response {
   222  	return &Response{
   223  		Value: &Response_PrepareProposal{&res},
   224  	}
   225  }
   226  
   227  func ToResponseProcessProposal(res ResponseProcessProposal) *Response {
   228  	return &Response{
   229  		Value: &Response_ProcessProposal{&res},
   230  	}
   231  }