Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan.balea committed Aug 19, 2024
2 parents e5900b0 + a621649 commit 1dab336
Show file tree
Hide file tree
Showing 87 changed files with 10,758 additions and 814 deletions.
87 changes: 87 additions & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
)

const (
denomMainnet = "ubze"
denomTestnet = "utbz"
)

func NewAnteHandler(options ante.HandlerOptions) (sdk.AnteHandler, error) {
if options.AccountKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for ante builder")
}

if options.BankKeeper == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
}

if options.SignModeHandler == nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder")
}

sigGasConsumer := options.SigGasConsumer
if sigGasConsumer == nil {
sigGasConsumer = ante.DefaultSigVerificationGasConsumer
}

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
ante.NewRejectExtensionOptionsDecorator(),
ante.NewMempoolFeeDecorator(),
ante.NewValidateBasicDecorator(),
NewValidateTxFeeDenomsDecorator(), //use our own validate basic to enforce denoms that should be used for fees
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
ante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer),
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
}

return sdk.ChainAnteDecorators(anteDecorators...), nil
}

// ValidateTxFeeDenomsDecorator will check if denominations used for tx fees are allowed and returns an error otherwise
type ValidateTxFeeDenomsDecorator struct{}

func NewValidateTxFeeDenomsDecorator() ValidateTxFeeDenomsDecorator {
return ValidateTxFeeDenomsDecorator{}
}

func (vbd ValidateTxFeeDenomsDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
// no need to validate basic on recheck tx, call next antehandler
if ctx.IsReCheckTx() {
return next(ctx, tx, simulate)
}

feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "ValidateTxFeeDenomsDecorator requires tx to be a FeeTx")
}

for _, c := range feeTx.GetFee() {
if !vbd.isAllowedDenom(c.Denom) {
return ctx, sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest,
"invalid fee supplied. cannot pay fee in %s denomination. Allowed denomination is %s for mainnet and %s for testnet",
c.Denom,
denomMainnet,
denomTestnet,
)
}
}

return next(ctx, tx, simulate)
}

func (vbd ValidateTxFeeDenomsDecorator) isAllowedDenom(denom string) bool {
return denom == denomMainnet || denom == denomTestnet
}
77 changes: 28 additions & 49 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package app

import (
"github.com/bze-alphateam/bze/app/openapi"
"github.com/bze-alphateam/bze/app/upgrades"
v700 "github.com/bze-alphateam/bze/app/upgrades/v700"
v710 "github.com/bze-alphateam/bze/app/upgrades/v710"
"github.com/bze-alphateam/bze/x/epochs"
epochskeeper "github.com/bze-alphateam/bze/x/epochs/keeper"
epochstypes "github.com/bze-alphateam/bze/x/epochs/types"
Expand Down Expand Up @@ -33,7 +32,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/api"
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -190,27 +188,29 @@ var (

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
scavengemoduletypes.ModuleName: nil,
cointrunkmoduletypes.ModuleName: nil,
burnermoduletypes.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tradebintypes.ModuleName: nil,
epochstypes.ModuleName: nil,
rewardstypes.ModuleName: {authtypes.Burner},
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
scavengemoduletypes.ModuleName: nil,
cointrunkmoduletypes.ModuleName: nil,
burnermoduletypes.ModuleName: {authtypes.Burner},
tokenfactorytypes.ModuleName: {authtypes.Minter, authtypes.Burner},
tradebintypes.ModuleName: nil,
epochstypes.ModuleName: nil,
rewardstypes.ModuleName: {authtypes.Burner},
burnermoduletypes.RaffleModuleName: {authtypes.Burner},
// this line is used by starport scaffolding # stargate/app/maccPerms
}

// a map of modules allowed to receive external funds
// this list will be excluded from bank/distribution modules blocked addresses
allowedModules = map[string]struct{}{
burnermoduletypes.ModuleName: {},
tradebintypes.ModuleName: {},
}
)

Expand Down Expand Up @@ -424,6 +424,12 @@ func New(
app.BankKeeper,
)

app.EpochsKeeper = *epochskeeper.NewKeeper(
appCodec,
keys[epochstypes.StoreKey],
keys[epochstypes.MemStoreKey],
)

app.CointrunkKeeper = *cointrunkmodulekeeper.NewKeeper(
appCodec,
keys[cointrunkmoduletypes.StoreKey],
Expand All @@ -442,6 +448,7 @@ func New(
app.GetSubspace(burnermoduletypes.ModuleName),
app.BankKeeper,
app.AccountKeeper,
app.EpochsKeeper,
)

app.TokenFactoryKeeper = *tokenfactorykeeper.NewKeeper(
Expand All @@ -463,12 +470,6 @@ func New(
app.DistrKeeper,
)

app.EpochsKeeper = *epochskeeper.NewKeeper(
appCodec,
keys[epochstypes.StoreKey],
keys[epochstypes.MemStoreKey],
)

app.RewardsKeeper = *rewardskeeper.NewKeeper(
appCodec,
keys[rewardstypes.StoreKey],
Expand All @@ -492,6 +493,7 @@ func New(
app.RewardsKeeper.GetUnlockPendingUnlockParticipantsHook(),
app.RewardsKeeper.GetRemoveExpiredPendingTradingRewardsHook(),
app.RewardsKeeper.GetTradingRewardsDistributionHook(),
app.BurnerKeeper.GetBurnerRaffleCleanupHook(),
},
)

Expand Down Expand Up @@ -676,7 +678,7 @@ func New(
app.SetInitChainer(app.InitChainer)
app.SetBeginBlocker(app.BeginBlocker)

anteHandler, err := ante.NewAnteHandler(
anteHandler, err := NewAnteHandler(
ante.HandlerOptions{
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
Expand Down Expand Up @@ -708,32 +710,9 @@ func New(

func (app *App) setupUpgradeHandlers(cfg module.Configurator) {
app.UpgradeKeeper.SetUpgradeHandler(
v700.UpgradeName,
v700.CreateUpgradeHandler(cfg, app.mm),
v710.UpgradeName,
v710.CreateUpgradeHandler(cfg, app.mm),
)

app.UpgradeKeeper.SetUpgradeHandler(
"v7.0.0-rc5",
upgrades.EmptyUpgradeHandler(),
)

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(err)
}

if app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
return
}

if upgradeInfo.Name == v700.UpgradeName {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{tokenfactorytypes.StoreKey, tradebintypes.StoreKey, epochstypes.StoreKey, rewardstypes.StoreKey},
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}

// Name returns the name of the App
Expand Down
18 changes: 18 additions & 0 deletions app/upgrades/v710/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package v710

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const UpgradeName = "v7.1.0"

func CreateUpgradeHandler(
cfg module.Configurator,
mm *module.Manager,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, cfg, vm)
}
}
Loading

0 comments on commit 1dab336

Please sign in to comment.