Skip to content

Commit 05ba4e5

Browse files
refactor: add missing files to api dir
1 parent 7e74a7a commit 05ba4e5

File tree

11 files changed

+727
-0
lines changed

11 files changed

+727
-0
lines changed

api/cometbft/abci/v1/types.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package v1
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/cosmos/gogoproto/jsonpb"
7+
)
8+
9+
const (
10+
CodeTypeOK uint32 = 0
11+
)
12+
13+
// IsOK returns true if Code is OK.
14+
func (r CheckTxResponse) IsOK() bool {
15+
return r.Code == CodeTypeOK
16+
}
17+
18+
// IsErr returns true if Code is something other than OK.
19+
func (r CheckTxResponse) IsErr() bool {
20+
return r.Code != CodeTypeOK
21+
}
22+
23+
// IsOK returns true if Code is OK.
24+
func (r QueryResponse) IsOK() bool {
25+
return r.Code == CodeTypeOK
26+
}
27+
28+
// IsErr returns true if Code is something other than OK.
29+
func (r QueryResponse) IsErr() bool {
30+
return r.Code != CodeTypeOK
31+
}
32+
33+
// IsAccepted returns true if Code is ACCEPT
34+
func (r ProcessProposalResponse) IsAccepted() bool {
35+
return r.Status == PROCESS_PROPOSAL_STATUS_ACCEPT
36+
}
37+
38+
// IsStatusUnknown returns true if Code is UNKNOWN
39+
func (r ProcessProposalResponse) IsStatusUnknown() bool {
40+
return r.Status == PROCESS_PROPOSAL_STATUS_UNKNOWN
41+
}
42+
43+
func (r VerifyVoteExtensionResponse) IsAccepted() bool {
44+
return r.Status == VERIFY_VOTE_EXTENSION_STATUS_ACCEPT
45+
}
46+
47+
// IsStatusUnknown returns true if Code is Unknown
48+
func (r VerifyVoteExtensionResponse) IsStatusUnknown() bool {
49+
return r.Status == VERIFY_VOTE_EXTENSION_STATUS_UNKNOWN
50+
}
51+
52+
// IsOK returns true if Code is OK.
53+
func (r ExecTxResult) IsOK() bool {
54+
return r.Code == CodeTypeOK
55+
}
56+
57+
// IsErr returns true if Code is something other than OK.
58+
func (r ExecTxResult) IsErr() bool {
59+
return r.Code != CodeTypeOK
60+
}
61+
62+
// ---------------------------------------------------------------------------
63+
// override JSON marshaling so we emit defaults (ie. disable omitempty)
64+
65+
var (
66+
jsonpbMarshaller = jsonpb.Marshaler{
67+
EnumsAsInts: true,
68+
EmitDefaults: true,
69+
}
70+
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
71+
)
72+
73+
func (r *CheckTxResponse) MarshalJSON() ([]byte, error) {
74+
s, err := jsonpbMarshaller.MarshalToString(r)
75+
return []byte(s), err
76+
}
77+
78+
func (r *CheckTxResponse) UnmarshalJSON(b []byte) error {
79+
reader := bytes.NewBuffer(b)
80+
return jsonpbUnmarshaller.Unmarshal(reader, r)
81+
}
82+
83+
func (r *QueryResponse) MarshalJSON() ([]byte, error) {
84+
s, err := jsonpbMarshaller.MarshalToString(r)
85+
return []byte(s), err
86+
}
87+
88+
func (r *QueryResponse) UnmarshalJSON(b []byte) error {
89+
reader := bytes.NewBuffer(b)
90+
return jsonpbUnmarshaller.Unmarshal(reader, r)
91+
}
92+
93+
func (r *CommitResponse) MarshalJSON() ([]byte, error) {
94+
s, err := jsonpbMarshaller.MarshalToString(r)
95+
return []byte(s), err
96+
}
97+
98+
func (r *CommitResponse) UnmarshalJSON(b []byte) error {
99+
reader := bytes.NewBuffer(b)
100+
return jsonpbUnmarshaller.Unmarshal(reader, r)
101+
}
102+
103+
func (r *EventAttribute) MarshalJSON() ([]byte, error) {
104+
s, err := jsonpbMarshaller.MarshalToString(r)
105+
return []byte(s), err
106+
}
107+
108+
func (r *EventAttribute) UnmarshalJSON(b []byte) error {
109+
reader := bytes.NewBuffer(b)
110+
return jsonpbUnmarshaller.Unmarshal(reader, r)
111+
}
112+
113+
func (r *ExecTxResult) MarshalJSON() ([]byte, error) {
114+
s, err := jsonpbMarshaller.MarshalToString(r)
115+
return []byte(s), err
116+
}
117+
118+
func (r *ExecTxResult) UnmarshalJSON(b []byte) error {
119+
reader := bytes.NewBuffer(b)
120+
return jsonpbUnmarshaller.Unmarshal(reader, r)
121+
}

