github.com/cosmos/cosmos-sdk@v0.50.10/server/types/app.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  	"io"
     6  
     7  	cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
     8  	cmttypes "github.com/cometbft/cometbft/types"
     9  	dbm "github.com/cosmos/cosmos-db"
    10  	"github.com/cosmos/gogoproto/grpc"
    11  	"github.com/spf13/cobra"
    12  
    13  	"cosmossdk.io/log"
    14  	"cosmossdk.io/store/snapshots"
    15  	storetypes "cosmossdk.io/store/types"
    16  
    17  	"github.com/cosmos/cosmos-sdk/client"
    18  	"github.com/cosmos/cosmos-sdk/server/api"
    19  	"github.com/cosmos/cosmos-sdk/server/config"
    20  )
    21  
    22  type (
    23  	// AppOptions defines an interface that is passed into an application
    24  	// constructor, typically used to set BaseApp options that are either supplied
    25  	// via config file or through CLI arguments/flags. The underlying implementation
    26  	// is defined by the server package and is typically implemented via a Viper
    27  	// literal defined on the server Context. Note, casting Get calls may not yield
    28  	// the expected types and could result in type assertion errors. It is recommend
    29  	// to either use the cast package or perform manual conversion for safety.
    30  	AppOptions interface {
    31  		Get(string) interface{}
    32  	}
    33  
    34  	// Application defines an application interface that wraps abci.Application.
    35  	// The interface defines the necessary contracts to be implemented in order
    36  	// to fully bootstrap and start an application.
    37  	Application interface {
    38  		ABCI
    39  
    40  		RegisterAPIRoutes(*api.Server, config.APIConfig)
    41  
    42  		// RegisterGRPCServer registers gRPC services directly with the gRPC
    43  		// server.
    44  		RegisterGRPCServer(grpc.Server)
    45  
    46  		// RegisterTxService registers the gRPC Query service for tx (such as tx
    47  		// simulation, fetching txs by hash...).
    48  		RegisterTxService(client.Context)
    49  
    50  		// RegisterTendermintService registers the gRPC Query service for CometBFT queries.
    51  		RegisterTendermintService(client.Context)
    52  
    53  		// RegisterNodeService registers the node gRPC Query service.
    54  		RegisterNodeService(client.Context, config.Config)
    55  
    56  		// CommitMultiStore return the multistore instance
    57  		CommitMultiStore() storetypes.CommitMultiStore
    58  
    59  		// Return the snapshot manager
    60  		SnapshotManager() *snapshots.Manager
    61  
    62  		// Close is called in start cmd to gracefully cleanup resources.
    63  		// Must be safe to be called multiple times.
    64  		Close() error
    65  	}
    66  
    67  	// AppCreator is a function that allows us to lazily initialize an
    68  	// application using various configurations.
    69  	AppCreator func(log.Logger, dbm.DB, io.Writer, AppOptions) Application
    70  
    71  	// ModuleInitFlags takes a start command and adds modules specific init flags.
    72  	ModuleInitFlags func(startCmd *cobra.Command)
    73  
    74  	// ExportedApp represents an exported app state, along with
    75  	// validators, consensus params and latest app height.
    76  	ExportedApp struct {
    77  		// AppState is the application state as JSON.
    78  		AppState json.RawMessage
    79  		// Validators is the exported validator set.
    80  		Validators []cmttypes.GenesisValidator
    81  		// Height is the app's latest block height.
    82  		Height int64
    83  		// ConsensusParams are the exported consensus params for ABCI.
    84  		ConsensusParams cmtproto.ConsensusParams
    85  	}
    86  
    87  	// AppExporter is a function that dumps all app state to
    88  	// JSON-serializable structure and returns the current validator set.
    89  	AppExporter func(
    90  		logger log.Logger,
    91  		db dbm.DB,
    92  		traceWriter io.Writer,
    93  		height int64,
    94  		forZeroHeight bool,
    95  		jailAllowedAddrs []string,
    96  		opts AppOptions,
    97  		modulesToExport []string,
    98  	) (ExportedApp, error)
    99  )