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

Remove ServiceMsgs from ADR-031 #9139

Merged
merged 56 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f1398cb
wip
aaronc Apr 12, 2021
b54d71f
wip
aaronc Apr 12, 2021
03a358d
wip
aaronc Apr 12, 2021
2a6223e
wip on refactoring adr 031 type URLs
aaronc Apr 12, 2021
559fc54
Fix msg_service_router
amaury1093 Apr 19, 2021
f2d8355
Fix gov client queries
amaury1093 Apr 19, 2021
d5c6ce9
Fix some modules tests
amaury1093 Apr 19, 2021
569f777
Remove all instances of "*.Msg/*"
amaury1093 Apr 19, 2021
19720e7
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 19, 2021
c52587c
Uncomment code
amaury1093 Apr 19, 2021
aa30868
Remove commented code
amaury1093 Apr 19, 2021
2919375
// simulation.NewWeightedOperation(
amaury1093 Apr 19, 2021
488dc62
Fix CopyTx
amaury1093 Apr 19, 2021
72c0cbc
Fix more tests
amaury1093 Apr 19, 2021
04ba707
Fix x/gov test
amaury1093 Apr 19, 2021
5f543a4
proto.MessageName->sdk.MsgName
amaury1093 Apr 20, 2021
6d1b1cc
Fix authz tests
amaury1093 Apr 20, 2021
16b72f1
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 20, 2021
d4130c2
Use MsgRoute in feegrant and staking/authz
amaury1093 Apr 20, 2021
5f4a19c
Fix more tests
amaury1093 Apr 20, 2021
d5a2982
Fix sims?
amaury1093 Apr 20, 2021
9743b9e
Add norace tag
amaury1093 Apr 20, 2021
a323bff
Add CL
amaury1093 Apr 20, 2021
14acc84
rebuild rosetta api test data
Apr 20, 2021
0e57b6f
Update ADR
amaury1093 Apr 21, 2021
0840c18
Rename MsgRoute -> MsgTypeURL
amaury1093 Apr 21, 2021
5cb4301
Fix codec registration
amaury1093 Apr 21, 2021
fc37733
Remove sdk.GetLegacySignBytes
amaury1093 Apr 21, 2021
5d1836b
Update types/tx_msg.go
amaury1093 Apr 21, 2021
fcaedf9
Update x/authz/simulation/operations.go
amaury1093 Apr 21, 2021
7904aef
Move LegacyMsg to legacytx
amaury1093 Apr 21, 2021
b2bf609
Merge branch 'am/adr-31-type-url' of ssh://github.com/cosmos/cosmos-s…
amaury1093 Apr 21, 2021
77e20c2
Update CHANGELOG.md
amaury1093 Apr 22, 2021
3cac0e6
Remove NewAnyWithCustomTypeURL
amaury1093 Apr 22, 2021
113ef64
Keep support for ServiceMsgs
amaury1093 Apr 22, 2021
1c3886d
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 22, 2021
09e81a2
Fix TxBody UnpackInterfaces
amaury1093 Apr 22, 2021
7e05b80
Fix test
amaury1093 Apr 22, 2021
68b7e5f
Address review
amaury1093 Apr 23, 2021
bb33c2b
Merge branch 'master' into am/adr-31-type-url
amaury1093 Apr 23, 2021
c2a024d
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 27, 2021
f25b2c6
Remove support for ServiceMsg typeURLs
amaury1093 Apr 27, 2021
31e5c2a
Fix lint
amaury1093 Apr 27, 2021
d6ab3eb
Update changelog
amaury1093 Apr 27, 2021
3e7d3ae
Fix tests
amaury1093 Apr 27, 2021
2000ebf
Use sdk.MsgTypeURL everywhere
amaury1093 Apr 27, 2021
a688c73
Fix tests
amaury1093 Apr 27, 2021
666fe92
Fix rosetta, run make rosetta-data
amaury1093 Apr 27, 2021
aa2b26c
Fix rosetta thanks to froydi
amaury1093 Apr 27, 2021
249f857
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 27, 2021
d2a8ae5
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 29, 2021
cd4bc02
Address reviews
amaury1093 Apr 29, 2021
774a4ab
Fix test
amaury1093 Apr 29, 2021
d3c3381
Remove stray log
amaury1093 Apr 30, 2021
98ad2b7
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/a…
amaury1093 Apr 30, 2021
e95ae32
Update CL
amaury1093 Apr 30, 2021
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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

## Features
### Features

