diff --git a/app/app.go b/app/app.go index d79aa2998..377affa48 100644 --- a/app/app.go +++ b/app/app.go @@ -105,6 +105,8 @@ import ( axelarnetKeeper "github.com/axelarnetwork/axelar-core/x/axelarnet/keeper" axelarnetTypes "github.com/axelarnetwork/axelar-core/x/axelarnet/types" axelarbankkeeper "github.com/axelarnetwork/axelar-core/x/bank/keeper" + "github.com/axelarnetwork/axelar-core/x/batcher" + batchertypes "github.com/axelarnetwork/axelar-core/x/batcher/types" "github.com/axelarnetwork/axelar-core/x/evm" evmKeeper "github.com/axelarnetwork/axelar-core/x/evm/keeper" evmTypes "github.com/axelarnetwork/axelar-core/x/evm/types" @@ -657,7 +659,9 @@ func initAppModules(keepers *KeeperCache, bApp *bam.BaseApp, encodingConfig axel bApp.Router(), ), permission.NewAppModule(*getKeeper[permissionKeeper.Keeper](keepers)), + batcher.NewAppModule(encodingConfig.Codec, bApp.MsgServiceRouter(), initMessageAnteDecorators(encodingConfig, keepers)), ) + return appModules } @@ -789,6 +793,7 @@ func orderMigrations() []string { permissionTypes.ModuleName, snapTypes.ModuleName, axelarnetTypes.ModuleName, + batchertypes.ModuleName, ) return migrationOrder } @@ -839,6 +844,7 @@ func orderBeginBlockers() []string { snapTypes.ModuleName, axelarnetTypes.ModuleName, voteTypes.ModuleName, + batchertypes.ModuleName, ) return beginBlockerOrder } @@ -884,6 +890,7 @@ func orderEndBlockers() []string { axelarnetTypes.ModuleName, permissionTypes.ModuleName, voteTypes.ModuleName, + batchertypes.ModuleName, ) return endBlockerOrder } @@ -932,6 +939,7 @@ func orderModulesForGenesis() []string { axelarnetTypes.ModuleName, rewardTypes.ModuleName, permissionTypes.ModuleName, + batchertypes.ModuleName, ) return genesisOrder } @@ -1102,6 +1110,7 @@ func GetModuleBasics() module.BasicManager { axelarnet.AppModuleBasic{}, reward.AppModuleBasic{}, permission.AppModuleBasic{}, + batcher.AppModuleBasic{}, } if IsWasmEnabled() { diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index ece9902be..31676b907 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -155,6 +155,20 @@ - [MsgService](#axelar.axelarnet.v1beta1.MsgService) - [QueryService](#axelar.axelarnet.v1beta1.QueryService) +- [axelar/batcher/v1beta1/events.proto](#axelar/batcher/v1beta1/events.proto) + - [FailedMessages](#axelar.batcher.v1beta1.FailedMessages) + - [FailedMessages.FailedMessage](#axelar.batcher.v1beta1.FailedMessages.FailedMessage) + +- [axelar/batcher/v1beta1/genesis.proto](#axelar/batcher/v1beta1/genesis.proto) + - [GenesisState](#axelar.batcher.v1beta1.GenesisState) + +- [axelar/batcher/v1beta1/tx.proto](#axelar/batcher/v1beta1/tx.proto) + - [BatchRequest](#axelar.batcher.v1beta1.BatchRequest) + - [BatchResponse](#axelar.batcher.v1beta1.BatchResponse) + +- [axelar/batcher/v1beta1/service.proto](#axelar/batcher/v1beta1/service.proto) + - [MsgService](#axelar.batcher.v1beta1.MsgService) + - [axelar/snapshot/exported/v1beta1/types.proto](#axelar/snapshot/exported/v1beta1/types.proto) - [Participant](#axelar.snapshot.exported.v1beta1.Participant) - [Snapshot](#axelar.snapshot.exported.v1beta1.Snapshot) @@ -2659,6 +2673,148 @@ QueryService defines the gRPC querier service. + +

Top

+ +## axelar/batcher/v1beta1/events.proto + + + + + +### FailedMessages + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `messages` | [FailedMessages.FailedMessage](#axelar.batcher.v1beta1.FailedMessages.FailedMessage) | repeated | | + + + + + + + + +### FailedMessages.FailedMessage + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `index` | [int32](#int32) | | | +| `error` | [string](#string) | | | + + + + + + + + + + + + + + + + +

Top

+ +## axelar/batcher/v1beta1/genesis.proto + + + + + +### GenesisState +GenesisState represents the genesis state + + + + + + + + + + + + + + + + +

Top

+ +## axelar/batcher/v1beta1/tx.proto + + + + + +### BatchRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `sender` | [bytes](#bytes) | | | +| `must_succeed_messages` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | +| `can_fail_messages` | [google.protobuf.Any](#google.protobuf.Any) | repeated | | + + + + + + + + +### BatchResponse + + + + + + + + + + + + + + + + + +

Top

+ +## axelar/batcher/v1beta1/service.proto + + + + + + + + + + + +### MsgService +Msg defines the nexus Msg service. + +| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint | +| ----------- | ------------ | ------------- | ------------| ------- | -------- | +| `Batch` | [BatchRequest](#axelar.batcher.v1beta1.BatchRequest) | [BatchResponse](#axelar.batcher.v1beta1.BatchResponse) | | POST|/axelar/batcher/batch| + + + + +

Top

diff --git a/proto/axelar/batcher/v1beta1/events.proto b/proto/axelar/batcher/v1beta1/events.proto new file mode 100644 index 000000000..58312b465 --- /dev/null +++ b/proto/axelar/batcher/v1beta1/events.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package axelar.batcher.v1beta1; + +option go_package = "github.com/axelarnetwork/axelar-core/x/batcher/types"; +option (gogoproto.messagename_all) = true; + +import "gogoproto/gogo.proto"; + +message FailedMessages { + message FailedMessage { + int32 index = 1; + string error = 2; + } + repeated FailedMessage messages = 1 [ (gogoproto.nullable) = false, (gogoproto.jsontag) = "messages,omitempty" ]; +} diff --git a/proto/axelar/batcher/v1beta1/genesis.proto b/proto/axelar/batcher/v1beta1/genesis.proto new file mode 100644 index 000000000..4d37a2ecf --- /dev/null +++ b/proto/axelar/batcher/v1beta1/genesis.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package axelar.batcher.v1beta1; + +option go_package = "github.com/axelarnetwork/axelar-core/x/batcher/types"; + +import "gogoproto/gogo.proto"; + +option (gogoproto.goproto_getters_all) = false; + +// GenesisState represents the genesis state +message GenesisState {} diff --git a/proto/axelar/batcher/v1beta1/service.proto b/proto/axelar/batcher/v1beta1/service.proto new file mode 100644 index 000000000..ccf08deff --- /dev/null +++ b/proto/axelar/batcher/v1beta1/service.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; +package axelar.batcher.v1beta1; + +option go_package = "github.com/axelarnetwork/axelar-core/x/batcher/types"; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "axelar/batcher/v1beta1/tx.proto"; + +option (gogoproto.goproto_registration) = true; + +// Msg defines the nexus Msg service. +service MsgService { + rpc Batch(BatchRequest) returns (BatchResponse) { + option (google.api.http) = { + post : "/axelar/batcher/batch" + body : "*" + }; + } +} diff --git a/proto/axelar/batcher/v1beta1/tx.proto b/proto/axelar/batcher/v1beta1/tx.proto new file mode 100644 index 000000000..0df9470d7 --- /dev/null +++ b/proto/axelar/batcher/v1beta1/tx.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; +package axelar.batcher.v1beta1; + +import "google/protobuf/any.proto"; +import "gogoproto/gogo.proto"; + +import "axelar/permission/exported/v1beta1/types.proto"; + +option go_package = "github.com/axelarnetwork/axelar-core/x/batcher/types"; + +message BatchRequest { + option (permission.exported.v1beta1.permission_role) = ROLE_UNRESTRICTED; + + bytes sender = 1 [ (gogoproto.casttype) = + "github.com/cosmos/cosmos-sdk/types.AccAddress" ]; + repeated google.protobuf.Any must_succeed_messages = 2 + [ (gogoproto.nullable) = false ]; + repeated google.protobuf.Any can_fail_messages = 3 + [ (gogoproto.nullable) = false ]; +} + +message BatchResponse {} diff --git a/third_party/proto/ibc/applications/transfer/v1/query.proto b/third_party/proto/ibc/applications/transfer/v1/query.proto index 075c0001c..52f2f2400 100644 --- a/third_party/proto/ibc/applications/transfer/v1/query.proto +++ b/third_party/proto/ibc/applications/transfer/v1/query.proto @@ -11,16 +11,16 @@ option go_package = "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"; // Query provides defines the gRPC querier service. service Query { - // DenomTrace queries a denomination trace information. - rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) { - option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash}"; - } - // DenomTraces queries all denomination traces. rpc DenomTraces(QueryDenomTracesRequest) returns (QueryDenomTracesResponse) { option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces"; } + // DenomTrace queries a denomination trace information. + rpc DenomTrace(QueryDenomTraceRequest) returns (QueryDenomTraceResponse) { + option (google.api.http).get = "/ibc/apps/transfer/v1/denom_traces/{hash=**}"; + } + // Params queries all parameters of the ibc-transfer module. rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { option (google.api.http).get = "/ibc/apps/transfer/v1/params"; @@ -28,7 +28,7 @@ service Query { // DenomHash queries a denomination hash information. rpc DenomHash(QueryDenomHashRequest) returns (QueryDenomHashResponse) { - option (google.api.http).get = "/ibc/apps/transfer/v1/denom_hashes/{trace}"; + option (google.api.http).get = "/ibc/apps/transfer/v1/denom_hashes/{trace=**}"; } // EscrowAddress returns the escrow address for a particular port and channel id. diff --git a/utils/events/event_imports_test.go b/utils/events/event_imports_test.go index a7eea9a23..762ff3b84 100644 --- a/utils/events/event_imports_test.go +++ b/utils/events/event_imports_test.go @@ -4,6 +4,7 @@ package events_test import ( _ "github.com/axelarnetwork/axelar-core/x/ante/types" _ "github.com/axelarnetwork/axelar-core/x/axelarnet/types" + _ "github.com/axelarnetwork/axelar-core/x/batcher/types" _ "github.com/axelarnetwork/axelar-core/x/evm/types" _ "github.com/axelarnetwork/axelar-core/x/multisig/types" _ "github.com/axelarnetwork/axelar-core/x/nexus/types" diff --git a/x/batcher/keeper/msg_server.go b/x/batcher/keeper/msg_server.go new file mode 100644 index 000000000..44613485b --- /dev/null +++ b/x/batcher/keeper/msg_server.go @@ -0,0 +1,100 @@ +package keeper + +import ( + "context" + "fmt" + + "github.com/cosmos/cosmos-sdk/baseapp" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/axelarnetwork/axelar-core/x/ante" + "github.com/axelarnetwork/axelar-core/x/batcher/types" + "github.com/axelarnetwork/utils/funcs" +) + +var _ types.MsgServiceServer = msgServer{} + +type msgServer struct { + cdc codec.Codec + router *baseapp.MsgServiceRouter + anteHandle ante.MessageAnteHandler +} + +func NewMsgServer(cdc codec.Codec, msgServiceRouter *baseapp.MsgServiceRouter, anteHandle ante.MessageAnteHandler) types.MsgServiceServer { + return msgServer{ + cdc, + msgServiceRouter, + anteHandle, + } +} + +func (s msgServer) Batch(c context.Context, req *types.BatchRequest) (*types.BatchResponse, error) { + ctx := sdk.UnwrapSDKContext(c) + + processMessage := func(ctx sdk.Context, i int, message *cdctypes.Any) (*sdk.Result, error) { + sdkMsg, err := unpackInnerMessage(s.cdc, message) + if err != nil { + return nil, fmt.Errorf("unpack failed at index %d: %s", i, err) + } + + if err = req.ValidateInnerMessage(sdkMsg); err != nil { + return nil, fmt.Errorf("message validation failed at index %d: %s", i, err) + } + + handler := s.router.Handler(sdkMsg) + if handler == nil { + return nil, fmt.Errorf("unrecognized message type at index %d: %s", i, sdkMsg) + } + + ctx, err = s.anteHandle(ctx, []sdk.Msg{sdkMsg}, false) + if err != nil { + return nil, fmt.Errorf("antehandler failed for message at index %d: %s", i, err) + } + + res, err := handler(ctx, sdkMsg) + if err != nil { + return nil, fmt.Errorf("execution failed for message at index %d: %s", i, err) + } + + return res, nil + } + + for i, message := range req.MustSucceedMessages { + if _, err := processMessage(ctx, i, &message); err != nil { + return nil, err + } + } + + var failedMessages []types.FailedMessages_FailedMessage + for i, message := range req.CanFailMessages { + cacheCtx, writeCache := ctx.CacheContext() + res, err := processMessage(cacheCtx, i, &message) + if err != nil { + failedMessages = append(failedMessages, types.FailedMessages_FailedMessage{ + Index: int32(i), + Error: err.Error(), + }) + } else { + writeCache() + ctx.EventManager().EmitEvents(res.GetEvents()) + } + } + + if len(failedMessages) > 0 { + funcs.MustNoErr(ctx.EventManager().EmitTypedEvent(&types.FailedMessages{ + Messages: failedMessages, + })) + } + + return &types.BatchResponse{}, nil +} + +func unpackInnerMessage(cdc codec.Codec, any *cdctypes.Any) (sdk.Msg, error) { + var sdkMsg sdk.Msg + if err := cdc.UnpackAny(any, &sdkMsg); err != nil { + return nil, err + } + return sdkMsg, nil +} diff --git a/x/batcher/keeper/msg_server_test.go b/x/batcher/keeper/msg_server_test.go new file mode 100644 index 000000000..d7bad1006 --- /dev/null +++ b/x/batcher/keeper/msg_server_test.go @@ -0,0 +1,202 @@ +package keeper_test + +import ( + "context" + "fmt" + "testing" + + bam "github.com/cosmos/cosmos-sdk/baseapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/assert" + "google.golang.org/grpc" + + appParams "github.com/axelarnetwork/axelar-core/app/params" + "github.com/axelarnetwork/axelar-core/testutils/fake" + "github.com/axelarnetwork/axelar-core/testutils/rand" + rand2 "github.com/axelarnetwork/axelar-core/testutils/rand" + "github.com/axelarnetwork/axelar-core/x/batcher/keeper" + "github.com/axelarnetwork/axelar-core/x/batcher/types" + evmTypes "github.com/axelarnetwork/axelar-core/x/evm/types" + nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported" + vote "github.com/axelarnetwork/axelar-core/x/vote/exported" + votetypes "github.com/axelarnetwork/axelar-core/x/vote/types" + "github.com/axelarnetwork/utils/slices" + . "github.com/axelarnetwork/utils/test" +) + +func TestBatching(t *testing.T) { + var ( + ctx sdk.Context + msgServer types.MsgServiceServer + msgServiceRouter *bam.MsgServiceRouter + + batchRequest *types.BatchRequest + antehandlerCalled bool + messagehandlerCalled bool + sender sdk.AccAddress + innerMessages []sdk.Msg + ) + + givenMsgServer := Given("a Batch msg server", func() { + ctx = rand2.Context(fake.NewMultiStore()) + msgServiceRouter = bam.NewMsgServiceRouter() + + antehandlerCalled = false + messagehandlerCalled = false + sender = rand.AccAddr() + innerMessages = slices.Expand2(func() sdk.Msg { + return votetypes.NewVoteRequest(sender, vote.PollID(rand.PosI64()), evmTypes.NewVoteEvents(nexus.ChainName(rand.NormalizedStr(3)))) + }, int(rand2.I64Between(2, 10))) + + anteHandler := func(ctx sdk.Context, msgs []sdk.Msg, simulate bool) (sdk.Context, error) { + antehandlerCalled = true + return ctx, nil + } + msgServer = keeper.NewMsgServer(appParams.MakeEncodingConfig().Codec, msgServiceRouter, anteHandler) + }) + + withMustSucceedMessage := func() GivenStatement { + return Given("must succeed messages", func() { + batchRequest = types.NewBatchRequest(sender, innerMessages, []sdk.Msg{}) + }) + } + + withCanFailMessage := func() GivenStatement { + return Given("can fail messages", func() { + batchRequest = types.NewBatchRequest(sender, []sdk.Msg{}, innerMessages) + }) + + } + + failedHandler := func(ctx context.Context, req interface{}) (interface{}, error) { + messagehandlerCalled = true + return &sdk.Result{}, fmt.Errorf("failed to execute message") + } + + succeededHandler := func(ctx context.Context, req interface{}) (interface{}, error) { + messagehandlerCalled = true + sdk.UnwrapSDKContext(ctx).EventManager().EmitEvents(sdk.Events{ + sdk.NewEvent("executed"), + }) + return &sdk.Result{}, nil + } + + givenMsgServer. + Branch( + withMustSucceedMessage(). + When("handler is not registered", func() {}). + Then("should fail batch message", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.Error(t, err) + }), + + withMustSucceedMessage(). + When("failed to executed must succeed messages", func() { + registerTestService(msgServiceRouter, failedHandler) + }). + Then("should fail batch message", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.Error(t, err) + println(err.Error()) + assert.True(t, antehandlerCalled) + assert.True(t, messagehandlerCalled) + }), + + withMustSucceedMessage(). + When("must succeed messages executed", func() { + registerTestService(msgServiceRouter, succeededHandler) + }). + Then("should execute batch message", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.NoError(t, err) + assert.True(t, antehandlerCalled) + assert.True(t, messagehandlerCalled) + }), + + withCanFailMessage(). + When("handler is not registered", func() {}). + Then("should not revert batch message", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.NoError(t, err) + + events := ctx.EventManager().Events() + failedMessageEvent := types.FailedMessages{} + assert.Equal(t, 1, len(events)) + assert.Equal(t, failedMessageEvent.XXX_MessageName(), events[0].Type) + + }), + + withCanFailMessage(). + When("failed to executed can fail messages", func() { + registerTestService(msgServiceRouter, failedHandler) + }). + Then("should not revert batch message", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.NoError(t, err) + assert.True(t, antehandlerCalled) + + events := ctx.EventManager().Events() + failedMessageEvent := types.FailedMessages{} + assert.Equal(t, 1, len(events)) + assert.Equal(t, failedMessageEvent.XXX_MessageName(), events[0].Type) + }), + + withCanFailMessage(). + When("executed can fail message", func() { + registerTestService(msgServiceRouter, succeededHandler) + }). + Then("should emit message execution events", func(t *testing.T) { + _, err := msgServer.Batch(sdk.WrapSDKContext(ctx), batchRequest) + assert.NoError(t, err) + assert.True(t, antehandlerCalled) + + events := ctx.EventManager().Events() + assert.Equal(t, len(batchRequest.CanFailMessages), len(events)) + assert.Equal(t, "executed", events[0].Type) + + }), + ). + Run(t) +} + +func registerTestService(msgServiceRouter *bam.MsgServiceRouter, msgHandler func(ctx context.Context, req interface{}) (interface{}, error)) { + encCfg := appParams.MakeEncodingConfig() + encCfg.InterfaceRegistry.RegisterImplementations((*sdk.Msg)(nil), &votetypes.VoteRequest{}) + msgServiceRouter.SetInterfaceRegistry(encCfg.InterfaceRegistry) + + handler := func(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(votetypes.VoteRequest) + if err := dec(in); err != nil { + return nil, err + } + + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/axelar.vote.v1beta1.MsgService/Vote", + } + + return interceptor(ctx, in, info, msgHandler) + } + + var serviceDesc = grpc.ServiceDesc{ + ServiceName: "axelar.vote.v1beta1.MsgService", + HandlerType: (*votetypes.MsgServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Vote", + Handler: handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "axelar/vote/v1beta1/service.proto", + } + msgServiceRouter.RegisterService(&serviceDesc, TestMsgServer{}) +} + +type TestMsgServer struct{} + +var _ votetypes.MsgServiceClient = TestMsgServer{} + +func (m TestMsgServer) Vote(_ context.Context, _ *votetypes.VoteRequest, _ ...grpc.CallOption) (*votetypes.VoteResponse, error) { + return &votetypes.VoteResponse{}, nil +} diff --git a/x/batcher/module.go b/x/batcher/module.go new file mode 100644 index 000000000..693fd25f7 --- /dev/null +++ b/x/batcher/module.go @@ -0,0 +1,139 @@ +package batcher + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/baseapp" + "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" + "github.com/gorilla/mux" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + + "github.com/axelarnetwork/axelar-core/utils/grpc" + "github.com/axelarnetwork/axelar-core/x/ante" + "github.com/axelarnetwork/axelar-core/x/batcher/keeper" + "github.com/axelarnetwork/axelar-core/x/batcher/types" +) + +var ( + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} +) + +// AppModuleBasic implements module.AppModuleBasic +type AppModuleBasic struct { +} + +// Name returns the name of the module +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +// RegisterLegacyAminoCodec registers the types necessary in this module with the given codec +func (AppModuleBasic) RegisterLegacyAminoCodec(*codec.LegacyAmino) {} + +// RegisterInterfaces registers the module's interface types +func (AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) { + types.RegisterInterfaces(reg) +} + +// DefaultGenesis returns the default genesis state +func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { + genesis := types.GenesisState{} + return cdc.MustMarshalJSON(&genesis) +} + +// ValidateGenesis checks the given genesis state for validity +func (AppModuleBasic) ValidateGenesis(_ codec.JSONCodec, _ client.TxEncodingConfig, _ json.RawMessage) error { + return nil +} + +// RegisterRESTRoutes registers the REST routes for this module +func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} + +// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module. +func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} + +// GetTxCmd returns all CLI tx commands for this module +func (AppModuleBasic) GetTxCmd() *cobra.Command { return nil } + +// GetQueryCmd returns all CLI query commands for this module +func (AppModuleBasic) GetQueryCmd() *cobra.Command { return nil } + +// AppModule implements module.AppModule +type AppModule struct { + AppModuleBasic + cdc codec.Codec + router *baseapp.MsgServiceRouter + anteHandle ante.MessageAnteHandler +} + +// NewAppModule creates a new AppModule object +func NewAppModule(cdc codec.Codec, router *baseapp.MsgServiceRouter, anteHandle ante.MessageAnteHandler) AppModule { + return AppModule{ + cdc: cdc, + router: router, + anteHandle: anteHandle, + } +} + +// RegisterInvariants registers this module's invariants +func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) { + // No invariants yet +} + +// InitGenesis initializes the module's keeper from the given genesis state +func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ExportGenesis exports a genesis state from the module's keeper +func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONCodec) json.RawMessage { + genesis := types.GenesisState{} + + return cdc.MustMarshalJSON(&genesis) +} + +// Route returns the module's route +func (am AppModule) Route() sdk.Route { + return sdk.NewRoute(types.RouterKey, nil) +} + +// QuerierRoute returns this module's query route +func (AppModule) QuerierRoute() string { + return "" +} + +// LegacyQuerierHandler returns a new query handler for this module +func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { + return nil +} + +// RegisterServices registers module services +func (am AppModule) RegisterServices(cfg module.Configurator) { + logger := func(ctx sdk.Context) log.Logger { + return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) + } + + types.RegisterMsgServiceServer(grpc.ServerWithSDKErrors{Server: cfg.MsgServer(), Err: types.ErrBatcher, Logger: logger}, keeper.NewMsgServer(am.cdc, am.router, am.anteHandle)) +} + +// BeginBlock executes all state transitions this module requires at the beginning of each new block +func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} + +// EndBlock executes all state transitions this module requires at the end of each new block +func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + return []abci.ValidatorUpdate{} +} + +// ConsensusVersion implements AppModule/ConsensusVersion. +func (AppModule) ConsensusVersion() uint64 { + return 1 +} diff --git a/x/batcher/types/codec.go b/x/batcher/types/codec.go new file mode 100644 index 000000000..e2f942e77 --- /dev/null +++ b/x/batcher/types/codec.go @@ -0,0 +1,13 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/msgservice" +) + +// RegisterInterfaces registers types and interfaces with the given registry +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations((*sdk.Msg)(nil), &BatchRequest{}) + msgservice.RegisterMsgServiceDesc(registry, &_MsgService_serviceDesc) +} diff --git a/x/batcher/types/errors.go b/x/batcher/types/errors.go new file mode 100644 index 000000000..2a60ccdc8 --- /dev/null +++ b/x/batcher/types/errors.go @@ -0,0 +1,12 @@ +package types + +import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +// module errors +var ( + // Code 1 is a reserved code for internal errors and should not be used for anything else + _ = sdkerrors.Register(ModuleName, 1, "internal error") + ErrBatcher = sdkerrors.Register(ModuleName, 2, "batcher module error") +) diff --git a/x/batcher/types/events.pb.go b/x/batcher/types/events.pb.go new file mode 100644 index 000000000..be625ae5b --- /dev/null +++ b/x/batcher/types/events.pb.go @@ -0,0 +1,547 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: axelar/batcher/v1beta1/events.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 FailedMessages struct { + Messages []FailedMessages_FailedMessage `protobuf:"bytes,1,rep,name=messages,proto3" json:"messages,omitempty"` +} + +func (m *FailedMessages) Reset() { *m = FailedMessages{} } +func (m *FailedMessages) String() string { return proto.CompactTextString(m) } +func (*FailedMessages) ProtoMessage() {} +func (*FailedMessages) Descriptor() ([]byte, []int) { + return fileDescriptor_7050452d381eaccc, []int{0} +} +func (m *FailedMessages) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FailedMessages) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FailedMessages.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 *FailedMessages) XXX_Merge(src proto.Message) { + xxx_messageInfo_FailedMessages.Merge(m, src) +} +func (m *FailedMessages) XXX_Size() int { + return m.Size() +} +func (m *FailedMessages) XXX_DiscardUnknown() { + xxx_messageInfo_FailedMessages.DiscardUnknown(m) +} + +var xxx_messageInfo_FailedMessages proto.InternalMessageInfo + +func (m *FailedMessages) GetMessages() []FailedMessages_FailedMessage { + if m != nil { + return m.Messages + } + return nil +} + +func (*FailedMessages) XXX_MessageName() string { + return "axelar.batcher.v1beta1.FailedMessages" +} + +type FailedMessages_FailedMessage struct { + Index int32 `protobuf:"varint,1,opt,name=index,proto3" json:"index,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` +} + +func (m *FailedMessages_FailedMessage) Reset() { *m = FailedMessages_FailedMessage{} } +func (m *FailedMessages_FailedMessage) String() string { return proto.CompactTextString(m) } +func (*FailedMessages_FailedMessage) ProtoMessage() {} +func (*FailedMessages_FailedMessage) Descriptor() ([]byte, []int) { + return fileDescriptor_7050452d381eaccc, []int{0, 0} +} +func (m *FailedMessages_FailedMessage) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *FailedMessages_FailedMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_FailedMessages_FailedMessage.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 *FailedMessages_FailedMessage) XXX_Merge(src proto.Message) { + xxx_messageInfo_FailedMessages_FailedMessage.Merge(m, src) +} +func (m *FailedMessages_FailedMessage) XXX_Size() int { + return m.Size() +} +func (m *FailedMessages_FailedMessage) XXX_DiscardUnknown() { + xxx_messageInfo_FailedMessages_FailedMessage.DiscardUnknown(m) +} + +var xxx_messageInfo_FailedMessages_FailedMessage proto.InternalMessageInfo + +func (m *FailedMessages_FailedMessage) GetIndex() int32 { + if m != nil { + return m.Index + } + return 0 +} + +func (m *FailedMessages_FailedMessage) GetError() string { + if m != nil { + return m.Error + } + return "" +} + +func (*FailedMessages_FailedMessage) XXX_MessageName() string { + return "axelar.batcher.v1beta1.FailedMessages.FailedMessage" +} +func init() { + proto.RegisterType((*FailedMessages)(nil), "axelar.batcher.v1beta1.FailedMessages") + proto.RegisterType((*FailedMessages_FailedMessage)(nil), "axelar.batcher.v1beta1.FailedMessages.FailedMessage") +} + +func init() { + proto.RegisterFile("axelar/batcher/v1beta1/events.proto", fileDescriptor_7050452d381eaccc) +} + +var fileDescriptor_7050452d381eaccc = []byte{ + // 267 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x4e, 0xac, 0x48, 0xcd, + 0x49, 0x2c, 0xd2, 0x4f, 0x4a, 0x2c, 0x49, 0xce, 0x48, 0x2d, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, + 0x49, 0x34, 0xd4, 0x4f, 0x2d, 0x4b, 0xcd, 0x2b, 0x29, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, + 0x12, 0x83, 0x28, 0xd2, 0x83, 0x2a, 0xd2, 0x83, 0x2a, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, + 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0x95, 0x76, 0x33, 0x72, 0xf1, 0xb9, 0x25, 0x66, 0xe6, 0xa4, + 0xa6, 0xf8, 0xa6, 0x16, 0x17, 0x27, 0xa6, 0xa7, 0x16, 0x0b, 0xe5, 0x70, 0x71, 0xe4, 0x42, 0xd9, + 0x12, 0x8c, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x26, 0x7a, 0xd8, 0xcd, 0xd4, 0x43, 0xd5, 0x89, 0xca, + 0x75, 0x92, 0x3a, 0x71, 0x4f, 0x9e, 0xe1, 0xd5, 0x3d, 0x79, 0x21, 0x98, 0x69, 0x3a, 0xf9, 0xb9, + 0x99, 0x25, 0xa9, 0xb9, 0x05, 0x25, 0x95, 0x41, 0x70, 0x1b, 0xa4, 0xac, 0xb9, 0x78, 0x51, 0xb4, + 0x09, 0x89, 0x70, 0xb1, 0x66, 0xe6, 0xa5, 0xa4, 0x56, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0xb0, 0x06, + 0x41, 0x38, 0x20, 0xd1, 0xd4, 0xa2, 0xa2, 0xfc, 0x22, 0x09, 0x26, 0x05, 0x46, 0x0d, 0xce, 0x20, + 0x08, 0xc7, 0x29, 0xe8, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, + 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc4, 0x63, 0x39, 0xc6, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, + 0x63, 0x88, 0x32, 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0xd5, 0x87, 0x78, + 0x20, 0x2f, 0xb5, 0xa4, 0x3c, 0xbf, 0x28, 0x1b, 0xca, 0xd3, 0x4d, 0xce, 0x2f, 0x4a, 0xd5, 0xaf, + 0x80, 0x07, 0x67, 0x49, 0x65, 0x41, 0x6a, 0x71, 0x12, 0x1b, 0x38, 0x60, 0x8c, 0x01, 0x01, 0x00, + 0x00, 0xff, 0xff, 0xbb, 0x53, 0xf8, 0xff, 0x6d, 0x01, 0x00, 0x00, +} + +func (m *FailedMessages) 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 *FailedMessages) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FailedMessages) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Messages) > 0 { + for iNdEx := len(m.Messages) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Messages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + } + } + return len(dAtA) - i, nil +} + +func (m *FailedMessages_FailedMessage) 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 *FailedMessages_FailedMessage) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *FailedMessages_FailedMessage) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Error) > 0 { + i -= len(m.Error) + copy(dAtA[i:], m.Error) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Error))) + i-- + dAtA[i] = 0x12 + } + if m.Index != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.Index)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + +func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { + offset -= sovEvents(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *FailedMessages) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.Messages) > 0 { + for _, e := range m.Messages { + l = e.Size() + n += 1 + l + sovEvents(uint64(l)) + } + } + return n +} + +func (m *FailedMessages_FailedMessage) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Index != 0 { + n += 1 + sovEvents(uint64(m.Index)) + } + l = len(m.Error) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + +func sovEvents(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozEvents(x uint64) (n int) { + return sovEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *FailedMessages) 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 ErrIntOverflowEvents + } + 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: FailedMessages: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FailedMessages: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Messages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Messages = append(m.Messages, FailedMessages_FailedMessage{}) + if err := m.Messages[len(m.Messages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *FailedMessages_FailedMessage) 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 ErrIntOverflowEvents + } + 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: FailedMessage: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: FailedMessage: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Error", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + 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 ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Error = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipEvents(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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrIntOverflowEvents + } + 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, ErrInvalidLengthEvents + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupEvents + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthEvents + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthEvents = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowEvents = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupEvents = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/batcher/types/genesis.pb.go b/x/batcher/types/genesis.pb.go new file mode 100644 index 000000000..8a8b4d93d --- /dev/null +++ b/x/batcher/types/genesis.pb.go @@ -0,0 +1,268 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: axelar/batcher/v1beta1/genesis.proto + +package types + +import ( + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 + +// GenesisState represents the genesis state +type GenesisState struct { +} + +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_010c5cd0ec2ea057, []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 init() { + proto.RegisterType((*GenesisState)(nil), "axelar.batcher.v1beta1.GenesisState") +} + +func init() { + proto.RegisterFile("axelar/batcher/v1beta1/genesis.proto", fileDescriptor_010c5cd0ec2ea057) +} + +var fileDescriptor_010c5cd0ec2ea057 = []byte{ + // 172 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xac, 0x48, 0xcd, + 0x49, 0x2c, 0xd2, 0x4f, 0x4a, 0x2c, 0x49, 0xce, 0x48, 0x2d, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, + 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x83, 0xa8, 0xd2, 0x83, 0xaa, 0xd2, 0x83, 0xaa, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0x95, 0xf8, 0xb8, 0x78, 0xdc, 0x21, 0xda, 0x83, 0x4b, + 0x12, 0x4b, 0x52, 0x9d, 0x82, 0x4e, 0x3c, 0x94, 0x63, 0x38, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, + 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, + 0x63, 0x39, 0x86, 0x28, 0x93, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, + 0x88, 0x35, 0x79, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0x50, 0x9e, 0x6e, 0x72, 0x7e, 0x51, 0xaa, + 0x7e, 0x05, 0xdc, 0x85, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0xab, 0x8c, 0x01, 0x01, + 0x00, 0x00, 0xff, 0xff, 0xed, 0xb0, 0xd6, 0xb6, 0xc0, 0x00, 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 + 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 + 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 { + 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/batcher/types/key.go b/x/batcher/types/key.go new file mode 100644 index 000000000..d987b30d2 --- /dev/null +++ b/x/batcher/types/key.go @@ -0,0 +1,9 @@ +package types + +const ( + // ModuleName is the name of the module + ModuleName = "batcher" + + // RouterKey to be used for routing msgs + RouterKey = ModuleName +) diff --git a/x/batcher/types/msg_batch.go b/x/batcher/types/msg_batch.go new file mode 100644 index 000000000..a59ed749b --- /dev/null +++ b/x/batcher/types/msg_batch.go @@ -0,0 +1,69 @@ +package types + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/codec/types" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + + "github.com/axelarnetwork/utils/slices" +) + +// NewBatchRequest is the constructor for BatchRequest +func NewBatchRequest(sender sdk.AccAddress, mustSucceedMessages []sdk.Msg, canFailMessages []sdk.Msg) *BatchRequest { + f := func(msg sdk.Msg) types.Any { + messageAny, err := cdctypes.NewAnyWithValue(msg) + if err != nil { + panic(err) + } + return *messageAny + } + + return &BatchRequest{ + Sender: sender, + MustSucceedMessages: slices.Map(mustSucceedMessages, f), + CanFailMessages: slices.Map(canFailMessages, f), + } +} + +// Route returns the route for this message +func (m BatchRequest) Route() string { + return RouterKey +} + +// Type returns the type of the message +func (m BatchRequest) Type() string { + return "Batch" +} + +// ValidateBasic executes a stateless message validation +func (m BatchRequest) ValidateBasic() error { + if err := sdk.VerifyAddressFormat(m.Sender); err != nil { + return sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, sdkerrors.Wrap(err, "sender").Error()) + } + + if len(m.MustSucceedMessages) == 0 && len(m.CanFailMessages) == 0 { + return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "empty batch") + } + + return nil +} + +// GetSigners returns the set of signers for this message +func (m BatchRequest) GetSigners() []sdk.AccAddress { + return []sdk.AccAddress{m.Sender} +} + +func (m BatchRequest) ValidateInnerMessage(msg sdk.Msg) error { + if !msg.GetSigners()[0].Equals(m.Sender) { + return fmt.Errorf("message signer %s does not match batch signer %s", msg.GetSigners()[0], m.Sender) + } + + if err := msg.ValidateBasic(); err != nil { + return err + } + + return nil +} diff --git a/x/batcher/types/service.pb.go b/x/batcher/types/service.pb.go new file mode 100644 index 000000000..daf0c1188 --- /dev/null +++ b/x/batcher/types/service.pb.go @@ -0,0 +1,137 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: axelar/batcher/v1beta1/service.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/gogo/protobuf/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + golang_proto "github.com/golang/protobuf/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" + math "math" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = golang_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 + +func init() { + proto.RegisterFile("axelar/batcher/v1beta1/service.proto", fileDescriptor_9d7f2e7d62747e5c) +} +func init() { + golang_proto.RegisterFile("axelar/batcher/v1beta1/service.proto", fileDescriptor_9d7f2e7d62747e5c) +} + +var fileDescriptor_9d7f2e7d62747e5c = []byte{ + // 254 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x52, 0x49, 0xac, 0x48, 0xcd, + 0x49, 0x2c, 0xd2, 0x4f, 0x4a, 0x2c, 0x49, 0xce, 0x48, 0x2d, 0xd2, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, + 0x49, 0x34, 0xd4, 0x2f, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, + 0x17, 0x12, 0x83, 0xa8, 0xd2, 0x83, 0xaa, 0xd2, 0x83, 0xaa, 0x92, 0x12, 0x49, 0xcf, 0x4f, 0xcf, + 0x07, 0x2b, 0xd1, 0x07, 0xb1, 0x20, 0xaa, 0xa5, 0x64, 0xd2, 0xf3, 0xf3, 0xd3, 0x73, 0x52, 0xf5, + 0x13, 0x0b, 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0xa1, + 0xb2, 0xf2, 0x38, 0x6c, 0x2c, 0xa9, 0x80, 0x28, 0x30, 0x6a, 0x61, 0xe4, 0xe2, 0xf2, 0x2d, 0x4e, + 0x0f, 0x86, 0xb8, 0x40, 0xa8, 0x8c, 0x8b, 0xd5, 0x09, 0xa4, 0x54, 0x48, 0x45, 0x0f, 0xbb, 0x2b, + 0xf4, 0xc0, 0xd2, 0x41, 0xa9, 0x85, 0xa5, 0xa9, 0xc5, 0x25, 0x52, 0xaa, 0x04, 0x54, 0x15, 0x17, + 0xe4, 0xe7, 0x15, 0xa7, 0x2a, 0x29, 0x34, 0x5d, 0x7e, 0x32, 0x99, 0x49, 0x4a, 0x49, 0x54, 0x1f, + 0xcd, 0x39, 0x60, 0xda, 0x8a, 0x51, 0xcb, 0x29, 0xe8, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, + 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x9c, 0xf0, 0x58, 0x8e, 0xe1, 0xc0, 0x63, 0x39, 0xc6, 0x0b, 0x8f, + 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0x32, 0x49, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, + 0xce, 0xcf, 0x85, 0x9a, 0x90, 0x97, 0x5a, 0x52, 0x9e, 0x5f, 0x94, 0x0d, 0xe5, 0xe9, 0x26, 0xe7, + 0x17, 0xa5, 0xea, 0x57, 0xc0, 0x8d, 0x2d, 0xa9, 0x2c, 0x48, 0x2d, 0x4e, 0x62, 0x03, 0xfb, 0xd0, + 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0xcc, 0x9f, 0x92, 0x82, 0x76, 0x01, 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 + +// MsgServiceClient is the client API for MsgService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgServiceClient interface { + Batch(ctx context.Context, in *BatchRequest, opts ...grpc.CallOption) (*BatchResponse, error) +} + +type msgServiceClient struct { + cc grpc1.ClientConn +} + +func NewMsgServiceClient(cc grpc1.ClientConn) MsgServiceClient { + return &msgServiceClient{cc} +} + +func (c *msgServiceClient) Batch(ctx context.Context, in *BatchRequest, opts ...grpc.CallOption) (*BatchResponse, error) { + out := new(BatchResponse) + err := c.cc.Invoke(ctx, "/axelar.batcher.v1beta1.MsgService/Batch", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServiceServer is the server API for MsgService service. +type MsgServiceServer interface { + Batch(context.Context, *BatchRequest) (*BatchResponse, error) +} + +// UnimplementedMsgServiceServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServiceServer struct { +} + +func (*UnimplementedMsgServiceServer) Batch(ctx context.Context, req *BatchRequest) (*BatchResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Batch not implemented") +} + +func RegisterMsgServiceServer(s grpc1.Server, srv MsgServiceServer) { + s.RegisterService(&_MsgService_serviceDesc, srv) +} + +func _MsgService_Batch_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BatchRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServiceServer).Batch(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/axelar.batcher.v1beta1.MsgService/Batch", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServiceServer).Batch(ctx, req.(*BatchRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _MsgService_serviceDesc = grpc.ServiceDesc{ + ServiceName: "axelar.batcher.v1beta1.MsgService", + HandlerType: (*MsgServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Batch", + Handler: _MsgService_Batch_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "axelar/batcher/v1beta1/service.proto", +} diff --git a/x/batcher/types/service.pb.gw.go b/x/batcher/types/service.pb.gw.go new file mode 100644 index 000000000..38b9fba71 --- /dev/null +++ b/x/batcher/types/service.pb.gw.go @@ -0,0 +1,164 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: axelar/batcher/v1beta1/service.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/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 + +func request_MsgService_Batch_0(ctx context.Context, marshaler runtime.Marshaler, client MsgServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq BatchRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Batch(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_MsgService_Batch_0(ctx context.Context, marshaler runtime.Marshaler, server MsgServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq BatchRequest + var metadata runtime.ServerMetadata + + newReader, berr := utilities.IOReaderFactory(req.Body) + if berr != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr) + } + if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Batch(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterMsgServiceHandlerServer registers the http handlers for service MsgService to "mux". +// UnaryRPC :call MsgServiceServer 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 (such as grpc.SendHeader, etc) to stop working. Consider using RegisterMsgServiceHandlerFromEndpoint instead. +func RegisterMsgServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server MsgServiceServer) error { + + mux.Handle("POST", pattern_MsgService_Batch_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.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_MsgService_Batch_0(rctx, inboundMarshaler, server, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_MsgService_Batch_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterMsgServiceHandlerFromEndpoint is same as RegisterMsgServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterMsgServiceHandlerFromEndpoint(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 RegisterMsgServiceHandler(ctx, mux, conn) +} + +// RegisterMsgServiceHandler registers the http handlers for service MsgService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterMsgServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterMsgServiceHandlerClient(ctx, mux, NewMsgServiceClient(conn)) +} + +// RegisterMsgServiceHandlerClient registers the http handlers for service MsgService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "MsgServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "MsgServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "MsgServiceClient" to call the correct interceptors. +func RegisterMsgServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client MsgServiceClient) error { + + mux.Handle("POST", pattern_MsgService_Batch_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_MsgService_Batch_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_MsgService_Batch_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_MsgService_Batch_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"axelar", "batcher", "batch"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_MsgService_Batch_0 = runtime.ForwardResponseMessage +) diff --git a/x/batcher/types/tx.pb.go b/x/batcher/types/tx.pb.go new file mode 100644 index 000000000..5e8835535 --- /dev/null +++ b/x/batcher/types/tx.pb.go @@ -0,0 +1,576 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: axelar/batcher/v1beta1/tx.proto + +package types + +import ( + fmt "fmt" + _ "github.com/axelarnetwork/axelar-core/x/permission/exported" + types "github.com/cosmos/cosmos-sdk/codec/types" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/gogo/protobuf/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 BatchRequest struct { + Sender github_com_cosmos_cosmos_sdk_types.AccAddress `protobuf:"bytes,1,opt,name=sender,proto3,casttype=github.com/cosmos/cosmos-sdk/types.AccAddress" json:"sender,omitempty"` + MustSucceedMessages []types.Any `protobuf:"bytes,2,rep,name=must_succeed_messages,json=mustSucceedMessages,proto3" json:"must_succeed_messages"` + CanFailMessages []types.Any `protobuf:"bytes,3,rep,name=can_fail_messages,json=canFailMessages,proto3" json:"can_fail_messages"` +} + +func (m *BatchRequest) Reset() { *m = BatchRequest{} } +func (m *BatchRequest) String() string { return proto.CompactTextString(m) } +func (*BatchRequest) ProtoMessage() {} +func (*BatchRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_2b64ca7fe92fc14d, []int{0} +} +func (m *BatchRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BatchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BatchRequest.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 *BatchRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_BatchRequest.Merge(m, src) +} +func (m *BatchRequest) XXX_Size() int { + return m.Size() +} +func (m *BatchRequest) XXX_DiscardUnknown() { + xxx_messageInfo_BatchRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_BatchRequest proto.InternalMessageInfo + +func (m *BatchRequest) GetSender() github_com_cosmos_cosmos_sdk_types.AccAddress { + if m != nil { + return m.Sender + } + return nil +} + +func (m *BatchRequest) GetMustSucceedMessages() []types.Any { + if m != nil { + return m.MustSucceedMessages + } + return nil +} + +func (m *BatchRequest) GetCanFailMessages() []types.Any { + if m != nil { + return m.CanFailMessages + } + return nil +} + +type BatchResponse struct { +} + +func (m *BatchResponse) Reset() { *m = BatchResponse{} } +func (m *BatchResponse) String() string { return proto.CompactTextString(m) } +func (*BatchResponse) ProtoMessage() {} +func (*BatchResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_2b64ca7fe92fc14d, []int{1} +} +func (m *BatchResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *BatchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_BatchResponse.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 *BatchResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_BatchResponse.Merge(m, src) +} +func (m *BatchResponse) XXX_Size() int { + return m.Size() +} +func (m *BatchResponse) XXX_DiscardUnknown() { + xxx_messageInfo_BatchResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_BatchResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*BatchRequest)(nil), "axelar.batcher.v1beta1.BatchRequest") + proto.RegisterType((*BatchResponse)(nil), "axelar.batcher.v1beta1.BatchResponse") +} + +func init() { proto.RegisterFile("axelar/batcher/v1beta1/tx.proto", fileDescriptor_2b64ca7fe92fc14d) } + +var fileDescriptor_2b64ca7fe92fc14d = []byte{ + // 359 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0x31, 0x6f, 0xda, 0x40, + 0x18, 0x86, 0xed, 0x82, 0x18, 0x5c, 0x2a, 0x54, 0x97, 0x56, 0x94, 0xc1, 0x20, 0x26, 0x16, 0xee, + 0x44, 0xdb, 0xa9, 0x1b, 0x1e, 0x90, 0x3a, 0x94, 0x81, 0x6e, 0x5d, 0xd0, 0xf9, 0xfc, 0x61, 0x2c, + 0xec, 0x3b, 0xe7, 0xbe, 0x73, 0x62, 0xb6, 0xfc, 0x84, 0xfc, 0x99, 0xfc, 0x07, 0x46, 0xc6, 0x4c, + 0x28, 0x82, 0x1f, 0x11, 0x29, 0x53, 0x84, 0x7d, 0x84, 0x6c, 0x99, 0xfc, 0xf9, 0xf4, 0xbe, 0xcf, + 0x7b, 0xef, 0x77, 0x4e, 0x8f, 0x15, 0x90, 0x30, 0x45, 0x03, 0xa6, 0xf9, 0x0a, 0x14, 0xbd, 0x1e, + 0x07, 0xa0, 0xd9, 0x98, 0xea, 0x82, 0x64, 0x4a, 0x6a, 0xe9, 0x7e, 0xab, 0x04, 0xc4, 0x08, 0x88, + 0x11, 0x74, 0xbf, 0x47, 0x52, 0x46, 0x09, 0xd0, 0x52, 0x15, 0xe4, 0x4b, 0xca, 0xc4, 0xa6, 0xb2, + 0x74, 0xdb, 0x91, 0x8c, 0x64, 0x39, 0xd2, 0xd3, 0x64, 0x4e, 0x89, 0x49, 0xca, 0x40, 0xa5, 0x31, + 0x62, 0x2c, 0x05, 0x85, 0x22, 0x93, 0x4a, 0x43, 0x78, 0x49, 0xdd, 0x64, 0x80, 0x95, 0x7e, 0xf0, + 0x64, 0x3b, 0x4d, 0xff, 0x14, 0x3a, 0x87, 0xab, 0x1c, 0x50, 0xbb, 0x7f, 0x9c, 0x06, 0x82, 0x08, + 0x41, 0x75, 0xec, 0xbe, 0x3d, 0x6c, 0xfa, 0xe3, 0xe7, 0x7d, 0x6f, 0x14, 0xc5, 0x7a, 0x95, 0x07, + 0x84, 0xcb, 0x94, 0x72, 0x89, 0xa9, 0x44, 0xf3, 0x19, 0x61, 0xb8, 0x36, 0xb8, 0x09, 0xe7, 0x93, + 0x30, 0x54, 0x80, 0x38, 0x37, 0x00, 0x77, 0xe6, 0x7c, 0x4d, 0x73, 0xd4, 0x0b, 0xcc, 0x39, 0x07, + 0x08, 0x17, 0x29, 0x20, 0xb2, 0x08, 0xb0, 0xf3, 0xa1, 0x5f, 0x1b, 0x7e, 0xfc, 0xd1, 0x26, 0x55, + 0x39, 0x72, 0x2e, 0x47, 0x26, 0x62, 0xe3, 0xd7, 0xb7, 0xfb, 0x9e, 0x35, 0xff, 0x72, 0x32, 0xfe, + 0xab, 0x7c, 0x7f, 0x8d, 0xcd, 0x9d, 0x3a, 0x9f, 0x39, 0x13, 0x8b, 0x25, 0x8b, 0x93, 0x0b, 0xab, + 0xf6, 0x2e, 0xab, 0xc5, 0x99, 0x98, 0xb2, 0x38, 0x39, 0x73, 0x7e, 0xd7, 0x6f, 0xef, 0x3b, 0xf6, + 0xa0, 0xe5, 0x7c, 0x32, 0xc5, 0x31, 0x93, 0x02, 0xc1, 0x9f, 0x6d, 0x0f, 0x9e, 0xbd, 0x3b, 0x78, + 0xf6, 0xe3, 0xc1, 0xb3, 0xef, 0x8e, 0x9e, 0xb5, 0x3b, 0x7a, 0xd6, 0xc3, 0xd1, 0xb3, 0xfe, 0xff, + 0x7a, 0xd3, 0xbf, 0xda, 0xaf, 0x00, 0x7d, 0x23, 0xd5, 0xda, 0xfc, 0x8d, 0xb8, 0x54, 0x40, 0x8b, + 0xd7, 0xe7, 0x2d, 0x37, 0x12, 0x34, 0xca, 0xbb, 0xfc, 0x7c, 0x09, 0x00, 0x00, 0xff, 0xff, 0x8a, + 0x4c, 0xee, 0xd1, 0xfd, 0x01, 0x00, 0x00, +} + +func (m *BatchRequest) 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 *BatchRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BatchRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.CanFailMessages) > 0 { + for iNdEx := len(m.CanFailMessages) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CanFailMessages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if len(m.MustSucceedMessages) > 0 { + for iNdEx := len(m.MustSucceedMessages) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.MustSucceedMessages[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + } + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *BatchResponse) 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 *BatchResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *BatchResponse) 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 *BatchRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if len(m.MustSucceedMessages) > 0 { + for _, e := range m.MustSucceedMessages { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + if len(m.CanFailMessages) > 0 { + for _, e := range m.CanFailMessages { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + return n +} + +func (m *BatchResponse) 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 *BatchRequest) 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: BatchRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BatchRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = append(m.Sender[:0], dAtA[iNdEx:postIndex]...) + if m.Sender == nil { + m.Sender = []byte{} + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field MustSucceedMessages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.MustSucceedMessages = append(m.MustSucceedMessages, types.Any{}) + if err := m.MustSucceedMessages[len(m.MustSucceedMessages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CanFailMessages", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CanFailMessages = append(m.CanFailMessages, types.Any{}) + if err := m.CanFailMessages[len(m.CanFailMessages)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + 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 *BatchResponse) 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: BatchResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: BatchResponse: 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") +)