forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add missing files to
api
dir
- Loading branch information
1 parent
7e74a7a
commit 05ba4e5
Showing
11 changed files
with
727 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package v1 | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/cosmos/gogoproto/jsonpb" | ||
) | ||
|
||
const ( | ||
CodeTypeOK uint32 = 0 | ||
) | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r CheckTxResponse) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r CheckTxResponse) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r QueryResponse) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r QueryResponse) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
// IsAccepted returns true if Code is ACCEPT | ||
func (r ProcessProposalResponse) IsAccepted() bool { | ||
return r.Status == PROCESS_PROPOSAL_STATUS_ACCEPT | ||
} | ||
|
||
// IsStatusUnknown returns true if Code is UNKNOWN | ||
func (r ProcessProposalResponse) IsStatusUnknown() bool { | ||
return r.Status == PROCESS_PROPOSAL_STATUS_UNKNOWN | ||
} | ||
|
||
func (r VerifyVoteExtensionResponse) IsAccepted() bool { | ||
return r.Status == VERIFY_VOTE_EXTENSION_STATUS_ACCEPT | ||
} | ||
|
||
// IsStatusUnknown returns true if Code is Unknown | ||
func (r VerifyVoteExtensionResponse) IsStatusUnknown() bool { | ||
return r.Status == VERIFY_VOTE_EXTENSION_STATUS_UNKNOWN | ||
} | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r ExecTxResult) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r ExecTxResult) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// override JSON marshaling so we emit defaults (ie. disable omitempty) | ||
|
||
var ( | ||
jsonpbMarshaller = jsonpb.Marshaler{ | ||
EnumsAsInts: true, | ||
EmitDefaults: true, | ||
} | ||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | ||
) | ||
|
||
func (r *CheckTxResponse) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *CheckTxResponse) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *QueryResponse) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *QueryResponse) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *CommitResponse) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *CommitResponse) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *EventAttribute) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *EventAttribute) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *ExecTxResult) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *ExecTxResult) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package v1beta1 | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/cosmos/gogoproto/jsonpb" | ||
) | ||
|
||
const ( | ||
CodeTypeOK uint32 = 0 | ||
) | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r ResponseQuery) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r ResponseQuery) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// override JSON marshaling so we emit defaults (ie. disable omitempty) | ||
|
||
var ( | ||
jsonpbMarshaller = jsonpb.Marshaler{ | ||
EnumsAsInts: true, | ||
EmitDefaults: true, | ||
} | ||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | ||
) | ||
|
||
func (r *ResponseQuery) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *ResponseQuery) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package v1beta2 | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/cosmos/gogoproto/jsonpb" | ||
) | ||
|
||
// IsAccepted returns true if Code is ACCEPT | ||
func (r ResponseProcessProposal) IsAccepted() bool { | ||
return r.Status == ResponseProcessProposal_ACCEPT | ||
} | ||
|
||
// IsStatusUnknown returns true if Code is UNKNOWN | ||
func (r ResponseProcessProposal) IsStatusUnknown() bool { | ||
return r.Status == ResponseProcessProposal_UNKNOWN | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// override JSON marshaling so we emit defaults (ie. disable omitempty) | ||
|
||
var ( | ||
jsonpbMarshaller = jsonpb.Marshaler{ | ||
EnumsAsInts: true, | ||
EmitDefaults: true, | ||
} | ||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | ||
) | ||
|
||
func (r *EventAttribute) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *EventAttribute) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package v1beta3 | ||
|
||
import ( | ||
"bytes" | ||
|
||
"github.com/cosmos/gogoproto/jsonpb" | ||
) | ||
|
||
const ( | ||
CodeTypeOK uint32 = 0 | ||
) | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r ResponseCheckTx) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r ResponseCheckTx) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
// IsOK returns true if Code is OK. | ||
func (r ExecTxResult) IsOK() bool { | ||
return r.Code == CodeTypeOK | ||
} | ||
|
||
// IsErr returns true if Code is something other than OK. | ||
func (r ExecTxResult) IsErr() bool { | ||
return r.Code != CodeTypeOK | ||
} | ||
|
||
func (r ResponseVerifyVoteExtension) IsAccepted() bool { | ||
return r.Status == ResponseVerifyVoteExtension_ACCEPT | ||
} | ||
|
||
// IsStatusUnknown returns true if Code is Unknown | ||
func (r ResponseVerifyVoteExtension) IsStatusUnknown() bool { | ||
return r.Status == ResponseVerifyVoteExtension_UNKNOWN | ||
} | ||
|
||
// --------------------------------------------------------------------------- | ||
// override JSON marshaling so we emit defaults (ie. disable omitempty) | ||
|
||
var ( | ||
jsonpbMarshaller = jsonpb.Marshaler{ | ||
EnumsAsInts: true, | ||
EmitDefaults: true, | ||
} | ||
jsonpbUnmarshaller = jsonpb.Unmarshaler{} | ||
) | ||
|
||
func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *ResponseCommit) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *ResponseCommit) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} | ||
|
||
func (r *ExecTxResult) MarshalJSON() ([]byte, error) { | ||
s, err := jsonpbMarshaller.MarshalToString(r) | ||
return []byte(s), err | ||
} | ||
|
||
func (r *ExecTxResult) UnmarshalJSON(b []byte) error { | ||
reader := bytes.NewBuffer(b) | ||
return jsonpbUnmarshaller.Unmarshal(reader, r) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
) | ||
|
||
const ( | ||
BlockResponseMessagePrefixSize = 4 | ||
BlockResponseMessageFieldKeySize = 1 | ||
) | ||
|
||
func (m *BlockRequest) Wrap() proto.Message { | ||
bm := &Message{} | ||
bm.Sum = &Message_BlockRequest{BlockRequest: m} | ||
return bm | ||
} | ||
|
||
func (m *BlockResponse) Wrap() proto.Message { | ||
bm := &Message{} | ||
bm.Sum = &Message_BlockResponse{BlockResponse: m} | ||
return bm | ||
} | ||
|
||
func (m *NoBlockResponse) Wrap() proto.Message { | ||
bm := &Message{} | ||
bm.Sum = &Message_NoBlockResponse{NoBlockResponse: m} | ||
return bm | ||
} | ||
|
||
func (m *StatusRequest) Wrap() proto.Message { | ||
bm := &Message{} | ||
bm.Sum = &Message_StatusRequest{StatusRequest: m} | ||
return bm | ||
} | ||
|
||
func (m *StatusResponse) Wrap() proto.Message { | ||
bm := &Message{} | ||
bm.Sum = &Message_StatusResponse{StatusResponse: m} | ||
return bm | ||
} | ||
|
||
// Unwrap implements the p2p Wrapper interface and unwraps a wrapped blockchain | ||
// message. | ||
func (m *Message) Unwrap() (proto.Message, error) { | ||
switch msg := m.Sum.(type) { | ||
case *Message_BlockRequest: | ||
return m.GetBlockRequest(), nil | ||
|
||
case *Message_BlockResponse: | ||
return m.GetBlockResponse(), nil | ||
|
||
case *Message_NoBlockResponse: | ||
return m.GetNoBlockResponse(), nil | ||
|
||
case *Message_StatusRequest: | ||
return m.GetStatusRequest(), nil | ||
|
||
case *Message_StatusResponse: | ||
return m.GetStatusResponse(), nil | ||
|
||
default: | ||
return nil, fmt.Errorf("unknown message: %T", msg) | ||
} | ||
} |
Oops, something went wrong.