api/cometbft/abci/v1beta1/types.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package v1beta1
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/cosmos/gogoproto/jsonpb"
7+
)
8+
9+
const (
10+
CodeTypeOK uint32 = 0
11+
)
12+
13+
// IsOK returns true if Code is OK.
14+
func (r ResponseQuery) IsOK() bool {
15+
return r.Code == CodeTypeOK
16+
}
17+
18+
// IsErr returns true if Code is something other than OK.
19+
func (r ResponseQuery) IsErr() bool {
20+
return r.Code != CodeTypeOK
21+
}
22+
23+
// ---------------------------------------------------------------------------
24+
// override JSON marshaling so we emit defaults (ie. disable omitempty)
25+
26+
var (
27+
jsonpbMarshaller = jsonpb.Marshaler{
28+
EnumsAsInts: true,
29+
EmitDefaults: true,
30+
}
31+
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
32+
)
33+
34+
func (r *ResponseQuery) MarshalJSON() ([]byte, error) {
35+
s, err := jsonpbMarshaller.MarshalToString(r)
36+
return []byte(s), err
37+
}
38+
39+
func (r *ResponseQuery) UnmarshalJSON(b []byte) error {
40+
reader := bytes.NewBuffer(b)
41+
return jsonpbUnmarshaller.Unmarshal(reader, r)
42+
}

api/cometbft/abci/v1beta2/types.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package v1beta2
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/cosmos/gogoproto/jsonpb"
7+
)
8+
9+
// IsAccepted returns true if Code is ACCEPT
10+
func (r ResponseProcessProposal) IsAccepted() bool {
11+
return r.Status == ResponseProcessProposal_ACCEPT
12+
}
13+
14+
// IsStatusUnknown returns true if Code is UNKNOWN
15+
func (r ResponseProcessProposal) IsStatusUnknown() bool {
16+
return r.Status == ResponseProcessProposal_UNKNOWN
17+
}
18+
19+
// ---------------------------------------------------------------------------
20+
// override JSON marshaling so we emit defaults (ie. disable omitempty)
21+
22+
var (
23+
jsonpbMarshaller = jsonpb.Marshaler{
24+
EnumsAsInts: true,
25+
EmitDefaults: true,
26+
}
27+
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
28+
)
29+
30+
func (r *EventAttribute) MarshalJSON() ([]byte, error) {
31+
s, err := jsonpbMarshaller.MarshalToString(r)
32+
return []byte(s), err
33+
}
34+
35+
func (r *EventAttribute) UnmarshalJSON(b []byte) error {
36+
reader := bytes.NewBuffer(b)
37+
return jsonpbUnmarshaller.Unmarshal(reader, r)
38+
}

