Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: zerodep core #21239

Merged
merged 10 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ require (
github.com/cosmos/crypto v0.1.2 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.6.0
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions client/v2/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4x
github.com/cosmos/gogogateway v1.2.0 h1:Ae/OivNhp8DqBi/sh2A8a1D0y638GpL3tkmLQAiKxTE=
github.com/cosmos/gogogateway v1.2.0/go.mod h1:iQpLkGWxYcnCdz5iAdLcRBSw3h7NXeOkZ4GUkT+tbFI=
github.com/cosmos/gogoproto v1.4.2/go.mod h1:cLxOsn1ljAHSV527CHOtaIP91kK6cCrZETRBrkzItWU=
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0 h1:qZdcY4sKyAnaUwFRtSKkk9YdeMuQixWxLagI/8jhJo4=
github.com/cosmos/gogoproto v1.6.1-0.20240809124342-d6a57064ada0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179 h1:wmwDn7V3RodN9auB3FooSQxs46nHVE3u0mb87TJkZFE=
github.com/cosmos/iavl v1.2.1-0.20240725141113-7adc688cf179/go.mod h1:GiM43q0pB+uG53mLxLDzimxM9l/5N9UuSY3/D0huuVw=
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
Expand Down
4 changes: 0 additions & 4 deletions collections/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ require (
)

require (
github.com/cosmos/gogoproto v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/tidwall/btree v1.7.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
10 changes: 0 additions & 10 deletions collections/go.sum
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI=
github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
13 changes: 8 additions & 5 deletions core/app/codec.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package app

import (
"github.com/cosmos/gogoproto/jsonpb"
gogoproto "github.com/cosmos/gogoproto/proto"
"cosmossdk.io/core/transaction"
)

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

type ProtoCodec interface {
Marshal(v gogoproto.Message) ([]byte, error)
Unmarshal(data []byte, v gogoproto.Message) error
Marshal(v transaction.Msg) ([]byte, error)
Unmarshal(data []byte, v transaction.Msg) error
Name() string
}

type InterfaceRegistry interface {
jsonpb.AnyResolver
AnyResolver
ListImplementations(ifaceTypeURL string) []string
ListAllInterfaces() []string
}

type AnyResolver = interface {
Resolve(typeUrl string) (transaction.Msg, error)
}
173 changes: 87 additions & 86 deletions core/appmodule/v2/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,103 +2,104 @@ package appmodule

import (
"context"
"fmt"

transaction "cosmossdk.io/core/transaction"
)

type (
// PreMsgHandler is a handler that is executed before Handler. If it errors the execution reverts.
PreMsgHandler = func(ctx context.Context, msg Message) error
PreMsgHandler = func(ctx context.Context, msg transaction.Msg) error
// Handler handles the state transition of the provided message.
Handler = func(ctx context.Context, msg Message) (msgResp Message, err error)
Handler = func(ctx context.Context, msg transaction.Msg) (msgResp transaction.Msg, err error)
// PostMsgHandler runs after Handler, only if Handler does not error. If PostMsgHandler errors
// then the execution is reverted.
PostMsgHandler = func(ctx context.Context, msg, msgResp Message) error
PostMsgHandler = func(ctx context.Context, msg, msgResp transaction.Msg) error
)

// RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the
// QueryRouter or MsgRouter. Example usage:
// ```go
//
// func (k Keeper) QueryBalance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) {
// ... query logic ...
// }
//
// func (m Module) RegisterQueryHandlers(router appmodule.QueryRouter) {
// appmodule.RegisterHandler(router, keeper.QueryBalance)
// }
//
// ```
func RegisterHandler[R interface{ Register(string, Handler) }, Req, Resp Message](
router R,
handler func(ctx context.Context, msg Req) (msgResp Resp, err error),
) {
untypedHandler := func(ctx context.Context, m Message) (Message, error) {
typed, ok := m.(Req)
if !ok {
return nil, fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
}
return handler(ctx, typed)
}
router.Register(messageName[Req](), untypedHandler)
}
// // RegisterHandler is a helper function that modules can use to not lose type safety when registering handlers to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// // QueryRouter or MsgRouter. Example usage:
// // ```go
// //
// // func (k Keeper) QueryBalance(ctx context.Context, req *types.QueryBalanceRequest) (*types.QueryBalanceResponse, error) {
// // ... query logic ...
// // }
// //
// // func (m Module) RegisterQueryHandlers(router appmodule.QueryRouter) {
// // appmodule.RegisterHandler(router, keeper.QueryBalance)
// // }
// //
// // ```
// func RegisterHandler[R interface{ Register(string, Handler) }, Req, Resp transaction.Msg](
// router R,
// handler func(ctx context.Context, msg Req) (msgResp Resp, err error),
// ) {
// untypedHandler := func(ctx context.Context, m transaction.Msg) (transaction.Msg, error) {
// typed, ok := m.(Req)
// if !ok {
// return nil, fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
// }
// return handler(ctx, typed)
// }
// router.Register(messageName[Req](), untypedHandler)
// }

// RegisterPreHandler is a helper function that modules can use to not lose type safety when registering PreMsgHandler to the
// PreMsgRouter. Example usage:
// ```go
//
// func (k Keeper) BeforeSend(ctx context.Context, req *types.MsgSend) (*types.QueryBalanceResponse, error) {
// ... before send logic ...
// }
//
// func (m Module) RegisterPreMsgHandlers(router appmodule.PreMsgRouter) {
// appmodule.RegisterPreHandler(router, keeper.BeforeSend)
// }
//
// ```
func RegisterPreHandler[Req Message](
router PreMsgRouter,
handler func(ctx context.Context, msg Req) error,
) {
untypedHandler := func(ctx context.Context, m Message) error {
typed, ok := m.(Req)
if !ok {
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
}
return handler(ctx, typed)
}
router.Register(messageName[Req](), untypedHandler)
}
// // RegisterPreHandler is a helper function that modules can use to not lose type safety when registering PreMsgHandler to the
// // PreMsgRouter. Example usage:
// // ```go
// //
// // func (k Keeper) BeforeSend(ctx context.Context, req *types.MsgSend) (*types.QueryBalanceResponse, error) {
// // ... before send logic ...
// // }
// //
// // func (m Module) RegisterPreMsgHandlers(router appmodule.PreMsgRouter) {
// // appmodule.RegisterPreHandler(router, keeper.BeforeSend)
// // }
// //
// // ```
// func RegisterPreHandler[Req transaction.Msg](
// router PreMsgRouter,
// handler func(ctx context.Context, msg Req) error,
// ) {
// untypedHandler := func(ctx context.Context, m transaction.Msg) error {
// typed, ok := m.(Req)
// if !ok {
// return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
// }
// return handler(ctx, typed)
// }
// router.Register(messageName[Req](), untypedHandler)
// }

// RegisterPostHandler is a helper function that modules can use to not lose type safety when registering handlers to the
// PostMsgRouter. Example usage:
// ```go
//
// func (k Keeper) AfterSend(ctx context.Context, req *types.MsgSend, resp *types.MsgSendResponse) error {
// ... query logic ...
// }
//
// func (m Module) RegisterPostMsgHandlers(router appmodule.PostMsgRouter) {
// appmodule.RegisterPostHandler(router, keeper.AfterSend)
// }
//
// ```
func RegisterPostHandler[Req, Resp Message](
router PostMsgRouter,
handler func(ctx context.Context, msg Req, msgResp Resp) error,
) {
untypedHandler := func(ctx context.Context, m, mResp Message) error {
typed, ok := m.(Req)
if !ok {
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
}
typedResp, ok := mResp.(Resp)
if !ok {
return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Resp))
}
return handler(ctx, typed, typedResp)
}
router.Register(messageName[Req](), untypedHandler)
}
// // RegisterPostHandler is a helper function that modules can use to not lose type safety when registering handlers to the
// // PostMsgRouter. Example usage:
// // ```go
// //
// // func (k Keeper) AfterSend(ctx context.Context, req *types.MsgSend, resp *types.MsgSendResponse) error {
// // ... query logic ...
// // }
// //
// // func (m Module) RegisterPostMsgHandlers(router appmodule.PostMsgRouter) {
// // appmodule.RegisterPostHandler(router, keeper.AfterSend)
// // }
// //
// // ```
// func RegisterPostHandler[Req, Resp transaction.Msg](
// router PostMsgRouter,
// handler func(ctx context.Context, msg Req, msgResp Resp) error,
// ) {
// untypedHandler := func(ctx context.Context, m, mResp transaction.Msg) error {
// typed, ok := m.(Req)
// if !ok {
// return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Req))
// }
// typedResp, ok := mResp.(Resp)
// if !ok {
// return fmt.Errorf("unexpected type %T, wanted: %T", m, *new(Resp))
// }
// return handler(ctx, typed, typedResp)
// }
// router.Register(messageName[Req](), untypedHandler)
// }

