feat(core,runtime): transaction service (exec mode) (#19953)
This commit is contained in:
parent
ab45a85307
commit
60496848d9
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
24
core/transaction/service.go
Normal file
24
core/transaction/service.go
Normal file
@ -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
|
||||
}
|
||||
@ -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",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
|
||||
@ -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{}
|
||||
|
||||
19
runtime/transaction.go
Normal file
19
runtime/transaction.go
Normal file
@ -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())
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user