Skip to content

Commit

Permalink
Merge pull request #272 from bianjieai/cyl/reform
Browse files Browse the repository at this point in the history
Added registration Module, AnteHandler, and Upgrade func
  • Loading branch information
zhangyelong authored Jun 7, 2024
2 parents 1bf5dcf + 196188e commit 44ffb01
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
47 changes: 32 additions & 15 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ var (
}
// module accounts that are allowed to receive tokens
allowedReceivingModAcc = map[string]bool{}
// app options
appOptions = IritaAppOptions{}
)

// Verify app interface at compile time
Expand Down Expand Up @@ -533,6 +535,11 @@ func NewIritaApp(
evmtypes.ModuleName, feemarkettypes.ModuleName,
)

// extend Modules
if appOptions.addModule != nil {
appOptions.addModule(app, app.mm, app.keys)
}

app.mm.SetOrderMigrations(
paramstypes.ModuleName,
upgradetypes.ModuleName,
Expand Down Expand Up @@ -603,21 +610,7 @@ func NewIritaApp(
// initialize BaseApp
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)
anteHandler := appante.NewAnteHandler(
appante.HandlerOptions{
AccountKeeper: app.accountKeeper,
BankKeeper: app.bankKeeper,
TokenKeeper: app.tokenKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
FeegrantKeeper: app.feeGrantKeeper,
SigGasConsumer: ethermintante.DefaultSigVerificationGasConsumer,

// evm
EvmFeeMarketKeeper: app.FeeMarketKeeper,
EvmKeeper: app.EvmKeeper,
},
)
app.SetAnteHandler(anteHandler)
app.SetAnteHandler(app.BuildAnteHandler(encodingConfig))
app.SetEndBlocker(app.EndBlocker)

// Set software upgrade execution logic
Expand All @@ -627,6 +620,9 @@ func NewIritaApp(
// },
// func(ctx sdk.Context, plan sdkupgrade.Plan) {},
// )
if appOptions.upgradePlan != nil {
appOptions.upgradePlan(app, app.configurator, app.mm)
}

// set peer filter by node ID
app.SetIDPeerFilter(app.nodeKeeper.FilterNodeByID)
Expand Down Expand Up @@ -807,6 +803,27 @@ func (app *IritaApp) RegisterUpgradePlan(planName string,
}
}

// BuildAnteHandler constructs the ante handler for App
func (app *IritaApp) BuildAnteHandler(encodingConfig simappparams.EncodingConfig) sdk.AnteHandler {
handlerOptions := appante.HandlerOptions{
AccountKeeper: app.accountKeeper,
BankKeeper: app.bankKeeper,
TokenKeeper: app.tokenKeeper,
FeegrantKeeper: app.feeGrantKeeper,
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ethermintante.DefaultSigVerificationGasConsumer,

// evm
EvmFeeMarketKeeper: app.FeeMarketKeeper,
EvmKeeper: app.EvmKeeper,
}

if appOptions.anteHandler != nil {
return appOptions.anteHandler(app, handlerOptions)
}
return appante.NewAnteHandler(handlerOptions)
}

// GetMaccPerms returns a copy of the module account permissions
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
Expand Down
29 changes: 29 additions & 0 deletions app/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

appante "github.com/bianjieai/irita/app/ante"
)

type AddModuleFun func(app *IritaApp, mm *module.Manager, keys map[string]*sdk.KVStoreKey)
type AnteHandlerFun func(app *IritaApp, handlerOptions appante.HandlerOptions) sdk.AnteHandler
type RegisterUpgradePlanFun func(app *IritaApp, configurator module.Configurator, mm *module.Manager)

type IritaAppOptions struct {
addModule AddModuleFun
anteHandler AnteHandlerFun
upgradePlan RegisterUpgradePlanFun
}

func NewAppOptions(addModule AddModuleFun, anteHandler AnteHandlerFun, registerUpgradePlan RegisterUpgradePlanFun, modules ...module.AppModuleBasic) {
for _, moduleBasic := range modules {
ModuleBasics[moduleBasic.Name()] = moduleBasic
}
appOptions = IritaAppOptions{
addModule: addModule,
anteHandler: anteHandler,
upgradePlan: registerUpgradePlan,
}
}

0 comments on commit 44ffb01

Please sign in to comment.