// msg handler

Expand Down
16 changes: 0 additions & 16 deletions core/appmodule/v2/message.go

This file was deleted.

4 changes: 2 additions & 2 deletions core/event/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package event
import (
"context"

gogoproto "github.com/cosmos/gogoproto/proto"
"cosmossdk.io/core/transaction"
)

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

// EmitKV emits an event based on an event and kv-pair attributes.
//
Expand Down
9 changes: 0 additions & 9 deletions core/go.mod
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,5 @@ module cosmossdk.io/core

go 1.20

require github.com/cosmos/gogoproto v1.6.0

require (
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

// Version tagged too early and incompatible with v0.50 (latest at the time of tagging)
retract v0.12.0
10 changes: 0 additions & 10 deletions core/go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
github.com/cosmos/gogoproto v1.6.0 h1:Xm0F/96O5Ox4g6xGgjA41rWaaPjYtOdTi59uBcV2qEE=
github.com/cosmos/gogoproto v1.6.0/go.mod h1:Y+g956rcUf2vr4uwtCcK/1Xx9BWVluCtcI9vsh0GHmk=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
6 changes: 3 additions & 3 deletions core/registry/legacy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package registry

import (
gogoproto "github.com/cosmos/gogoproto/proto"
"cosmossdk.io/core/transaction"
)

type InterfaceRegistrar interface {
Expand All @@ -14,12 +14,12 @@ type InterfaceRegistrar interface {
//
// Ex:
// registry.RegisterInterface("cosmos.base.v1beta1.Msg", (*sdk.Msg)(nil))
RegisterInterface(protoName string, iface interface{}, impls ...gogoproto.Message)
RegisterInterface(protoName string, iface interface{}, impls ...transaction.Msg)

// RegisterImplementations registers impls as concrete implementations of
// the interface iface.
//
// Ex:
// registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{})
RegisterImplementations(iface interface{}, impls ...gogoproto.Message)
RegisterImplementations(iface interface{}, impls ...transaction.Msg)
}
8 changes: 4 additions & 4 deletions core/router/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package router
import (
"context"

gogoproto "github.com/cosmos/gogoproto/proto"
"cosmossdk.io/core/transaction"
)

// Service is the interface that wraps the basic methods for a router.
Expand All @@ -12,7 +12,7 @@ type Service interface {
// CanInvoke returns an error if the given request cannot be invoked.
CanInvoke(ctx context.Context, typeURL string) error
// InvokeTyped execute a message or query. It should be used when the called knows the type of the response.
InvokeTyped(ctx context.Context, req, res gogoproto.Message) error
// InvokeUntyped execute a message or query. It should be used when the called doesn't know the type of the response.
InvokeUntyped(ctx context.Context, req gogoproto.Message) (res gogoproto.Message, err error)
InvokeTyped(ctx context.Context, req, res transaction.Msg) error
// InvokeUntyped execute a Msg or query. It should be used when the called doesn't know the type of the response.
InvokeUntyped(ctx context.Context, req transaction.Msg) (res transaction.Msg, err error)
}
Loading
Loading