From 567cf9b1ae9852a95fc3b57f295396e0dcf5c768 Mon Sep 17 00:00:00 2001 From: xujiacheng Date: Thu, 27 Sep 2018 11:12:56 +0800 Subject: [PATCH 1/2] IRISHUB-475:replace the old iparam with the new iparam --- app/app.go | 15 +- baseapp/fee.go | 24 +- client/gov/cli/query.go | 14 +- cmd/irisdebug/hack.go | 7 +- docs/zh/modules/upgrade/README.md | 13 + modules/gov/genesis.go | 8 +- modules/gov/keeper.go | 6 +- modules/gov/msgs.go | 4 +- modules/gov/params/gov_params.go | 29 +- modules/gov/params/gov_params_test.go | 38 +- modules/gov/proposal_params.go | 4 +- modules/gov/test_common.go | 4 +- modules/{parameter => iparam}/errors.go | 2 +- modules/{parameter => iparam}/helper.go | 2 +- modules/{parameter => iparam}/helper_test.go | 2 +- modules/{parameter => iparam}/parameter.go | 2 +- modules/iparams/getter.go | 523 ------------------- modules/iparams/keeper.go | 92 ---- modules/iparams/keeper_test.go | 280 ---------- modules/iparams/msg_status.go | 36 -- modules/iparams/proxy.go | 24 - modules/iparams/setter.go | 222 -------- modules/upgrade/genesis.go | 6 +- modules/upgrade/params/upgrade_params.go | 6 +- 24 files changed, 83 insertions(+), 1280 deletions(-) create mode 100644 docs/zh/modules/upgrade/README.md rename modules/{parameter => iparam}/errors.go (98%) rename modules/{parameter => iparam}/helper.go (97%) rename modules/{parameter => iparam}/helper_test.go (99%) rename modules/{parameter => iparam}/parameter.go (97%) delete mode 100644 modules/iparams/getter.go delete mode 100644 modules/iparams/keeper.go delete mode 100644 modules/iparams/keeper_test.go delete mode 100644 modules/iparams/msg_status.go delete mode 100644 modules/iparams/proxy.go delete mode 100644 modules/iparams/setter.go diff --git a/app/app.go b/app/app.go index 40278b7b8..f72bd9c30 100644 --- a/app/app.go +++ b/app/app.go @@ -16,8 +16,7 @@ import ( bam "github.com/irisnet/irishub/baseapp" "github.com/irisnet/irishub/modules/gov" "github.com/irisnet/irishub/modules/gov/params" - "github.com/irisnet/irishub/modules/iparams" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" "github.com/irisnet/irishub/modules/upgrade" "github.com/irisnet/irishub/modules/upgrade/params" "github.com/spf13/viper" @@ -73,7 +72,6 @@ type IrisApp struct { slashingKeeper slashing.Keeper paramsKeeper params.Keeper govKeeper gov.Keeper - iparamsKeeper iparams.Keeper upgradeKeeper upgrade.Keeper // fee manager @@ -116,14 +114,13 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio // add handlers app.paramsKeeper = params.NewKeeper(cdc, app.keyParams) - app.iparamsKeeper = iparams.NewKeeper(app.cdc, app.keyIparams) app.coinKeeper = bank.NewKeeper(app.accountMapper) app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace)) app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace)) app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection) app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper) - app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.iparamsKeeper.GovSetter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) + app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) // register message routes // need to update each module's msg type @@ -135,7 +132,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio AddRoute("gov", []*sdk.KVStoreKey{app.keyGov, app.keyAccount, app.keyStake, app.keyIparams, app.keyParams}, gov.NewHandler(app.govKeeper)). AddRoute("upgrade", []*sdk.KVStoreKey{app.keyUpgrade, app.keyStake}, upgrade.NewHandler(app.upgradeKeeper)) - app.feeManager = bam.NewFeeManager(app.iparamsKeeper.GlobalGetter(), app.iparamsKeeper.GovGetter()) + app.feeManager = bam.NewFeeManager(app.paramsKeeper.Setter()) // initialize BaseApp app.SetInitChainer(app.initChainer) app.SetBeginBlocker(app.BeginBlocker) @@ -157,14 +154,14 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio } upgrade.RegisterModuleList(app.Router()) - parameter.SetParamReadWriter(app.paramsKeeper.Setter(), + iparam.SetParamReadWriter(app.paramsKeeper.Setter(), &govparams.DepositProcedureParameter, &govparams.VotingProcedureParameter, &govparams.TallyingProcedureParameter, &upgradeparams.CurrentUpgradeProposalIdParameter, &upgradeparams.ProposalAcceptHeightParameter) - parameter.RegisterGovParamMapping(&govparams.DepositProcedureParameter, + iparam.RegisterGovParamMapping(&govparams.DepositProcedureParameter, &govparams.VotingProcedureParameter, &govparams.TallyingProcedureParameter,) @@ -257,7 +254,7 @@ func (app *IrisApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci GasPriceThreshold: 20000000000, // 20(glue), 20*10^9, 1 glue = 10^9 lue/gas, 1 iris = 10^18 lue } - bam.InitGenesis(ctx, app.iparamsKeeper.GlobalSetter(), app.iparamsKeeper.GovSetter(), feeTokenGensisConfig) + bam.InitGenesis(ctx, app.paramsKeeper.Setter(), feeTokenGensisConfig) // load the address to pubkey map slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.StakeData) diff --git a/baseapp/fee.go b/baseapp/fee.go index 4a8302fdf..0c74e51d1 100644 --- a/baseapp/fee.go +++ b/baseapp/fee.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "errors" "github.com/irisnet/irishub/types" - "github.com/irisnet/irishub/modules/iparams" + "github.com/cosmos/cosmos-sdk/x/params" ) var ( @@ -54,7 +54,7 @@ func NewFeeRefundHandler(am auth.AccountMapper, fck auth.FeeCollectionKeeper, fm } // Refund process will also cost gas, but this is compensation for previous fee deduction. // It is not reasonable to consume users' gas. So the context gas is reset to transaction gas - ctx = ctx.WithGasMeter(sdk.NewGasMeter(stdTx.Fee.Gas)) + ctx = ctx.WithGasMeter(sdk.NewInfiniteGasMeter()) fee := auth.StdFee{ Gas: stdTx.Fee.Gas, @@ -99,19 +99,17 @@ func NewFeeRefundHandler(am auth.AccountMapper, fck auth.FeeCollectionKeeper, fm // FeeManager do fee tokens preprocess according to fee token configuration type FeeManager struct { - globalGetter iparams.GlobalGetter - govGetter iparams.GovGetter + ps params.Setter } -func NewFeeManager(globalGetter iparams.GlobalGetter, govGetter iparams.GovGetter) FeeManager { +func NewFeeManager(ps params.Setter) FeeManager { return FeeManager{ - globalGetter: globalGetter, - govGetter: govGetter, + ps:ps, } } func (fck FeeManager) getNativeFeeToken(ctx sdk.Context, coins sdk.Coins) sdk.Coin { - nativeFeeToken, err := fck.globalGetter.GetString(ctx, nativeFeeTokenKey) + nativeFeeToken, err := fck.ps.GetString(ctx, nativeFeeTokenKey) if err != nil { panic(err) } @@ -127,11 +125,11 @@ func (fck FeeManager) feePreprocess(ctx sdk.Context, coins sdk.Coins, gasLimit i if gasLimit <= 0 { return sdk.ErrInternal(fmt.Sprintf("gaslimit %d should be larger than 0", gasLimit)) } - nativeFeeToken, err := fck.globalGetter.GetString(ctx, nativeFeeTokenKey) + nativeFeeToken, err := fck.ps.GetString(ctx, nativeFeeTokenKey) if err != nil { panic(err) } - nativeGasPriceThreshold, err := fck.govGetter.GetString(ctx, nativeGasPriceThresholdKey) + nativeGasPriceThreshold, err := fck.ps.GetString(ctx, nativeGasPriceThresholdKey) if err != nil { panic(err) } @@ -177,7 +175,7 @@ type FeeGenesisStateConfig struct { GasPriceThreshold int64 `json:"gas_price_threshold"` } -func InitGenesis(ctx sdk.Context, globalSetter iparams.GlobalSetter, govSetter iparams.GovSetter, data FeeGenesisStateConfig) { - globalSetter.SetString(ctx, nativeFeeTokenKey, data.FeeTokenNative) - govSetter.SetString(ctx, nativeGasPriceThresholdKey, sdk.NewInt(data.GasPriceThreshold).String()) +func InitGenesis(ctx sdk.Context, ps params.Setter, data FeeGenesisStateConfig) { + ps.SetString(ctx, nativeFeeTokenKey, data.FeeTokenNative) + ps.SetString(ctx, nativeGasPriceThresholdKey, sdk.NewInt(data.GasPriceThreshold).String()) } diff --git a/client/gov/cli/query.go b/client/gov/cli/query.go index 81d103b00..5dfb52edc 100644 --- a/client/gov/cli/query.go +++ b/client/gov/cli/query.go @@ -9,7 +9,7 @@ import ( govClient "github.com/irisnet/irishub/client/gov" "github.com/irisnet/irishub/modules/gov" "github.com/irisnet/irishub/modules/gov/params" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" "github.com/spf13/cobra" "github.com/spf13/viper" cmn "github.com/tendermint/tendermint/libs/common" @@ -287,17 +287,17 @@ func GetCmdQueryGovConfig(storeName string, cdc *wire.Codec) *cobra.Command { } if keyStr != "" { - parameter.RegisterGovParamMapping(&govparams.DepositProcedureParameter, + iparam.RegisterGovParamMapping(&govparams.DepositProcedureParameter, &govparams.VotingProcedureParameter, &govparams.TallyingProcedureParameter) res, err := ctx.QueryStore([]byte(keyStr), storeName) if err == nil { - if p, ok := parameter.ParamMapping[keyStr]; ok { + if p, ok := iparam.ParamMapping[keyStr]; ok { p.GetValueFromRawData(cdc, res) //.(govparams.TallyingProcedure) PrintParamStr(p, keyStr) } else { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidTallyingProcedure, fmt.Sprintf(keyStr+" is not found")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidTallyingProcedure, fmt.Sprintf(keyStr+" is not found")) } } else { return err @@ -314,7 +314,7 @@ func GetCmdQueryGovConfig(storeName string, cdc *wire.Codec) *cobra.Command { return cmd } -func PrintParamStr(p parameter.GovParameter, keyStr string) { +func PrintParamStr(p iparam.GovParameter, keyStr string) { var param gov.Param param.Key = keyStr param.Value = p.ToJson() @@ -351,7 +351,7 @@ func (pd *ParameterConfigFile) WriteFile(cdc *wire.Codec, res []sdk.KVPair) erro case "Gov/gov/TallyingProcedure": cdc.MustUnmarshalBinary(kv.Value, &pd.Govparams.TallyingProcedure) default: - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidTallyingProcedure, fmt.Sprintf(string(kv.Key)+" is not found")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidTallyingProcedure, fmt.Sprintf(string(kv.Key)+" is not found")) } } output, err := cdc.MarshalJSONIndent(pd, "", " ") @@ -384,7 +384,7 @@ func (pd *ParameterConfigFile) GetParamFromKey(keyStr string, opStr string) (gov case "Gov/gov/TallyingProcedure": jsonBytes, err = json.Marshal(pd.Govparams.TallyingProcedure) default: - return param, sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidTallyingProcedure, fmt.Sprintf(keyStr+" is not found")) + return param, sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidTallyingProcedure, fmt.Sprintf(keyStr+" is not found")) } if err != nil { diff --git a/cmd/irisdebug/hack.go b/cmd/irisdebug/hack.go index de636446f..99cd3cc50 100644 --- a/cmd/irisdebug/hack.go +++ b/cmd/irisdebug/hack.go @@ -28,7 +28,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/stake" iris "github.com/irisnet/irishub/app" - "github.com/irisnet/irishub/modules/iparams" "github.com/irisnet/irishub/modules/upgrade" "github.com/irisnet/irishub/modules/gov" ) @@ -151,7 +150,6 @@ type IrisApp struct { slashingKeeper slashing.Keeper paramsKeeper params.Keeper govKeeper gov.Keeper - iparamsKeeper iparams.Keeper upgradeKeeper upgrade.Keeper // fee manager @@ -189,14 +187,13 @@ func NewIrisApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp // add handlers app.paramsKeeper = params.NewKeeper(cdc, app.keyParams) - app.iparamsKeeper = iparams.NewKeeper(app.cdc, app.keyIparams) app.coinKeeper = bank.NewKeeper(app.accountMapper) app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, app.RegisterCodespace(ibc.DefaultCodespace)) app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.coinKeeper, app.RegisterCodespace(stake.DefaultCodespace)) app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Getter(), app.RegisterCodespace(slashing.DefaultCodespace)) app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(app.cdc, app.keyFeeCollection) - app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper, app.iparamsKeeper.GovSetter()) - app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.iparamsKeeper.GovSetter(), app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) + app.upgradeKeeper = upgrade.NewKeeper(app.cdc, app.keyUpgrade, app.stakeKeeper) + app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.coinKeeper, app.stakeKeeper, app.RegisterCodespace(gov.DefaultCodespace)) // register message routes app.Router(). diff --git a/docs/zh/modules/upgrade/README.md b/docs/zh/modules/upgrade/README.md new file mode 100644 index 000000000..4df273034 --- /dev/null +++ b/docs/zh/modules/upgrade/README.md @@ -0,0 +1,13 @@ +# Upgrade User Guide + +## 基本功能描述 + +## 交互流程 + +### 软件升级提议治理流程 + +### 升级软件流程 + +## 使用场景 + +## 命令详情 \ No newline at end of file diff --git a/modules/gov/genesis.go b/modules/gov/genesis.go index 9efe5fa59..f9a597945 100644 --- a/modules/gov/genesis.go +++ b/modules/gov/genesis.go @@ -3,7 +3,7 @@ package gov import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/irisnet/irishub/modules/gov/params" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" ) // GenesisState - all staking state that must be provided at genesis @@ -31,9 +31,9 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { panic(err) } //k.setDepositProcedure(ctx, data.DepositProcedure) - parameter.InitGenesisParameter(&govparams.DepositProcedureParameter, ctx, data.DepositProcedure) - parameter.InitGenesisParameter(&govparams.VotingProcedureParameter, ctx, data.VotingProcedure) - parameter.InitGenesisParameter(&govparams.TallyingProcedureParameter, ctx, data.TallyingProcedure) + iparam.InitGenesisParameter(&govparams.DepositProcedureParameter, ctx, data.DepositProcedure) + iparam.InitGenesisParameter(&govparams.VotingProcedureParameter, ctx, data.VotingProcedure) + iparam.InitGenesisParameter(&govparams.TallyingProcedureParameter, ctx, data.TallyingProcedure) } diff --git a/modules/gov/keeper.go b/modules/gov/keeper.go index fc15f2208..77a0c0efb 100644 --- a/modules/gov/keeper.go +++ b/modules/gov/keeper.go @@ -5,15 +5,12 @@ import ( "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/bank" "github.com/irisnet/irishub/modules/gov/params" - "github.com/irisnet/irishub/modules/iparams" ) // nolint // Governance Keeper type Keeper struct { - // The reference to the ParamSetter to get and set Global Params - ps iparams.GovSetter // The reference to the CoinKeeper to modify balances ck bank.Keeper @@ -35,10 +32,9 @@ type Keeper struct { } // NewGovernanceMapper returns a mapper that uses go-wire to (binary) encode and decode gov types. -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ps iparams.GovSetter, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { +func NewKeeper(cdc *wire.Codec, key sdk.StoreKey, ck bank.Keeper, ds sdk.DelegationSet, codespace sdk.CodespaceType) Keeper { return Keeper{ storeKey: key, - ps: ps, ck: ck, ds: ds, vs: ds.GetValidatorSet(), diff --git a/modules/gov/msgs.go b/modules/gov/msgs.go index 7d01b63c8..ea3048af6 100644 --- a/modules/gov/msgs.go +++ b/modules/gov/msgs.go @@ -4,7 +4,7 @@ import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" ) // name to idetify transaction types @@ -58,7 +58,7 @@ func (msg MsgSubmitProposal) ValidateBasic() sdk.Error { if msg.ProposalType == ProposalTypeParameterChange { - if p, ok := parameter.ParamMapping[msg.Param.Key]; ok{ + if p, ok := iparam.ParamMapping[msg.Param.Key]; ok{ return p.Valid(msg.Param.Value) } else { return ErrInvalidParam(DefaultCodespace) diff --git a/modules/gov/params/gov_params.go b/modules/gov/params/gov_params.go index 12298c580..9b418e388 100644 --- a/modules/gov/params/gov_params.go +++ b/modules/gov/params/gov_params.go @@ -6,9 +6,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" "github.com/irisnet/irishub/types" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" "github.com/cosmos/cosmos-sdk/wire" - "strconv" ) @@ -22,7 +21,7 @@ var ( const LOWER_BOUND_AMOUNT = 1 const UPPER_BOUND_AMOUNT = 200 -var _ parameter.GovParameter = (*DepositProcedureParam)(nil) +var _ iparam.GovParameter = (*DepositProcedureParam)(nil) type ParamSet struct { DepositProcedure DepositProcedure `json:"Gov/gov/DepositProcedure"` @@ -96,30 +95,30 @@ func (param *DepositProcedureParam) Valid(jsonStr string) sdk.Error { if err = json.Unmarshal([]byte(jsonStr), ¶m.Value); err == nil { if param.Value.MinDeposit[0].Denom != "iris-atto" { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidMinDepositDenom, fmt.Sprintf("It should be iris-atto! git")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidMinDepositDenom, fmt.Sprintf("It should be iris-atto! git")) } LowerBound, _ := types.NewDefaultCoinType("iris").ConvertToMinCoin(fmt.Sprintf("%d%s", LOWER_BOUND_AMOUNT, "iris")) UpperBound, _ := types.NewDefaultCoinType("iris").ConvertToMinCoin(fmt.Sprintf("%d%s", UPPER_BOUND_AMOUNT, "iris")) if param.Value.MinDeposit[0].Amount.LT(LowerBound.Amount) || param.Value.MinDeposit[0].Amount.GT(UpperBound.Amount) { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidMinDepositAmount, fmt.Sprintf("MinDepositAmount"+param.Value.MinDeposit[0].String()+" should be larger than 10 and less than 20000")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidMinDepositAmount, fmt.Sprintf("MinDepositAmount"+param.Value.MinDeposit[0].String()+" should be larger than 10 and less than 20000")) } if param.Value.MaxDepositPeriod < 20 || param.Value.MaxDepositPeriod > 20000 { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidDepositPeriod, fmt.Sprintf("MaxDepositPeriod ("+strconv.Itoa(int(param.Value.MaxDepositPeriod))+") should be larger than 20 and less than 20000")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidDepositPeriod, fmt.Sprintf("MaxDepositPeriod ("+strconv.Itoa(int(param.Value.MaxDepositPeriod))+") should be larger than 20 and less than 20000")) } return nil } - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidMinDeposit, fmt.Sprintf("Json is not valid")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidMinDeposit, fmt.Sprintf("Json is not valid")) } var VotingProcedureParameter VotingProcedureParam -var _ parameter.GovParameter = (*VotingProcedureParam)(nil) +var _ iparam.GovParameter = (*VotingProcedureParam)(nil) // Procedure around Voting in governance type VotingProcedure struct { @@ -184,17 +183,17 @@ func (param *VotingProcedureParam) Valid(jsonStr string) sdk.Error { if err = json.Unmarshal([]byte(jsonStr), ¶m.Value); err == nil { if param.Value.VotingPeriod < 20 || param.Value.VotingPeriod > 20000 { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidVotingPeriod, fmt.Sprintf("VotingPeriod ("+strconv.Itoa(int(param.Value.VotingPeriod))+") should be larger than 20 and less than 20000")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidVotingPeriod, fmt.Sprintf("VotingPeriod ("+strconv.Itoa(int(param.Value.VotingPeriod))+") should be larger than 20 and less than 20000")) } return nil } - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidVotingProcedure, fmt.Sprintf("Json is not valid")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidVotingProcedure, fmt.Sprintf("Json is not valid")) } var TallyingProcedureParameter TallyingProcedureParam -var _ parameter.GovParameter = (*TallyingProcedureParam)(nil) +var _ iparam.GovParameter = (*TallyingProcedureParam)(nil) // Procedure around Tallying votes in governance type TallyingProcedure struct { @@ -266,19 +265,19 @@ func (param *TallyingProcedureParam) Valid(jsonStr string) sdk.Error { if err = json.Unmarshal([]byte(jsonStr), ¶m.Value); err == nil { if param.Value.Threshold.LT(sdk.NewRat(0)) || param.Value.Threshold.GT(sdk.NewRat(1)) { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidThreshold, fmt.Sprintf("VotingPeriod ( "+param.Value.Threshold.String()+" ) should be between 0 and 1")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidThreshold, fmt.Sprintf("VotingPeriod ( "+param.Value.Threshold.String()+" ) should be between 0 and 1")) } if param.Value.GovernancePenalty.LT(sdk.NewRat(0)) || param.Value.GovernancePenalty.GT(sdk.NewRat(1)) { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidGovernancePenalty, fmt.Sprintf("VotingPeriod ( "+param.Value.GovernancePenalty.String()+" ) should be between 0 and 1")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidGovernancePenalty, fmt.Sprintf("VotingPeriod ( "+param.Value.GovernancePenalty.String()+" ) should be between 0 and 1")) } if param.Value.Veto.LT(sdk.NewRat(0)) || param.Value.Veto.GT(sdk.NewRat(1)) { - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidVeto, fmt.Sprintf("VotingPeriod ( "+param.Value.Veto.String()+" ) should be between 0 and 1")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidVeto, fmt.Sprintf("VotingPeriod ( "+param.Value.Veto.String()+" ) should be between 0 and 1")) } return nil } - return sdk.NewError(parameter.DefaultCodespace, parameter.CodeInvalidTallyingProcedure, fmt.Sprintf("Json is not valid")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidTallyingProcedure, fmt.Sprintf("Json is not valid")) } diff --git a/modules/gov/params/gov_params_test.go b/modules/gov/params/gov_params_test.go index b26351edd..4129a3c3f 100644 --- a/modules/gov/params/gov_params_test.go +++ b/modules/gov/params/gov_params_test.go @@ -55,35 +55,9 @@ func TestDepositProcedureParam(t *testing.T) { result := DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"atom\",\"amount\":\"200000000000000000000\"}],\"max_deposit_period\":1440}") require.Error(t, result) - DepositProcedureParameter.InitGenesis(p2) - require.Equal(t, p2, DepositProcedureParameter.Value) - DepositProcedureParameter.InitGenesis(p1) - require.Equal(t, p1, DepositProcedureParameter.Value) - - DepositProcedureParameter.LoadValue(ctx) - require.Equal(t, p2, DepositProcedureParameter.Value) - -} - -func TestDepositProcedureParamValid(t *testing.T) { - skey := sdk.NewKVStoreKey("params") - ctx := defaultContext(skey) - paramKeeper := params.NewKeeper(wire.NewCodec(), skey) - - p1deposit, _ := types.NewDefaultCoinType("iris").ConvertToMinCoin(fmt.Sprintf("%d%s", 10, "iris")) - p1 := DepositProcedure{ - MinDeposit: sdk.Coins{p1deposit}, - MaxDepositPeriod: 1440} - - DepositProcedureParameter.SetReadWriter(paramKeeper.Setter()) - find := DepositProcedureParameter.LoadValue(ctx) - require.Equal(t, find, false) - - DepositProcedureParameter.InitGenesis(nil) - require.Equal(t, p1, DepositProcedureParameter.Value) - - result := DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"iris-atto\",\"amount\":\"2000000000000000000\"}],\"max_deposit_period\":1440}") + result = DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"iris-atto\",\"amount\":\"2000000000000000000\"}],\"max_deposit_period\":1440}") require.NoError(t, result) + result = DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"iris-atto\",\"amount\":\"2000000000000000000000\"}],\"max_deposit_period\":1440}") require.Error(t, result) result = DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"iris-atto\",\"amount\":\"200000000000000000\"}],\"max_deposit_period\":1440}") @@ -101,6 +75,14 @@ func TestDepositProcedureParamValid(t *testing.T) { result = DepositProcedureParameter.Valid("{\"min_deposit\":[{\"denom\":\"iris-atto\",\"amount\":\"2000000000000000000\"}],\"max_deposit_period\":1440000}") require.Error(t, result) + DepositProcedureParameter.InitGenesis(p2) + require.Equal(t, p2, DepositProcedureParameter.Value) + DepositProcedureParameter.InitGenesis(p1) + require.Equal(t, p1, DepositProcedureParameter.Value) + + DepositProcedureParameter.LoadValue(ctx) + require.Equal(t, p2, DepositProcedureParameter.Value) + } func TestVotingProcedureParam(t *testing.T) { diff --git a/modules/gov/proposal_params.go b/modules/gov/proposal_params.go index 70ddaa5e2..3c27741ec 100644 --- a/modules/gov/proposal_params.go +++ b/modules/gov/proposal_params.go @@ -3,7 +3,7 @@ package gov import ( "fmt" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" ) const ( @@ -30,7 +30,7 @@ func (pp *ParameterProposal) Execute(ctx sdk.Context, k Keeper) (err error) { logger := ctx.Logger().With("module", "x/gov") logger.Info("Execute ParameterProposal begin", "info", fmt.Sprintf("current height:%d", ctx.BlockHeight())) if pp.Param.Op == Update { - parameter.ParamMapping[pp.Param.Key].Update(ctx, pp.Param.Value) + iparam.ParamMapping[pp.Param.Key].Update(ctx, pp.Param.Value) } else if pp.Param.Op == Insert { //Todo: insert } diff --git a/modules/gov/test_common.go b/modules/gov/test_common.go index a33150b0b..c993d7392 100644 --- a/modules/gov/test_common.go +++ b/modules/gov/test_common.go @@ -16,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/mock" "github.com/cosmos/cosmos-sdk/x/stake" "github.com/irisnet/irishub/modules/gov/params" - "github.com/irisnet/irishub/modules/iparams" "github.com/irisnet/irishub/types" ) @@ -31,10 +30,9 @@ func getMockApp(t *testing.T, numGenAccs int) (*mock.App, Keeper, stake.Keeper, keyStake := sdk.NewKVStoreKey("stake") keyGov := sdk.NewKVStoreKey("gov") - pk := iparams.NewKeeper(mapp.Cdc, keyGlobalParams) ck := bank.NewKeeper(mapp.AccountMapper) sk := stake.NewKeeper(mapp.Cdc, keyStake, ck, mapp.RegisterCodespace(stake.DefaultCodespace)) - keeper := NewKeeper(mapp.Cdc, keyGov, pk.GovSetter(), ck, sk, DefaultCodespace) + keeper := NewKeeper(mapp.Cdc, keyGov, ck, sk, DefaultCodespace) mapp.Router().AddRoute("gov", NewHandler(keeper)) mapp.SetEndBlocker(getEndBlocker(keeper)) diff --git a/modules/parameter/errors.go b/modules/iparam/errors.go similarity index 98% rename from modules/parameter/errors.go rename to modules/iparam/errors.go index 892d6b259..2a72be310 100644 --- a/modules/parameter/errors.go +++ b/modules/iparam/errors.go @@ -1,4 +1,4 @@ -package parameter +package iparam import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/modules/parameter/helper.go b/modules/iparam/helper.go similarity index 97% rename from modules/parameter/helper.go rename to modules/iparam/helper.go index 65d0c5c83..fe71c785b 100644 --- a/modules/parameter/helper.go +++ b/modules/iparam/helper.go @@ -1,4 +1,4 @@ -package parameter +package iparam import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/modules/parameter/helper_test.go b/modules/iparam/helper_test.go similarity index 99% rename from modules/parameter/helper_test.go rename to modules/iparam/helper_test.go index 6325d333b..d34c551e9 100644 --- a/modules/parameter/helper_test.go +++ b/modules/iparam/helper_test.go @@ -1,4 +1,4 @@ -package parameter +package iparam import ( "github.com/cosmos/cosmos-sdk/store" diff --git a/modules/parameter/parameter.go b/modules/iparam/parameter.go similarity index 97% rename from modules/parameter/parameter.go rename to modules/iparam/parameter.go index 90f4d35f6..b32cb98ee 100644 --- a/modules/parameter/parameter.go +++ b/modules/iparam/parameter.go @@ -1,4 +1,4 @@ -package parameter +package iparam import ( sdk "github.com/cosmos/cosmos-sdk/types" diff --git a/modules/iparams/getter.go b/modules/iparams/getter.go deleted file mode 100644 index 73228a244..000000000 --- a/modules/iparams/getter.go +++ /dev/null @@ -1,523 +0,0 @@ -package iparams - -import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" - "strings" -) - -type Getter interface { - Get(ctx sdk.Context, key string, ptr interface{}) error - GetRaw(ctx sdk.Context, key string) []byte - GetString(ctx sdk.Context, key string) (res string, err error) - GetBoolWithDefault(ctx sdk.Context, key string, def bool) (res bool) -} - -// Getter exposes methods related with only getting params -type GlobalGetter struct { - k Keeper -} - -type GovGetter struct { - k Keeper -} - -func getGlobalStoreKey(key string) string { - if strings.HasPrefix(key, Global+"/") { - return key - } - return fmt.Sprintf("%s/%s", Global, key) -} - -func getGovStoreKey(key string) string { - if strings.HasPrefix(key, Gov+"/") { - return key - } - return fmt.Sprintf("%s/%s", Gov, key) -} - -// Get exposes get -func (k GlobalGetter) Get(ctx sdk.Context, key string, ptr interface{}) error { - key = getGlobalStoreKey(key) - return k.k.get(ctx, key, ptr) -} - -// GetRaw exposes getRaw -func (k GlobalGetter) GetRaw(ctx sdk.Context, key string) []byte { - key = getGlobalStoreKey(key) - return k.k.getRaw(ctx, key) -} - -// GetString is helper function for string params -func (k GlobalGetter) GetString(ctx sdk.Context, key string) (res string, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetBool is helper function for bool params -func (k GlobalGetter) GetBool(ctx sdk.Context, key string) (res bool, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt16 is helper function for int16 params -func (k GlobalGetter) GetInt16(ctx sdk.Context, key string) (res int16, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt32 is helper function for int32 params -func (k GlobalGetter) GetInt32(ctx sdk.Context, key string) (res int32, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt64 is helper function for int64 params -func (k GlobalGetter) GetInt64(ctx sdk.Context, key string) (res int64, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint16 is helper function for uint16 params -func (k GlobalGetter) GetUint16(ctx sdk.Context, key string) (res uint16, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint32 is helper function for uint32 params -func (k GlobalGetter) GetUint32(ctx sdk.Context, key string) (res uint32, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint64 is helper function for uint64 params -func (k GlobalGetter) GetUint64(ctx sdk.Context, key string) (res uint64, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt is helper function for sdk.Int params -func (k GlobalGetter) GetInt(ctx sdk.Context, key string) (res sdk.Int, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint is helper function for sdk.Uint params -func (k GlobalGetter) GetUint(ctx sdk.Context, key string) (res sdk.Uint, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetRat is helper function for rat params -func (k GlobalGetter) GetRat(ctx sdk.Context, key string) (res sdk.Rat, err error) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetStringWithDefault is helper function for string params with default value -func (k GlobalGetter) GetStringWithDefault(ctx sdk.Context, key string, def string) (res string) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetBoolWithDefault is helper function for bool params with default value -func (k GlobalGetter) GetBoolWithDefault(ctx sdk.Context, key string, def bool) (res bool) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt16WithDefault is helper function for int16 params with default value -func (k GlobalGetter) GetInt16WithDefault(ctx sdk.Context, key string, def int16) (res int16) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt32WithDefault is helper function for int32 params with default value -func (k GlobalGetter) GetInt32WithDefault(ctx sdk.Context, key string, def int32) (res int32) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt64WithDefault is helper function for int64 params with default value -func (k GlobalGetter) GetInt64WithDefault(ctx sdk.Context, key string, def int64) (res int64) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint16WithDefault is helper function for uint16 params with default value -func (k GlobalGetter) GetUint16WithDefault(ctx sdk.Context, key string, def uint16) (res uint16) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint32WithDefault is helper function for uint32 params with default value -func (k GlobalGetter) GetUint32WithDefault(ctx sdk.Context, key string, def uint32) (res uint32) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint64WithDefault is helper function for uint64 params with default value -func (k GlobalGetter) GetUint64WithDefault(ctx sdk.Context, key string, def uint64) (res uint64) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetIntWithDefault is helper function for sdk.Int params with default value -func (k GlobalGetter) GetIntWithDefault(ctx sdk.Context, key string, def sdk.Int) (res sdk.Int) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUintWithDefault is helper function for sdk.Uint params with default value -func (k GlobalGetter) GetUintWithDefault(ctx sdk.Context, key string, def sdk.Uint) (res sdk.Uint) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetRatWithDefault is helper function for sdk.Rat params with default value -func (k GlobalGetter) GetRatWithDefault(ctx sdk.Context, key string, def sdk.Rat) (res sdk.Rat) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// Get exposes get -func (k GovGetter) Get(ctx sdk.Context, key string, ptr interface{}) error { - key = getGovStoreKey(key) - return k.k.get(ctx, key, ptr) -} - -// GetRaw exposes getRaw -func (k GovGetter) GetRaw(ctx sdk.Context, key string) []byte { - key = getGovStoreKey(key) - return k.k.getRaw(ctx, key) -} - -// GetString is helper function for string params -func (k GovGetter) GetString(ctx sdk.Context, key string) (res string, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetBool is helper function for bool params -func (k GovGetter) GetBool(ctx sdk.Context, key string) (res bool, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt16 is helper function for int16 params -func (k GovGetter) GetInt16(ctx sdk.Context, key string) (res int16, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt32 is helper function for int32 params -func (k GovGetter) GetInt32(ctx sdk.Context, key string) (res int32, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt64 is helper function for int64 params -func (k GovGetter) GetInt64(ctx sdk.Context, key string) (res int64, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint16 is helper function for uint16 params -func (k GovGetter) GetUint16(ctx sdk.Context, key string) (res uint16, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint32 is helper function for uint32 params -func (k GovGetter) GetUint32(ctx sdk.Context, key string) (res uint32, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint64 is helper function for uint64 params -func (k GovGetter) GetUint64(ctx sdk.Context, key string) (res uint64, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetInt is helper function for sdk.Int params -func (k GovGetter) GetInt(ctx sdk.Context, key string) (res sdk.Int, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetUint is helper function for sdk.Uint params -func (k GovGetter) GetUint(ctx sdk.Context, key string) (res sdk.Uint, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetRat is helper function for rat params -func (k GovGetter) GetRat(ctx sdk.Context, key string) (res sdk.Rat, err error) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - err = k.k.cdc.UnmarshalBinary(bz, &res) - return -} - -// GetStringWithDefault is helper function for string params with default value -func (k GovGetter) GetStringWithDefault(ctx sdk.Context, key string, def string) (res string) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetBoolWithDefault is helper function for bool params with default value -func (k GovGetter) GetBoolWithDefault(ctx sdk.Context, key string, def bool) (res bool) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt16WithDefault is helper function for int16 params with default value -func (k GovGetter) GetInt16WithDefault(ctx sdk.Context, key string, def int16) (res int16) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt32WithDefault is helper function for int32 params with default value -func (k GovGetter) GetInt32WithDefault(ctx sdk.Context, key string, def int32) (res int32) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetInt64WithDefault is helper function for int64 params with default value -func (k GovGetter) GetInt64WithDefault(ctx sdk.Context, key string, def int64) (res int64) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint16WithDefault is helper function for uint16 params with default value -func (k GovGetter) GetUint16WithDefault(ctx sdk.Context, key string, def uint16) (res uint16) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint32WithDefault is helper function for uint32 params with default value -func (k GovGetter) GetUint32WithDefault(ctx sdk.Context, key string, def uint32) (res uint32) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUint64WithDefault is helper function for uint64 params with default value -func (k GovGetter) GetUint64WithDefault(ctx sdk.Context, key string, def uint64) (res uint64) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetIntWithDefault is helper function for sdk.Int params with default value -func (k GovGetter) GetIntWithDefault(ctx sdk.Context, key string, def sdk.Int) (res sdk.Int) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetUintWithDefault is helper function for sdk.Uint params with default value -func (k GovGetter) GetUintWithDefault(ctx sdk.Context, key string, def sdk.Uint) (res sdk.Uint) { - key = getGovStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} - -// GetRatWithDefault is helper function for sdk.Rat params with default value -func (k GovGetter) GetRatWithDefault(ctx sdk.Context, key string, def sdk.Rat) (res sdk.Rat) { - key = getGlobalStoreKey(key) - store := ctx.KVStore(k.k.key) - bz := store.Get([]byte(key)) - if bz == nil { - return def - } - k.k.cdc.MustUnmarshalBinary(bz, &res) - return -} diff --git a/modules/iparams/keeper.go b/modules/iparams/keeper.go deleted file mode 100644 index efc9f317a..000000000 --- a/modules/iparams/keeper.go +++ /dev/null @@ -1,92 +0,0 @@ -package iparams - -import ( - "fmt" - "reflect" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" -) - -// Keeper manages global parameter store -type Keeper struct { - cdc *wire.Codec - key sdk.StoreKey -} - -// NewKeeper constructs a new Keeper -func NewKeeper(cdc *wire.Codec, key sdk.StoreKey) Keeper { - return Keeper{ - cdc: cdc, - key: key, - } -} - -// InitKeeper constructs a new Keeper with initial parameters -func InitKeeper(ctx sdk.Context, cdc *wire.Codec, key sdk.StoreKey, params ...interface{}) Keeper { - if len(params)%2 != 0 { - panic("Odd params list length for InitKeeper") - } - - k := NewKeeper(cdc, key) - - for i := 0; i < len(params); i += 2 { - k.set(ctx, params[i].(string), params[i+1]) - } - - return k -} - -// get automatically unmarshalls parameter to pointer -func (k Keeper) get(ctx sdk.Context, key string, ptr interface{}) error { - store := ctx.KVStore(k.key) - bz := store.Get([]byte(key)) - return k.cdc.UnmarshalBinary(bz, ptr) -} - -// getRaw returns raw byte slice -func (k Keeper) getRaw(ctx sdk.Context, key string) []byte { - store := ctx.KVStore(k.key) - return store.Get([]byte(key)) -} - -// set automatically marshalls and type check parameter -func (k Keeper) set(ctx sdk.Context, key string, param interface{}) error { - store := ctx.KVStore(k.key) - bz := store.Get([]byte(key)) - if bz != nil { - ptrty := reflect.PtrTo(reflect.TypeOf(param)) - ptr := reflect.New(ptrty).Interface() - - if k.cdc.UnmarshalBinary(bz, ptr) != nil { - return fmt.Errorf("Type mismatch with stored param and provided param") - } - } - - bz, err := k.cdc.MarshalBinary(param) - if err != nil { - return err - } - store.Set([]byte(key), bz) - - return nil -} - -// setRaw sets raw byte slice -func (k Keeper) setRaw(ctx sdk.Context, key string, param []byte) { - store := ctx.KVStore(k.key) - store.Set([]byte(key), param) -} - -//// Getter returns readonly struct -//func (k Keeper) Getter() Getter { -// return Getter{k} -//} -// -//// Setter returns read/write struct -//func (k Keeper) Setter() Setter { -// return Setter{Getter{k}} -//} - - - diff --git a/modules/iparams/keeper_test.go b/modules/iparams/keeper_test.go deleted file mode 100644 index fa747690f..000000000 --- a/modules/iparams/keeper_test.go +++ /dev/null @@ -1,280 +0,0 @@ -package iparams - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - abci "github.com/tendermint/tendermint/abci/types" - dbm "github.com/tendermint/tendermint/libs/db" - "github.com/tendermint/tendermint/libs/log" - - "github.com/cosmos/cosmos-sdk/store" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" -) - -func defaultContext(key sdk.StoreKey) sdk.Context { - db := dbm.NewMemDB() - cms := store.NewCommitMultiStore(db) - cms.MountStoreWithDB(key, sdk.StoreTypeIAVL, db) - cms.LoadLatestVersion() - ctx := sdk.NewContext(cms, abci.Header{}, false, log.NewNopLogger()) - return ctx -} - -func TestKeeper(t *testing.T) { - kvs := []struct { - key string - param int64 - }{ - {"key1", 10}, - {"key2", 55}, - {"key3", 182}, - {"key4", 17582}, - {"key5", 2768554}, - } - - skey := sdk.NewKVStoreKey("test") - ctx := defaultContext(skey) - setter := NewKeeper(wire.NewCodec(), skey).Setter() - - for _, kv := range kvs { - err := setter.Set(ctx, kv.key, kv.param) - assert.Nil(t, err) - } - - for _, kv := range kvs { - var param int64 - err := setter.Get(ctx, kv.key, ¶m) - assert.Nil(t, err) - assert.Equal(t, kv.param, param) - } - - cdc := wire.NewCodec() - for _, kv := range kvs { - var param int64 - bz := setter.GetRaw(ctx, kv.key) - err := cdc.UnmarshalBinary(bz, ¶m) - assert.Nil(t, err) - assert.Equal(t, kv.param, param) - } - - for _, kv := range kvs { - var param bool - err := setter.Get(ctx, kv.key, ¶m) - assert.NotNil(t, err) - } - - for _, kv := range kvs { - err := setter.Set(ctx, kv.key, true) - assert.NotNil(t, err) - } -} - -func TestGetter(t *testing.T) { - key := sdk.NewKVStoreKey("test") - ctx := defaultContext(key) - keeper := NewKeeper(wire.NewCodec(), key) - - g := keeper.Getter() - s := keeper.Setter() - - kvs := []struct { - key string - param interface{} - }{ - {"string", "test"}, - {"bool", true}, - {"int16", int16(1)}, - {"int32", int32(1)}, - {"int64", int64(1)}, - {"uint16", uint16(1)}, - {"uint32", uint32(1)}, - {"uint64", uint64(1)}, - {"int", sdk.NewInt(1)}, - {"uint", sdk.NewUint(1)}, - {"rat", sdk.NewRat(1)}, - } - - assert.NotPanics(t, func() { s.SetString(ctx, kvs[0].key, "test") }) - assert.NotPanics(t, func() { s.SetBool(ctx, kvs[1].key, true) }) - assert.NotPanics(t, func() { s.SetInt16(ctx, kvs[2].key, int16(1)) }) - assert.NotPanics(t, func() { s.SetInt32(ctx, kvs[3].key, int32(1)) }) - assert.NotPanics(t, func() { s.SetInt64(ctx, kvs[4].key, int64(1)) }) - assert.NotPanics(t, func() { s.SetUint16(ctx, kvs[5].key, uint16(1)) }) - assert.NotPanics(t, func() { s.SetUint32(ctx, kvs[6].key, uint32(1)) }) - assert.NotPanics(t, func() { s.SetUint64(ctx, kvs[7].key, uint64(1)) }) - assert.NotPanics(t, func() { s.SetInt(ctx, kvs[8].key, sdk.NewInt(1)) }) - assert.NotPanics(t, func() { s.SetUint(ctx, kvs[9].key, sdk.NewUint(1)) }) - assert.NotPanics(t, func() { s.SetRat(ctx, kvs[10].key, sdk.NewRat(1)) }) - - var res interface{} - var err error - - // String - def0 := "default" - res, err = g.GetString(ctx, kvs[0].key) - assert.Nil(t, err) - assert.Equal(t, kvs[0].param, res) - - _, err = g.GetString(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetStringWithDefault(ctx, kvs[0].key, def0) - assert.Equal(t, kvs[0].param, res) - - res = g.GetStringWithDefault(ctx, "invalid", def0) - assert.Equal(t, def0, res) - - // Bool - def1 := false - res, err = g.GetBool(ctx, kvs[1].key) - assert.Nil(t, err) - assert.Equal(t, kvs[1].param, res) - - _, err = g.GetBool(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetBoolWithDefault(ctx, kvs[1].key, def1) - assert.Equal(t, kvs[1].param, res) - - res = g.GetBoolWithDefault(ctx, "invalid", def1) - assert.Equal(t, def1, res) - - // Int16 - def2 := int16(0) - res, err = g.GetInt16(ctx, kvs[2].key) - assert.Nil(t, err) - assert.Equal(t, kvs[2].param, res) - - _, err = g.GetInt16(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetInt16WithDefault(ctx, kvs[2].key, def2) - assert.Equal(t, kvs[2].param, res) - - res = g.GetInt16WithDefault(ctx, "invalid", def2) - assert.Equal(t, def2, res) - - // Int32 - def3 := int32(0) - res, err = g.GetInt32(ctx, kvs[3].key) - assert.Nil(t, err) - assert.Equal(t, kvs[3].param, res) - - _, err = g.GetInt32(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetInt32WithDefault(ctx, kvs[3].key, def3) - assert.Equal(t, kvs[3].param, res) - - res = g.GetInt32WithDefault(ctx, "invalid", def3) - assert.Equal(t, def3, res) - - // Int64 - def4 := int64(0) - res, err = g.GetInt64(ctx, kvs[4].key) - assert.Nil(t, err) - assert.Equal(t, kvs[4].param, res) - - _, err = g.GetInt64(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetInt64WithDefault(ctx, kvs[4].key, def4) - assert.Equal(t, kvs[4].param, res) - - res = g.GetInt64WithDefault(ctx, "invalid", def4) - assert.Equal(t, def4, res) - - // Uint16 - def5 := uint16(0) - res, err = g.GetUint16(ctx, kvs[5].key) - assert.Nil(t, err) - assert.Equal(t, kvs[5].param, res) - - _, err = g.GetUint16(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetUint16WithDefault(ctx, kvs[5].key, def5) - assert.Equal(t, kvs[5].param, res) - - res = g.GetUint16WithDefault(ctx, "invalid", def5) - assert.Equal(t, def5, res) - - // Uint32 - def6 := uint32(0) - res, err = g.GetUint32(ctx, kvs[6].key) - assert.Nil(t, err) - assert.Equal(t, kvs[6].param, res) - - _, err = g.GetUint32(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetUint32WithDefault(ctx, kvs[6].key, def6) - assert.Equal(t, kvs[6].param, res) - - res = g.GetUint32WithDefault(ctx, "invalid", def6) - assert.Equal(t, def6, res) - - // Uint64 - def7 := uint64(0) - res, err = g.GetUint64(ctx, kvs[7].key) - assert.Nil(t, err) - assert.Equal(t, kvs[7].param, res) - - _, err = g.GetUint64(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetUint64WithDefault(ctx, kvs[7].key, def7) - assert.Equal(t, kvs[7].param, res) - - res = g.GetUint64WithDefault(ctx, "invalid", def7) - assert.Equal(t, def7, res) - - // Int - def8 := sdk.NewInt(0) - res, err = g.GetInt(ctx, kvs[8].key) - assert.Nil(t, err) - assert.Equal(t, kvs[8].param, res) - - _, err = g.GetInt(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetIntWithDefault(ctx, kvs[8].key, def8) - assert.Equal(t, kvs[8].param, res) - - res = g.GetIntWithDefault(ctx, "invalid", def8) - assert.Equal(t, def8, res) - - // Uint - def9 := sdk.NewUint(0) - res, err = g.GetUint(ctx, kvs[9].key) - assert.Nil(t, err) - assert.Equal(t, kvs[9].param, res) - - _, err = g.GetUint(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetUintWithDefault(ctx, kvs[9].key, def9) - assert.Equal(t, kvs[9].param, res) - - res = g.GetUintWithDefault(ctx, "invalid", def9) - assert.Equal(t, def9, res) - - // Rat - def10 := sdk.NewRat(0) - res, err = g.GetRat(ctx, kvs[10].key) - assert.Nil(t, err) - assert.Equal(t, kvs[10].param, res) - - _, err = g.GetRat(ctx, "invalid") - assert.NotNil(t, err) - - res = g.GetRatWithDefault(ctx, kvs[10].key, def10) - assert.Equal(t, kvs[10].param, res) - - res = g.GetRatWithDefault(ctx, "invalid", def10) - assert.Equal(t, def10, res) - -} diff --git a/modules/iparams/msg_status.go b/modules/iparams/msg_status.go deleted file mode 100644 index c90da64b7..000000000 --- a/modules/iparams/msg_status.go +++ /dev/null @@ -1,36 +0,0 @@ -package iparams - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -// GenesisState defines initial activated msg types -type GenesisState struct { - ActivatedTypes []string `json:"activated-types"` -} - -// ActivatedParamKey - paramstore key for msg type activation -func ActivatedParamKey(ty string) string { - return "Activated/" + ty -} - -// InitGenesis stores activated type to param store -func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) { - for _, ty := range data.ActivatedTypes { - k.set(ctx, ActivatedParamKey(ty), true) - } -} - -// NewAnteHandler returns an AnteHandler that checks -// whether msg type is activate or not -func NewAnteHandler(k Keeper) sdk.AnteHandler { - return func(ctx sdk.Context, tx sdk.Tx) (sdk.Context, sdk.Result, bool) { - for _, msg := range tx.GetMsgs() { - ok := k.GlobalGetter().GetBoolWithDefault(ctx, ActivatedParamKey(msg.Type()), false) - if !ok { - return ctx, sdk.ErrUnauthorized("deactivated msg type").Result(), true - } - } - return ctx, sdk.Result{}, false - } -} diff --git a/modules/iparams/proxy.go b/modules/iparams/proxy.go deleted file mode 100644 index c87181ab2..000000000 --- a/modules/iparams/proxy.go +++ /dev/null @@ -1,24 +0,0 @@ -package iparams - -const ( - Gov = "gov" - Global = "global" -) - -// Getter returns readonly struct,default get from Global -func (k Keeper) GlobalGetter() GlobalGetter { - return GlobalGetter{k} -} - -// Getter returns readonly struct,default get from Global -func (k Keeper) GovGetter() GovGetter { - return GovGetter{k} -} - -func (k Keeper) GlobalSetter() GlobalSetter { - return GlobalSetter{GlobalGetter{k}} -} - -func (k Keeper) GovSetter() GovSetter { - return GovSetter{GovGetter{k}} -} diff --git a/modules/iparams/setter.go b/modules/iparams/setter.go deleted file mode 100644 index eb5d58240..000000000 --- a/modules/iparams/setter.go +++ /dev/null @@ -1,222 +0,0 @@ -package iparams - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) - -type Setter interface { - Set(ctx sdk.Context, key string, ptr interface{}) error - SetRaw(ctx sdk.Context, key string, param []byte) - SetString(ctx sdk.Context, key string, param string) -} - -// Setter exposes all methods including Set -type GlobalSetter struct { - GlobalGetter -} - -// Setter exposes all methods including Set -type GovSetter struct { - GovGetter -} - -// Set exposes set -func (k GlobalSetter) Set(ctx sdk.Context, key string, param interface{}) error { - key = getGlobalStoreKey(key) - return k.k.set(ctx, key, param) -} - -// SetRaw exposes setRaw -func (k GlobalSetter) SetRaw(ctx sdk.Context, key string, param []byte) { - key = getGlobalStoreKey(key) - k.k.setRaw(ctx, key, param) -} - -// SetString is helper function for string params -func (k GlobalSetter) SetString(ctx sdk.Context, key string, param string) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetBool is helper function for bool params -func (k GlobalSetter) SetBool(ctx sdk.Context, key string, param bool) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt16 is helper function for int16 params -func (k GlobalSetter) SetInt16(ctx sdk.Context, key string, param int16) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt32 is helper function for int32 params -func (k GlobalSetter) SetInt32(ctx sdk.Context, key string, param int32) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt64 is helper function for int64 params -func (k GlobalSetter) SetInt64(ctx sdk.Context, key string, param int64) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint16 is helper function for uint16 params -func (k GlobalSetter) SetUint16(ctx sdk.Context, key string, param uint16) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint32 is helper function for uint32 params -func (k GlobalSetter) SetUint32(ctx sdk.Context, key string, param uint32) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint64 is helper function for uint64 params -func (k GlobalSetter) SetUint64(ctx sdk.Context, key string, param uint64) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt is helper function for sdk.Int params -func (k GlobalSetter) SetInt(ctx sdk.Context, key string, param sdk.Int) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint is helper function for sdk.Uint params -func (k GlobalSetter) SetUint(ctx sdk.Context, key string, param sdk.Uint) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetRat is helper function for rat params -func (k GlobalSetter) SetRat(ctx sdk.Context, key string, param sdk.Rat) { - key = getGlobalStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - - -// Set exposes set -func (k GovSetter) Set(ctx sdk.Context, key string, param interface{}) error { - key = getGovStoreKey(key) - return k.k.set(ctx, key, param) -} - -// SetRaw exposes setRaw -func (k GovSetter) SetRaw(ctx sdk.Context, key string, param []byte) { - key = getGovStoreKey(key) - k.k.setRaw(ctx, key, param) -} - -// SetString is helper function for string params -func (k GovSetter) SetString(ctx sdk.Context, key string, param string) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetBool is helper function for bool params -func (k GovSetter) SetBool(ctx sdk.Context, key string, param bool) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt16 is helper function for int16 params -func (k GovSetter) SetInt16(ctx sdk.Context, key string, param int16) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt32 is helper function for int32 params -func (k GovSetter) SetInt32(ctx sdk.Context, key string, param int32) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt64 is helper function for int64 params -func (k GovSetter) SetInt64(ctx sdk.Context, key string, param int64) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint16 is helper function for uint16 params -func (k GovSetter) SetUint16(ctx sdk.Context, key string, param uint16) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint32 is helper function for uint32 params -func (k GovSetter) SetUint32(ctx sdk.Context, key string, param uint32) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint64 is helper function for uint64 params -func (k GovSetter) SetUint64(ctx sdk.Context, key string, param uint64) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetInt is helper function for sdk.Int params -func (k GovSetter) SetInt(ctx sdk.Context, key string, param sdk.Int) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetUint is helper function for sdk.Uint params -func (k GovSetter) SetUint(ctx sdk.Context, key string, param sdk.Uint) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} - -// SetRat is helper function for rat params -func (k GovSetter) SetRat(ctx sdk.Context, key string, param sdk.Rat) { - key = getGovStoreKey(key) - if err := k.k.set(ctx, key, param); err != nil { - panic(err) - } -} diff --git a/modules/upgrade/genesis.go b/modules/upgrade/genesis.go index 24e5e5293..81bb4a71b 100644 --- a/modules/upgrade/genesis.go +++ b/modules/upgrade/genesis.go @@ -4,7 +4,7 @@ import ( bam "github.com/irisnet/irishub/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" "fmt" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" "github.com/irisnet/irishub/modules/upgrade/params" ) @@ -22,7 +22,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, router bam.Router) { genesisVersion := NewVersion(0, 0, 0, moduleList) k.AddNewVersion(ctx, genesisVersion) - parameter.InitGenesisParameter(&upgradeparams.ProposalAcceptHeightParameter, ctx, -1) - parameter.InitGenesisParameter(&upgradeparams.CurrentUpgradeProposalIdParameter, ctx, -1) + iparam.InitGenesisParameter(&upgradeparams.ProposalAcceptHeightParameter, ctx, -1) + iparam.InitGenesisParameter(&upgradeparams.CurrentUpgradeProposalIdParameter, ctx, -1) InitGenesis_commitID(ctx, k) } diff --git a/modules/upgrade/params/upgrade_params.go b/modules/upgrade/params/upgrade_params.go index 609c1709d..f1477a351 100644 --- a/modules/upgrade/params/upgrade_params.go +++ b/modules/upgrade/params/upgrade_params.go @@ -3,12 +3,12 @@ package upgradeparams import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/irisnet/irishub/modules/parameter" + "github.com/irisnet/irishub/modules/iparam" ) var CurrentUpgradeProposalIdParameter CurrentUpgradeProposalIdParam -var _ parameter.SignalParameter = (*CurrentUpgradeProposalIdParam)(nil) +var _ iparam.SignalParameter = (*CurrentUpgradeProposalIdParam)(nil) type CurrentUpgradeProposalIdParam struct { Value int64 @@ -44,7 +44,7 @@ func (param *CurrentUpgradeProposalIdParam) LoadValue(ctx sdk.Context) bool { var ProposalAcceptHeightParameter ProposalAcceptHeightParam -var _ parameter.SignalParameter = (*ProposalAcceptHeightParam)(nil) +var _ iparam.SignalParameter = (*ProposalAcceptHeightParam)(nil) type ProposalAcceptHeightParam struct { Value int64 From 369d9179ec457d11d3d1d8d5d8efd57a8c35d053 Mon Sep 17 00:00:00 2001 From: xujiacheng Date: Thu, 27 Sep 2018 11:16:59 +0800 Subject: [PATCH 2/2] IRISHUB-461:Add the unit --- docs/zh/modules/upgrade/README.md | 13 ------------- modules/gov/params/gov_params.go | 2 +- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 docs/zh/modules/upgrade/README.md diff --git a/docs/zh/modules/upgrade/README.md b/docs/zh/modules/upgrade/README.md deleted file mode 100644 index 4df273034..000000000 --- a/docs/zh/modules/upgrade/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Upgrade User Guide - -## 基本功能描述 - -## 交互流程 - -### 软件升级提议治理流程 - -### 升级软件流程 - -## 使用场景 - -## 命令详情 \ No newline at end of file diff --git a/modules/gov/params/gov_params.go b/modules/gov/params/gov_params.go index 9b418e388..76c5bf7f8 100644 --- a/modules/gov/params/gov_params.go +++ b/modules/gov/params/gov_params.go @@ -102,7 +102,7 @@ func (param *DepositProcedureParam) Valid(jsonStr string) sdk.Error { UpperBound, _ := types.NewDefaultCoinType("iris").ConvertToMinCoin(fmt.Sprintf("%d%s", UPPER_BOUND_AMOUNT, "iris")) if param.Value.MinDeposit[0].Amount.LT(LowerBound.Amount) || param.Value.MinDeposit[0].Amount.GT(UpperBound.Amount) { - return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidMinDepositAmount, fmt.Sprintf("MinDepositAmount"+param.Value.MinDeposit[0].String()+" should be larger than 10 and less than 20000")) + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidMinDepositAmount, fmt.Sprintf("MinDepositAmount"+param.Value.MinDeposit[0].String()+" should be larger than 1iris and less than 20000iris")) }