diff --git a/CHANGELOG.md b/CHANGELOG.md index 76f93f30c5f..419f2ec401e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,8 +42,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i ### Features +* (runtime) [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Implement `core/transaction.Service` in runtime. * (client) [#19905](https://github.com/cosmos/cosmos-sdk/pull/19905) Add grpc client config to `client.toml`. -* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` it in runtime. This service is present in all modules (when using depinject). +* (runtime) [#19571](https://github.com/cosmos/cosmos-sdk/pull/19571) Implement `core/router.Service` in runtime. This service is present in all modules (when using depinject). * (types) [#19164](https://github.com/cosmos/cosmos-sdk/pull/19164) Add a ValueCodec for the math.Uint type that can be used in collections maps. * (types) [#19281](https://github.com/cosmos/cosmos-sdk/pull/19281) Added a new method, `IsGT`, for `types.Coin`. This method is used to check if a `types.Coin` is greater than another `types.Coin`. * (client) [#18557](https://github.com/cosmos/cosmos-sdk/pull/18557) Add `--qrcode` flag to `keys show` command to support displaying keys address QR code. diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index d44c84f4c1a..15de1f38e2d 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -38,6 +38,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +* [#19953](https://github.com/cosmos/cosmos-sdk/pull/19953) Add transaction service. * [#18379](https://github.com/cosmos/cosmos-sdk/pull/18379) Add branch service. * [#18457](https://github.com/cosmos/cosmos-sdk/pull/18457) Add branch.ExecuteWithGasLimit. * [#19041](https://github.com/cosmos/cosmos-sdk/pull/19041) Add `appmodule.Environment` interface to fetch different services diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index eccc7eb297a..e3592eb210a 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/core/header" "cosmossdk.io/core/router" "cosmossdk.io/core/store" + "cosmossdk.io/core/transaction" "cosmossdk.io/log" ) @@ -14,11 +15,12 @@ import ( type Environment struct { Logger log.Logger - BranchService branch.Service - EventService event.Service - GasService gas.Service - HeaderService header.Service - RouterService router.Service + BranchService branch.Service + EventService event.Service + GasService gas.Service + HeaderService header.Service + RouterService router.Service + TransactionService transaction.Service KVStoreService store.KVStoreService MemStoreService store.MemoryStoreService diff --git a/core/transaction/service.go b/core/transaction/service.go new file mode 100644 index 00000000000..bddc2ba4e63 --- /dev/null +++ b/core/transaction/service.go @@ -0,0 +1,24 @@ +package transaction + +import "context" + +// ExecMode defines the execution mode +type ExecMode uint8 + +// All possible execution modes. +// For backwards compatibility and easier casting, the exec mode values must be the same as in cosmos/cosmos-sdk/types package. +const ( + ExecModeCheck ExecMode = iota + _ + ExecModeSimulate + _ + _ + _ + _ + ExecModeFinalize +) + +// Service creates a transaction service. +type Service interface { + ExecMode(ctx context.Context) ExecMode +} diff --git a/runtime/autocli.go b/runtime/autocli.go deleted file mode 100644 index a942a3bee2f..00000000000 --- a/runtime/autocli.go +++ /dev/null @@ -1,33 +0,0 @@ -package runtime - -import ( - autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" -) - -func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { - return &autocliv1.ModuleOptions{ - Query: &autocliv1.ServiceCommandDescriptor{ - SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ - "autocli": { - Service: autocliv1.Query_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "AppOptions", - Short: "Query the custom autocli options", - }, - }, - }, - "reflection": { - Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, - RpcCommandOptions: []*autocliv1.RpcCommandOptions{ - { - RpcMethod: "FileDescriptors", - Short: "Query the app's protobuf file descriptors", - }, - }, - }, - }, - }, - } -} diff --git a/runtime/environment.go b/runtime/environment.go index 38500ecb6b3..6fce64b35de 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -17,12 +17,13 @@ func NewEnvironment( opts ...EnvOption, ) appmodule.Environment { env := appmodule.Environment{ - Logger: logger, - EventService: EventService{}, - HeaderService: HeaderService{}, - BranchService: BranchService{}, - GasService: GasService{}, - KVStoreService: kvService, + Logger: logger, + EventService: EventService{}, + HeaderService: HeaderService{}, + BranchService: BranchService{}, + GasService: GasService{}, + TransactionService: TransactionService{}, + KVStoreService: kvService, } for _, opt := range opts { diff --git a/runtime/module.go b/runtime/module.go index 41b6b55318d..65a3ddcf4ec 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -11,6 +11,8 @@ import ( runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1" "cosmossdk.io/core/address" "cosmossdk.io/core/appmodule" @@ -31,10 +33,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/msgservice" ) +// appModule defines runtime as an AppModule type appModule struct { app *App } +func (m appModule) IsOnePerModuleType() {} +func (m appModule) IsAppModule() {} + func (m appModule) RegisterServices(configurator module.Configurator) { // nolint:staticcheck // SA1019: Configurator is deprecated but still used in runtime v1. err := m.app.registerRuntimeServices(configurator) if err != nil { @@ -42,8 +48,32 @@ func (m appModule) RegisterServices(configurator module.Configurator) { // nolin } } -func (m appModule) IsOnePerModuleType() {} -func (m appModule) IsAppModule() {} +func (m appModule) AutoCLIOptions() *autocliv1.ModuleOptions { + return &autocliv1.ModuleOptions{ + Query: &autocliv1.ServiceCommandDescriptor{ + SubCommands: map[string]*autocliv1.ServiceCommandDescriptor{ + "autocli": { + Service: autocliv1.Query_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "AppOptions", + Short: "Query the custom autocli options", + }, + }, + }, + "reflection": { + Service: reflectionv1.ReflectionService_ServiceDesc.ServiceName, + RpcCommandOptions: []*autocliv1.RpcCommandOptions{ + { + RpcMethod: "FileDescriptors", + Short: "Query the app's protobuf file descriptors", + }, + }, + }, + }, + }, + } +} var ( _ appmodule.AppModule = appModule{} diff --git a/runtime/transaction.go b/runtime/transaction.go new file mode 100644 index 00000000000..27b4734661d --- /dev/null +++ b/runtime/transaction.go @@ -0,0 +1,19 @@ +package runtime + +import ( + "context" + + "cosmossdk.io/core/transaction" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ transaction.Service = TransactionService{} + +type TransactionService struct{} + +// ExecMode implements transaction.Service. +func (t TransactionService) ExecMode(ctx context.Context) transaction.ExecMode { + sdkCtx := sdk.UnwrapSDKContext(ctx) + return transaction.ExecMode(sdkCtx.ExecMode()) +}