feat: streamline app initialization and dependency management

This commit is contained in:
Prad N
2025-03-19 14:47:22 -04:00
parent 00b23353c9
commit 8b4d51ee30
7 changed files with 50 additions and 99 deletions
+13 -17
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"os"
"path/filepath"
"sort"
@@ -60,7 +61,6 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/auth/posthandler"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
txmodule "github.com/cosmos/cosmos-sdk/x/auth/tx/config"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@@ -127,7 +127,7 @@ import (
ibctransferkeeper "github.com/cosmos/ibc-go/v8/modules/apps/transfer/keeper"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v8/modules/core"
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint:staticcheck
ibcclienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" //nolint
ibcconnectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcchanneltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
@@ -373,8 +373,8 @@ func NewChainApp(
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
// register streaming services
if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil {
panic(err)
if errb := bApp.RegisterStreamingServices(appOpts, keys); errb != nil {
panic(errb)
}
app := &SonrApp{
@@ -440,12 +440,12 @@ func NewChainApp(
)
// enable sign mode textual by overwriting the default tx config (after setting the bank keeper)
enabledSignModes := append(tx.DefaultSignModes, signingtype.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := tx.ConfigOptions{
enabledSignModes := append(authtx.DefaultSignModes, signingtype.SignMode_SIGN_MODE_TEXTUAL)
txConfigOpts := authtx.ConfigOptions{
EnabledSignModes: enabledSignModes,
TextualCoinMetadataQueryFn: txmodule.NewBankKeeperCoinMetadataQueryFn(app.BankKeeper),
}
txConfig, err = tx.NewTxConfigWithOptions(
txConfig, err = authtx.NewTxConfigWithOptions(
appCodec,
txConfigOpts,
)
@@ -520,7 +520,7 @@ func NewChainApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.AccountKeeper.AddressCodec(),
)
app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper)
app.SetCircuitBreaker(&app.CircuitKeeper)
app.AuthzKeeper = authzkeeper.NewKeeper(
sdkruntime.NewKVStoreService(keys[authzkeeper.StoreKey]),
@@ -1158,7 +1158,7 @@ func NewChainApp(
panic(fmt.Errorf("error loading last version: %w", err))
}
ctx := app.BaseApp.NewUncachedContext(true, tmproto.Header{})
ctx := app.NewUncachedContext(true, tmproto.Header{})
_ = ctx
}
@@ -1399,9 +1399,9 @@ func (app *SonrApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APICo
// RegisterTxService implements the Application.RegisterTxService method.
func (app *SonrApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(
app.BaseApp.GRPCQueryRouter(),
app.GRPCQueryRouter(),
clientCtx,
app.BaseApp.Simulate,
app.Simulate,
app.interfaceRegistry,
)
}
@@ -1411,7 +1411,7 @@ func (app *SonrApp) RegisterTendermintService(clientCtx client.Context) {
cmtApp := server.NewCometABCIWrapper(app)
cmtservice.RegisterTendermintService(
clientCtx,
app.BaseApp.GRPCQueryRouter(),
app.GRPCQueryRouter(),
app.interfaceRegistry,
cmtApp.Query,
)
@@ -1422,13 +1422,9 @@ func (app *SonrApp) RegisterNodeService(clientCtx client.Context, cfg config.Con
}
// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}
maps.Copy(dupMaccPerms, maccPerms)
return dupMaccPerms
}