Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-zq committed Apr 18, 2024
1 parent c4ffb1f commit 0d5b9a3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 15 deletions.
8 changes: 4 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion modules/mint/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "", " ")
Expand Down
3 changes: 1 addition & 2 deletions modules/mint/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
// params store for inflation params
KeyInflation = []byte("Inflation")
KeyMintDenom = []byte("MintDenom")
MintDenom = sdk.DefaultBondDenom
)

// ParamTable for mint module
Expand All @@ -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,
}
}

Expand Down
2 changes: 2 additions & 0 deletions types/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
53 changes: 53 additions & 0 deletions wrapper/farm.go
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 5 additions & 5 deletions modules/token/wrapper.go → wrapper/token.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package token
package wrapper

import (
"context"
Expand Down Expand Up @@ -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}
}

Expand Down Expand Up @@ -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}
}

Expand Down

0 comments on commit 0d5b9a3

Please sign in to comment.