* [\#8965](https://github.com/cosmos/cosmos-sdk/pull/8965) cosmos reflection now provides more information on the application such as: deliverable msgs, sdk.Config info etc (still in alpha stage).
* [\#8559](https://github.com/cosmos/cosmos-sdk/pull/8559) Added Protobuf compatible secp256r1 ECDSA signatures.
* [\#8786](https://github.com/cosmos/cosmos-sdk/pull/8786) Enabled secp256r1 in x/auth.
Expand All @@ -45,6 +46,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#9088](https://github.com/cosmos/cosmos-sdk/pull/9088) Added implementation to ADR-28 Derived Addresses.

### Client Breaking Changes

* [\#8363](https://github.com/cosmos/cosmos-sdk/pull/8363) Addresses no longer have a fixed 20-byte length. From the SDK modules' point of view, any 1-255 bytes-long byte array is a valid address.
* [\#8346](https://github.com/cosmos/cosmos-sdk/pull/8346) All CLI `tx` commands generate ServiceMsgs by default. Graceful Amino support has been added to ServiceMsgs to support signing legacy Msgs.
* (crypto/ed25519) [\#8690] Adopt zip1215 ed2559 verification rules.
Expand Down Expand Up @@ -83,7 +85,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (auth/tx) [\#8926](https://github.com/cosmos/cosmos-sdk/pull/8926) The `ProtoTxProvider` interface used as a workaround for transaction simulation has been removed.
* (x/bank) [\#8798](https://github.com/cosmos/cosmos-sdk/pull/8798) `GetTotalSupply` is removed in favour of `GetPaginatedTotalSupply`
* (x/bank/types) [\#9061](https://github.com/cosmos/cosmos-sdk/pull/9061) `AddressFromBalancesStore` now returns an error for invalid key instead of panic.

* [\#9139](https://github.com/cosmos/cosmos-sdk/pull/9139) ServiceMsgs as defined in ADR-031 have been removed, so that the SDK adheres to the Protobuf spec of `Any` packing. This has multiple consequences:
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
* The `sdk.ServiceMsg` interface has been removed.
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
* `sdk.Msg` now only contains `ValidateBasic` and `GetSigners` methods. The remaining methods `GetSignBytes`, `Route` and `Type` are moved to `legacytx.LegacyMsg`.
* The `RegisterCustomTypeURL` function and the `cosmos.base.v1beta1.ServiceMsg` interface have been removed from the interface registry.


### State Machine Breaking
Expand Down
33 changes: 16 additions & 17 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/rootmulti"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
)

const (
Expand Down Expand Up @@ -703,37 +704,35 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
}

var (
msgEvents sdk.Events
msgResult *sdk.Result
msgFqName string
err error
msgResult *sdk.Result
msgEventAction string // name to use as value in event `message.action`
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
err error
)

if svcMsg, ok := msg.(sdk.ServiceMsg); ok {
msgFqName = svcMsg.MethodName
Copy link
Contributor

Choose a reason for hiding this comment

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

The message.action is very important for relayers as it is used to distinguish when the next message event starts/ends and what type of event is occurring. Relayers may be connected to chains on the old version and the new version and thus need to be aware of this change to ensure IBC continues to work between chains with different versions

Does the svcMsg.MethodName != sdk.MsgTypeURL(msg)? Or is there no breaking change here for Msgs migrated to proto messages registered on a Msg service (which from my understanding is the case for the current IBC Msgs). I'm a little fuzzy on the exact differences between the legacy messages, the proto message req/resp types and the msg service router, so please excuse me if I used the terminology wrong

Copy link
Contributor Author

@amaury1093 amaury1093 May 7, 2021

Choose a reason for hiding this comment

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

It's just confusing, to me too. I tried to simplify it like this:

In v0.42, these message.actions were emitted:

  1. either message.action='/cosmos.bank.v1beta1.Msg/Send' if the user explicity sent a ServiceMsg tx (note the 2 /)
  2. or message.action='send' for all other messages (99% of the messages)

After this PR:

  • (1) is completely removed
  • (2) has been converted to message.action='/cosmos.bank.v1beta1.MsgSend' (note only 1 /), so legacy message.action='send' are not emitted anymore (unless the app developer didn't wire up proto registration correctly). This is not retroactive though.

Let me know if that works for IBC.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, thanks for the response! This makes sense. This should be fine for relayers, but it will likely require a small change. Relayer should now check for message.action='send' || message.action='/cosmos.bank.v1beta1.MsgSend'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's the approach I'm taking too, e.g. if querying deposits here.

handler := app.msgServiceRouter.Handler(msgFqName)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message service method: %s; message index: %d", msgFqName, i)
}
msgResult, err = handler(ctx, svcMsg.Request)
} else {
if handler := app.msgServiceRouter.Handler(msg); handler != nil {
// ADR 031 request type routing
msgResult, err = handler(ctx, msg)
msgEventAction = sdk.MsgName(msg)
Copy link
Member

Choose a reason for hiding this comment

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

type URL right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, changed! See #9139 (comment) for reason.

} else if legacyMsg, ok := msg.(legacytx.LegacyMsg); ok {
// legacy sdk.Msg routing
msgRoute := msg.Route()
msgFqName = msg.Type()
msgRoute := legacyMsg.Route()
msgEventAction = legacyMsg.Type()
handler := app.router.Route(ctx, msgRoute)
if handler == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized message route: %s; message index: %d", msgRoute, i)
}

msgResult, err = handler(ctx, msg)
} else {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "can't route message %+v", msg)
}

if err != nil {
return nil, sdkerrors.Wrapf(err, "failed to execute message; message index: %d", i)
}

msgEvents = sdk.Events{
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, msgFqName)),
msgEvents := sdk.Events{
sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, msgEventAction)),
}
msgEvents = msgEvents.AppendEvents(msgResult.GetEvents())

Expand All @@ -743,7 +742,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (*s
// separate each result.
events = events.AppendEvents(msgEvents)

txMsgData.Data = append(txMsgData.Data, &sdk.MsgData{MsgType: msg.Type(), Data: msgResult.Data})
txMsgData.Data = append(txMsgData.Data, &sdk.MsgData{MsgType: sdk.MsgName(msg), Data: msgResult.Data})
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
msgLogs = append(msgLogs, sdk.NewABCIMessageLog(uint32(i), msgResult.Log, msgEvents))
}

Expand Down
46 changes: 37 additions & 9 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ func NewMsgServiceRouter() *MsgServiceRouter {
}

// MsgServiceHandler defines a function type which handles Msg service message.
type MsgServiceHandler = func(ctx sdk.Context, req sdk.MsgRequest) (*sdk.Result, error)
type MsgServiceHandler = func(ctx sdk.Context, req sdk.Msg) (*sdk.Result, error)

// Handler returns the MsgServiceHandler for a given query route path or nil
// Handler returns the MsgServiceHandler for a given msg or nil if not found.
func (msr *MsgServiceRouter) Handler(msg sdk.Msg) MsgServiceHandler {
return msr.routes[sdk.MsgTypeURL(msg)]
}

// HandlerbyTypeURL returns the MsgServiceHandler for a given query route path or nil
// if not found.
func (msr *MsgServiceRouter) Handler(methodName string) MsgServiceHandler {
return msr.routes[methodName]
func (msr *MsgServiceRouter) HandlerbyTypeURL(msgName string) MsgServiceHandler {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
return msr.routes[msgName]
}

// RegisterService implements the gRPC Server.RegisterService method. sd is a gRPC
Expand All @@ -50,20 +55,41 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
fqMethod := fmt.Sprintf("/%s/%s", sd.ServiceName, method.MethodName)
methodHandler := method.Handler

var requestTypeName string

// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.
// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.
// We use a no-op interceptor to avoid actually calling into the handler itself.
_, _ = methodHandler(nil, context.Background(), func(i interface{}) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

is there context available in sd? We should use it instead of context.Background

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not, sd is just a descriptor.

msg, ok := i.(sdk.Msg)
if !ok {
// We panic here because there is no other alternative and the app cannot be initialized correctly
// this should only happen if there is a problem with code generation in which case the app won't
// work correctly anyway.
panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
Copy link
Collaborator

Choose a reason for hiding this comment

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

why we don't return an error?

Copy link
Contributor Author

@amaury1093 amaury1093 Apr 29, 2021

Choose a reason for hiding this comment

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

If we return an error, then the app will continue running, with potential encoding errors that are hard to debug down the road.

}

requestTypeName = sdk.MsgTypeURL(msg)
return nil
}, func(_ context.Context, _ interface{}, _ *grpc.UnaryServerInfo, _ grpc.UnaryHandler) (interface{}, error) {
return nil, nil
},
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
)

// Check that the service Msg fully-qualified method name has already
// been registered (via RegisterInterfaces). If the user registers a
// service without registering according service Msg type, there might be
// some unexpected behavior down the road. Since we can't return an error
// (`Server.RegisterService` interface restriction) we panic (at startup).
serviceMsg, err := msr.interfaceRegistry.Resolve(fqMethod)
if err != nil || serviceMsg == nil {
reqType, err := msr.interfaceRegistry.Resolve(requestTypeName)
if err != nil || reqType == nil {
panic(
fmt.Errorf(
"type_url %s has not been registered yet. "+
"Before calling RegisterService, you must register all interfaces by calling the `RegisterInterfaces` "+
"method on module.BasicManager. Each module should call `msgservice.RegisterMsgServiceDesc` inside its "+
"`RegisterInterfaces` method with the `_Msg_serviceDesc` generated by proto-gen",
fqMethod,
requestTypeName,
),
)
}
Expand All @@ -72,7 +98,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
// registered more than once, then we should error. Since we can't
// return an error (`Server.RegisterService` interface restriction) we
// panic (at startup).
_, found := msr.routes[fqMethod]
Copy link
Collaborator

Choose a reason for hiding this comment

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

whenever I see it I always read FAQ method 🤣

_, found := msr.routes[requestTypeName]
if found {
panic(
fmt.Errorf(
Expand All @@ -83,7 +109,7 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter
)
}

msr.routes[fqMethod] = func(ctx sdk.Context, req sdk.MsgRequest) (*sdk.Result, error) {
handler := func(ctx sdk.Context, req sdk.Msg) (*sdk.Result, error) {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
ctx = ctx.WithEventManager(sdk.NewEventManager())
interceptor := func(goCtx context.Context, _ interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
goCtx = context.WithValue(goCtx, sdk.SdkContextKey, ctx)
Expand All @@ -103,6 +129,8 @@ func (msr *MsgServiceRouter) RegisterService(sd *grpc.ServiceDesc, handler inter

return sdk.WrapServiceResult(ctx, resMsg, err)
}

msr.routes[requestTypeName] = handler
}
}

Expand Down
4 changes: 2 additions & 2 deletions baseapp/msg_service_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func TestMsgService(t *testing.T) {
)
_ = app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: 1}})

msg := testdata.NewServiceMsgCreateDog(&testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}})
msg := testdata.MsgCreateDog{Dog: &testdata.Dog{Name: "Spot"}}
txBuilder := encCfg.TxConfig.NewTxBuilder()
txBuilder.SetFeeAmount(testdata.NewTestFeeAmount())
txBuilder.SetGasLimit(testdata.NewTestGasLimit())
err := txBuilder.SetMsgs(msg)
err := txBuilder.SetMsgs(&msg)
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)

// First round: we gather all the signer infos. We use the "set empty
Expand Down
12 changes: 4 additions & 8 deletions client/tx/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
signing2 "github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/legacytx"
"github.com/cosmos/cosmos-sdk/x/auth/signing"
Expand All @@ -39,10 +38,7 @@ var (
},
}
msg0 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 1)))
msg1 = sdk.ServiceMsg{
MethodName: "/cosmos.bank.v1beta1.Msg/Send",
Request: banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2))),
}
msg1 = banktypes.NewMsgSend(addr1, addr2, types.NewCoins(types.NewInt64Coin("wack", 2)))
)

