docs(core): add core documentation and principles (#21511)
Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
This commit is contained in:
parent
70488a89a8
commit
6fc677faec
@ -1,11 +1,19 @@
|
||||
# Cosmos SDK Core
|
||||
|
||||
The [cosmossdk.io/core](https://pkg.go.dev/cosmossdk.io/core) go module defines
|
||||
"core" functionality for the Cosmos SDK.
|
||||
The [cosmossdk.io/core](https://pkg.go.dev/cosmossdk.io/core) Go module defines essential APIs and interfaces for the Cosmos SDK ecosystem. It serves as a foundation for building modular blockchain applications.
|
||||
|
||||
Currently functionality for registering modules using the [appmodule](https://pkg.go.dev/cosmossdk.io/core/appmodule)
|
||||
package and composing apps using the [appconfig](https://pkg.go.dev/cosmossdk.io/core/appconfig)
|
||||
package is provided.
|
||||
Key features and principles:
|
||||
|
||||
In the future core functionality for building Cosmos SDK app modules will be
|
||||
provided in this go module.
|
||||
1. Provides stable, long-term maintained APIs for module development and app composition.
|
||||
2. Focuses on interface definitions without implementation details.
|
||||
3. Implementations are housed in the runtime(/v2) or individual modules.
|
||||
4. Modules depend solely on core APIs for maximum compatibility.
|
||||
5. New API additions undergo thorough consideration to maintain stability.
|
||||
6. Adheres to a no-breaking-changes policy for reliable dependency management.
|
||||
7. Aimed to have zero dependencies, ensuring a lightweight and self-contained foundation.
|
||||
|
||||
The core module offers the [appmodule](https://pkg.go.dev/cosmossdk.io/core/appmodule) and [appmodule/v2](https://pkg.go.dev/cosmossdk.io/core/appmodule/v2) packages that include APIs to describe how modules can be written.
|
||||
Additionally, it contains all core services APIs that can be used in modules to interact with the SDK, majoritarily via the `appmodule.Environment` struct.
|
||||
Last but not least, it provides codecs and packages for the Cosmos SDK's core types (think of, for instance, logger, store interface or an address codec).
|
||||
|
||||
Developers and contributors approach core API design with careful deliberation, ensuring that additions provide significant value while maintaining the module's stability and simplicity.
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
# Appmodule
|
||||
|
||||
<!-- TODO add more docs here with https://github.com/cosmos/cosmos-sdk/issues/17207 -->
|
||||
|
||||
This package defines what is needed for an module to be used in the Cosmos SDK.
|
||||
|
||||
If you are looking at integrating Dependency injection into your module please see [depinject appconfig documentation](../../depinject/appconfig/README.md)
|
||||
@ -1,5 +1,4 @@
|
||||
// Package appmodule defines the functionality for registering Cosmos SDK app
|
||||
// modules that are assembled using the cosmossdk.io/depinject
|
||||
// dependency injection system and the declarative app configuration format
|
||||
// handled by the appconfig package.
|
||||
// Package appmodule defines what is needed for an module to be used in the Cosmos SDK (runtime).
|
||||
// It is equivalent to the appmodulev2 package, but less flexible to stay compatible with baseapp instead of server/v2.
|
||||
// If you are looking at integrating dependency injection into your module please see depinject appconfig documentation.
|
||||
package appmodule
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
package appmodule
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
)
|
||||
|
||||
// Environment is used to get all services to their respective module
|
||||
// Contract: All fields of environment are always populated.
|
||||
type Environment = appmodule.Environment
|
||||
// Environment is used to get all services to their respective module.
|
||||
// Contract: All fields of environment are always populated by runtime.
|
||||
type Environment = appmodulev2.Environment
|
||||
|
||||
@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
)
|
||||
|
||||
// HasGenesisBasics is the legacy interface for stateless genesis methods.
|
||||
@ -15,18 +15,18 @@ type HasGenesisBasics interface {
|
||||
}
|
||||
|
||||
// HasGenesis defines a custom genesis handling API implementation.
|
||||
type HasGenesis = appmodule.HasGenesis
|
||||
type HasGenesis = appmodulev2.HasGenesis
|
||||
|
||||
// HasABCIGenesis defines a custom genesis handling API implementation for ABCI.
|
||||
// (stateful genesis methods which returns validator updates)
|
||||
// Most modules should not implement this interface.
|
||||
type HasABCIGenesis = appmodule.HasABCIGenesis
|
||||
type HasABCIGenesis = appmodulev2.HasABCIGenesis
|
||||
|
||||
// HasGenesisAuto is the extension interface that modules should implement to handle
|
||||
// genesis data and state initialization.
|
||||
// WARNING: This interface is experimental and may change at any time.
|
||||
// WARNING: This interface is experimental and may change at any time and has been dropped in v2.
|
||||
type HasGenesisAuto interface {
|
||||
appmodule.AppModule
|
||||
appmodulev2.AppModule
|
||||
|
||||
// DefaultGenesis writes the default genesis for this module to the target.
|
||||
DefaultGenesis(GenesisTarget) error
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
package appmodule
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
)
|
||||
|
||||
// HasConsensusVersion is the interface for declaring a module consensus version.
|
||||
type HasConsensusVersion = appmodule.HasConsensusVersion
|
||||
type HasConsensusVersion = appmodulev2.HasConsensusVersion
|
||||
|
||||
// HasMigrations is implemented by a module which upgrades or has upgraded to a new consensus version.
|
||||
type HasMigrations = appmodule.HasMigrations
|
||||
type HasMigrations = appmodulev2.HasMigrations
|
||||
|
||||
// MigrationRegistrar is the interface for registering in-place store migrations.
|
||||
type MigrationRegistrar = appmodule.MigrationRegistrar
|
||||
type MigrationRegistrar = appmodulev2.MigrationRegistrar
|
||||
|
||||
// MigrationHandler is the migration function that each module registers.
|
||||
type MigrationHandler = appmodule.MigrationHandler
|
||||
type MigrationHandler = appmodulev2.MigrationHandler
|
||||
|
||||
// VersionMap is a map of moduleName -> version
|
||||
type VersionMap = appmodule.VersionMap
|
||||
type VersionMap = appmodulev2.VersionMap
|
||||
|
||||
@ -3,7 +3,7 @@ package appmodule
|
||||
import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/legacy"
|
||||
)
|
||||
|
||||
@ -11,25 +11,25 @@ import (
|
||||
// for extension interfaces. It provides no functionality itself, but is the
|
||||
// type that all valid app modules should provide so that they can be identified
|
||||
// by other modules (usually via depinject) as app modules.
|
||||
type AppModule = appmodule.AppModule
|
||||
type AppModule = appmodulev2.AppModule
|
||||
|
||||
// HasPreBlocker is the extension interface that modules should implement to run
|
||||
// custom logic before BeginBlock.
|
||||
type HasPreBlocker = appmodule.HasPreBlocker
|
||||
type HasPreBlocker = appmodulev2.HasPreBlocker
|
||||
|
||||
// HasBeginBlocker is the extension interface that modules should implement to run
|
||||
// custom logic before transaction processing in a block.
|
||||
type HasBeginBlocker = appmodule.HasBeginBlocker
|
||||
type HasBeginBlocker = appmodulev2.HasBeginBlocker
|
||||
|
||||
// HasEndBlocker is the extension interface that modules should implement to run
|
||||
// custom logic after transaction processing in a block.
|
||||
type HasEndBlocker = appmodule.HasEndBlocker
|
||||
type HasEndBlocker = appmodulev2.HasEndBlocker
|
||||
|
||||
// HasRegisterInterfaces is the interface for modules to register their msg types.
|
||||
type HasRegisterInterfaces = appmodule.HasRegisterInterfaces
|
||||
type HasRegisterInterfaces = appmodulev2.HasRegisterInterfaces
|
||||
|
||||
// ValidatorUpdate defines a validator update.
|
||||
type ValidatorUpdate = appmodule.ValidatorUpdate
|
||||
type ValidatorUpdate = appmodulev2.ValidatorUpdate
|
||||
|
||||
// HasServices is the extension interface that modules should implement to register
|
||||
// implementations of services defined in .proto files.
|
||||
@ -55,13 +55,13 @@ type ValidatorUpdate = appmodule.ValidatorUpdate
|
||||
// HasPrepareCheckState is an extension interface that contains information about the AppModule
|
||||
// and PrepareCheckState.
|
||||
type HasPrepareCheckState interface {
|
||||
appmodule.AppModule
|
||||
appmodulev2.AppModule
|
||||
PrepareCheckState(context.Context) error
|
||||
}
|
||||
|
||||
// HasPrecommit is an extension interface that contains information about the appmodule.AppModule and Precommit.
|
||||
type HasPrecommit interface {
|
||||
appmodule.AppModule
|
||||
appmodulev2.AppModule
|
||||
Precommit(context.Context) error
|
||||
}
|
||||
|
||||
|
||||
3
core/appmodule/v2/doc.go
Normal file
3
core/appmodule/v2/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
// Package appmodule defines what is needed for an module to be used in the Cosmos SDK (runtime/v2).
|
||||
// If you are looking at integrating dependency injection into your module please see depinject appconfig documentation.
|
||||
package appmodulev2
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import (
|
||||
"cosmossdk.io/core/branch"
|
||||
@ -11,8 +11,8 @@ import (
|
||||
"cosmossdk.io/core/transaction"
|
||||
)
|
||||
|
||||
// Environment is used to get all services to their respective module
|
||||
// Contract: All fields of environment are always populated.
|
||||
// Environment is used to get all services to their respective module.
|
||||
// Contract: All fields of environment are always populated by runtime.
|
||||
type Environment struct {
|
||||
Logger log.Logger
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import "context"
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package appmodule
|
||||
package appmodulev2
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
@ -12,8 +12,8 @@ var (
|
||||
ExecModeKey = execModeKey{}
|
||||
// CometInfoKey is the context key for allowing modules to get CometInfo.
|
||||
CometInfoKey = cometInfoKey{}
|
||||
// InitInfoKey is the context key for setting consensus params from genesis in the consensus module.
|
||||
InitInfoKey = initInfoKey{}
|
||||
// CometParamsInitInfoKey is the context key for setting consensus params from genesis in the consensus module.
|
||||
CometParamsInitInfoKey = initInfoKey{}
|
||||
|
||||
// EnvironmentContextKey is the context key for the environment.
|
||||
// A caller should not assume the environment is available in each context.
|
||||
|
||||
@ -6,6 +6,8 @@ type (
|
||||
)
|
||||
|
||||
var (
|
||||
// LoggerContextKey is the context key where the logger can be found.
|
||||
LoggerContextKey loggerContextKey
|
||||
ViperContextKey viperContextKey
|
||||
// ViperContextKey is the context key where the viper instance can be found.
|
||||
ViperContextKey viperContextKey
|
||||
)
|
||||
|
||||
@ -42,6 +42,7 @@ type Meter interface {
|
||||
Limit() Gas
|
||||
}
|
||||
|
||||
// GasConfig defines the gas costs for the application.
|
||||
type GasConfig struct {
|
||||
HasCost Gas
|
||||
DeleteCost Gas
|
||||
|
||||
3
core/genesis/doc.go
Normal file
3
core/genesis/doc.go
Normal file
@ -0,0 +1,3 @@
|
||||
// package genesis is used to define appmodule.HasGenesisAuto experimental auto genesis.
|
||||
// This genesis package isn't supported in server/v2.
|
||||
package genesis
|
||||
@ -1,5 +1,6 @@
|
||||
package legacy
|
||||
|
||||
// Amino is an interface that allow to register concrete types and interfaces with the Amino codec.
|
||||
type Amino interface {
|
||||
// RegisterInterface registers an interface and its concrete type with the Amino codec.
|
||||
RegisterInterface(interfacePtr any, iopts *InterfaceOptions)
|
||||
@ -8,6 +9,7 @@ type Amino interface {
|
||||
RegisterConcrete(cdcType interface{}, name string)
|
||||
}
|
||||
|
||||
// InterfaceOptions defines options for registering an interface with the Amino codec.
|
||||
type InterfaceOptions struct {
|
||||
Priority []string // Disamb priority.
|
||||
AlwaysDisambiguate bool // If true, include disamb for all types.
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"cosmossdk.io/core/transaction"
|
||||
)
|
||||
|
||||
// InterfaceRegistrar is an interface for registering interfaces and their implementation.
|
||||
// It is a subset of the Cosmos SDK InterfaceRegistry for registration only.
|
||||
type InterfaceRegistrar interface {
|
||||
// RegisterInterface associates protoName as the public name for the
|
||||
// interface passed in as iface. This is to be used primarily to create
|
||||
|
||||
@ -20,5 +20,6 @@ const (
|
||||
|
||||
// Service creates a transaction service.
|
||||
type Service interface {
|
||||
// ExecMode returns the current execution mode.
|
||||
ExecMode(ctx context.Context) ExecMode
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ type Codec[T Tx] interface {
|
||||
DecodeJSON([]byte) (T, error)
|
||||
}
|
||||
|
||||
// Tx defines the interface for a transaction.
|
||||
// All custom transactions must implement this interface.
|
||||
type Tx interface {
|
||||
// Hash returns the unique identifier for the Tx.
|
||||
Hash() [32]byte
|
||||
|
||||
@ -245,7 +245,7 @@ func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRe
|
||||
}
|
||||
|
||||
if req.ConsensusParams != nil {
|
||||
ctx = context.WithValue(ctx, corecontext.InitInfoKey, &consensustypes.MsgUpdateParams{
|
||||
ctx = context.WithValue(ctx, corecontext.CometParamsInitInfoKey, &consensustypes.MsgUpdateParams{
|
||||
Authority: c.consensusAuthority,
|
||||
Block: req.ConsensusParams.Block,
|
||||
Evidence: req.ConsensusParams.Evidence,
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
gogotypes "github.com/cosmos/gogoproto/types"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/transaction"
|
||||
)
|
||||
|
||||
@ -18,7 +18,7 @@ func TestRouter(t *testing.T) {
|
||||
|
||||
expectedResp := &gogotypes.StringValue{Value: "test"}
|
||||
|
||||
router := coreRouterImpl{handlers: map[string]appmodule.Handler{
|
||||
router := coreRouterImpl{handlers: map[string]appmodulev2.Handler{
|
||||
gogoproto.MessageName(expectedMsg): func(ctx context.Context, gotMsg transaction.Msg) (msgResp transaction.Msg, err error) {
|
||||
if !reflect.DeepEqual(expectedMsg, gotMsg) {
|
||||
t.Errorf("expected message: %v, got: %v", expectedMsg, gotMsg)
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
reflect "reflect"
|
||||
|
||||
appmodule "cosmossdk.io/core/appmodule"
|
||||
appmodule0 "cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
types "github.com/cosmos/cosmos-sdk/types"
|
||||
module "github.com/cosmos/cosmos-sdk/types/module"
|
||||
gomock "github.com/golang/mock/gomock"
|
||||
@ -269,10 +269,10 @@ func (mr *MockAppModuleWithAllExtensionsABCIMockRecorder) ExportGenesis(ctx inte
|
||||
}
|
||||
|
||||
// InitGenesis mocks base method.
|
||||
func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(ctx context.Context, data json.RawMessage) ([]appmodule0.ValidatorUpdate, error) {
|
||||
func (m *MockAppModuleWithAllExtensionsABCI) InitGenesis(ctx context.Context, data json.RawMessage) ([]appmodulev2.ValidatorUpdate, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "InitGenesis", ctx, data)
|
||||
ret0, _ := ret[0].([]appmodule0.ValidatorUpdate)
|
||||
ret0, _ := ret[0].([]appmodulev2.ValidatorUpdate)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/store"
|
||||
@ -73,7 +73,7 @@ func makeMockDependencies(storeservice store.KVStoreService) accountstd.Dependen
|
||||
SchemaBuilder: sb,
|
||||
AddressCodec: addressCodec{},
|
||||
LegacyStateCodec: mockStateCodec{},
|
||||
Environment: appmodule.Environment{
|
||||
Environment: appmodulev2.Environment{
|
||||
EventService: eventService{},
|
||||
HeaderService: headerService{},
|
||||
},
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/store"
|
||||
"cosmossdk.io/core/transaction"
|
||||
@ -114,7 +114,7 @@ func makeMockDependencies(storeservice store.KVStoreService) accountstd.Dependen
|
||||
SchemaBuilder: sb,
|
||||
AddressCodec: addressCodec{},
|
||||
LegacyStateCodec: mockStateCodec{},
|
||||
Environment: appmodule.Environment{
|
||||
Environment: appmodulev2.Environment{
|
||||
HeaderService: headerService{},
|
||||
},
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/event"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/core/store"
|
||||
@ -185,7 +185,7 @@ func makeMockDependencies(storeservice store.KVStoreService, timefn func() time.
|
||||
SchemaBuilder: sb,
|
||||
AddressCodec: addressCodec{},
|
||||
LegacyStateCodec: mockStateCodec{},
|
||||
Environment: appmodule.Environment{
|
||||
Environment: appmodulev2.Environment{
|
||||
HeaderService: headerService{timefn},
|
||||
EventService: eventService{},
|
||||
},
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/transaction"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -24,10 +24,10 @@ import (
|
||||
// ValidateBasicDecorator decorator will not get executed on ReCheckTx since it
|
||||
// is not dependent on application state.
|
||||
type ValidateBasicDecorator struct {
|
||||
env appmodule.Environment
|
||||
env appmodulev2.Environment
|
||||
}
|
||||
|
||||
func NewValidateBasicDecorator(env appmodule.Environment) ValidateBasicDecorator {
|
||||
func NewValidateBasicDecorator(env appmodulev2.Environment) ValidateBasicDecorator {
|
||||
return ValidateBasicDecorator{
|
||||
env: env,
|
||||
}
|
||||
@ -219,7 +219,7 @@ type (
|
||||
// TxTimeoutHeightDecorator defines an AnteHandler decorator that checks for a
|
||||
// tx height timeout.
|
||||
TxTimeoutHeightDecorator struct {
|
||||
env appmodule.Environment
|
||||
env appmodulev2.Environment
|
||||
}
|
||||
|
||||
// TxWithTimeoutHeight defines the interface a tx must implement in order for
|
||||
@ -234,7 +234,7 @@ type (
|
||||
|
||||
// TxTimeoutHeightDecorator defines an AnteHandler decorator that checks for a
|
||||
// tx height timeout.
|
||||
func NewTxTimeoutHeightDecorator(env appmodule.Environment) TxTimeoutHeightDecorator {
|
||||
func NewTxTimeoutHeightDecorator(env appmodulev2.Environment) TxTimeoutHeightDecorator {
|
||||
return TxTimeoutHeightDecorator{
|
||||
env: env,
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/header"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
@ -189,7 +189,7 @@ func TestTxHeightTimeoutDecorator(t *testing.T) {
|
||||
suite := SetupTestSuite(t, true)
|
||||
|
||||
mockHeaderService := &mockHeaderService{}
|
||||
antehandler := sdk.ChainAnteDecorators(ante.NewTxTimeoutHeightDecorator(appmodule.Environment{HeaderService: mockHeaderService}))
|
||||
antehandler := sdk.ChainAnteDecorators(ante.NewTxTimeoutHeightDecorator(appmodulev2.Environment{HeaderService: mockHeaderService}))
|
||||
|
||||
// keys and addresses
|
||||
priv1, _, addr1 := testdata.KeyTestPubAddr()
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
"github.com/cosmos/gogoproto/proto"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/transaction"
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
|
||||
@ -47,14 +47,14 @@ type UnorderedTxDecorator struct {
|
||||
// maxUnOrderedTTL defines the maximum TTL a transaction can define.
|
||||
maxTimeoutDuration time.Duration
|
||||
txManager *unorderedtx.Manager
|
||||
env appmodule.Environment
|
||||
env appmodulev2.Environment
|
||||
sha256Cost uint64
|
||||
}
|
||||
|
||||
func NewUnorderedTxDecorator(
|
||||
maxDuration time.Duration,
|
||||
m *unorderedtx.Manager,
|
||||
env appmodule.Environment,
|
||||
env appmodulev2.Environment,
|
||||
gasCost uint64,
|
||||
) *UnorderedTxDecorator {
|
||||
return &UnorderedTxDecorator{
|
||||
|
||||
@ -15,7 +15,7 @@ import (
|
||||
bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
|
||||
txconfigv1 "cosmossdk.io/api/cosmos/tx/config/v1"
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
"cosmossdk.io/core/transaction"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/depinject/appconfig"
|
||||
@ -53,25 +53,25 @@ type ModuleInputs struct {
|
||||
ValidatorAddressCodec address.ValidatorAddressCodec
|
||||
Codec codec.Codec
|
||||
ProtoFileResolver txsigning.ProtoFileResolver
|
||||
Environment appmodule.Environment
|
||||
Environment appmodulev2.Environment
|
||||
// BankKeeper is the expected bank keeper to be passed to AnteHandlers / Tx Validators
|
||||
BankKeeper authtypes.BankKeeper `optional:"true"`
|
||||
MetadataBankKeeper BankKeeper `optional:"true"`
|
||||
AccountKeeper ante.AccountKeeper `optional:"true"`
|
||||
FeeGrantKeeper ante.FeegrantKeeper `optional:"true"`
|
||||
AccountAbstractionKeeper ante.AccountAbstractionKeeper `optional:"true"`
|
||||
CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"`
|
||||
CustomGetSigners []txsigning.CustomGetSigner `optional:"true"`
|
||||
ExtraTxValidators []appmodule.TxValidator[transaction.Tx] `optional:"true"`
|
||||
UnorderedTxManager *unorderedtx.Manager `optional:"true"`
|
||||
TxFeeChecker ante.TxFeeChecker `optional:"true"`
|
||||
Viper *viper.Viper `optional:"true"` // server v2
|
||||
BankKeeper authtypes.BankKeeper `optional:"true"`
|
||||
MetadataBankKeeper BankKeeper `optional:"true"`
|
||||
AccountKeeper ante.AccountKeeper `optional:"true"`
|
||||
FeeGrantKeeper ante.FeegrantKeeper `optional:"true"`
|
||||
AccountAbstractionKeeper ante.AccountAbstractionKeeper `optional:"true"`
|
||||
CustomSignModeHandlers func() []txsigning.SignModeHandler `optional:"true"`
|
||||
CustomGetSigners []txsigning.CustomGetSigner `optional:"true"`
|
||||
ExtraTxValidators []appmodulev2.TxValidator[transaction.Tx] `optional:"true"`
|
||||
UnorderedTxManager *unorderedtx.Manager `optional:"true"`
|
||||
TxFeeChecker ante.TxFeeChecker `optional:"true"`
|
||||
Viper *viper.Viper `optional:"true"` // server v2
|
||||
}
|
||||
|
||||
type ModuleOutputs struct {
|
||||
depinject.Out
|
||||
|
||||
Module appmodule.AppModule // This is only useful for chains using server/v2. It setup tx validators that don't belong to other modules.
|
||||
Module appmodulev2.AppModule // This is only useful for chains using server/v2. It setup tx validators that don't belong to other modules.
|
||||
BaseAppOption runtime.BaseAppOption // This is only useful for chains using baseapp. Server/v2 chains use TxValidator.
|
||||
TxConfig client.TxConfig
|
||||
TxConfigOptions tx.ConfigOptions
|
||||
|
||||
@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"cosmossdk.io/core/address"
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
@ -42,7 +42,7 @@ func (a SendAuthorization) Accept(ctx context.Context, msg sdk.Msg) (authz.Accep
|
||||
return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit")
|
||||
}
|
||||
|
||||
authzEnv, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodule.Environment)
|
||||
authzEnv, ok := ctx.Value(corecontext.EnvironmentContextKey).(appmodulev2.Environment)
|
||||
if !ok {
|
||||
return authz.AcceptResponse{}, sdkerrors.ErrUnauthorized.Wrap("environment not set")
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
coregas "cosmossdk.io/core/gas"
|
||||
coreheader "cosmossdk.io/core/header"
|
||||
@ -54,7 +54,7 @@ func (m mockGasMeter) Consume(amount coregas.Gas, descriptor string) error {
|
||||
func TestSendAuthorization(t *testing.T) {
|
||||
ac := codectestutil.CodecOptions{}.GetAddressCodec()
|
||||
sdkCtx := testutil.DefaultContextWithDB(t, storetypes.NewKVStoreKey(types.StoreKey), storetypes.NewTransientStoreKey("transient_test")).Ctx.WithHeaderInfo(coreheader.Info{})
|
||||
ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodule.Environment{
|
||||
ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodulev2.Environment{
|
||||
HeaderService: headerService{},
|
||||
GasService: mockGasService{},
|
||||
})
|
||||
|
||||
@ -47,7 +47,7 @@ func (k *Keeper) GetAuthority() string {
|
||||
|
||||
// InitGenesis initializes the initial state of the module
|
||||
func (k *Keeper) InitGenesis(ctx context.Context) error {
|
||||
value, ok := ctx.Value(corecontext.InitInfoKey).(*types.MsgUpdateParams)
|
||||
value, ok := ctx.Value(corecontext.CometParamsInitInfoKey).(*types.MsgUpdateParams)
|
||||
if !ok || value == nil {
|
||||
// no error for appv1 and appv2
|
||||
return nil
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
"cosmossdk.io/core/header"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -140,7 +140,7 @@ func TestBasicFeeValidAllow(t *testing.T) {
|
||||
|
||||
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: tc.blockTime})
|
||||
// now try to deduct
|
||||
removed, err := tc.allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{
|
||||
removed, err := tc.allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{
|
||||
HeaderService: mockHeaderService{},
|
||||
GasService: mockGasService{},
|
||||
}), tc.fee, []sdk.Msg{})
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
"cosmossdk.io/core/header"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -158,7 +158,7 @@ func TestFilteredFeeValidAllow(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// now try to deduct
|
||||
removed, err := allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{
|
||||
removed, err := allowance.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{
|
||||
HeaderService: mockHeaderService{},
|
||||
GasService: mockGasService{},
|
||||
}), tc.fee, []sdk.Msg{&call})
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
"cosmossdk.io/core/header"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
@ -223,7 +223,7 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: tc.blockTime})
|
||||
// now try to deduct
|
||||
// Set environment to ctx
|
||||
remove, err := tc.allow.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodule.Environment{
|
||||
remove, err := tc.allow.Accept(context.WithValue(ctx, corecontext.EnvironmentContextKey, appmodulev2.Environment{
|
||||
HeaderService: mockHeaderService{},
|
||||
GasService: mockGasService{},
|
||||
}), tc.fee, []sdk.Msg{})
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/appmodule/v2"
|
||||
appmodulev2 "cosmossdk.io/core/appmodule/v2"
|
||||
corecontext "cosmossdk.io/core/context"
|
||||
coregas "cosmossdk.io/core/gas"
|
||||
coreheader "cosmossdk.io/core/header"
|
||||
@ -69,7 +69,7 @@ func TestAuthzAuthorizations(t *testing.T) {
|
||||
key := storetypes.NewKVStoreKey(stakingtypes.StoreKey)
|
||||
testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
sdkCtx := testCtx.Ctx.WithHeaderInfo(coreheader.Info{})
|
||||
ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodule.Environment{
|
||||
ctx := context.WithValue(sdkCtx.Context(), corecontext.EnvironmentContextKey, appmodulev2.Environment{
|
||||
HeaderService: headerService{},
|
||||
GasService: mockGasService{},
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user