diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index d60fbcf9..13523f80 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -126,6 +126,7 @@ jobs: "CellarFees", "Incentives", "Pubsub", + "Addresses", ] steps: - name: Set up Go 1.22 diff --git a/Makefile b/Makefile index 0cf6219d..314f45e1 100644 --- a/Makefile +++ b/Makefile @@ -211,12 +211,12 @@ test-docker-push: test-docker ############################################################################### ### Protobuf ### ############################################################################### -protoVer=0.13.1 +protoVer=0.15.1 protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer) protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) proto-all: proto-format proto-lint proto-gen - + proto-gen: @echo "Generating Protobuf files" # todo: figure out why this old method was failing @@ -391,6 +391,9 @@ e2e_incentives_test: e2e_clean_slate e2e_pubsub_test: e2e_clean_slate @E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestPubsub || make -s fail +e2e_addresses_test: e2e_clean_slate + @E2E_SKIP_CLEANUP=true integration_tests/integration_tests.test -test.failfast -test.v -test.run IntegrationTestSuite -testify.m TestAddresses || make -s fail + fail: @echo 'test failed; dumping container logs into ./testlogs for review' @docker logs ethereum > testlogs/ethereum.log 2>&1 || true diff --git a/app/app.go b/app/app.go index 70678bb1..5b1350e2 100644 --- a/app/app.go +++ b/app/app.go @@ -106,6 +106,9 @@ import ( gravitykeeper "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/keeper" gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" appParams "github.com/peggyjv/sommelier/v7/app/params" + "github.com/peggyjv/sommelier/v7/x/addresses" + addresseskeeper "github.com/peggyjv/sommelier/v7/x/addresses/keeper" + addressestypes "github.com/peggyjv/sommelier/v7/x/addresses/types" "github.com/peggyjv/sommelier/v7/x/auction" auctionclient "github.com/peggyjv/sommelier/v7/x/auction/client" auctionkeeper "github.com/peggyjv/sommelier/v7/x/auction/keeper" @@ -201,6 +204,7 @@ var ( incentives.AppModuleBasic{}, auction.AppModuleBasic{}, pubsub.AppModuleBasic{}, + addresses.AppModuleBasic{}, ) // module account permissions @@ -219,6 +223,7 @@ var ( axelarcorktypes.ModuleName: nil, auctiontypes.ModuleName: {authtypes.Burner}, pubsubtypes.ModuleName: nil, + addressestypes.ModuleName: nil, } // module accounts that are allowed to receive tokens @@ -276,6 +281,7 @@ type SommelierApp struct { IncentivesKeeper incentiveskeeper.Keeper AuctionKeeper auctionkeeper.Keeper PubsubKeeper pubsubkeeper.Keeper + AddressesKeeper addresseskeeper.Keeper // make capability scoped keepers public for test purposes (IBC only) ScopedAxelarCorkKeeper capabilitykeeper.ScopedKeeper @@ -343,6 +349,7 @@ func NewSommelierApp( auctiontypes.StoreKey, cellarfeestypes.StoreKey, pubsubtypes.StoreKey, + addressestypes.StoreKey, ) tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) @@ -524,6 +531,10 @@ func NewSommelierApp( app.CorkKeeper.Hooks(), )) + app.AddressesKeeper = *addresseskeeper.NewKeeper( + appCodec, keys[addressestypes.StoreKey], app.GetSubspace(addressestypes.ModuleName), + ) + // register the proposal types govRouter := govtypesv1beta1.NewRouter() govRouter.AddRoute(govtypes.RouterKey, govtypesv1beta1.ProposalHandler). @@ -604,6 +615,7 @@ func NewSommelierApp( cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper), auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec), pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper), + addresses.NewAppModule(appCodec, app.AddressesKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -638,6 +650,7 @@ func NewSommelierApp( cellarfeestypes.ModuleName, auctiontypes.ModuleName, pubsubtypes.ModuleName, + addressestypes.ModuleName, ) // NOTE gov must come before staking @@ -668,6 +681,7 @@ func NewSommelierApp( cellarfeestypes.ModuleName, auctiontypes.ModuleName, pubsubtypes.ModuleName, + addressestypes.ModuleName, ) // NOTE: The genutils module must occur after staking so that pools are @@ -706,6 +720,7 @@ func NewSommelierApp( cellarfeestypes.ModuleName, auctiontypes.ModuleName, pubsubtypes.ModuleName, + addressestypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) @@ -741,6 +756,7 @@ func NewSommelierApp( cellarfees.NewAppModule(app.CellarFeesKeeper, appCodec, app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.CorkKeeper, app.AuctionKeeper), auction.NewAppModule(app.AuctionKeeper, app.BankKeeper, app.AccountKeeper, appCodec), pubsub.NewAppModule(appCodec, app.PubsubKeeper, app.StakingKeeper, app.GravityKeeper), + addresses.NewAppModule(appCodec, app.AddressesKeeper), ) app.sm.RegisterStoreDecoders() @@ -992,6 +1008,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(incentivestypes.ModuleName) paramsKeeper.Subspace(auctiontypes.ModuleName) paramsKeeper.Subspace(pubsubtypes.ModuleName) + paramsKeeper.Subspace(addressestypes.ModuleName) return paramsKeeper } diff --git a/go.mod b/go.mod index 2e465ff7..74b49009 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/peggyjv/sommelier/v7 go 1.22 -toolchain go1.22.2 +toolchain go1.22.1 require ( cosmossdk.io/api v0.3.1 diff --git a/integration_tests/addresses_test.go b/integration_tests/addresses_test.go new file mode 100644 index 00000000..e6688590 --- /dev/null +++ b/integration_tests/addresses_test.go @@ -0,0 +1,145 @@ +package integration_tests + +import ( + "context" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +func (s *IntegrationTestSuite) TestAddresses() { + s.Run("Bring up chain, submit, query, and remove address mappings", func() { + s.T().Log("Starting x/addresses tests") + val := s.chain.validators[0] + kb, err := val.keyring() + s.Require().NoError(err) + val0ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", &kb, "val", val.address()) + s.Require().NoError(err) + addressesQueryClient := types.NewQueryClient(val0ClientCtx) + + orch := s.chain.orchestrators[0] + orchClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch.keyring, "orch", orch.address()) + s.Require().NoError(err) + + evmAddress := common.HexToAddress("0x1234567890123456789012345678901234567890") + cosmosAddress := orch.address() + + addAddressMappingMsg, err := types.NewMsgAddAddressMapping(evmAddress, cosmosAddress) + s.Require().NoError(err) + + s.T().Logf("Submitting mapping from %s to %s", evmAddress.Hex(), cosmosAddress.String()) + _, err = s.chain.sendMsgs(*orchClientCtx, addAddressMappingMsg) + s.Require().NoError(err) + + s.T().Log("Testing queries return expected addresses") + s.Require().Eventually(func() bool { + queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{}) + if err != nil { + s.T().Logf("Error querying address mappings: %s", err) + return false + } + + return len(queryRes.AddressMappings) == 1 && evmAddress.Hex() == queryRes.AddressMappings[0].EvmAddress + }, 20*time.Second, 4*time.Second, "address mapping never found") + + queryByEvmRes, err := addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddress.Hex()}) + s.Require().NoError(err) + s.Require().Equal(cosmosAddress.String(), queryByEvmRes.CosmosAddress, "Cosmos address does not match") + s.Require().Equal(evmAddress.Hex(), queryByEvmRes.EvmAddress, "EVM address does not match") + + queryByCosmosRes, err := addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddress.String()}) + s.Require().NoError(err) + s.Require().Equal(cosmosAddress.String(), queryByCosmosRes.CosmosAddress, "Cosmos address does not match") + s.Require().Equal(evmAddress.Hex(), queryByCosmosRes.EvmAddress, "EVM address does not match") + + s.T().Log("Removing address mapping") + removeAddressMappingMsg, err := types.NewMsgRemoveAddressMapping(cosmosAddress) + s.Require().NoError(err) + + _, err = s.chain.sendMsgs(*orchClientCtx, removeAddressMappingMsg) + s.Require().NoError(err) + + s.T().Log("Testing mappings query returns no addresses") + s.Require().Eventually(func() bool { + queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{}) + if err != nil { + s.T().Logf("Error querying address mappings: %s", err) + return false + } + + return len(queryRes.AddressMappings) == 0 + }, 20*time.Second, 4*time.Second, "address mapping not deleted") + + _, err = addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddress.Hex()}) + s.Require().Error(err) + s.Require().Contains(err.Error(), "code = NotFound") + + _, err = addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddress.String()}) + s.Require().Error(err) + s.Require().Contains(err.Error(), "code = NotFound") + + // Test error cases + + // Test adding multiple mappings + s.T().Log("Adding multiple mappings") + evmAddress2 := common.HexToAddress("0x2345678901234567890123456789012345678901") + cosmosAddress2 := s.chain.orchestrators[1].address() + orch1 := s.chain.orchestrators[1] + orch1ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch1.keyring, "orch", orch1.address()) + s.Require().NoError(err) + + addAddressMappingMsg2, err := types.NewMsgAddAddressMapping(evmAddress2, cosmosAddress2) + s.Require().NoError(err) + + _, err = s.chain.sendMsgs(*orchClientCtx, addAddressMappingMsg) + s.Require().NoError(err) + _, err = s.chain.sendMsgs(*orch1ClientCtx, addAddressMappingMsg2) + s.Require().NoError(err) + + // Query multiple mappings + s.T().Log("Querying multiple mappings") + s.Require().Eventually(func() bool { + queryRes, err := addressesQueryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{}) + if err != nil { + s.T().Logf("Error querying address mappings: %s", err) + return false + } + + return len(queryRes.AddressMappings) == 2 + }, 20*time.Second, 4*time.Second, "expected two address mappings") + + // Test adding a duplicate mapping + s.T().Log("Adding a duplicate mapping") + duplicateMsg, err := types.NewMsgAddAddressMapping(evmAddress, cosmosAddress) + s.Require().NoError(err) + + _, err = s.chain.sendMsgs(*orchClientCtx, duplicateMsg) + s.Require().NoError(err) + _, err = s.chain.sendMsgs(*orchClientCtx, duplicateMsg) + s.Require().NoError(err) + + // Test removing a non-existent mapping + s.T().Log("Removing a non-existent mapping") + nonExistentAddress := s.chain.orchestrators[2].address() + orch2 := s.chain.orchestrators[2] + orch2ClientCtx, err := s.chain.clientContext("tcp://localhost:26657", orch2.keyring, "orch", orch2.address()) + s.Require().NoError(err) + removeNonExistentMsg, err := types.NewMsgRemoveAddressMapping(nonExistentAddress) + s.Require().NoError(err) + + _, err = s.chain.sendMsgs(*orch2ClientCtx, removeNonExistentMsg) + s.Require().NoError(err) + + // Test querying with invalid addresses + s.T().Log("Querying with invalid addresses") + _, err = addressesQueryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: "invalid"}) + s.Require().Error(err) + s.Require().Contains(err.Error(), "invalid EVM address") + + s.T().Log("Querying with invalid cosmos address") + _, err = addressesQueryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: "invalid"}) + s.Require().Error(err) + s.Require().Contains(err.Error(), "failed to parse cosmos address") + }) +} diff --git a/integration_tests/setup_test.go b/integration_tests/setup_test.go index cee977a0..20aa3243 100644 --- a/integration_tests/setup_test.go +++ b/integration_tests/setup_test.go @@ -18,6 +18,7 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" gravitytypes "github.com/peggyjv/gravity-bridge/module/v4/x/gravity/types" "github.com/peggyjv/sommelier/v7/app/params" + addressestypes "github.com/peggyjv/sommelier/v7/x/addresses/types" auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types" axelarcorktypes "github.com/peggyjv/sommelier/v7/x/axelarcork/types" cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types" @@ -483,6 +484,11 @@ func (s *IntegrationTestSuite) initGenesis() { s.Require().NoError(err) appGenState[pubsubtypes.ModuleName] = bz + // set addresses gen state + addressesGenState := addressestypes.DefaultGenesisState() + s.Require().NoError(cdc.UnmarshalJSON(appGenState[addressestypes.ModuleName], &addressesGenState)) + appGenState[addressestypes.ModuleName] = cdc.MustMarshalJSON(&addressesGenState) + // generate genesis txs genTxs := make([]json.RawMessage, len(s.chain.validators)) for i, val := range s.chain.validators { diff --git a/proto/addresses/v1/addresses.proto b/proto/addresses/v1/addresses.proto new file mode 100644 index 00000000..d5c0dce4 --- /dev/null +++ b/proto/addresses/v1/addresses.proto @@ -0,0 +1,10 @@ +syntax = "proto3"; +package addresses.v1; + +option go_package = "github.com/peggyjv/sommelier/v7/x/addresses/types"; + +message AddressMapping { + string cosmos_address = 1; + string evm_address = 2; +} + diff --git a/proto/addresses/v1/genesis.proto b/proto/addresses/v1/genesis.proto new file mode 100644 index 00000000..429874f5 --- /dev/null +++ b/proto/addresses/v1/genesis.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package addresses.v1; + +option go_package = "github.com/peggyjv/sommelier/v7/x/addresses/types"; + +import "addresses/v1/addresses.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; + +message GenesisState { + Params params = 1 [ (gogoproto.nullable) = false ]; + repeated AddressMapping address_mappings = 2; +} + +message Params {} diff --git a/proto/addresses/v1/query.proto b/proto/addresses/v1/query.proto new file mode 100644 index 00000000..f85fe617 --- /dev/null +++ b/proto/addresses/v1/query.proto @@ -0,0 +1,67 @@ +syntax = "proto3"; + +package addresses.v1; + +import "addresses/v1/addresses.proto"; +import "addresses/v1/genesis.proto"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "cosmos/base/query/v1beta1/pagination.proto"; +import "cosmos/query/v1/query.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/addresses/types"; + +service Query { + rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/sommelier/addresses/v1/params"; + } + + rpc QueryAddressMappings(QueryAddressMappingsRequest) returns (QueryAddressMappingsResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/sommelier/addresses/v1/address_mappings"; + } + + rpc QueryAddressMappingByEVMAddress(QueryAddressMappingByEVMAddressRequest) returns (QueryAddressMappingByEVMAddressResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/sommelier/addresses/v1/address_mappings/evm/{evm_address}"; + } + + rpc QueryAddressMappingByCosmosAddress(QueryAddressMappingByCosmosAddressRequest) returns (QueryAddressMappingByCosmosAddressResponse) { + option (cosmos.query.v1.module_query_safe) = true; + option (google.api.http).get = "/sommelier/addresses/v1/address_mappings/cosmos/{cosmos_address}"; + } +} + +message QueryParamsRequest {} + +message QueryParamsResponse { + Params params = 1; +} + +message QueryAddressMappingsRequest { + cosmos.base.query.v1beta1.PageRequest pagination = 1 [ (gogoproto.nullable) = false ]; +} + +message QueryAddressMappingsResponse { + repeated AddressMapping address_mappings = 1; + cosmos.base.query.v1beta1.PageResponse pagination = 2 [ (gogoproto.nullable) = false ]; +} + +message QueryAddressMappingByEVMAddressRequest { + string evm_address = 1; +} + +message QueryAddressMappingByEVMAddressResponse { + string cosmos_address = 1; + string evm_address = 2; +} + +message QueryAddressMappingByCosmosAddressRequest { + string cosmos_address = 1; +} + +message QueryAddressMappingByCosmosAddressResponse { + string cosmos_address = 1; + string evm_address = 2; +} diff --git a/proto/addresses/v1/tx.proto b/proto/addresses/v1/tx.proto new file mode 100644 index 00000000..fe5c9733 --- /dev/null +++ b/proto/addresses/v1/tx.proto @@ -0,0 +1,33 @@ +syntax = "proto3"; +package addresses.v1; + +import "cosmos/msg/v1/msg.proto"; + +option go_package = "github.com/peggyjv/sommelier/v7/x/addresses/types"; + +service Msg { + option (cosmos.msg.v1.service) = true; + + // Adds a mapping between the cosmos address of the sender and the provided EVM address + rpc AddAddressMapping (MsgAddAddressMapping) returns (MsgAddAddressMappingResponse); + // Removes the mapping containing the cosmos address of the sender + rpc RemoveAddressMapping (MsgRemoveAddressMapping) returns (MsgRemoveAddressMappingResponse); +} + +message MsgAddAddressMapping { + option (cosmos.msg.v1.signer) = "signer"; + + string evm_address = 1; + string signer = 2; +} + +message MsgAddAddressMappingResponse {} + +message MsgRemoveAddressMapping { + option (cosmos.msg.v1.signer) = "signer"; + + string signer = 1; +} + +message MsgRemoveAddressMappingResponse {} + diff --git a/x/addresses/client/cli/query.go b/x/addresses/client/cli/query.go new file mode 100644 index 00000000..d2992d3f --- /dev/null +++ b/x/addresses/client/cli/query.go @@ -0,0 +1,136 @@ +package cli + +import ( + "context" + "fmt" + + // "strings" + + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + + // "github.com/cosmos/cosmos-sdk/client/flags" + // sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +// GetQueryCmd returns the cli query commands for this module +func GetQueryCmd(queryRoute string) *cobra.Command { + // Group addresses queries under a subcommand + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + cmd.AddCommand(CmdQueryAddressMappings()) + cmd.AddCommand(CmdQueryAddressMappingByCosmosAddress()) + cmd.AddCommand(CmdQueryAddressMappingByEVMAddress()) + + return cmd +} + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.QueryParams(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryAddressMappings() *cobra.Command { + cmd := &cobra.Command{ + Use: "address-mappings", + Aliases: []string{"am"}, + Short: "shows the address mappings", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.QueryAddressMappings(context.Background(), &types.QueryAddressMappingsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryAddressMappingByCosmosAddress() *cobra.Command { + cmd := &cobra.Command{ + Use: "address-mapping-by-cosmos-address [cosmos-address]", + Aliases: []string{"ambca"}, + Short: "shows evm address that maps to the provided cosmos address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.QueryAddressMappingByCosmosAddress(context.Background(), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: args[0]}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} + +func CmdQueryAddressMappingByEVMAddress() *cobra.Command { + cmd := &cobra.Command{ + Use: "address-mapping-by-evm-address [evm-address]", + Aliases: []string{"ambea"}, + Short: "shows cosmos address that maps to the provided evm address", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.QueryAddressMappingByEVMAddress(context.Background(), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: args[0]}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/addresses/client/cli/query_test.go b/x/addresses/client/cli/query_test.go new file mode 100644 index 00000000..ef4a39e5 --- /dev/null +++ b/x/addresses/client/cli/query_test.go @@ -0,0 +1,116 @@ +package cli + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestQueryParamsCmd(t *testing.T) { + testCases := []struct { + name string + args []string + err error + }{ + { + name: "Does not accept args", + args: []string{ + "1", + }, + err: fmt.Errorf("unknown command \"1\" for \"params\""), + }, + } + + for _, tc := range testCases { + cmd := *CmdQueryParams() + cmd.SetArgs(tc.args) + err := cmd.Execute() + + require.Equal(t, tc.err.Error(), err.Error()) + } +} + +func TestQueryAddressMappings(t *testing.T) { + testCases := []struct { + name string + args []string + err error + }{ + { + name: "Does not accept args", + args: []string{ + "1", + }, + err: fmt.Errorf("unknown command \"1\" for \"address-mappings\""), + }, + } + + for _, tc := range testCases { + cmd := *CmdQueryAddressMappings() + cmd.SetArgs(tc.args) + err := cmd.Execute() + + require.Equal(t, tc.err.Error(), err.Error()) + } +} + +func TestQueryAddressMappingByCosmosAddress(t *testing.T) { + testCases := []struct { + name string + args []string + err error + }{ + { + name: "Insufficient args", + args: []string{}, + err: fmt.Errorf("accepts 1 arg(s), received 0"), + }, + { + name: "Too many args", + args: []string{ + "1", + "2", + }, + err: fmt.Errorf("accepts 1 arg(s), received 2"), + }, + } + + for _, tc := range testCases { + cmd := *CmdQueryAddressMappingByCosmosAddress() + cmd.SetArgs(tc.args) + err := cmd.Execute() + + require.Equal(t, tc.err.Error(), err.Error()) + } +} + +func TestAddressMappingByEVMAddressCmd(t *testing.T) { + testCases := []struct { + name string + args []string + err error + }{ + { + name: "Insufficient args", + args: []string{}, + err: fmt.Errorf("accepts 1 arg(s), received 0"), + }, + { + name: "Too many args", + args: []string{ + "1", + "2", + }, + err: fmt.Errorf("accepts 1 arg(s), received 2"), + }, + } + + for _, tc := range testCases { + cmd := *CmdQueryAddressMappingByEVMAddress() + cmd.SetArgs(tc.args) + err := cmd.Execute() + + require.Equal(t, tc.err.Error(), err.Error()) + } +} diff --git a/x/addresses/client/cli/tx.go b/x/addresses/client/cli/tx.go new file mode 100644 index 00000000..211a19b3 --- /dev/null +++ b/x/addresses/client/cli/tx.go @@ -0,0 +1,111 @@ +package cli + +import ( + "fmt" + "strings" + + "github.com/ethereum/go-ethereum/common" + "github.com/spf13/cobra" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + "github.com/cosmos/cosmos-sdk/version" + + // "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +// GetTxCmd returns the transaction commands for this module +func GetTxCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("%s transactions subcommands", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand([]*cobra.Command{ + GetCmdAddAddressMapping(), + GetCmdRemoveAddressMapping(), + }...) + + return cmd +} + +// GetCmdAddAddressMapping implements the command to submit a token price set proposal +func GetCmdAddAddressMapping() *cobra.Command { + cmd := &cobra.Command{ + Use: "add-address-mapping [evm-address]", + Args: cobra.ExactArgs(1), + Short: "Add a mapping from your signer address to an EVM address", + Long: strings.TrimSpace( + fmt.Sprintf(`Add a mapping from your Cosmos (signer) address to an EVM address. + +Example: +$ %s tx addresses add-address-mapping 0x1111111111111111111111111111111111111111 --from= +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + if !common.IsHexAddress(args[0]) { + return fmt.Errorf("%s is not a valid EVM address", args[0]) + } + + evmAddress := common.HexToAddress(args[0]) + + from := clientCtx.GetFromAddress() + msg, err := types.NewMsgAddAddressMapping(evmAddress, from) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// GetCmdRemoveAddressMapping implements the command to submit a token price set proposal +func GetCmdRemoveAddressMapping() *cobra.Command { + cmd := &cobra.Command{ + Use: "remove-address-mapping", + Args: cobra.NoArgs, + Short: "Remove the mapping from your signer address to an EVM address", + Long: strings.TrimSpace( + fmt.Sprintf(`Remove the mapping from your Cosmos (signer) address to an EVM address. + +Example: +$ %s tx addresses remove-address-mapping --from= +`, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + from := clientCtx.GetFromAddress() + msg, err := types.NewMsgRemoveAddressMapping(from) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd +} diff --git a/x/addresses/client/cli/tx_test.go b/x/addresses/client/cli/tx_test.go new file mode 100644 index 00000000..391360dc --- /dev/null +++ b/x/addresses/client/cli/tx_test.go @@ -0,0 +1,60 @@ +package cli + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestAddAddressMapping(t *testing.T) { + testCases := []struct { + name string + args []string + err error + }{ + { + name: "Valid cmd", + args: []string{ + "0xdac17f958d2ee523a2206206994597c13d831ec7", + fmt.Sprintf("--%s=%s", "from", "cosmos16zrkzad482haunrn25ywvwy6fclh3vh7r0hcny"), + }, + err: fmt.Errorf("key with address cosmos16zrkzad482haunrn25ywvwy6fclh3vh7r0hcny not found: key not found"), // Expect key not found error since this is just a mock request + }, + { + name: "Insufficient args", + args: []string{}, + err: fmt.Errorf("accepts 1 arg(s), received 0"), + }, + { + name: "Too many args", + args: []string{ + "1", + "2", + }, + err: fmt.Errorf("accepts 1 arg(s), received 2"), + }, + { + name: "Missing 'from' field", + args: []string{ + "0xdac17f958d2ee523a2206206994597c13d831ec7", + }, + err: fmt.Errorf("empty address string is not allowed: invalid address"), + }, + { + name: "Invalid EVM address", + args: []string{ + "sdlkfjlskdjfsld", + }, + err: fmt.Errorf("sdlkfjlskdjfsld is not a valid EVM address"), + }, + } + + for _, tc := range testCases { + cmd := GetCmdAddAddressMapping() + cmd.SetArgs(tc.args) + err := cmd.Execute() + + require.Equal(t, tc.err.Error(), err.Error()) + } +} diff --git a/x/addresses/keeper/genesis.go b/x/addresses/keeper/genesis.go new file mode 100644 index 00000000..849ad6e3 --- /dev/null +++ b/x/addresses/keeper/genesis.go @@ -0,0 +1,52 @@ +package keeper + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +// InitGenesis initializes the module's state from a provided genesis +// state. +func InitGenesis(ctx sdk.Context, k Keeper, gs types.GenesisState) { + if err := gs.Validate(); err != nil { + panic(fmt.Sprintf("failed to validate %s genesis state: %s", types.ModuleName, err)) + } + + k.setParams(ctx, gs.Params) + + for _, mapping := range gs.AddressMappings { + cosmosAcc, err := sdk.AccAddressFromBech32(mapping.CosmosAddress) + if err != nil { + panic(err) + } + + if !common.IsHexAddress(mapping.EvmAddress) { + panic(fmt.Sprintf("invalid EVM address %s", mapping.EvmAddress)) + } + + evmAddr := common.HexToAddress(mapping.EvmAddress).Bytes() + + k.SetAddressMapping(ctx, cosmosAcc.Bytes(), evmAddr) + } +} + +// ExportGenesis returns the module's exported genesis. +func ExportGenesis(ctx sdk.Context, k Keeper) types.GenesisState { + mappings := []*types.AddressMapping{} + k.IterateAddressMappings(ctx, func(cosmosAddr []byte, evmAddr []byte) bool { + mappings = append(mappings, &types.AddressMapping{ + CosmosAddress: sdk.AccAddress(cosmosAddr).String(), + EvmAddress: common.BytesToAddress(evmAddr).Hex(), + }) + + return false + }) + + return types.GenesisState{ + Params: k.GetParamSet(ctx), + AddressMappings: mappings, + } +} diff --git a/x/addresses/keeper/genesis_test.go b/x/addresses/keeper/genesis_test.go new file mode 100644 index 00000000..67ff6d90 --- /dev/null +++ b/x/addresses/keeper/genesis_test.go @@ -0,0 +1,80 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +func (suite *KeeperTestSuite) TestImportExportGenesis() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + expectedGenesis := types.DefaultGenesisState() + + InitGenesis(ctx, addressesKeeper, expectedGenesis) + + actualGenesis := ExportGenesis(ctx, addressesKeeper) + require.Equal(expectedGenesis, actualGenesis) +} + +func (suite *KeeperTestSuite) TestGenesisValidation() { + require := suite.Require() + + genesis := types.DefaultGenesisState() + require.NoError(genesis.Validate()) + + genesis.AddressMappings = append(genesis.AddressMappings, &types.AddressMapping{CosmosAddress: "sldjflslkfjsdf", EvmAddress: "0x0000000000000000000000000000000000000000"}) + require.Error(genesis.Validate()) + + genesis.AddressMappings = types.DefaultGenesisState().AddressMappings + genesis.AddressMappings = append(genesis.AddressMappings, &types.AddressMapping{CosmosAddress: cosmosAddrString, EvmAddress: "zzzz"}) + require.Error(genesis.Validate()) + + // Test with invalid EVM address + genesis.AddressMappings = []*types.AddressMapping{ + {CosmosAddress: cosmosAddrString, EvmAddress: "invalid_evm_address"}, + } + require.Error(genesis.Validate()) + + // Test with duplicate mappings + genesis.AddressMappings = []*types.AddressMapping{ + {CosmosAddress: cosmosAddrString, EvmAddress: evmAddrString}, + {CosmosAddress: cosmosAddrString, EvmAddress: evmAddrString}, + } + require.Error(genesis.Validate()) + + // Test with empty mappings + genesis.AddressMappings = []*types.AddressMapping{} + require.NoError(genesis.Validate()) +} + +// Add a new test function for InitGenesis +func (suite *KeeperTestSuite) TestInitGenesis() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + genesis := types.GenesisState{ + Params: types.DefaultParams(), + AddressMappings: []*types.AddressMapping{ + {CosmosAddress: cosmosAddrString, EvmAddress: evmAddrString}, + }, + } + + InitGenesis(ctx, addressesKeeper, genesis) + + // Verify that the address mapping was set + evmAddr := common.HexToAddress(evmAddrString).Bytes() + cosmosAddr, err := sdk.AccAddressFromBech32(cosmosAddrString) + require.NoError(err) + + result := addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.Equal(cosmosAddr.Bytes(), result) + + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr.Bytes()) + require.Equal(evmAddr, result) + + // Verify that params were set + params := addressesKeeper.GetParamSet(ctx) + require.Equal(genesis.Params, params) +} diff --git a/x/addresses/keeper/keeper.go b/x/addresses/keeper/keeper.go new file mode 100644 index 00000000..c798e086 --- /dev/null +++ b/x/addresses/keeper/keeper.go @@ -0,0 +1,143 @@ +package keeper + +import ( + "fmt" + + errorsmod "cosmossdk.io/errors" + "github.com/cometbft/cometbft/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +type ( + Keeper struct { + cdc codec.BinaryCodec + storeKey storetypes.StoreKey + paramstore paramtypes.Subspace + } +) + +func NewKeeper( + cdc codec.BinaryCodec, + key storetypes.StoreKey, + ps paramtypes.Subspace, +) *Keeper { + // set KeyTable if it has not already been set + if !ps.HasKeyTable() { + ps = ps.WithKeyTable(types.ParamKeyTable()) + } + + return &Keeper{ + cdc: cdc, + storeKey: key, + paramstore: ps, + } +} + +func (k Keeper) Logger(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) +} + +//////////// +// Params // +//////////// + +// GetParamSet returns the vote period from the parameters +func (k Keeper) GetParamSet(ctx sdk.Context) types.Params { + var p types.Params + k.paramstore.GetParamSet(ctx, &p) + return p +} + +// setParams sets the parameters in the store +func (k Keeper) setParams(ctx sdk.Context, params types.Params) { + k.paramstore.SetParamSet(ctx, ¶ms) +} + +/////////////////////// +/// AddressMappings /// +/////////////////////// + +// SetAddressMapping stores the mapping between the cosmos and evm addresses +func (k Keeper) SetAddressMapping(ctx sdk.Context, cosmosAddr []byte, evmAddr []byte) error { + // sanity check, shouldn't be possible with proper validation in the message handler + if len(cosmosAddr) == 0 { + return errorsmod.Wrap(types.ErrNilCosmosAddress, "cosmos address cannot be empty") + } + + if len(evmAddr) == 0 { + return errorsmod.Wrap(types.ErrNilEvmAddress, "evm address cannot be empty") + } + + k.setCosmosToEvmMapping(ctx, cosmosAddr, evmAddr) + k.setEvmToCosmosMapping(ctx, evmAddr, cosmosAddr) + + return nil +} + +func (k Keeper) setCosmosToEvmMapping(ctx sdk.Context, cosmosAddr []byte, evmAddr []byte) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetCosmosToEvmMapKey(cosmosAddr), evmAddr) +} + +func (k Keeper) setEvmToCosmosMapping(ctx sdk.Context, evmAddr []byte, cosmosAddr []byte) { + store := ctx.KVStore(k.storeKey) + store.Set(types.GetEvmToCosmosMapKey(evmAddr), cosmosAddr) +} + +// DeleteAddressMapping deletes the mapping between the cosmos and evm addresses +func (k Keeper) DeleteAddressMapping(ctx sdk.Context, cosmosAddr []byte) error { + // sanity check, shouldn't be possible with proper validation in the message handler + if len(cosmosAddr) == 0 { + return errorsmod.Wrap(types.ErrNilCosmosAddress, "cosmos address cannot be empty") + } + + evmAddr := k.GetEvmAddressByCosmosAddress(ctx, cosmosAddr) + + if len(evmAddr) == 0 { + return nil + } + + k.deleteEvmToCosmosMapping(ctx, evmAddr) + k.deleteCosmosToEvmMapping(ctx, cosmosAddr) + + return nil +} + +func (k Keeper) deleteCosmosToEvmMapping(ctx sdk.Context, cosmosAddr []byte) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetCosmosToEvmMapKey(cosmosAddr)) +} + +func (k Keeper) deleteEvmToCosmosMapping(ctx sdk.Context, evmAddr []byte) { + store := ctx.KVStore(k.storeKey) + store.Delete(types.GetEvmToCosmosMapKey(evmAddr)) +} + +func (k Keeper) GetCosmosAddressByEvmAddress(ctx sdk.Context, evmAddr []byte) []byte { + store := ctx.KVStore(k.storeKey) + return store.Get(types.GetEvmToCosmosMapKey(evmAddr)) +} + +func (k Keeper) GetEvmAddressByCosmosAddress(ctx sdk.Context, cosmosAddr []byte) []byte { + store := ctx.KVStore(k.storeKey) + return store.Get(types.GetCosmosToEvmMapKey(cosmosAddr)) +} + +// IterateAddressMappings iterates over all Cosmos to EVM address mappings +func (k Keeper) IterateAddressMappings(ctx sdk.Context, cb func(cosmosAddr []byte, evmAddr []byte) (stop bool)) { + store := ctx.KVStore(k.storeKey) + iterator := sdk.KVStorePrefixIterator(store, types.GetCosmosToEvmMapPrefix()) + defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { + cosmosAddr := iterator.Key()[1:] + evmAddr := iterator.Value() + if cb(cosmosAddr, evmAddr) { + break + } + } +} diff --git a/x/addresses/keeper/keeper_test.go b/x/addresses/keeper/keeper_test.go new file mode 100644 index 00000000..9a4b8f34 --- /dev/null +++ b/x/addresses/keeper/keeper_test.go @@ -0,0 +1,185 @@ +package keeper + +import ( + "testing" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/testutil" + "github.com/ethereum/go-ethereum/common" + "github.com/golang/mock/gomock" + "github.com/stretchr/testify/suite" + + sdk "github.com/cosmos/cosmos-sdk/types" + + moduletestutil "github.com/peggyjv/sommelier/v7/testutil" + "github.com/peggyjv/sommelier/v7/x/addresses/types" + + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + tmtime "github.com/cometbft/cometbft/types/time" + paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" +) + +const ( + cosmosAddrString = "cosmos154d0p9xhrruhxvazumej9nq29afeura2alje4u" + cosmosAddrStringInvalid = "cosmos154d0p9xhrruhxvazumej9nq29afeura2alje41" + evmAddrString = "0x1111111111111111111111111111111111111111" +) + +type KeeperTestSuite struct { + suite.Suite + + ctx sdk.Context + addressesKeeper Keeper + + queryClient types.QueryClient + + encCfg moduletestutil.TestEncodingConfig +} + +func (suite *KeeperTestSuite) SetupTest() { + key := sdk.NewKVStoreKey(types.StoreKey) + tkey := sdk.NewTransientStoreKey("transient_test") + testCtx := testutil.DefaultContext(key, tkey) + ctx := testCtx.WithBlockHeader(tmproto.Header{Height: 5, Time: tmtime.Now()}) + encCfg := moduletestutil.MakeTestEncodingConfig() + + // gomock initializations + ctrl := gomock.NewController(suite.T()) + defer ctrl.Finish() + + suite.ctx = ctx + + params := paramskeeper.NewKeeper( + encCfg.Codec, + codec.NewLegacyAmino(), + key, + tkey, + ) + + params.Subspace(types.ModuleName) + subSpace, found := params.GetSubspace(types.ModuleName) + suite.Assertions.True(found) + + suite.addressesKeeper = *NewKeeper( + encCfg.Codec, + key, + subSpace, + ) + + types.RegisterInterfaces(encCfg.InterfaceRegistry) + + queryHelper := baseapp.NewQueryServerTestHelper(ctx, encCfg.InterfaceRegistry) + types.RegisterQueryServer(queryHelper, suite.addressesKeeper) + queryClient := types.NewQueryClient(queryHelper) + + suite.queryClient = queryClient + suite.encCfg = encCfg +} + +func TestKeeperTestSuite(t *testing.T) { + suite.Run(t, new(KeeperTestSuite)) +} + +func (suite *KeeperTestSuite) TestSetGetDeleteParams() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + params := types.DefaultParams() + addressesKeeper.setParams(ctx, params) + + retrievedParams := addressesKeeper.GetParamSet(ctx) + require.Equal(params, retrievedParams) +} + +func (suite *KeeperTestSuite) TestSetGetDeleteAddressMappings() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + evmAddrString := "0x1111111111111111111111111111111111111111" + require.Equal(42, len(evmAddrString)) + evmAddr := common.HexToAddress(evmAddrString).Bytes() + + acc, err := sdk.AccAddressFromBech32(cosmosAddrString) + require.NoError(err) + + cosmosAddr := acc.Bytes() + + // Set + err = addressesKeeper.SetAddressMapping(ctx, cosmosAddr, evmAddr) + require.NoError(err) + + // Get + cosmosResult := addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.Equal(cosmosAddr, cosmosResult) + + evmResult := addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr) + require.Equal(evmAddr, evmResult) + + // Iterate + var mappings []*types.AddressMapping + addressesKeeper.IterateAddressMappings(ctx, func(cosmosAddr []byte, evmAddr []byte) (stop bool) { + mapping := types.AddressMapping{ + CosmosAddress: sdk.MustBech32ifyAddressBytes("cosmos", cosmosAddr), + EvmAddress: common.BytesToAddress(evmAddr).Hex(), + } + mappings = append(mappings, &mapping) + + return false + }) + + // Invalid input + err = addressesKeeper.SetAddressMapping(ctx, nil, evmAddr) + require.Error(err) + + // Test setting multiple mappings + evmAddr2 := common.HexToAddress("0x2222222222222222222222222222222222222222").Bytes() + cosmosAddr2, _ := sdk.AccAddressFromBech32("cosmos1y6d5kasehecexf09ka6y0ggl0pxzt6dgk0gnl9") + + err = addressesKeeper.SetAddressMapping(ctx, cosmosAddr2, evmAddr2) + require.NoError(err) + + // Verify second mapping exists + result := addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr2) + require.Equal(cosmosAddr2.Bytes(), result) + + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr2) + require.Equal(evmAddr2, result) + + // Test deleting one mapping + err = addressesKeeper.DeleteAddressMapping(ctx, cosmosAddr) + require.NoError(err) + + // Verify the deleted mapping is gone but the other remains + result = addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.Nil(result) + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr) + require.Nil(result) + + result = addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr2) + require.Equal(cosmosAddr2.Bytes(), result) + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr2) + require.Equal(evmAddr2, result) + + // Test IterateAddressMappings + var mappings2 []*types.AddressMapping + addressesKeeper.IterateAddressMappings(ctx, func(cosmosAddr []byte, evmAddr []byte) bool { + mappings2 = append(mappings2, &types.AddressMapping{ + CosmosAddress: sdk.AccAddress(cosmosAddr).String(), + EvmAddress: common.BytesToAddress(evmAddr).Hex(), + }) + return false + }) + require.Len(mappings2, 1) + require.Equal(cosmosAddr2.String(), mappings2[0].CosmosAddress) + require.Equal(common.BytesToAddress(evmAddr2).Hex(), mappings2[0].EvmAddress) + + // Delete second mapping + err = addressesKeeper.DeleteAddressMapping(ctx, cosmosAddr2) + require.NoError(err) + + cosmosResult = addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr2) + require.Nil(cosmosResult) + evmResult = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, cosmosAddr2) + require.Nil(evmResult) +} diff --git a/x/addresses/keeper/msg_server.go b/x/addresses/keeper/msg_server.go new file mode 100644 index 00000000..4007b0b1 --- /dev/null +++ b/x/addresses/keeper/msg_server.go @@ -0,0 +1,51 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +var _ types.MsgServer = Keeper{} + +func (k Keeper) AddAddressMapping(c context.Context, req *types.MsgAddAddressMapping) (*types.MsgAddAddressMappingResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + signer, err := sdk.AccAddressFromBech32(req.GetSigner()) + if err != nil { + return &types.MsgAddAddressMappingResponse{}, status.Errorf(codes.InvalidArgument, "invalid signer address %s", req.GetSigner()) + } + + if !common.IsHexAddress(req.EvmAddress) { + return &types.MsgAddAddressMappingResponse{}, status.Errorf(codes.InvalidArgument, "invalid EVM address %s", req.EvmAddress) + } + + evmAddr := common.HexToAddress(req.EvmAddress).Bytes() + + err = k.SetAddressMapping(ctx, signer.Bytes(), evmAddr) + if err != nil { + return &types.MsgAddAddressMappingResponse{}, status.Errorf(codes.Internal, "failed to set address mapping: %s", err) + } + + return &types.MsgAddAddressMappingResponse{}, nil +} + +func (k Keeper) RemoveAddressMapping(c context.Context, req *types.MsgRemoveAddressMapping) (*types.MsgRemoveAddressMappingResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + signer, err := sdk.AccAddressFromBech32(req.GetSigner()) + if err != nil { + return &types.MsgRemoveAddressMappingResponse{}, status.Errorf(codes.InvalidArgument, "invalid signer address %s", req.GetSigner()) + } + + err = k.DeleteAddressMapping(ctx, signer.Bytes()) + if err != nil { + return &types.MsgRemoveAddressMappingResponse{}, status.Errorf(codes.Internal, "failed to remove address mapping: %s", err) + } + + return &types.MsgRemoveAddressMappingResponse{}, nil +} diff --git a/x/addresses/keeper/msg_server_test.go b/x/addresses/keeper/msg_server_test.go new file mode 100644 index 00000000..9f363b36 --- /dev/null +++ b/x/addresses/keeper/msg_server_test.go @@ -0,0 +1,90 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +func (suite *KeeperTestSuite) TestHappyPathsForMsgServer() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + // Test AddAddressMapping + _, err := sdk.AccAddressFromBech32(cosmosAddrString) + require.NoError(err) + + _, err = addressesKeeper.AddAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgAddAddressMapping{Signer: cosmosAddrString, EvmAddress: evmAddrString}) + require.NoError(err) + + evmAddr := common.HexToAddress(evmAddrString).Bytes() + + result := addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.NotNil(result) + actualCosmosAddrString := sdk.AccAddress(result).String() + require.Equal(cosmosAddrString, actualCosmosAddrString) + + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, sdk.AccAddress(result).Bytes()) + require.NotNil(result) + + actualEvmAddrString := common.BytesToAddress(result).Hex() + require.Equal(evmAddrString, actualEvmAddrString) + + // Test RemoveAddressMapping + _, err = addressesKeeper.RemoveAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgRemoveAddressMapping{Signer: cosmosAddrString}) + require.NoError(err) + + result = addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.Nil(result) + + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, sdk.AccAddress(result).Bytes()) + require.Nil(result) +} + +func (suite *KeeperTestSuite) TestUnhappyPathsForMsgServer() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + // Test AddAddressMapping + // too long evm address + evmAddrStringInvalid := "0x11111111111111111111111111111111111111111" + _, err := sdk.AccAddressFromBech32(cosmosAddrStringInvalid) + require.Error(err) + + _, err = addressesKeeper.AddAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgAddAddressMapping{Signer: cosmosAddrStringInvalid, EvmAddress: evmAddrString}) + require.Error(err) + require.Contains(err.Error(), "invalid signer address") + + _, err = sdk.AccAddressFromBech32(cosmosAddrString) + require.NoError(err) + evmAddr := common.HexToAddress(evmAddrString).Bytes() + + _, err = addressesKeeper.AddAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgAddAddressMapping{Signer: cosmosAddrString, EvmAddress: evmAddrStringInvalid}) + require.Error(err) + require.Contains(err.Error(), "invalid EVM address") + + result := addressesKeeper.GetCosmosAddressByEvmAddress(ctx, evmAddr) + require.Nil(result) + + result = addressesKeeper.GetEvmAddressByCosmosAddress(ctx, sdk.AccAddress(result).Bytes()) + require.Nil(result) + + // Test adding a mapping for an already mapped Cosmos address + _, err = addressesKeeper.AddAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgAddAddressMapping{Signer: cosmosAddrString, EvmAddress: evmAddrString}) + require.NoError(err) + + _, err = addressesKeeper.AddAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgAddAddressMapping{Signer: cosmosAddrString, EvmAddress: "0x2222222222222222222222222222222222222222"}) + require.NoError(err) + + // Test removing a non-existent mapping + _, err = addressesKeeper.RemoveAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgRemoveAddressMapping{Signer: "cosmos1y6d5kasehecexf09ka6y0ggl0pxzt6dgk0gnl9"}) + require.NoError(err) + + // Test RemoveAddressMapping + _, err = sdk.AccAddressFromBech32(cosmosAddrStringInvalid) + require.Error(err) + + _, err = addressesKeeper.RemoveAddressMapping(sdk.WrapSDKContext(ctx), &types.MsgRemoveAddressMapping{Signer: cosmosAddrStringInvalid}) + require.Error(err) + require.Contains(err.Error(), "invalid signer address") +} diff --git a/x/addresses/keeper/query_server.go b/x/addresses/keeper/query_server.go new file mode 100644 index 00000000..db931d1e --- /dev/null +++ b/x/addresses/keeper/query_server.go @@ -0,0 +1,114 @@ +package keeper + +import ( + "context" + + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/cosmos-sdk/types/bech32" + "github.com/cosmos/cosmos-sdk/types/query" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +var _ types.QueryServer = Keeper{} + +// QueryParams implements QueryServer +func (k Keeper) QueryParams(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + params := k.GetParamSet(sdk.UnwrapSDKContext(c)) + + return &types.QueryParamsResponse{ + Params: ¶ms, + }, nil +} + +func (k Keeper) QueryAddressMappings(c context.Context, request *types.QueryAddressMappingsRequest) (*types.QueryAddressMappingsResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + var mappings []*types.AddressMapping + var err error + store := ctx.KVStore(k.storeKey) + prefixStore := prefix.NewStore(store, types.GetCosmosToEvmMapPrefix()) + + pageRes, err := query.FilteredPaginate( + prefixStore, + &request.Pagination, + func(key []byte, value []byte, accumulate bool) (bool, error) { + cosmosAddr, err := sdk.Bech32ifyAddressBytes(sdk.GetConfig().GetBech32AccountAddrPrefix(), key) + if err != nil { + return false, err + } + + evmAddr := common.BytesToAddress(value).Hex() + mapping := types.AddressMapping{ + CosmosAddress: cosmosAddr, + EvmAddress: evmAddr, + } + + if accumulate { + mappings = append(mappings, &mapping) + } + return true, nil + }, + ) + + if err != nil { + // this shouldn't be possible if the msg server is doing proper validation + k.Logger(ctx).Error("failed to paginate cosmos to evm address mappings", "error", err) + return nil, status.Error(codes.Internal, "error during pagination") + } + + return &types.QueryAddressMappingsResponse{AddressMappings: mappings, Pagination: *pageRes}, nil +} + +func (k Keeper) QueryAddressMappingByCosmosAddress(c context.Context, request *types.QueryAddressMappingByCosmosAddressRequest) (*types.QueryAddressMappingByCosmosAddressResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + _, cosmosAddr, err := bech32.DecodeAndConvert(request.GetCosmosAddress()) + if err != nil { + return &types.QueryAddressMappingByCosmosAddressResponse{}, status.Errorf(codes.InvalidArgument, "failed to parse cosmos address %s as bech32", request.GetCosmosAddress()) + } + + rawEvmAddr := k.GetEvmAddressByCosmosAddress(ctx, cosmosAddr) + + if len(rawEvmAddr) == 0 { + return &types.QueryAddressMappingByCosmosAddressResponse{}, status.Errorf(codes.NotFound, "no EVM address mapping for cosmos address %s", request.GetCosmosAddress()) + } + + evmAddr := common.BytesToAddress(rawEvmAddr) + + return &types.QueryAddressMappingByCosmosAddressResponse{ + CosmosAddress: request.GetCosmosAddress(), + EvmAddress: evmAddr.Hex(), + }, nil +} + +func (k Keeper) QueryAddressMappingByEVMAddress(c context.Context, request *types.QueryAddressMappingByEVMAddressRequest) (*types.QueryAddressMappingByEVMAddressResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + if !common.IsHexAddress(request.GetEvmAddress()) { + return &types.QueryAddressMappingByEVMAddressResponse{}, status.Errorf(codes.InvalidArgument, "invalid EVM address %s", request.GetEvmAddress()) + } + + evmAddr := common.HexToAddress(request.GetEvmAddress()).Bytes() + rawCosmosAddr := k.GetCosmosAddressByEvmAddress(ctx, evmAddr) + + if len(rawCosmosAddr) == 0 { + return &types.QueryAddressMappingByEVMAddressResponse{}, status.Errorf(codes.NotFound, "no cosmos address mapping for EVM address %s", request.GetEvmAddress()) + } + + prefix := sdk.GetConfig().GetBech32AccountAddrPrefix() + cosmosAddr, err := sdk.Bech32ifyAddressBytes(prefix, rawCosmosAddr) + if err != nil { + // this shouldn't happen if msg server is doing proper validation + return &types.QueryAddressMappingByEVMAddressResponse{}, status.Errorf(codes.Internal, "failed to convert cosmos address to bech32: %s", err) + } + + return &types.QueryAddressMappingByEVMAddressResponse{ + CosmosAddress: cosmosAddr, + EvmAddress: request.GetEvmAddress(), + }, nil +} diff --git a/x/addresses/keeper/query_server_test.go b/x/addresses/keeper/query_server_test.go new file mode 100644 index 00000000..2367c2b0 --- /dev/null +++ b/x/addresses/keeper/query_server_test.go @@ -0,0 +1,165 @@ +package keeper + +import ( + "fmt" + "strings" + + sdk "github.com/cosmos/cosmos-sdk/types" + query "github.com/cosmos/cosmos-sdk/types/query" + "github.com/ethereum/go-ethereum/common" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +// Happy path test for query server functions +func (suite *KeeperTestSuite) TestHappyPathsForQueryServer() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + params := types.DefaultParams() + addressesKeeper.setParams(ctx, params) + + evmAddr := common.HexToAddress(evmAddrString).Bytes() + acc, err := sdk.AccAddressFromBech32(cosmosAddrString) + require.NoError(err) + + cosmosAddr := acc.Bytes() + + addressesKeeper.SetAddressMapping(ctx, cosmosAddr, evmAddr) + + // Test QueryParams + queryParams, err := addressesKeeper.QueryParams(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + require.NoError(err) + require.Equal(¶ms, queryParams.Params) + + // Test QueryAddressMappingByEvmAddress + addressMappingByEvmAddress, err := addressesKeeper.QueryAddressMappingByEVMAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddrString}) + require.NoError(err) + require.Equal(cosmosAddrString, addressMappingByEvmAddress.CosmosAddress) + + // Test QueryAddressMappingByCosmosAddress + addressMappingByCosmosAddress, err := addressesKeeper.QueryAddressMappingByCosmosAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddrString}) + require.NoError(err) + require.Equal(evmAddrString, addressMappingByCosmosAddress.EvmAddress) + + // Test QueryAddressMappings + addressMappings, err := addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1) + require.Equal(cosmosAddrString, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString, addressMappings.AddressMappings[0].EvmAddress) + + // Test QueryAddressMappings with pagination + addressMappings, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 1}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1) + require.Equal(cosmosAddrString, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString, addressMappings.AddressMappings[0].EvmAddress) + + evmAddrString2 := "0x2222222222222222222222222222222222222222" + // keys stored in ascending order, so this one will be stored before the previous value (cosmos15...) + cosmosAddrString2 := "cosmos1y6d5kasehecexf09ka6y0ggl0pxzt6dgk0gnl9" + evmAddr2 := common.HexToAddress(evmAddrString2).Bytes() + acc2, err := sdk.AccAddressFromBech32(cosmosAddrString2) + require.NoError(err) + + cosmosAddr2 := acc2.Bytes() + + addressesKeeper.SetAddressMapping(ctx, cosmosAddr2, evmAddr2) + + addressMappings, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 1, Offset: 1}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1) + require.Equal(cosmosAddrString, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString, addressMappings.AddressMappings[0].EvmAddress) + + addressMappings, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 1}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1) + require.Equal(cosmosAddrString2, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString2, addressMappings.AddressMappings[0].EvmAddress) + + addressMappings, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Key: addressMappings.Pagination.NextKey}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1) + require.Equal(cosmosAddrString, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString, addressMappings.AddressMappings[0].EvmAddress) + + addressMappings, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 2}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 2) + require.Equal(cosmosAddrString, addressMappings.AddressMappings[1].CosmosAddress) + require.Equal(evmAddrString, addressMappings.AddressMappings[1].EvmAddress) + require.Equal(cosmosAddrString2, addressMappings.AddressMappings[0].CosmosAddress) + require.Equal(evmAddrString2, addressMappings.AddressMappings[0].EvmAddress) +} + +// Unhappy path test for query server functions +func (suite *KeeperTestSuite) TestUnhappyPathsForQueryServer() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + params := types.DefaultParams() + addressesKeeper.setParams(ctx, params) + + // invalid length evm address + evmAddrStringInvalid := "0x11111111111111111111111111111111111111111" + _, err := sdk.AccAddressFromBech32(cosmosAddrStringInvalid) + require.Error(err) + + // Test QueryParams + queryParams, err := addressesKeeper.QueryParams(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{}) + require.NoError(err) + require.Equal(¶ms, queryParams.Params) + + // Test QueryAddressMappingByEvmAddress + _, err = addressesKeeper.QueryAddressMappingByEVMAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddrStringInvalid}) + require.Error(err) + require.Contains(err.Error(), "invalid EVM address") + + // valid evm address + _, err = addressesKeeper.QueryAddressMappingByEVMAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByEVMAddressRequest{EvmAddress: evmAddrString}) + require.Error(err) + require.Contains(err.Error(), "no cosmos address mapping for EVM address") + + // Test QueryAddressMappingByCosmosAddress + _, err = addressesKeeper.QueryAddressMappingByCosmosAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddrStringInvalid}) + require.Error(err) + require.Contains(err.Error(), "failed to parse cosmos address") + + // valid cosmos address + _, err = addressesKeeper.QueryAddressMappingByCosmosAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: cosmosAddrString}) + require.Error(err) + require.Contains(err.Error(), "no EVM address mapping for cosmos address") + + // Test QueryAddressMappings with invalid pagination + _, err = addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 0, Offset: 1}}) + require.NoError(err) + + // Test QueryAddressMappings with no results + addressMappings, err := addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 0) +} + +// Edge cases test for query server functions +func (suite *KeeperTestSuite) TestQueryServerEdgeCases() { + ctx, addressesKeeper := suite.ctx, suite.addressesKeeper + require := suite.Require() + + // Test with maximum number of address mappings + for i := 0; i < 1000; i++ { + cosmosAddr := sdk.AccAddress([]byte(fmt.Sprintf("cosmos%d", i))) + evmAddr := common.HexToAddress(fmt.Sprintf("0x%040d", i)) + addressesKeeper.SetAddressMapping(ctx, cosmosAddr, evmAddr.Bytes()) + } + + addressMappings, err := addressesKeeper.QueryAddressMappings(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingsRequest{Pagination: query.PageRequest{Limit: 1000}}) + require.NoError(err) + require.Len(addressMappings.AddressMappings, 1000) + + // Test with very long Cosmos address (edge case, might not be valid in practice) + longCosmosAddr := "cosmos" + strings.Repeat("1", 100) + _, err = addressesKeeper.QueryAddressMappingByCosmosAddress(sdk.WrapSDKContext(ctx), &types.QueryAddressMappingByCosmosAddressRequest{CosmosAddress: longCosmosAddr}) + require.Error(err) + require.Contains(err.Error(), "failed to parse cosmos address") +} diff --git a/x/addresses/module.go b/x/addresses/module.go new file mode 100644 index 00000000..cc2edc9a --- /dev/null +++ b/x/addresses/module.go @@ -0,0 +1,166 @@ +package addresses + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + + abci "github.com/cometbft/cometbft/abci/types" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + sim "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/peggyjv/sommelier/v7/x/addresses/client/cli" + "github.com/peggyjv/sommelier/v7/x/addresses/keeper" + "github.com/peggyjv/sommelier/v7/x/addresses/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// ---------------------------------------------------------------------------- +// AppModuleBasic +// ---------------------------------------------------------------------------- + +// AppModuleBasic implements the AppModuleBasic interface that defines the independent methods a Cosmos SDK module needs to implement. +type AppModuleBasic struct { + cdc codec.BinaryCodec +} + +func NewAppModuleBasic(cdc codec.BinaryCodec) AppModuleBasic { + return AppModuleBasic{cdc: cdc} +} + +// Name returns the name of the module as a string +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the amino codec for the module, which is used to marshal and unmarshal structs to/from []byte in order to persist them in the module's KVStore +func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { + types.RegisterCodec(cdc) +} + +// RegisterInterfaces registers a module's interface types and their concrete implementations as proto.Message +func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns a default GenesisState for the module, marshalled to json.RawMessage. The default GenesisState need to be defined by the module developer and is primarily used for testing +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + gs := types.DefaultGenesisState() + return cdc.MustMarshalJSON(&gs) +} + +// ValidateGenesis used to validate the GenesisState, given in its json.RawMessage form +func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncodingConfig, bz json.RawMessage) error { + var genState types.GenesisState + if err := cdc.UnmarshalJSON(bz, &genState); err != nil { + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) + } + return genState.Validate() +} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +} + +// GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module +func (a AppModuleBasic) GetTxCmd() *cobra.Command { + return cli.GetTxCmd() +} + +// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { + return cli.GetQueryCmd(types.StoreKey) +} + +// ---------------------------------------------------------------------------- +// AppModule +// ---------------------------------------------------------------------------- + +// AppModule implements the AppModule interface that defines the inter-dependent methods that modules need to implement +type AppModule struct { + AppModuleBasic + + keeper keeper.Keeper +} + +func NewAppModule( + cdc codec.Codec, + keeper keeper.Keeper, +) AppModule { + return AppModule{ + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + } +} + +// Deprecated: use RegisterServices +func (AppModule) QuerierRoute() string { return types.RouterKey } + +// RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries +func (am AppModule) RegisterServices(cfg module.Configurator) { + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) +} + +// RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) +func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} + +// InitGenesis performs the module's genesis initialization. It returns no validator updates. +func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate { + var genState types.GenesisState + // Initialize global index to index in genesis state + cdc.MustUnmarshalJSON(gs, &genState) + + keeper.InitGenesis(ctx, am.keeper, genState) + + return []abci.ValidatorUpdate{} +} + +// ExportGenesis returns the module's exported genesis state as raw JSON bytes. +func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genState := keeper.ExportGenesis(ctx, am.keeper) + return cdc.MustMarshalJSON(&genState) +} + +// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1 +func (AppModule) ConsensusVersion() uint64 { return 1 } + +func (am AppModule) WeightedOperations(simState module.SimulationState) []sim.WeightedOperation { + return nil +} + +// BeginBlock contains the logic that is automatically triggered at the beginning of each block +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock contains the logic that is automatically triggered at the end of each block +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// AppModuleSimulation functions + +// GenerateGenesisState creates a randomized GenState of the distribution module. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { +} + +// ProposalContents returns all the distribution content functions used to +// simulate governance proposals. +func (am AppModule) ProposalContents(_ module.SimulationState) []sim.WeightedProposalMsg { + return nil +} + +// RegisterStoreDecoder registers a decoder for distribution module's types +func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) { +} diff --git a/x/addresses/types/addresses.go b/x/addresses/types/addresses.go new file mode 100644 index 00000000..403c19c7 --- /dev/null +++ b/x/addresses/types/addresses.go @@ -0,0 +1,19 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/ethereum/go-ethereum/common" +) + +func (am AddressMapping) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(am.CosmosAddress); err != nil { + return errorsmod.Wrapf(ErrInvalidCosmosAddress, "%s is not a valid cosmos address", am.CosmosAddress) + } + + if !common.IsHexAddress(am.EvmAddress) { + return errorsmod.Wrapf(ErrInvalidEvmAddress, "%s is not a valid EVM address", am.EvmAddress) + } + + return nil +} diff --git a/x/addresses/types/addresses.pb.go b/x/addresses/types/addresses.pb.go new file mode 100644 index 00000000..fa24cd7a --- /dev/null +++ b/x/addresses/types/addresses.pb.go @@ -0,0 +1,367 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: addresses/v1/addresses.proto + +package types + +import ( + fmt "fmt" + proto "github.com/cosmos/gogoproto/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type AddressMapping struct { + CosmosAddress string `protobuf:"bytes,1,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` + EvmAddress string `protobuf:"bytes,2,opt,name=evm_address,json=evmAddress,proto3" json:"evm_address,omitempty"` +} + +func (m *AddressMapping) Reset() { *m = AddressMapping{} } +func (m *AddressMapping) String() string { return proto.CompactTextString(m) } +func (*AddressMapping) ProtoMessage() {} +func (*AddressMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_f62edfd8f2ffb6f4, []int{0} +} +func (m *AddressMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AddressMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AddressMapping.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *AddressMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_AddressMapping.Merge(m, src) +} +func (m *AddressMapping) XXX_Size() int { + return m.Size() +} +func (m *AddressMapping) XXX_DiscardUnknown() { + xxx_messageInfo_AddressMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_AddressMapping proto.InternalMessageInfo + +func (m *AddressMapping) GetCosmosAddress() string { + if m != nil { + return m.CosmosAddress + } + return "" +} + +func (m *AddressMapping) GetEvmAddress() string { + if m != nil { + return m.EvmAddress + } + return "" +} + +func init() { + proto.RegisterType((*AddressMapping)(nil), "addresses.v1.AddressMapping") +} + +func init() { proto.RegisterFile("addresses/v1/addresses.proto", fileDescriptor_f62edfd8f2ffb6f4) } + +var fileDescriptor_f62edfd8f2ffb6f4 = []byte{ + // 185 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x49, 0x4c, 0x49, 0x29, + 0x4a, 0x2d, 0x2e, 0x4e, 0x2d, 0xd6, 0x2f, 0x33, 0xd4, 0x87, 0x73, 0xf4, 0x0a, 0x8a, 0xf2, 0x4b, + 0xf2, 0x85, 0x78, 0x10, 0x02, 0x65, 0x86, 0x4a, 0x11, 0x5c, 0x7c, 0x8e, 0x10, 0xbe, 0x6f, 0x62, + 0x41, 0x41, 0x66, 0x5e, 0xba, 0x90, 0x2a, 0x17, 0x5f, 0x72, 0x7e, 0x71, 0x6e, 0x7e, 0x71, 0x3c, + 0x54, 0xa1, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x2f, 0x44, 0x14, 0xaa, 0x5a, 0x48, 0x9e, + 0x8b, 0x3b, 0xb5, 0x2c, 0x17, 0xae, 0x86, 0x09, 0xac, 0x86, 0x2b, 0xb5, 0x2c, 0x17, 0xaa, 0xc0, + 0xc9, 0xfb, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, + 0x58, 0x8e, 0xe1, 0xc2, 0x63, 0x39, 0x86, 0x1b, 0x8f, 0xe5, 0x18, 0xa2, 0x0c, 0xd3, 0x33, 0x4b, + 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x0b, 0x52, 0xd3, 0xd3, 0x2b, 0xb3, 0xca, 0xf4, + 0x8b, 0xf3, 0x73, 0x73, 0x53, 0x73, 0x32, 0x53, 0x8b, 0xf4, 0xcb, 0xcc, 0xf5, 0x2b, 0x10, 0x8e, + 0xd6, 0x2f, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xbb, 0xdd, 0x18, 0x10, 0x00, 0x00, 0xff, + 0xff, 0x88, 0x59, 0xca, 0xf1, 0xdb, 0x00, 0x00, 0x00, +} + +func (m *AddressMapping) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *AddressMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AddressMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EvmAddress) > 0 { + i -= len(m.EvmAddress) + copy(dAtA[i:], m.EvmAddress) + i = encodeVarintAddresses(dAtA, i, uint64(len(m.EvmAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.CosmosAddress) > 0 { + i -= len(m.CosmosAddress) + copy(dAtA[i:], m.CosmosAddress) + i = encodeVarintAddresses(dAtA, i, uint64(len(m.CosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintAddresses(dAtA []byte, offset int, v uint64) int { + offset -= sovAddresses(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *AddressMapping) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CosmosAddress) + if l > 0 { + n += 1 + l + sovAddresses(uint64(l)) + } + l = len(m.EvmAddress) + if l > 0 { + n += 1 + l + sovAddresses(uint64(l)) + } + return n +} + +func sovAddresses(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozAddresses(x uint64) (n int) { + return sovAddresses(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *AddressMapping) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddresses + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: AddressMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AddressMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddresses + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAddresses + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAddresses + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvmAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowAddresses + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthAddresses + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthAddresses + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EvmAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipAddresses(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthAddresses + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipAddresses(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddresses + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddresses + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowAddresses + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthAddresses + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupAddresses + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthAddresses + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthAddresses = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowAddresses = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupAddresses = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/addresses/types/addresses_test.go b/x/addresses/types/addresses_test.go new file mode 100644 index 00000000..15e45ced --- /dev/null +++ b/x/addresses/types/addresses_test.go @@ -0,0 +1,84 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestAddressMapping_ValidateBasic(t *testing.T) { + tests := []struct { + name string + mapping AddressMapping + wantErr bool + }{ + { + name: "valid mapping", + mapping: AddressMapping{ + CosmosAddress: "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu", + EvmAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", + }, + wantErr: false, + }, + { + name: "invalid cosmos address", + mapping: AddressMapping{ + CosmosAddress: "invalid", + EvmAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", + }, + wantErr: true, + }, + { + name: "invalid evm address", + mapping: AddressMapping{ + CosmosAddress: "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu", + EvmAddress: "invalid", + }, + wantErr: true, + }, + { + name: "both addresses invalid", + mapping: AddressMapping{ + CosmosAddress: "invalid", + EvmAddress: "invalid", + }, + wantErr: true, + }, + { + name: "empty cosmos address", + mapping: AddressMapping{ + CosmosAddress: "", + EvmAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", + }, + wantErr: true, + }, + { + name: "empty evm address", + mapping: AddressMapping{ + CosmosAddress: "cosmos1qypqxpq9qcrsszg2pvxq6rs0zqg3yyc5lzv7xu", + EvmAddress: "", + }, + wantErr: true, + }, + { + name: "both addresses empty", + mapping: AddressMapping{ + CosmosAddress: "", + EvmAddress: "", + }, + wantErr: true, + }, + } + + for _, tt := range tests { + tt := tt // create a local copy + t.Run(tt.name, func(t *testing.T) { + err := tt.mapping.ValidateBasic() + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + }) + } +} diff --git a/x/addresses/types/codec.go b/x/addresses/types/codec.go new file mode 100644 index 00000000..4e1cb5f6 --- /dev/null +++ b/x/addresses/types/codec.go @@ -0,0 +1,22 @@ +package types + +import ( + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +func RegisterCodec(cdc *codec.LegacyAmino) { + cdc.RegisterConcrete(&MsgAddAddressMapping{}, "addresses/MsgAddAddressMapping", nil) + cdc.RegisterConcrete(&MsgRemoveAddressMapping{}, "addresses/MsgRemoveAddressMapping", nil) +} + +func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { + msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) +} + +var ( + Amino = codec.NewLegacyAmino() + ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry()) +) diff --git a/x/addresses/types/errors.go b/x/addresses/types/errors.go new file mode 100644 index 00000000..1067b1a4 --- /dev/null +++ b/x/addresses/types/errors.go @@ -0,0 +1,10 @@ +package types + +import errorsmod "cosmossdk.io/errors" + +var ( + ErrInvalidEvmAddress = errorsmod.Register(ModuleName, 2, "invalid evm address") + ErrInvalidCosmosAddress = errorsmod.Register(ModuleName, 3, "invalid cosmos address") + ErrNilCosmosAddress = errorsmod.Register(ModuleName, 4, "cosmos address cannot be nil") + ErrNilEvmAddress = errorsmod.Register(ModuleName, 5, "evm address cannot be nil") +) diff --git a/x/addresses/types/genesis.go b/x/addresses/types/genesis.go new file mode 100644 index 00000000..13ce6932 --- /dev/null +++ b/x/addresses/types/genesis.go @@ -0,0 +1,38 @@ +package types + +import fmt "fmt" + +// DefaultIndex is the default global index +const DefaultIndex uint64 = 1 + +// DefaultGenesis returns the default genesis state +func DefaultGenesisState() GenesisState { + return GenesisState{ + Params: DefaultParams(), + AddressMappings: []*AddressMapping{}, + } +} + +// Validate performs basic genesis state validation returning an error upon any +// failure. +func (gs GenesisState) Validate() error { + if err := gs.Params.ValidateBasic(); err != nil { + return err + } + + seenMappings := make(map[string]string) + for _, mapping := range gs.AddressMappings { + if err := mapping.ValidateBasic(); err != nil { + return err + } + + // Check for duplicate mappings + key := mapping.CosmosAddress + "|" + mapping.EvmAddress + if _, exists := seenMappings[key]; exists { + return fmt.Errorf("duplicate address mapping found: %s", key) + } + seenMappings[key] = "" + } + + return nil +} diff --git a/x/addresses/types/genesis.pb.go b/x/addresses/types/genesis.pb.go new file mode 100644 index 00000000..d4b76da4 --- /dev/null +++ b/x/addresses/types/genesis.pb.go @@ -0,0 +1,506 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: addresses/v1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type GenesisState struct { + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + AddressMappings []*AddressMapping `protobuf:"bytes,2,rep,name=address_mappings,json=addressMappings,proto3" json:"address_mappings,omitempty"` +} + +func (m *GenesisState) Reset() { *m = GenesisState{} } +func (m *GenesisState) String() string { return proto.CompactTextString(m) } +func (*GenesisState) ProtoMessage() {} +func (*GenesisState) Descriptor() ([]byte, []int) { + return fileDescriptor_b55f1bec9bbe9669, []int{0} +} +func (m *GenesisState) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisState) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisState.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisState) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisState.Merge(m, src) +} +func (m *GenesisState) XXX_Size() int { + return m.Size() +} +func (m *GenesisState) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisState.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisState proto.InternalMessageInfo + +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func (m *GenesisState) GetAddressMappings() []*AddressMapping { + if m != nil { + return m.AddressMappings + } + return nil +} + +type Params struct { +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_b55f1bec9bbe9669, []int{1} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*GenesisState)(nil), "addresses.v1.GenesisState") + proto.RegisterType((*Params)(nil), "addresses.v1.Params") +} + +func init() { proto.RegisterFile("addresses/v1/genesis.proto", fileDescriptor_b55f1bec9bbe9669) } + +var fileDescriptor_b55f1bec9bbe9669 = []byte{ + // 269 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x54, 0x90, 0x31, 0x4b, 0xc3, 0x40, + 0x1c, 0xc5, 0x73, 0x2a, 0x41, 0xd2, 0x82, 0x12, 0x3a, 0x94, 0x10, 0xce, 0xd2, 0xa9, 0x53, 0x8e, + 0xc4, 0xc1, 0x59, 0x97, 0x0e, 0x22, 0x48, 0xdd, 0x5c, 0xe4, 0x6a, 0xff, 0x9c, 0x27, 0x4d, 0xfe, + 0x47, 0xfe, 0x67, 0xb0, 0x9f, 0xc1, 0xc5, 0x8f, 0xd5, 0xb1, 0xa3, 0x93, 0x48, 0xf2, 0x45, 0xc4, + 0xe4, 0xb0, 0xcd, 0xf6, 0xde, 0xbd, 0xdf, 0xe3, 0xdd, 0x5d, 0x10, 0xc9, 0xd5, 0xaa, 0x04, 0x22, + 0x20, 0x51, 0xa5, 0x42, 0x41, 0x01, 0xa4, 0x29, 0x31, 0x25, 0x5a, 0x0c, 0x87, 0xff, 0x59, 0x52, + 0xa5, 0x51, 0xdc, 0x23, 0xf7, 0x51, 0xcb, 0x46, 0x23, 0x85, 0x0a, 0x5b, 0x29, 0xfe, 0x94, 0x3b, + 0x8d, 0x15, 0xa2, 0x5a, 0x83, 0x90, 0x46, 0x0b, 0x59, 0x14, 0x68, 0xa5, 0xd5, 0x58, 0xb8, 0xce, + 0xf4, 0x83, 0x05, 0xc3, 0x79, 0xb7, 0xf8, 0x60, 0xa5, 0x85, 0x30, 0x0b, 0x7c, 0x23, 0x4b, 0x99, + 0xd3, 0x98, 0x4d, 0xd8, 0x6c, 0x90, 0x8d, 0x92, 0xc3, 0x1b, 0x24, 0xf7, 0x6d, 0x76, 0x73, 0xb2, + 0xfd, 0xbe, 0xf0, 0x16, 0x8e, 0x0c, 0xe7, 0xc1, 0xb9, 0x83, 0x9e, 0x72, 0x69, 0x8c, 0x2e, 0x14, + 0x8d, 0x8f, 0x26, 0xc7, 0xb3, 0x41, 0x16, 0xf7, 0xdb, 0xd7, 0x9d, 0xb9, 0xeb, 0xa0, 0xc5, 0x99, + 0xec, 0x79, 0x9a, 0x9e, 0x06, 0xbe, 0x1b, 0xb8, 0xdd, 0xd6, 0x9c, 0xed, 0x6a, 0xce, 0x7e, 0x6a, + 0xce, 0x3e, 0x1b, 0xee, 0xed, 0x1a, 0xee, 0x7d, 0x35, 0xdc, 0x7b, 0x4c, 0x95, 0xb6, 0x2f, 0x6f, + 0xcb, 0xe4, 0x19, 0x73, 0x61, 0x40, 0xa9, 0xcd, 0x6b, 0x25, 0x08, 0xf3, 0x1c, 0xd6, 0x1a, 0x4a, + 0x51, 0x5d, 0x89, 0xf7, 0xfd, 0xc7, 0x08, 0xbb, 0x31, 0x40, 0x4b, 0xbf, 0x7d, 0xeb, 0xe5, 0x6f, + 0x00, 0x00, 0x00, 0xff, 0xff, 0x37, 0x46, 0xa8, 0x48, 0x69, 0x01, 0x00, 0x00, +} + +func (m *GenesisState) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisState) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.AddressMappings) > 0 { + for iNdEx := len(m.AddressMappings) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AddressMappings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { + offset -= sovGenesis(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *GenesisState) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.AddressMappings) > 0 { + for _, e := range m.AddressMappings { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovGenesis(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozGenesis(x uint64) (n int) { + return sovGenesis(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *GenesisState) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisState: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AddressMappings", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AddressMappings = append(m.AddressMappings, &AddressMapping{}) + if err := m.AddressMappings[len(m.AddressMappings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipGenesis(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowGenesis + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthGenesis + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupGenesis + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthGenesis + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthGenesis = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowGenesis = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/addresses/types/genesis_test.go b/x/addresses/types/genesis_test.go new file mode 100644 index 00000000..9a66fc58 --- /dev/null +++ b/x/addresses/types/genesis_test.go @@ -0,0 +1,205 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGenesisState_Validate(t *testing.T) { + def := DefaultGenesisState() + testCases := []struct { + desc string + genState *GenesisState + valid bool + }{ + { + desc: "default is valid", + genState: &def, + valid: true, + }, + { + desc: "valid genesis state", + genState: &GenesisState{}, + valid: true, + }, + { + desc: "invalid address mapping - invalid cosmos address", + genState: &GenesisState{ + AddressMappings: []*AddressMapping{ + { + CosmosAddress: "invalid_cosmos_address", + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + }, + }, + valid: false, + }, + { + desc: "invalid address mapping - invalid evm address", + genState: &GenesisState{ + AddressMappings: []*AddressMapping{ + { + CosmosAddress: cosmosAddress1, + EvmAddress: "invalid_evm_address", + }, + }, + }, + valid: false, + }, + { + desc: "duplicate address mappings", + genState: &GenesisState{ + AddressMappings: []*AddressMapping{ + { + CosmosAddress: cosmosAddress1, + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + { + CosmosAddress: cosmosAddress1, + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + }, + }, + valid: false, + }, + { + desc: "duplicate cosmos address", + genState: &GenesisState{ + AddressMappings: []*AddressMapping{ + { + CosmosAddress: cosmosAddress1, + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + { + CosmosAddress: cosmosAddress1, + EvmAddress: "0x0987654321098765432109876543210987654321", + }, + }, + }, + valid: true, + }, + } + + for _, tc := range testCases { + tc := tc // create a local copy + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} + +func TestValidateGenesis(t *testing.T) { + testCases := []struct { + desc string + genState GenesisState + valid bool + }{ + { + desc: "default genesis state", + genState: DefaultGenesisState(), + valid: true, + }, + { + desc: "custom genesis state", + genState: GenesisState{ + Params: DefaultParams(), + AddressMappings: []*AddressMapping{ + { + CosmosAddress: "cosmos1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrql8a", + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + }, + }, + valid: true, + }, + } + + for _, tc := range testCases { + tc := tc // create a local copy + t.Run(tc.desc, func(t *testing.T) { + err := tc.genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} + +func TestDefaultGenesisState(t *testing.T) { + defaultGenesis := DefaultGenesisState() + require.NotNil(t, defaultGenesis.Params) + require.Equal(t, DefaultParams(), defaultGenesis.Params) + require.Empty(t, defaultGenesis.AddressMappings) +} + +func TestGenesisState_ValidateAddressMappings(t *testing.T) { + testCases := []struct { + desc string + mappings []*AddressMapping + valid bool + }{ + { + desc: "empty mappings", + mappings: []*AddressMapping{}, + valid: true, + }, + { + desc: "valid mappings", + mappings: []*AddressMapping{ + { + CosmosAddress: cosmosAddress1, + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + { + CosmosAddress: cosmosAddress2, + EvmAddress: "0x0987654321098765432109876543210987654321", + }, + }, + valid: true, + }, + { + desc: "invalid cosmos address", + mappings: []*AddressMapping{ + { + CosmosAddress: "invalid_cosmos_address", + EvmAddress: "0x1234567890123456789012345678901234567890", + }, + }, + valid: false, + }, + { + desc: "invalid evm address", + mappings: []*AddressMapping{ + { + CosmosAddress: cosmosAddress1, + EvmAddress: "invalid_evm_address", + }, + }, + valid: false, + }, + } + + for _, tc := range testCases { + tc := tc // create a local copy + t.Run(tc.desc, func(t *testing.T) { + genState := GenesisState{ + Params: DefaultParams(), + AddressMappings: tc.mappings, + } + err := genState.Validate() + if tc.valid { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/x/addresses/types/keys.go b/x/addresses/types/keys.go new file mode 100644 index 00000000..036d9f98 --- /dev/null +++ b/x/addresses/types/keys.go @@ -0,0 +1,42 @@ +package types + +import "bytes" + +const ( + // ModuleName defines the module name + ModuleName = "addresses" + + // StoreKey defines the primary module store key + StoreKey = ModuleName + + // RouterKey defines the module's message routing key + RouterKey = ModuleName + + // MemStoreKey defines the in-memory store key + MemStoreKey = "mem_addresses" +) +const ( + _ = byte(iota) + + // + CosmosToEvmMapPrefix + + // + EvmToCosmosMapPrefix +) + +func GetCosmosToEvmMapPrefix() []byte { + return []byte{CosmosToEvmMapPrefix} +} + +func GetCosmosToEvmMapKey(cosmosAddr []byte) []byte { + return bytes.Join([][]byte{{CosmosToEvmMapPrefix}, cosmosAddr}, []byte{}) +} + +func GetEvmToCosmosMapPrefix() []byte { + return []byte{EvmToCosmosMapPrefix} +} + +func GetEvmToCosmosMapKey(evmAddr []byte) []byte { + return bytes.Join([][]byte{{EvmToCosmosMapPrefix}, evmAddr}, []byte{}) +} diff --git a/x/addresses/types/msgs.go b/x/addresses/types/msgs.go new file mode 100644 index 00000000..c54f0361 --- /dev/null +++ b/x/addresses/types/msgs.go @@ -0,0 +1,125 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" +) + +var ( + _ sdk.Msg = &MsgAddAddressMapping{} + _ sdk.Msg = &MsgRemoveAddressMapping{} +) + +const ( + TypeMsgAddAddressMapping = "add_address_mapping" + TypeMsgRemoveAddressMapping = "remove_address_mapping" +) + +////////////////////////// +// MsgAddAddressMapping // +////////////////////////// + +// NewMsgAddAddressMapping return a new MsgAddAddressMapping +func NewMsgAddAddressMapping(evmAddres common.Address, signer sdk.AccAddress) (*MsgAddAddressMapping, error) { + msg := &MsgAddAddressMapping{ + EvmAddress: evmAddres.Hex(), + Signer: signer.String(), + } + + if err := msg.ValidateBasic(); err != nil { + return nil, err + } + + return msg, nil +} + +// Route implements sdk.Msg +func (m *MsgAddAddressMapping) Route() string { return ModuleName } + +// Type implements sdk.Msg +func (m *MsgAddAddressMapping) Type() string { return TypeMsgAddAddressMapping } + +// ValidateBasic implements sdk.Msg +func (m *MsgAddAddressMapping) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Signer); err != nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) + } + + if !common.IsHexAddress(m.EvmAddress) { + return errorsmod.Wrapf(ErrInvalidEvmAddress, "%s is not a valid hex address", m.EvmAddress) + } + + return nil +} + +// GetSignBytes implements sdk.Msg +func (m *MsgAddAddressMapping) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +// GetSigners implements sdk.Msg +func (m *MsgAddAddressMapping) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{m.MustGetSigner()} +} + +// MustGetSigner returns the signer address (which is also the bidder) +func (m *MsgAddAddressMapping) MustGetSigner() sdk.AccAddress { + addr, err := sdk.AccAddressFromBech32(m.Signer) + if err != nil { + panic(err) + } + return addr +} + +///////////////////////////// +// MsgRemoveAddressMapping // +///////////////////////////// + +// NewMsgRemoveAddressMapping return a new MsgRemoveAddressMapping +func NewMsgRemoveAddressMapping(signer sdk.AccAddress) (*MsgRemoveAddressMapping, error) { + msg := &MsgRemoveAddressMapping{ + Signer: signer.String(), + } + + if err := msg.ValidateBasic(); err != nil { + return nil, err + } + + return msg, nil +} + +// Route implements sdk.Msg +func (m *MsgRemoveAddressMapping) Route() string { return ModuleName } + +// Type implements sdk.Msg +func (m *MsgRemoveAddressMapping) Type() string { return TypeMsgRemoveAddressMapping } + +// ValidateBasic implements sdk.Msg +func (m *MsgRemoveAddressMapping) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Signer); err != nil { + return errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) + } + + return nil +} + +// GetSignBytes implements sdk.Msg +func (m *MsgRemoveAddressMapping) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(m)) +} + +// GetSigners implements sdk.Msg +func (m *MsgRemoveAddressMapping) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{m.MustGetSigner()} +} + +// MustGetSigner returns the signer address (which is also the bidder) +func (m *MsgRemoveAddressMapping) MustGetSigner() sdk.AccAddress { + addr, err := sdk.AccAddressFromBech32(m.Signer) + if err != nil { + panic(err) + } + return addr +} diff --git a/x/addresses/types/msgs_test.go b/x/addresses/types/msgs_test.go new file mode 100644 index 00000000..f763d99d --- /dev/null +++ b/x/addresses/types/msgs_test.go @@ -0,0 +1,225 @@ +package types + +import ( + "testing" + + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" +) + +const ( + evmAddress1 = "0x1111111111111111111111111111111111111111" + cosmosAddress1 = "cosmos154d0p9xhrruhxvazumej9nq29afeura2alje4u" + cosmosAddress2 = "cosmos1y6d5kasehecexf09ka6y0ggl0pxzt6dgk0gnl9" +) + +func TestNewMsgAddAddressMappingFormatting(t *testing.T) { + expectedMsg := &MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: cosmosAddress1, + } + + cosmosAccount1, err := sdk.AccAddressFromBech32(cosmosAddress1) + require.NoError(t, err) + createdMsg, err := NewMsgAddAddressMapping(common.HexToAddress(evmAddress1), cosmosAccount1) + require.NoError(t, err) + require.Equal(t, expectedMsg, createdMsg) + + // Test with nil Cosmos address + _, err = NewMsgAddAddressMapping(common.HexToAddress(evmAddress1), nil) + require.Error(t, err) + require.Contains(t, err.Error(), "invalid address") +} + +func TestMsgAddAddressMappingValidate(t *testing.T) { + testCases := []struct { + name string + msgAddAddressMapping MsgAddAddressMapping + expPass bool + err error + }{ + { + name: "Happy path", + msgAddAddressMapping: MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: cosmosAddress1, + }, + expPass: true, + err: nil, + }, + { + name: "Invalid signer address", + msgAddAddressMapping: MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: "sladjflaksjfd", + }, + expPass: false, + err: errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "decoding bech32 failed: invalid separator index -1"), + }, + { + name: "Invalid EVM address", + msgAddAddressMapping: MsgAddAddressMapping{ + EvmAddress: "lasjfdlsdf", + Signer: cosmosAddress1, + }, + expPass: false, + err: errorsmod.Wrap(ErrInvalidEvmAddress, "lasjfdlsdf is not a valid hex address"), + }, + { + name: "Empty EVM address", + msgAddAddressMapping: MsgAddAddressMapping{ + EvmAddress: "", + Signer: cosmosAddress1, + }, + expPass: false, + err: errorsmod.Wrap(ErrInvalidEvmAddress, " is not a valid hex address"), + }, + { + name: "Empty signer address", + msgAddAddressMapping: MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: "", + }, + expPass: false, + err: errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "empty address string is not allowed"), + }, + } + + for _, tc := range testCases { + tc := tc // create a local copy + t.Run(tc.name, func(t *testing.T) { + err := tc.msgAddAddressMapping.ValidateBasic() + if tc.expPass { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + require.Equal(t, tc.err.Error(), err.Error(), tc.name) + } + }) + } +} + +func TestNewMsgRemoveAddressMappingFormatting(t *testing.T) { + expectedMsg := &MsgRemoveAddressMapping{ + Signer: cosmosAddress1, + } + + cosmosAccount1, err := sdk.AccAddressFromBech32(cosmosAddress1) + require.NoError(t, err) + createdMsg, err := NewMsgRemoveAddressMapping(cosmosAccount1) + require.NoError(t, err) + require.Equal(t, expectedMsg, createdMsg) + + // Test with nil Cosmos address + _, err = NewMsgRemoveAddressMapping(nil) + require.Error(t, err) + require.Contains(t, err.Error(), "invalid address") +} + +func TestMsgRemoveAddressMappingValidate(t *testing.T) { + testCases := []struct { + name string + msgRemoveAddressMapping MsgRemoveAddressMapping + expPass bool + err error + }{ + { + name: "Happy path", + msgRemoveAddressMapping: MsgRemoveAddressMapping{ + Signer: cosmosAddress1, + }, + expPass: true, + err: nil, + }, + { + name: "Invalid signer address", + msgRemoveAddressMapping: MsgRemoveAddressMapping{ + Signer: "sladjflaksjfd", + }, + expPass: false, + err: errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "decoding bech32 failed: invalid separator index -1"), + }, + { + name: "Empty signer address", + msgRemoveAddressMapping: MsgRemoveAddressMapping{ + Signer: "", + }, + expPass: false, + err: errorsmod.Wrap(sdkerrors.ErrInvalidAddress, "empty address string is not allowed"), + }, + } + + for _, tc := range testCases { + tc := tc // create a local copy + t.Run(tc.name, func(t *testing.T) { + err := tc.msgRemoveAddressMapping.ValidateBasic() + if tc.expPass { + require.NoError(t, err, tc.name) + } else { + require.Error(t, err, tc.name) + require.Equal(t, tc.err.Error(), err.Error(), tc.name) + } + }) + } +} + +func TestMsgAddAddressMappingGetSigners(t *testing.T) { + msg := MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: cosmosAddress1, + } + + signers := msg.GetSigners() + require.Len(t, signers, 1) + require.Equal(t, cosmosAddress1, signers[0].String()) + + // Test with invalid signer address + msg.Signer = "invalid_address" + require.Panics(t, func() { msg.GetSigners() }) +} + +func TestMsgRemoveAddressMappingGetSigners(t *testing.T) { + msg := MsgRemoveAddressMapping{ + Signer: cosmosAddress1, + } + + signers := msg.GetSigners() + require.Len(t, signers, 1) + require.Equal(t, cosmosAddress1, signers[0].String()) + + // Test with invalid signer address + msg.Signer = "invalid_address" + require.Panics(t, func() { msg.GetSigners() }) +} + +func TestMsgAddAddressMappingType(t *testing.T) { + msg := MsgAddAddressMapping{} + require.Equal(t, "add_address_mapping", msg.Type()) +} + +func TestMsgRemoveAddressMappingType(t *testing.T) { + msg := MsgRemoveAddressMapping{} + require.Equal(t, "remove_address_mapping", msg.Type()) +} + +func TestMsgAddAddressMappingGetSignBytes(t *testing.T) { + msg := MsgAddAddressMapping{ + EvmAddress: evmAddress1, + Signer: cosmosAddress1, + } + + signBytes := msg.GetSignBytes() + require.NotEmpty(t, signBytes) +} + +func TestMsgRemoveAddressMappingGetSignBytes(t *testing.T) { + msg := MsgRemoveAddressMapping{ + Signer: cosmosAddress1, + } + + signBytes := msg.GetSignBytes() + require.NotEmpty(t, signBytes) +} diff --git a/x/addresses/types/params.go b/x/addresses/types/params.go new file mode 100644 index 00000000..7cfc4e7f --- /dev/null +++ b/x/addresses/types/params.go @@ -0,0 +1,33 @@ +//nolint:all +package types + +import ( + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +// ParamKeyTable the param key table for launch module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams() Params { + return Params{} +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams() +} + +// ParamSetPairs get the params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{} +} + +// Validate validates the set of params +func (p Params) ValidateBasic() error { + return nil +} diff --git a/x/addresses/types/query.pb.go b/x/addresses/types/query.pb.go new file mode 100644 index 00000000..19a761cb --- /dev/null +++ b/x/addresses/types/query.pb.go @@ -0,0 +1,1868 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: addresses/v1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +type QueryParamsResponse struct { + Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *Params { + if m != nil { + return m.Params + } + return nil +} + +type QueryAddressMappingsRequest struct { + Pagination query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination"` +} + +func (m *QueryAddressMappingsRequest) Reset() { *m = QueryAddressMappingsRequest{} } +func (m *QueryAddressMappingsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAddressMappingsRequest) ProtoMessage() {} +func (*QueryAddressMappingsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{2} +} +func (m *QueryAddressMappingsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingsRequest.Merge(m, src) +} +func (m *QueryAddressMappingsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingsRequest proto.InternalMessageInfo + +func (m *QueryAddressMappingsRequest) GetPagination() query.PageRequest { + if m != nil { + return m.Pagination + } + return query.PageRequest{} +} + +type QueryAddressMappingsResponse struct { + AddressMappings []*AddressMapping `protobuf:"bytes,1,rep,name=address_mappings,json=addressMappings,proto3" json:"address_mappings,omitempty"` + Pagination query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination"` +} + +func (m *QueryAddressMappingsResponse) Reset() { *m = QueryAddressMappingsResponse{} } +func (m *QueryAddressMappingsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAddressMappingsResponse) ProtoMessage() {} +func (*QueryAddressMappingsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{3} +} +func (m *QueryAddressMappingsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingsResponse.Merge(m, src) +} +func (m *QueryAddressMappingsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingsResponse proto.InternalMessageInfo + +func (m *QueryAddressMappingsResponse) GetAddressMappings() []*AddressMapping { + if m != nil { + return m.AddressMappings + } + return nil +} + +func (m *QueryAddressMappingsResponse) GetPagination() query.PageResponse { + if m != nil { + return m.Pagination + } + return query.PageResponse{} +} + +type QueryAddressMappingByEVMAddressRequest struct { + EvmAddress string `protobuf:"bytes,1,opt,name=evm_address,json=evmAddress,proto3" json:"evm_address,omitempty"` +} + +func (m *QueryAddressMappingByEVMAddressRequest) Reset() { + *m = QueryAddressMappingByEVMAddressRequest{} +} +func (m *QueryAddressMappingByEVMAddressRequest) String() string { return proto.CompactTextString(m) } +func (*QueryAddressMappingByEVMAddressRequest) ProtoMessage() {} +func (*QueryAddressMappingByEVMAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{4} +} +func (m *QueryAddressMappingByEVMAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingByEVMAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingByEVMAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingByEVMAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingByEVMAddressRequest.Merge(m, src) +} +func (m *QueryAddressMappingByEVMAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingByEVMAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingByEVMAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingByEVMAddressRequest proto.InternalMessageInfo + +func (m *QueryAddressMappingByEVMAddressRequest) GetEvmAddress() string { + if m != nil { + return m.EvmAddress + } + return "" +} + +type QueryAddressMappingByEVMAddressResponse struct { + CosmosAddress string `protobuf:"bytes,1,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` + EvmAddress string `protobuf:"bytes,2,opt,name=evm_address,json=evmAddress,proto3" json:"evm_address,omitempty"` +} + +func (m *QueryAddressMappingByEVMAddressResponse) Reset() { + *m = QueryAddressMappingByEVMAddressResponse{} +} +func (m *QueryAddressMappingByEVMAddressResponse) String() string { return proto.CompactTextString(m) } +func (*QueryAddressMappingByEVMAddressResponse) ProtoMessage() {} +func (*QueryAddressMappingByEVMAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{5} +} +func (m *QueryAddressMappingByEVMAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingByEVMAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingByEVMAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingByEVMAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingByEVMAddressResponse.Merge(m, src) +} +func (m *QueryAddressMappingByEVMAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingByEVMAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingByEVMAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingByEVMAddressResponse proto.InternalMessageInfo + +func (m *QueryAddressMappingByEVMAddressResponse) GetCosmosAddress() string { + if m != nil { + return m.CosmosAddress + } + return "" +} + +func (m *QueryAddressMappingByEVMAddressResponse) GetEvmAddress() string { + if m != nil { + return m.EvmAddress + } + return "" +} + +type QueryAddressMappingByCosmosAddressRequest struct { + CosmosAddress string `protobuf:"bytes,1,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` +} + +func (m *QueryAddressMappingByCosmosAddressRequest) Reset() { + *m = QueryAddressMappingByCosmosAddressRequest{} +} +func (m *QueryAddressMappingByCosmosAddressRequest) String() string { + return proto.CompactTextString(m) +} +func (*QueryAddressMappingByCosmosAddressRequest) ProtoMessage() {} +func (*QueryAddressMappingByCosmosAddressRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{6} +} +func (m *QueryAddressMappingByCosmosAddressRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingByCosmosAddressRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingByCosmosAddressRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingByCosmosAddressRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingByCosmosAddressRequest.Merge(m, src) +} +func (m *QueryAddressMappingByCosmosAddressRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingByCosmosAddressRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingByCosmosAddressRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingByCosmosAddressRequest proto.InternalMessageInfo + +func (m *QueryAddressMappingByCosmosAddressRequest) GetCosmosAddress() string { + if m != nil { + return m.CosmosAddress + } + return "" +} + +type QueryAddressMappingByCosmosAddressResponse struct { + CosmosAddress string `protobuf:"bytes,1,opt,name=cosmos_address,json=cosmosAddress,proto3" json:"cosmos_address,omitempty"` + EvmAddress string `protobuf:"bytes,2,opt,name=evm_address,json=evmAddress,proto3" json:"evm_address,omitempty"` +} + +func (m *QueryAddressMappingByCosmosAddressResponse) Reset() { + *m = QueryAddressMappingByCosmosAddressResponse{} +} +func (m *QueryAddressMappingByCosmosAddressResponse) String() string { + return proto.CompactTextString(m) +} +func (*QueryAddressMappingByCosmosAddressResponse) ProtoMessage() {} +func (*QueryAddressMappingByCosmosAddressResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_ebe10bad8a6f145d, []int{7} +} +func (m *QueryAddressMappingByCosmosAddressResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryAddressMappingByCosmosAddressResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryAddressMappingByCosmosAddressResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryAddressMappingByCosmosAddressResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryAddressMappingByCosmosAddressResponse.Merge(m, src) +} +func (m *QueryAddressMappingByCosmosAddressResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryAddressMappingByCosmosAddressResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryAddressMappingByCosmosAddressResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryAddressMappingByCosmosAddressResponse proto.InternalMessageInfo + +func (m *QueryAddressMappingByCosmosAddressResponse) GetCosmosAddress() string { + if m != nil { + return m.CosmosAddress + } + return "" +} + +func (m *QueryAddressMappingByCosmosAddressResponse) GetEvmAddress() string { + if m != nil { + return m.EvmAddress + } + return "" +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "addresses.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "addresses.v1.QueryParamsResponse") + proto.RegisterType((*QueryAddressMappingsRequest)(nil), "addresses.v1.QueryAddressMappingsRequest") + proto.RegisterType((*QueryAddressMappingsResponse)(nil), "addresses.v1.QueryAddressMappingsResponse") + proto.RegisterType((*QueryAddressMappingByEVMAddressRequest)(nil), "addresses.v1.QueryAddressMappingByEVMAddressRequest") + proto.RegisterType((*QueryAddressMappingByEVMAddressResponse)(nil), "addresses.v1.QueryAddressMappingByEVMAddressResponse") + proto.RegisterType((*QueryAddressMappingByCosmosAddressRequest)(nil), "addresses.v1.QueryAddressMappingByCosmosAddressRequest") + proto.RegisterType((*QueryAddressMappingByCosmosAddressResponse)(nil), "addresses.v1.QueryAddressMappingByCosmosAddressResponse") +} + +func init() { proto.RegisterFile("addresses/v1/query.proto", fileDescriptor_ebe10bad8a6f145d) } + +var fileDescriptor_ebe10bad8a6f145d = []byte{ + // 618 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x95, 0x4f, 0x6b, 0x13, 0x41, + 0x18, 0xc6, 0x33, 0xd1, 0x16, 0x7c, 0xe3, 0x3f, 0xc6, 0x1c, 0xc2, 0x36, 0x6c, 0xe2, 0x82, 0x6d, + 0x1a, 0x65, 0x87, 0x44, 0x4b, 0x45, 0x3c, 0x68, 0x8a, 0x14, 0xd1, 0x40, 0xcd, 0xc1, 0x83, 0x97, + 0x32, 0x69, 0x87, 0x71, 0xb5, 0xbb, 0xb3, 0xc9, 0x6c, 0x16, 0x43, 0x29, 0x82, 0x27, 0x8f, 0x82, + 0x5f, 0xc1, 0x0f, 0xe0, 0xc9, 0xcf, 0xd0, 0x63, 0xc1, 0x83, 0x9e, 0x44, 0x12, 0xd1, 0xbb, 0x9f, + 0x40, 0xb2, 0x3b, 0x6b, 0x76, 0xd3, 0xd5, 0x6c, 0xa1, 0xb7, 0xcd, 0xcc, 0x33, 0xef, 0xf3, 0x7b, + 0x86, 0xf7, 0xcd, 0x40, 0x89, 0xee, 0xee, 0xf6, 0x99, 0x94, 0x4c, 0x12, 0xbf, 0x41, 0x7a, 0x03, + 0xd6, 0x1f, 0x9a, 0x6e, 0x5f, 0x78, 0x02, 0x9f, 0xff, 0xbb, 0x63, 0xfa, 0x0d, 0xad, 0x9c, 0xd0, + 0x4d, 0xb7, 0x02, 0xad, 0xa6, 0x25, 0x76, 0x39, 0x73, 0x98, 0xb4, 0xa2, 0xbd, 0x22, 0x17, 0x5c, + 0x04, 0x9f, 0x64, 0xf2, 0xa5, 0x56, 0xcb, 0x5c, 0x08, 0xbe, 0xc7, 0x08, 0x75, 0x2d, 0x42, 0x1d, + 0x47, 0x78, 0xd4, 0xb3, 0x84, 0x13, 0x9d, 0xa9, 0xef, 0x08, 0x69, 0x0b, 0x49, 0xba, 0x54, 0xb2, + 0x10, 0x8a, 0xf8, 0x8d, 0x2e, 0xf3, 0x68, 0x83, 0xb8, 0x94, 0x5b, 0x4e, 0x20, 0x56, 0xda, 0x25, + 0xa5, 0x8d, 0x64, 0xf1, 0x10, 0x46, 0x11, 0xf0, 0x93, 0xc9, 0xcf, 0x2d, 0xda, 0xa7, 0xb6, 0xec, + 0xb0, 0xde, 0x80, 0x49, 0xcf, 0xd8, 0x80, 0x2b, 0x89, 0x55, 0xe9, 0x0a, 0x47, 0x32, 0x7c, 0x03, + 0x16, 0xdd, 0x60, 0xa5, 0x84, 0xaa, 0xa8, 0x56, 0x68, 0x16, 0xcd, 0xf8, 0x15, 0x98, 0x4a, 0xad, + 0x34, 0xc6, 0x4b, 0x58, 0x0a, 0x8a, 0xdc, 0x0f, 0x35, 0x6d, 0xea, 0xba, 0x96, 0xc3, 0x23, 0x0f, + 0xfc, 0x18, 0x60, 0x8a, 0xaa, 0x0a, 0x2e, 0x9b, 0x21, 0xab, 0x39, 0xc9, 0x65, 0x86, 0x9c, 0x2a, + 0x97, 0xb9, 0x45, 0x39, 0x53, 0x67, 0x5b, 0x67, 0x0f, 0xbf, 0x55, 0x72, 0x9d, 0xd8, 0x79, 0xe3, + 0x13, 0x82, 0x72, 0xba, 0x9b, 0x62, 0xdf, 0x84, 0xcb, 0x0a, 0x76, 0xdb, 0x56, 0x7b, 0x25, 0x54, + 0x3d, 0x53, 0x2b, 0x34, 0xcb, 0xc9, 0x14, 0xc9, 0x02, 0x9d, 0x4b, 0x34, 0x59, 0x10, 0xb7, 0x13, + 0xdc, 0xf9, 0x80, 0x7b, 0x65, 0x2e, 0x77, 0x48, 0x91, 0x02, 0xfe, 0x10, 0x96, 0x53, 0xb8, 0x5b, + 0xc3, 0x07, 0x4f, 0xdb, 0x6a, 0x29, 0xba, 0xb0, 0x0a, 0x14, 0x98, 0x6f, 0x6f, 0x2b, 0x9e, 0xe0, + 0xc6, 0xce, 0x75, 0x80, 0xf9, 0xb6, 0xd2, 0x19, 0x3d, 0x58, 0x99, 0x5b, 0x4a, 0xdd, 0xc6, 0x35, + 0xb8, 0x18, 0x12, 0xcf, 0x94, 0xbb, 0x10, 0xae, 0x2a, 0xf9, 0xac, 0x65, 0xfe, 0x98, 0x65, 0x07, + 0x56, 0x53, 0x2d, 0x37, 0xe2, 0x65, 0xa2, 0x00, 0xd9, 0x4c, 0x0d, 0x0f, 0xea, 0x59, 0x6a, 0x9e, + 0x6e, 0x92, 0xe6, 0xef, 0x05, 0x58, 0x08, 0x6c, 0xf1, 0x6b, 0x28, 0xc4, 0x9a, 0x1f, 0x57, 0x93, + 0xed, 0x71, 0x7c, 0x5a, 0xb4, 0xab, 0xff, 0x51, 0x84, 0x94, 0xc6, 0xf5, 0xb7, 0xbf, 0x3e, 0xd6, + 0xd1, 0x9b, 0xcf, 0x3f, 0xde, 0xe7, 0xab, 0x58, 0x27, 0x52, 0xd8, 0x36, 0xdb, 0xb3, 0x58, 0x9f, + 0x24, 0xfe, 0x17, 0xc2, 0xc1, 0xc1, 0x1f, 0x10, 0x14, 0xd3, 0x7a, 0x19, 0xaf, 0xa6, 0x18, 0xa5, + 0x4f, 0x97, 0x56, 0xcf, 0x22, 0x55, 0x70, 0x6b, 0x53, 0xb8, 0x3a, 0xae, 0xfd, 0x0b, 0x6e, 0x76, + 0x7a, 0xf0, 0x17, 0x04, 0x95, 0x39, 0xfd, 0x86, 0x6f, 0xcd, 0xc5, 0x48, 0xe9, 0x74, 0x6d, 0xed, + 0x84, 0xa7, 0x54, 0x8e, 0xcd, 0x69, 0x8e, 0xbb, 0xf8, 0x4e, 0xd6, 0x1c, 0x84, 0xf9, 0x36, 0xd9, + 0x8f, 0x35, 0xc7, 0x01, 0xfe, 0x89, 0xc0, 0x98, 0xdf, 0x82, 0x78, 0x3d, 0x03, 0x66, 0xda, 0x20, + 0x68, 0xb7, 0x4f, 0x7e, 0x50, 0x45, 0x6c, 0x4f, 0x23, 0xb6, 0xf0, 0xbd, 0xcc, 0x11, 0xd5, 0x0b, + 0xb0, 0x9f, 0x9c, 0x94, 0x83, 0xd6, 0xa3, 0xc3, 0x91, 0x8e, 0x8e, 0x46, 0x3a, 0xfa, 0x3e, 0xd2, + 0xd1, 0xbb, 0xb1, 0x9e, 0x3b, 0x1a, 0xeb, 0xb9, 0xaf, 0x63, 0x3d, 0xf7, 0xac, 0xc1, 0x2d, 0xef, + 0xf9, 0xa0, 0x6b, 0xee, 0x08, 0x9b, 0xb8, 0x8c, 0xf3, 0xe1, 0x0b, 0x3f, 0xe6, 0xe6, 0xaf, 0x93, + 0x57, 0x31, 0x4b, 0x6f, 0xe8, 0x32, 0xd9, 0x5d, 0x0c, 0x5e, 0x94, 0x9b, 0x7f, 0x02, 0x00, 0x00, + 0xff, 0xff, 0x2e, 0xfa, 0x78, 0x5a, 0x32, 0x07, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) + QueryAddressMappings(ctx context.Context, in *QueryAddressMappingsRequest, opts ...grpc.CallOption) (*QueryAddressMappingsResponse, error) + QueryAddressMappingByEVMAddress(ctx context.Context, in *QueryAddressMappingByEVMAddressRequest, opts ...grpc.CallOption) (*QueryAddressMappingByEVMAddressResponse, error) + QueryAddressMappingByCosmosAddress(ctx context.Context, in *QueryAddressMappingByCosmosAddressRequest, opts ...grpc.CallOption) (*QueryAddressMappingByCosmosAddressResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Query/QueryParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryAddressMappings(ctx context.Context, in *QueryAddressMappingsRequest, opts ...grpc.CallOption) (*QueryAddressMappingsResponse, error) { + out := new(QueryAddressMappingsResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Query/QueryAddressMappings", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryAddressMappingByEVMAddress(ctx context.Context, in *QueryAddressMappingByEVMAddressRequest, opts ...grpc.CallOption) (*QueryAddressMappingByEVMAddressResponse, error) { + out := new(QueryAddressMappingByEVMAddressResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Query/QueryAddressMappingByEVMAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) QueryAddressMappingByCosmosAddress(ctx context.Context, in *QueryAddressMappingByCosmosAddressRequest, opts ...grpc.CallOption) (*QueryAddressMappingByCosmosAddressResponse, error) { + out := new(QueryAddressMappingByCosmosAddressResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Query/QueryAddressMappingByCosmosAddress", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + QueryParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) + QueryAddressMappings(context.Context, *QueryAddressMappingsRequest) (*QueryAddressMappingsResponse, error) + QueryAddressMappingByEVMAddress(context.Context, *QueryAddressMappingByEVMAddressRequest) (*QueryAddressMappingByEVMAddressResponse, error) + QueryAddressMappingByCosmosAddress(context.Context, *QueryAddressMappingByCosmosAddressRequest) (*QueryAddressMappingByCosmosAddressResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) QueryParams(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryParams not implemented") +} +func (*UnimplementedQueryServer) QueryAddressMappings(ctx context.Context, req *QueryAddressMappingsRequest) (*QueryAddressMappingsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryAddressMappings not implemented") +} +func (*UnimplementedQueryServer) QueryAddressMappingByEVMAddress(ctx context.Context, req *QueryAddressMappingByEVMAddressRequest) (*QueryAddressMappingByEVMAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryAddressMappingByEVMAddress not implemented") +} +func (*UnimplementedQueryServer) QueryAddressMappingByCosmosAddress(ctx context.Context, req *QueryAddressMappingByCosmosAddressRequest) (*QueryAddressMappingByCosmosAddressResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryAddressMappingByCosmosAddress not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_QueryParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Query/QueryParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryParams(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryAddressMappings_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAddressMappingsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryAddressMappings(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Query/QueryAddressMappings", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryAddressMappings(ctx, req.(*QueryAddressMappingsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryAddressMappingByEVMAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAddressMappingByEVMAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryAddressMappingByEVMAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Query/QueryAddressMappingByEVMAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryAddressMappingByEVMAddress(ctx, req.(*QueryAddressMappingByEVMAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_QueryAddressMappingByCosmosAddress_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryAddressMappingByCosmosAddressRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryAddressMappingByCosmosAddress(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Query/QueryAddressMappingByCosmosAddress", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryAddressMappingByCosmosAddress(ctx, req.(*QueryAddressMappingByCosmosAddressRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var Query_serviceDesc = _Query_serviceDesc +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "addresses.v1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "QueryParams", + Handler: _Query_QueryParams_Handler, + }, + { + MethodName: "QueryAddressMappings", + Handler: _Query_QueryAddressMappings_Handler, + }, + { + MethodName: "QueryAddressMappingByEVMAddress", + Handler: _Query_QueryAddressMappingByEVMAddress_Handler, + }, + { + MethodName: "QueryAddressMappingByCosmosAddress", + Handler: _Query_QueryAddressMappingByCosmosAddress_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "addresses/v1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Params != nil { + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Pagination.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.AddressMappings) > 0 { + for iNdEx := len(m.AddressMappings) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.AddressMappings[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingByEVMAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingByEVMAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingByEVMAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EvmAddress) > 0 { + i -= len(m.EvmAddress) + copy(dAtA[i:], m.EvmAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.EvmAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingByEVMAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingByEVMAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingByEVMAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EvmAddress) > 0 { + i -= len(m.EvmAddress) + copy(dAtA[i:], m.EvmAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.EvmAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.CosmosAddress) > 0 { + i -= len(m.CosmosAddress) + copy(dAtA[i:], m.CosmosAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingByCosmosAddressRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingByCosmosAddressRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingByCosmosAddressRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CosmosAddress) > 0 { + i -= len(m.CosmosAddress) + copy(dAtA[i:], m.CosmosAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryAddressMappingByCosmosAddressResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryAddressMappingByCosmosAddressResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryAddressMappingByCosmosAddressResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.EvmAddress) > 0 { + i -= len(m.EvmAddress) + copy(dAtA[i:], m.EvmAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.EvmAddress))) + i-- + dAtA[i] = 0x12 + } + if len(m.CosmosAddress) > 0 { + i -= len(m.CosmosAddress) + copy(dAtA[i:], m.CosmosAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.CosmosAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAddressMappingsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAddressMappingsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.AddressMappings) > 0 { + for _, e := range m.AddressMappings { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + l = m.Pagination.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func (m *QueryAddressMappingByEVMAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.EvmAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAddressMappingByEVMAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CosmosAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.EvmAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAddressMappingByCosmosAddressRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CosmosAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryAddressMappingByCosmosAddressResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.CosmosAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = len(m.EvmAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Params == nil { + m.Params = &Params{} + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field AddressMappings", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.AddressMappings = append(m.AddressMappings, &AddressMapping{}) + if err := m.AddressMappings[len(m.AddressMappings)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Pagination", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Pagination.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingByEVMAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingByEVMAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingByEVMAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvmAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EvmAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingByEVMAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingByEVMAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingByEVMAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvmAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EvmAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingByCosmosAddressRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingByCosmosAddressRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingByCosmosAddressRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryAddressMappingByCosmosAddressResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryAddressMappingByCosmosAddressResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryAddressMappingByCosmosAddressResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CosmosAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CosmosAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvmAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EvmAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/addresses/types/query.pb.gw.go b/x/addresses/types/query.pb.gw.go new file mode 100644 index 00000000..9761538a --- /dev/null +++ b/x/addresses/types/query.pb.gw.go @@ -0,0 +1,438 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: addresses/v1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryParams(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_Query_QueryAddressMappings_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_QueryAddressMappings_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryAddressMappings_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.QueryAddressMappings(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryAddressMappings_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingsRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_QueryAddressMappings_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.QueryAddressMappings(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryAddressMappingByEVMAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingByEVMAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["evm_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "evm_address") + } + + protoReq.EvmAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "evm_address", err) + } + + msg, err := client.QueryAddressMappingByEVMAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryAddressMappingByEVMAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingByEVMAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["evm_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "evm_address") + } + + protoReq.EvmAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "evm_address", err) + } + + msg, err := server.QueryAddressMappingByEVMAddress(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_QueryAddressMappingByCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingByCosmosAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["cosmos_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_address") + } + + protoReq.CosmosAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_address", err) + } + + msg, err := client.QueryAddressMappingByCosmosAddress(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryAddressMappingByCosmosAddress_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryAddressMappingByCosmosAddressRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["cosmos_address"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "cosmos_address") + } + + protoReq.CosmosAddress, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "cosmos_address", err) + } + + msg, err := server.QueryAddressMappingByCosmosAddress(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryParams_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryAddressMappings_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappingByEVMAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryAddressMappingByEVMAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappingByEVMAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappingByCosmosAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryAddressMappingByCosmosAddress_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappingByCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryParams_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappings_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryAddressMappings_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappings_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappingByEVMAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryAddressMappingByEVMAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappingByEVMAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_QueryAddressMappingByCosmosAddress_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryAddressMappingByCosmosAddress_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryAddressMappingByCosmosAddress_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_QueryParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "addresses", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryAddressMappings_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"sommelier", "addresses", "v1", "address_mappings"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryAddressMappingByEVMAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"sommelier", "addresses", "v1", "address_mappings", "evm", "evm_address"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryAddressMappingByCosmosAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"sommelier", "addresses", "v1", "address_mappings", "cosmos", "cosmos_address"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_QueryParams_0 = runtime.ForwardResponseMessage + + forward_Query_QueryAddressMappings_0 = runtime.ForwardResponseMessage + + forward_Query_QueryAddressMappingByEVMAddress_0 = runtime.ForwardResponseMessage + + forward_Query_QueryAddressMappingByCosmosAddress_0 = runtime.ForwardResponseMessage +) diff --git a/x/addresses/types/tx.pb.go b/x/addresses/types/tx.pb.go new file mode 100644 index 00000000..a189e6aa --- /dev/null +++ b/x/addresses/types/tx.pb.go @@ -0,0 +1,910 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: addresses/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/cosmos-sdk/types/msgservice" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +type MsgAddAddressMapping struct { + EvmAddress string `protobuf:"bytes,1,opt,name=evm_address,json=evmAddress,proto3" json:"evm_address,omitempty"` + Signer string `protobuf:"bytes,2,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgAddAddressMapping) Reset() { *m = MsgAddAddressMapping{} } +func (m *MsgAddAddressMapping) String() string { return proto.CompactTextString(m) } +func (*MsgAddAddressMapping) ProtoMessage() {} +func (*MsgAddAddressMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_dbc33d4b2b06ba95, []int{0} +} +func (m *MsgAddAddressMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAddressMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAddressMapping.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAddressMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAddressMapping.Merge(m, src) +} +func (m *MsgAddAddressMapping) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAddressMapping) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAddressMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAddressMapping proto.InternalMessageInfo + +func (m *MsgAddAddressMapping) GetEvmAddress() string { + if m != nil { + return m.EvmAddress + } + return "" +} + +func (m *MsgAddAddressMapping) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + +type MsgAddAddressMappingResponse struct { +} + +func (m *MsgAddAddressMappingResponse) Reset() { *m = MsgAddAddressMappingResponse{} } +func (m *MsgAddAddressMappingResponse) String() string { return proto.CompactTextString(m) } +func (*MsgAddAddressMappingResponse) ProtoMessage() {} +func (*MsgAddAddressMappingResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dbc33d4b2b06ba95, []int{1} +} +func (m *MsgAddAddressMappingResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgAddAddressMappingResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgAddAddressMappingResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgAddAddressMappingResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgAddAddressMappingResponse.Merge(m, src) +} +func (m *MsgAddAddressMappingResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgAddAddressMappingResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgAddAddressMappingResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgAddAddressMappingResponse proto.InternalMessageInfo + +type MsgRemoveAddressMapping struct { + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` +} + +func (m *MsgRemoveAddressMapping) Reset() { *m = MsgRemoveAddressMapping{} } +func (m *MsgRemoveAddressMapping) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAddressMapping) ProtoMessage() {} +func (*MsgRemoveAddressMapping) Descriptor() ([]byte, []int) { + return fileDescriptor_dbc33d4b2b06ba95, []int{2} +} +func (m *MsgRemoveAddressMapping) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAddressMapping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAddressMapping.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAddressMapping) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAddressMapping.Merge(m, src) +} +func (m *MsgRemoveAddressMapping) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAddressMapping) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAddressMapping.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAddressMapping proto.InternalMessageInfo + +func (m *MsgRemoveAddressMapping) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + +type MsgRemoveAddressMappingResponse struct { +} + +func (m *MsgRemoveAddressMappingResponse) Reset() { *m = MsgRemoveAddressMappingResponse{} } +func (m *MsgRemoveAddressMappingResponse) String() string { return proto.CompactTextString(m) } +func (*MsgRemoveAddressMappingResponse) ProtoMessage() {} +func (*MsgRemoveAddressMappingResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_dbc33d4b2b06ba95, []int{3} +} +func (m *MsgRemoveAddressMappingResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgRemoveAddressMappingResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgRemoveAddressMappingResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgRemoveAddressMappingResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgRemoveAddressMappingResponse.Merge(m, src) +} +func (m *MsgRemoveAddressMappingResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgRemoveAddressMappingResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgRemoveAddressMappingResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgRemoveAddressMappingResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgAddAddressMapping)(nil), "addresses.v1.MsgAddAddressMapping") + proto.RegisterType((*MsgAddAddressMappingResponse)(nil), "addresses.v1.MsgAddAddressMappingResponse") + proto.RegisterType((*MsgRemoveAddressMapping)(nil), "addresses.v1.MsgRemoveAddressMapping") + proto.RegisterType((*MsgRemoveAddressMappingResponse)(nil), "addresses.v1.MsgRemoveAddressMappingResponse") +} + +func init() { proto.RegisterFile("addresses/v1/tx.proto", fileDescriptor_dbc33d4b2b06ba95) } + +var fileDescriptor_dbc33d4b2b06ba95 = []byte{ + // 313 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4d, 0x4c, 0x49, 0x29, + 0x4a, 0x2d, 0x2e, 0x4e, 0x2d, 0xd6, 0x2f, 0x33, 0xd4, 0x2f, 0xa9, 0xd0, 0x2b, 0x28, 0xca, 0x2f, + 0xc9, 0x17, 0xe2, 0x81, 0x0b, 0xeb, 0x95, 0x19, 0x4a, 0x89, 0x27, 0xe7, 0x17, 0xe7, 0xe6, 0x17, + 0xeb, 0xe7, 0x16, 0xa7, 0x83, 0x54, 0xe5, 0x16, 0xa7, 0x43, 0x94, 0x29, 0xc5, 0x70, 0x89, 0xf8, + 0x16, 0xa7, 0x3b, 0xa6, 0xa4, 0x38, 0x42, 0x94, 0xfb, 0x26, 0x16, 0x14, 0x64, 0xe6, 0xa5, 0x0b, + 0xc9, 0x73, 0x71, 0xa7, 0x96, 0xe5, 0xc6, 0x43, 0x0d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, + 0xe2, 0x4a, 0x2d, 0xcb, 0x85, 0xaa, 0x13, 0x12, 0xe3, 0x62, 0x2b, 0xce, 0x4c, 0xcf, 0x4b, 0x2d, + 0x92, 0x60, 0x02, 0xcb, 0x41, 0x79, 0x56, 0xdc, 0x4d, 0xcf, 0x37, 0x68, 0x41, 0x39, 0x4a, 0x72, + 0x5c, 0x32, 0xd8, 0x4c, 0x0f, 0x4a, 0x2d, 0x2e, 0xc8, 0xcf, 0x2b, 0x4e, 0x55, 0xb2, 0xe3, 0x12, + 0xf7, 0x2d, 0x4e, 0x0f, 0x4a, 0xcd, 0xcd, 0x2f, 0x4b, 0x45, 0x73, 0x00, 0xc2, 0x7c, 0x46, 0xdc, + 0xe6, 0x2b, 0x72, 0xc9, 0xe3, 0xd0, 0x0f, 0xb3, 0xc2, 0xe8, 0x3e, 0x23, 0x17, 0xb3, 0x6f, 0x71, + 0xba, 0x50, 0x32, 0x97, 0x20, 0xa6, 0x2f, 0x95, 0xf4, 0x90, 0x43, 0x49, 0x0f, 0x9b, 0x5b, 0xa5, + 0xb4, 0x08, 0xab, 0x81, 0x59, 0x26, 0x94, 0xc3, 0x25, 0x82, 0xd5, 0x33, 0xaa, 0x18, 0x66, 0x60, + 0x53, 0x26, 0xa5, 0x4b, 0x94, 0x32, 0x98, 0x6d, 0x52, 0xac, 0x0d, 0xcf, 0x37, 0x68, 0x31, 0x3a, + 0x79, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, + 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x61, 0x7a, 0x66, 0x49, + 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x7e, 0x41, 0x6a, 0x7a, 0x7a, 0x65, 0x56, 0x99, 0x7e, + 0x71, 0x7e, 0x6e, 0x6e, 0x6a, 0x4e, 0x66, 0x6a, 0x91, 0x7e, 0x99, 0xb9, 0x7e, 0x85, 0x3e, 0x22, + 0xf1, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x93, 0x85, 0x31, 0x20, 0x00, 0x00, 0xff, + 0xff, 0xc4, 0xe4, 0x89, 0xa0, 0x56, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // Adds a mapping between the cosmos address of the sender and the provided EVM address + AddAddressMapping(ctx context.Context, in *MsgAddAddressMapping, opts ...grpc.CallOption) (*MsgAddAddressMappingResponse, error) + // Removes the mapping containing the cosmos address of the sender + RemoveAddressMapping(ctx context.Context, in *MsgRemoveAddressMapping, opts ...grpc.CallOption) (*MsgRemoveAddressMappingResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) AddAddressMapping(ctx context.Context, in *MsgAddAddressMapping, opts ...grpc.CallOption) (*MsgAddAddressMappingResponse, error) { + out := new(MsgAddAddressMappingResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Msg/AddAddressMapping", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *msgClient) RemoveAddressMapping(ctx context.Context, in *MsgRemoveAddressMapping, opts ...grpc.CallOption) (*MsgRemoveAddressMappingResponse, error) { + out := new(MsgRemoveAddressMappingResponse) + err := c.cc.Invoke(ctx, "/addresses.v1.Msg/RemoveAddressMapping", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // Adds a mapping between the cosmos address of the sender and the provided EVM address + AddAddressMapping(context.Context, *MsgAddAddressMapping) (*MsgAddAddressMappingResponse, error) + // Removes the mapping containing the cosmos address of the sender + RemoveAddressMapping(context.Context, *MsgRemoveAddressMapping) (*MsgRemoveAddressMappingResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) AddAddressMapping(ctx context.Context, req *MsgAddAddressMapping) (*MsgAddAddressMappingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method AddAddressMapping not implemented") +} +func (*UnimplementedMsgServer) RemoveAddressMapping(ctx context.Context, req *MsgRemoveAddressMapping) (*MsgRemoveAddressMappingResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RemoveAddressMapping not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_AddAddressMapping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgAddAddressMapping) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).AddAddressMapping(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Msg/AddAddressMapping", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).AddAddressMapping(ctx, req.(*MsgAddAddressMapping)) + } + return interceptor(ctx, in, info, handler) +} + +func _Msg_RemoveAddressMapping_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgRemoveAddressMapping) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).RemoveAddressMapping(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/addresses.v1.Msg/RemoveAddressMapping", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).RemoveAddressMapping(ctx, req.(*MsgRemoveAddressMapping)) + } + return interceptor(ctx, in, info, handler) +} + +var Msg_serviceDesc = _Msg_serviceDesc +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "addresses.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "AddAddressMapping", + Handler: _Msg_AddAddressMapping_Handler, + }, + { + MethodName: "RemoveAddressMapping", + Handler: _Msg_RemoveAddressMapping_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "addresses/v1/tx.proto", +} + +func (m *MsgAddAddressMapping) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddAddressMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddAddressMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0x12 + } + if len(m.EvmAddress) > 0 { + i -= len(m.EvmAddress) + copy(dAtA[i:], m.EvmAddress) + i = encodeVarintTx(dAtA, i, uint64(len(m.EvmAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgAddAddressMappingResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgAddAddressMappingResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgAddAddressMappingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *MsgRemoveAddressMapping) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveAddressMapping) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveAddressMapping) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgRemoveAddressMappingResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgRemoveAddressMappingResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgRemoveAddressMappingResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgAddAddressMapping) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.EvmAddress) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgAddAddressMappingResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *MsgRemoveAddressMapping) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgRemoveAddressMappingResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgAddAddressMapping) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAddressMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAddressMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field EvmAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.EvmAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgAddAddressMappingResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgAddAddressMappingResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgAddAddressMappingResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAddressMapping) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAddressMapping: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAddressMapping: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Signer = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgRemoveAddressMappingResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgRemoveAddressMappingResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgRemoveAddressMappingResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/auction/types/query.pb.go b/x/auction/types/query.pb.go index 0f784ead..e21782a1 100644 --- a/x/auction/types/query.pb.go +++ b/x/auction/types/query.pb.go @@ -1239,6 +1239,7 @@ func _Query_QueryTokenPrices_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "auction.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/auction/types/tx.pb.go b/x/auction/types/tx.pb.go index 61451994..b507eda5 100644 --- a/x/auction/types/tx.pb.go +++ b/x/auction/types/tx.pb.go @@ -248,6 +248,7 @@ func _Msg_SubmitBid_Handler(srv interface{}, ctx context.Context, dec func(inter return interceptor(ctx, in, info, handler) } +var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "auction.v1.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/axelarcork/types/query.pb.go b/x/axelarcork/types/query.pb.go index 4711a6b9..4c71c01b 100644 --- a/x/axelarcork/types/query.pb.go +++ b/x/axelarcork/types/query.pb.go @@ -1896,6 +1896,7 @@ func _Query_QueryWinningAxelarCorks_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "axelarcork.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/axelarcork/types/tx.pb.go b/x/axelarcork/types/tx.pb.go index db693630..101a0d2b 100644 --- a/x/axelarcork/types/tx.pb.go +++ b/x/axelarcork/types/tx.pb.go @@ -779,6 +779,7 @@ func _Msg_CancelScheduledCork_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "axelarcork.v1.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/cellarfees/types/v1/query.pb.go b/x/cellarfees/types/v1/query.pb.go index 788633d2..782936e6 100644 --- a/x/cellarfees/types/v1/query.pb.go +++ b/x/cellarfees/types/v1/query.pb.go @@ -677,6 +677,7 @@ func _Query_QueryAPY_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cellarfees.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/cellarfees/types/v2/query.pb.go b/x/cellarfees/types/v2/query.pb.go index 873e8d16..88d832eb 100644 --- a/x/cellarfees/types/v2/query.pb.go +++ b/x/cellarfees/types/v2/query.pb.go @@ -806,6 +806,7 @@ func _Query_QueryFeeTokenBalance_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cellarfees.v2.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/cork/types/v2/query.pb.go b/x/cork/types/v2/query.pb.go index 23068177..89999d5b 100644 --- a/x/cork/types/v2/query.pb.go +++ b/x/cork/types/v2/query.pb.go @@ -1088,6 +1088,7 @@ func _Query_QueryCorkResults_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "cork.v2.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/cork/types/v2/tx.pb.go b/x/cork/types/v2/tx.pb.go index afe04923..87dbddc9 100644 --- a/x/cork/types/v2/tx.pb.go +++ b/x/cork/types/v2/tx.pb.go @@ -237,6 +237,7 @@ func _Msg_ScheduleCork_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "cork.v2.Msg", HandlerType: (*MsgServer)(nil), diff --git a/x/incentives/types/query.pb.go b/x/incentives/types/query.pb.go index 258e630d..46f1b1a7 100644 --- a/x/incentives/types/query.pb.go +++ b/x/incentives/types/query.pb.go @@ -334,6 +334,7 @@ func _Query_QueryAPY_Handler(srv interface{}, ctx context.Context, dec func(inte return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "incentives.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/pubsub/types/query.pb.go b/x/pubsub/types/query.pb.go index 9d477c93..76ad699c 100644 --- a/x/pubsub/types/query.pb.go +++ b/x/pubsub/types/query.pb.go @@ -2230,6 +2230,7 @@ func _Query_QueryDefaultSubscriptions_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } +var Query_serviceDesc = _Query_serviceDesc var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "pubsub.v1.Query", HandlerType: (*QueryServer)(nil), diff --git a/x/pubsub/types/tx.pb.go b/x/pubsub/types/tx.pb.go index 0975322c..2f4829fb 100644 --- a/x/pubsub/types/tx.pb.go +++ b/x/pubsub/types/tx.pb.go @@ -984,6 +984,7 @@ func _Msg_RemoveSubscriberIntent_Handler(srv interface{}, ctx context.Context, d return interceptor(ctx, in, info, handler) } +var Msg_serviceDesc = _Msg_serviceDesc var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "pubsub.v1.Msg", HandlerType: (*MsgServer)(nil),