api/cometbft/abci/v1beta3/types.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package v1beta3
2+
3+
import (
4+
"bytes"
5+
6+
"github.com/cosmos/gogoproto/jsonpb"
7+
)
8+
9+
const (
10+
CodeTypeOK uint32 = 0
11+
)
12+
13+
// IsOK returns true if Code is OK.
14+
func (r ResponseCheckTx) IsOK() bool {
15+
return r.Code == CodeTypeOK
16+
}
17+
18+
// IsErr returns true if Code is something other than OK.
19+
func (r ResponseCheckTx) IsErr() bool {
20+
return r.Code != CodeTypeOK
21+
}
22+
23+
// IsOK returns true if Code is OK.
24+
func (r ExecTxResult) IsOK() bool {
25+
return r.Code == CodeTypeOK
26+
}
27+
28+
// IsErr returns true if Code is something other than OK.
29+
func (r ExecTxResult) IsErr() bool {
30+
return r.Code != CodeTypeOK
31+
}
32+
33+
func (r ResponseVerifyVoteExtension) IsAccepted() bool {
34+
return r.Status == ResponseVerifyVoteExtension_ACCEPT
35+
}
36+
37+
// IsStatusUnknown returns true if Code is Unknown
38+
func (r ResponseVerifyVoteExtension) IsStatusUnknown() bool {
39+
return r.Status == ResponseVerifyVoteExtension_UNKNOWN
40+
}
41+
42+
// ---------------------------------------------------------------------------
43+
// override JSON marshaling so we emit defaults (ie. disable omitempty)
44+
45+
var (
46+
jsonpbMarshaller = jsonpb.Marshaler{
47+
EnumsAsInts: true,
48+
EmitDefaults: true,
49+
}
50+
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
51+
)
52+
53+
func (r *ResponseCheckTx) MarshalJSON() ([]byte, error) {
54+
s, err := jsonpbMarshaller.MarshalToString(r)
55+
return []byte(s), err
56+
}
57+
58+
func (r *ResponseCheckTx) UnmarshalJSON(b []byte) error {
59+
reader := bytes.NewBuffer(b)
60+
return jsonpbUnmarshaller.Unmarshal(reader, r)
61+
}
62+
63+
func (r *ResponseCommit) MarshalJSON() ([]byte, error) {
64+
s, err := jsonpbMarshaller.MarshalToString(r)
65+
return []byte(s), err
66+
}
67+
68+
func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
69+
reader := bytes.NewBuffer(b)
70+
return jsonpbUnmarshaller.Unmarshal(reader, r)
71+
}
72+
73+
func (r *ExecTxResult) MarshalJSON() ([]byte, error) {
74+
s, err := jsonpbMarshaller.MarshalToString(r)
75+
return []byte(s), err
76+
}
77+
78+
func (r *ExecTxResult) UnmarshalJSON(b []byte) error {
79+
reader := bytes.NewBuffer(b)
80+
return jsonpbUnmarshaller.Unmarshal(reader, r)
81+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package v1
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/cosmos/gogoproto/proto"
7+
)
8+
9+
const (
10+
BlockResponseMessagePrefixSize = 4
11+
BlockResponseMessageFieldKeySize = 1
12+
)
13+
14+
func (m *BlockRequest) Wrap() proto.Message {
15+
bm := &Message{}
16+
bm.Sum = &Message_BlockRequest{BlockRequest: m}
17+
return bm
18+
}
19+
20+
func (m *BlockResponse) Wrap() proto.Message {
21+
bm := &Message{}
22+
bm.Sum = &Message_BlockResponse{BlockResponse: m}
23+
return bm
24+
}
25+
26+
func (m *NoBlockResponse) Wrap() proto.Message {
27+
bm := &Message{}
28+
bm.Sum = &Message_NoBlockResponse{NoBlockResponse: m}
29+
return bm
30+
}
31+
32+
func (m *StatusRequest) Wrap() proto.Message {
33+
bm := &Message{}
34+
bm.Sum = &Message_StatusRequest{StatusRequest: m}
35+
return bm
36+
}
37+
38+
func (m *StatusResponse) Wrap() proto.Message {
39+
bm := &Message{}
40+
bm.Sum = &Message_StatusResponse{StatusResponse: m}
41+
return bm
42+
}
43+
44+
// Unwrap implements the p2p Wrapper interface and unwraps a wrapped blockchain
45+
// message.
46+
func (m *Message) Unwrap() (proto.Message, error) {
47+
switch msg := m.Sum.(type) {
48+
case *Message_BlockRequest:
49+
return m.GetBlockRequest(), nil
50+
51+
case *Message_BlockResponse:
52+
return m.GetBlockResponse(), nil
53+
54+
case *Message_NoBlockResponse:
55+
return m.GetNoBlockResponse(), nil
56+
57+
case *Message_StatusRequest:
58+
return m.GetStatusRequest(), nil
59+
60+
case *Message_StatusResponse:
61+
return m.GetStatusResponse(), nil
62+
63+
default:
64+
return nil, fmt.Errorf("unknown message: %T", msg)
65+
}
66+
}

0 commit comments

Comments
 (0)