func buildTestTx(t *testing.T, builder client.TxBuilder) {
Expand Down Expand Up @@ -88,7 +84,7 @@ func (s *TestSuite) TestCopyTx() {
s.Require().Equal(sigsV2_1, sigsV2_2)
s.Require().Equal(protoBuilder.GetTx().GetSigners(), protoBuilder2.GetTx().GetSigners())
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[0], protoBuilder2.GetTx().GetMsgs()[0])
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1].(sdk.ServiceMsg).Request, protoBuilder2.GetTx().GetMsgs()[1]) // We lose the "ServiceMsg" information
s.Require().Equal(protoBuilder.GetTx().GetMsgs()[1], protoBuilder2.GetTx().GetMsgs()[1])

// amino -> proto -> amino
aminoBuilder = s.aminoCfg.NewTxBuilder()
Expand Down Expand Up @@ -120,7 +116,7 @@ func (s *TestSuite) TestConvertTxToStdTx() {
s.Require().Equal(gas, stdTx.Fee.Gas)
s.Require().Equal(fee, stdTx.Fee.Amount)
s.Require().Equal(msg0, stdTx.Msgs[0])
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
s.Require().Equal(msg1, stdTx.Msgs[1])
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
s.Require().Equal(sig.PubKey, stdTx.Signatures[0].PubKey)
s.Require().Equal(sig.Data.(*signing2.SingleSignatureData).Signature, stdTx.Signatures[0].Signature)
Expand All @@ -140,7 +136,7 @@ func (s *TestSuite) TestConvertTxToStdTx() {
s.Require().Equal(gas, stdTx.Fee.Gas)
s.Require().Equal(fee, stdTx.Fee.Amount)
s.Require().Equal(msg0, stdTx.Msgs[0])
s.Require().Equal(msg1.Request, stdTx.Msgs[1])
s.Require().Equal(msg1, stdTx.Msgs[1])
s.Require().Equal(timeoutHeight, stdTx.TimeoutHeight)
s.Require().Empty(stdTx.Signatures)

Expand Down
20 changes: 0 additions & 20 deletions codec/types/interface_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ type InterfaceRegistry interface {
// registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSend{}, &MsgMultiSend{})
RegisterImplementations(iface interface{}, impls ...proto.Message)

// RegisterCustomTypeURL allows a protobuf message to be registered as a
// google.protobuf.Any with a custom typeURL (besides its own canonical
// typeURL). iface should be an interface as type, as in RegisterInterface
// and RegisterImplementations.
//
// Ex:
// This will allow us to pack service methods in Any's using the full method name
// as the type URL and the request body as the value, and allow us to unpack
// such packed methods using the normal UnpackAny method for the interface iface.
RegisterCustomTypeURL(iface interface{}, typeURL string, impl proto.Message)

// ListAllInterfaces list the type URLs of all registered interfaces.
ListAllInterfaces() []string

Expand Down Expand Up @@ -127,15 +116,6 @@ func (registry *interfaceRegistry) RegisterImplementations(iface interface{}, im
}
}

// RegisterCustomTypeURL registers a concrete type which implements the given
// interface under `typeURL`.
//
// This function PANICs if different concrete types are registered under the
// same typeURL.
func (registry *interfaceRegistry) RegisterCustomTypeURL(iface interface{}, typeURL string, impl proto.Message) {
registry.registerImpl(iface, typeURL, impl)
}

// registerImpl registers a concrete type which implements the given
// interface under `typeURL`.
//
Expand Down
62 changes: 0 additions & 62 deletions codec/types/types_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package types_test

import (
"context"
"fmt"
"strings"
"testing"

"github.com/gogo/protobuf/grpc"
"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/require"
grpc2 "google.golang.org/grpc"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
)
Expand Down Expand Up @@ -185,60 +180,3 @@ func TestAny_ProtoJSON(t *testing.T) {
require.NoError(t, err)
require.Equal(t, spot, ha2.Animal.GetCachedValue())
}

// this instance of grpc.ClientConn is used to test packing service method
// requests into Any's
type testAnyPackClient struct {
any types.Any
interfaceRegistry types.InterfaceRegistry
}

var _ grpc.ClientConn = &testAnyPackClient{}

func (t *testAnyPackClient) Invoke(_ context.Context, method string, args, _ interface{}, _ ...grpc2.CallOption) error {
reqMsg, ok := args.(proto.Message)
if !ok {
return fmt.Errorf("can't proto marshal %T", args)
}

// registry the method request type with the interface registry
t.interfaceRegistry.RegisterCustomTypeURL((*interface{})(nil), method, reqMsg)

bz, err := proto.Marshal(reqMsg)
if err != nil {
return err
}

t.any.TypeUrl = method
t.any.Value = bz

return nil
}

func (t *testAnyPackClient) NewStream(context.Context, *grpc2.StreamDesc, string, ...grpc2.CallOption) (grpc2.ClientStream, error) {
return nil, fmt.Errorf("not supported")
}

func TestAny_ServiceRequestProtoJSON(t *testing.T) {
interfaceRegistry := types.NewInterfaceRegistry()
anyPacker := &testAnyPackClient{interfaceRegistry: interfaceRegistry}
dogMsgClient := testdata.NewMsgClient(anyPacker)
_, err := dogMsgClient.CreateDog(context.Background(), &testdata.MsgCreateDog{Dog: &testdata.Dog{
Name: "spot",
}})
require.NoError(t, err)

// marshal JSON
cdc := codec.NewProtoCodec(interfaceRegistry)
bz, err := cdc.MarshalJSON(&anyPacker.any)
require.NoError(t, err)
require.Equal(t,
`{"@type":"/testdata.Msg/CreateDog","dog":{"size":"","name":"spot"}}`,
string(bz))

// unmarshal JSON
var any2 types.Any
err = cdc.UnmarshalJSON(bz, &any2)
require.NoError(t, err)
require.Equal(t, anyPacker.any, any2)
}
Binary file modified contrib/rosetta/node/data.tar.gz
Binary file not shown.
Loading