From 0d5b9a3a2a6f69b7f27c1d507184602f1c740fc8 Mon Sep 17 00:00:00 2001 From: dreamer Date: Thu, 18 Apr 2024 17:58:02 +0800 Subject: [PATCH] refactor code --- app/keepers/keepers.go | 8 +-- go.mod | 2 +- go.sum | 4 +- modules/mint/simulation/genesis.go | 2 +- modules/mint/types/params.go | 3 +- types/runtime.go | 2 + wrapper/farm.go | 53 ++++++++++++++++++++ modules/token/wrapper.go => wrapper/token.go | 10 ++-- 8 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 wrapper/farm.go rename modules/token/wrapper.go => wrapper/token.go (89%) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 0597f78b2..579d6ac3a 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -110,8 +110,8 @@ import ( "github.com/irisnet/irishub/v3/modules/internft" mintkeeper "github.com/irisnet/irishub/v3/modules/mint/keeper" minttypes "github.com/irisnet/irishub/v3/modules/mint/types" - iristoken "github.com/irisnet/irishub/v3/modules/token" iristypes "github.com/irisnet/irishub/v3/types" + "github.com/irisnet/irishub/v3/wrapper" ) // AppKeepers defines a structure used to consolidate all @@ -518,7 +518,7 @@ func New( AddRoute(farmtypes.RouterKey, farm.NewCommunityPoolCreateFarmProposalHandler(appKeepers.FarmKeeper)) appKeepers.GovKeeper.SetHooks(govtypes.NewMultiGovHooks( - farmkeeper.NewGovHook(appKeepers.FarmKeeper), + wrapper.NewFarmGovHook(farmkeeper.NewGovHook(appKeepers.FarmKeeper)), )) appKeepers.GovKeeper.SetLegacyRouter(govRouter) @@ -551,8 +551,8 @@ func New( appKeepers.keys[tokentypes.StoreKey], appKeepers.BankKeeper, appKeepers.AccountKeeper, - iristoken.WrapEVMKeeper(appKeepers.EvmKeeper), - iristoken.WrapICS20Keeper(appKeepers.IBCTransferKeeper), + wrapper.NewEVMKeeper(appKeepers.EvmKeeper), + wrapper.NewICS20Keeper(appKeepers.IBCTransferKeeper), authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ).WithSwapRegistry(tokenv1.SwapRegistry{ diff --git a/go.mod b/go.mod index 19f499206..694294842 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/cosmos/iavl v0.20.1 // indirect github.com/cosmos/ibc-go/v7 v7.3.0 github.com/evmos/ethermint v0.22.0 - github.com/irisnet/irismod v1.8.1-0.20240418084635-44011b7a2626 //release/v1.8.0-lsm + github.com/irisnet/irismod v1.8.1-0.20240418095024-5fb0418185bd //release/v1.8.0-lsm ) require ( diff --git a/go.sum b/go.sum index e92711b4b..fcb556c92 100644 --- a/go.sum +++ b/go.sum @@ -846,8 +846,8 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE= github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0= github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po= -github.com/irisnet/irismod v1.8.1-0.20240418084635-44011b7a2626 h1:MH+/S1tunWuoxZ3X4YsnG1LbUw1BHEJcDyFr3wimRGw= -github.com/irisnet/irismod v1.8.1-0.20240418084635-44011b7a2626/go.mod h1:yR/g0kuqqdrUdoXJsRHyajGZxogAJZjRbj8OWEfK9cA= +github.com/irisnet/irismod v1.8.1-0.20240418095024-5fb0418185bd h1:vU9Ui6o0BenMVVkpRmTYdbMkLgqHRmLk7HNDKjVy700= +github.com/irisnet/irismod v1.8.1-0.20240418095024-5fb0418185bd/go.mod h1:TQDhEmxqCIzo7OjyNy//UI0xKDuMtONjoy5LzUeRhVo= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU= diff --git a/modules/mint/simulation/genesis.go b/modules/mint/simulation/genesis.go index 9d18523f4..6bbd698c8 100644 --- a/modules/mint/simulation/genesis.go +++ b/modules/mint/simulation/genesis.go @@ -32,7 +32,7 @@ func RandomizedGenState(simState *module.SimulationState) { func(r *rand.Rand) { inflation = GenInflation(r) }, ) - params := types.Params{Inflation: inflation, MintDenom: types.MintDenom} + params := types.Params{Inflation: inflation, MintDenom: sdk.DefaultBondDenom} mintGenesis := types.NewGenesisState(types.DefaultMinter(), params) bz, err := json.MarshalIndent(&mintGenesis, "", " ") diff --git a/modules/mint/types/params.go b/modules/mint/types/params.go index a7fb4505a..3882ccb70 100644 --- a/modules/mint/types/params.go +++ b/modules/mint/types/params.go @@ -22,7 +22,6 @@ var ( // params store for inflation params KeyInflation = []byte("Inflation") KeyMintDenom = []byte("MintDenom") - MintDenom = sdk.DefaultBondDenom ) // ParamTable for mint module @@ -41,7 +40,7 @@ func NewParams(mintDenom string, inflation sdk.Dec) Params { func DefaultParams() Params { return Params{ Inflation: sdk.NewDecWithPrec(4, 2), - MintDenom: MintDenom, + MintDenom: sdk.DefaultBondDenom, } } diff --git a/types/runtime.go b/types/runtime.go index fb04585c0..99a60c58c 100644 --- a/types/runtime.go +++ b/types/runtime.go @@ -62,6 +62,8 @@ func init() { Mintable: true, Owner: sdk.AccAddress(crypto.AddressHash([]byte(tokentypes.ModuleName))).String(), } + sdk.DefaultBondDenom = NativeToken.MinUnit + userHomeDir, err := os.UserHomeDir() if err != nil { diff --git a/wrapper/farm.go b/wrapper/farm.go new file mode 100644 index 000000000..624b29411 --- /dev/null +++ b/wrapper/farm.go @@ -0,0 +1,53 @@ +package wrapper + +import ( + "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + + farmkeeper "github.com/irisnet/irismod/modules/farm/keeper" +) + +var _ govtypes.GovHooks = farmGovHook{} + +type farmGovHook struct { + gh farmkeeper.GovHook +} + +// NewFarmGovHook creates a new farmGovHook instance. +// +// It takes a parameter of type farmkeeper.GovHook and returns a farmGovHook. +func NewFarmGovHook(gh farmkeeper.GovHook) govtypes.GovHooks { + return farmGovHook{ + gh: gh, + } +} + +// AfterProposalDeposit implements types.GovHooks. +func (f farmGovHook) AfterProposalDeposit(ctx types.Context, proposalID uint64, depositorAddr types.AccAddress) error { + f.gh.AfterProposalDeposit(ctx, proposalID, depositorAddr) + return nil +} + +// AfterProposalFailedMinDeposit implements types.GovHooks. +func (f farmGovHook) AfterProposalFailedMinDeposit(ctx types.Context, proposalID uint64) error { + f.gh.AfterProposalFailedMinDeposit(ctx, proposalID) + return nil +} + +// AfterProposalSubmission implements types.GovHooks. +func (f farmGovHook) AfterProposalSubmission(ctx types.Context, proposalID uint64) error { + f.gh.AfterProposalSubmission(ctx, proposalID) + return nil +} + +// AfterProposalVote implements types.GovHooks. +func (f farmGovHook) AfterProposalVote(ctx types.Context, proposalID uint64, voterAddr types.AccAddress) error { + f.gh.AfterProposalVote(ctx, proposalID,voterAddr) + return nil +} + +// AfterProposalVotingPeriodEnded implements types.GovHooks. +func (f farmGovHook) AfterProposalVotingPeriodEnded(ctx types.Context, proposalID uint64) error { + f.gh.AfterProposalVotingPeriodEnded(ctx, proposalID) + return nil +} diff --git a/modules/token/wrapper.go b/wrapper/token.go similarity index 89% rename from modules/token/wrapper.go rename to wrapper/token.go index 8d330c6f3..e0d87a3f1 100644 --- a/modules/token/wrapper.go +++ b/wrapper/token.go @@ -1,4 +1,4 @@ -package token +package wrapper import ( "context" @@ -27,11 +27,11 @@ var ( _ tokentypes.ICS20Keeper = (*ics20Keeper)(nil) ) -// WrapEVMKeeper wraps the given evmkeeper.Keeper and returns a new evmKeeper. +// NewEVMKeeper wraps the given evmkeeper.Keeper and returns a new evmKeeper. // // ek: The evmkeeper.Keeper to be wrapped. // Returns a pointer to the wrapped evmKeeper. -func WrapEVMKeeper(ek *evmkeeper.Keeper) tokentypes.EVMKeeper { +func NewEVMKeeper(ek *evmkeeper.Keeper) tokentypes.EVMKeeper { return &evmKeeper{ek: ek} } @@ -79,14 +79,14 @@ func (e *evmKeeper) SupportedKey(pubKey cryptotypes.PubKey) bool { return ok } -// WrapICS20Keeper wraps the given ibctransferkeeper.Keeper into an ics20Keeper. +// NewICS20Keeper wraps the given ibctransferkeeper.Keeper into an ics20Keeper. // // Parameters: // - ik: the ibctransferkeeper.Keeper to be wrapped. // // Return: // - *ics20Keeper: the wrapped ics20Keeper. -func WrapICS20Keeper(ik ibctransferkeeper.Keeper) tokentypes.ICS20Keeper { +func NewICS20Keeper(ik ibctransferkeeper.Keeper) tokentypes.ICS20Keeper { return &ics20Keeper{ik: ik} }