Skip to content

Commit 810a542

Browse files
authored
refactor: zerodep core (#21239)
1 parent fba4dac commit 810a542

89 files changed

Lines changed: 165 additions & 373 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

client/v2/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ require (
5454
github.com/cosmos/crypto v0.1.2 // indirect
5555
github.com/cosmos/go-bip39 v1.0.0 // indirect
5656
github.com/cosmos/gogogateway v1.2.0 // indirect
57-
github.com/cosmos/gogoproto v1.6.0
57+
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0
5858
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 // indirect
5959
github.com/cosmos/ics23/go v0.10.0 // indirect
6060
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect

client/v2/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x
117117
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
118118
github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI=
119119
github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU=
120-
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
121-
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
120+
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0 h1:qZdcY4sKyAnaUwFRtSKkk9YdeMuQixWxLagI/8jhJo4=
121+
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
122122
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 h1:wmwDn7V3RodN9auB3FooSQxs46nHVE3u0mb87TJkZFE=
123123
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw=
124124
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=

collections/go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ require (
1010
)
1111

1212
require (
13-
github.com/cosmos/gogoproto v1.6.0 // indirect
1413
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
15-
github.com/google/go-cmp v0.6.0 // indirect
1614
github.com/pmezard/go-difflib v1.0.0 // indirect
1715
github.com/tidwall/btree v1.7.0 // indirect
18-
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
19-
google.golang.org/protobuf v1.34.2 // indirect
2016
gopkg.in/yaml.v3 v3.0.1 // indirect
2117
)
2218

collections/go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
1-
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
2-
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
31
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
42
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5-
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
6-
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
7-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
8-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
93
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
104
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
115
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
126
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
137
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
148
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
15-
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
16-
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
17-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
18-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
199
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2010
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2111
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

core/app/codec.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
package app
22

33
import (
4-
"github.com/cosmos/gogoproto/jsonpb"
5-
gogoproto "github.com/cosmos/gogoproto/proto"
4+
"cosmossdk.io/core/transaction"
65
)
76

87
// MsgInterfaceProtoName defines the protobuf name of the cosmos Msg interface
98
const MsgInterfaceProtoName = "cosmos.base.v1beta1.Msg"
109

1110
type ProtoCodec interface {
12-
Marshal(v gogoproto.Message) ([]byte, error)
13-
Unmarshal(data []byte, v gogoproto.Message) error
11+
Marshal(v transaction.Msg) ([]byte, error)
12+
Unmarshal(data []byte, v transaction.Msg) error
1413
Name() string
1514
}
1615

1716
type InterfaceRegistry interface {
18-
jsonpb.AnyResolver
17+
AnyResolver
1918
ListImplementations(ifaceTypeURL string) []string
2019
ListAllInterfaces() []string
2120
}
21+
22+
type AnyResolver = interface {
23+
Resolve(typeUrl string) (transaction.Msg, error)
24+
}

core/appmodule/v2/handlers.go

Lines changed: 5 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,104 +2,20 @@ package appmodule
22

33
import (
44
"context"
5-
"fmt"
5+
6+
transaction "cosmossdk.io/core/transaction"
67
)
78

89
type (
910
// PreMsgHandler is a handler that is executed before Handler. If it errors the execution reverts.
10-
PreMsgHandler = func(ctx context.Context, msg Message) error
11+
PreMsgHandler = func(ctx context.Context, msg transaction.Msg) error
1112
// Handler handles the state transition of the provided message.
12-
Handler = func(ctx context.Context, msg Message) (msgResp Message, err error)
13+
Handler = func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error)
1314
// PostMsgHandler runs after Handler, only if Handler does not error. If PostMsgHandler errors
1415
// then the execution is reverted.
15-
PostMsgHandler = func(ctx context.Context, msg, msgResp Message) error
16+
PostMsgHandler = func(ctx context.Context, msg, msgResp transaction.Msg) error
1617
)
1718

18-
// RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the
19-
// QueryRouter or MsgRouter. Example usage:
20-
// ```go
21-
//
22-
// func (k Keeper) QueryBalance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) {
23-
// ... query logic ...
24-
// }
25-
//
26-
// func (m Module) RegisterQueryHandlers(router appmodule.QueryRouter) {
27-
// appmodule.RegisterHandler(router, keeper.QueryBalance)
28-
// }
29-
//
30-
// ```
31-
func RegisterHandler[R interface{ Register(string, Handler) }, Req, Resp Message](
32-
router R,
33-
handler func(ctx context.Context, msg Req) (msgResp Resp, err error),
34-
) {
35-
untypedHandler := func(ctx context.Context, m Message) (Message, error) {
36-
typed, ok := m.(Req)
37-
if !ok {
38-
return nil, fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
39-
}
40-
return handler(ctx, typed)
41-
}
42-
router.Register(messageName[Req](), untypedHandler)
43-
}
44-
45-
// RegisterPreHandler is a helper function that modules can use to not lose type safety when registering PreMsgHandler to the
46-
// PreMsgRouter. Example usage:
47-
// ```go
48-
//
49-
// func (k Keeper) BeforeSend(ctx context.Context, req *types.MsgSend) (*types.QueryBalanceResponse, error) {
50-
// ... before send logic ...
51-
// }
52-
//
53-
// func (m Module) RegisterPreMsgHandlers(router appmodule.PreMsgRouter) {
54-
// appmodule.RegisterPreHandler(router, keeper.BeforeSend)
55-
// }
56-
//
57-
// ```
58-
func RegisterPreHandler[Req Message](
59-
router PreMsgRouter,
60-
handler func(ctx context.Context, msg Req) error,
61-
) {
62-
untypedHandler := func(ctx context.Context, m Message) error {
63-
typed, ok := m.(Req)
64-
if !ok {
65-
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
66-
}
67-
return handler(ctx, typed)
68-
}
69-
router.Register(messageName[Req](), untypedHandler)
70-
}
71-
72-
// RegisterPostHandler is a helper function that modules can use to not lose type safety when registering handlers to the
73-
// PostMsgRouter. Example usage:
74-
// ```go
75-
//
76-
// func (k Keeper) AfterSend(ctx context.Context, req *types.MsgSend, resp *types.MsgSendResponse) error {
77-
// ... query logic ...
78-
// }
79-
//
80-
// func (m Module) RegisterPostMsgHandlers(router appmodule.PostMsgRouter) {
81-
// appmodule.RegisterPostHandler(router, keeper.AfterSend)
82-
// }
83-
//
84-
// ```
85-
func RegisterPostHandler[Req, Resp Message](
86-
router PostMsgRouter,
87-
handler func(ctx context.Context, msg Req, msgResp Resp) error,
88-
) {
89-
untypedHandler := func(ctx context.Context, m, mResp Message) error {
90-
typed, ok := m.(Req)
91-
if !ok {
92-
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
93-
}
94-
typedResp, ok := mResp.(Resp)
95-
if !ok {
96-
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Resp))
97-
}
98-
return handler(ctx, typed, typedResp)
99-
}
100-
router.Register(messageName[Req](), untypedHandler)
101-
}
102-
10319
// msg handler
10420

10521
type PreMsgRouter interface {

core/appmodule/v2/message.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

core/event/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package event
44
import (
55
"context"
66

7-
gogoproto "github.com/cosmos/gogoproto/proto"
7+
"cosmossdk.io/core/transaction"
88
)
99

1010
// Service represents an event service which can retrieve and set an event manager in a context.
@@ -19,7 +19,7 @@ type Manager interface {
1919
// Emit emits events represented as a protobuf message (as described in ADR 032).
2020
//
2121
// Callers SHOULD assume that these events will not be included in consensus.
22-
Emit(event gogoproto.Message) error
22+
Emit(event transaction.Msg) error
2323

2424
// EmitKV emits an event based on an event and kv-pair attributes.
2525
//

core/go.mod

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
module cosmossdk.io/core
22

3-
go 1.20
4-
5-
require github.com/cosmos/gogoproto v1.6.0
3+
// Core is meant to have zero dependencies, so we can use it as a dependency
4+
// in other modules without having to worry about circular dependencies.
65

7-
require (
8-
github.com/golang/protobuf v1.5.4 // indirect
9-
github.com/google/go-cmp v0.6.0 // indirect
10-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
11-
google.golang.org/protobuf v1.34.2 // indirect
12-
)
6+
go 1.20
137

148
// Version tagged too early and incompatible with v0.50 (latest at the time of tagging)
159
retract v0.12.0

core/go.sum

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
2-
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
3-
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
4-
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
5-
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
6-
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
7-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
8-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
9-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
10-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=

0 commit comments

Comments
 (0)