Skip to content

Commit

Permalink
Merge pull request #217 from irisnet/feature/gov
Browse files Browse the repository at this point in the history
merge Feature/gov to Develop
  • Loading branch information
wukongcheng authored Sep 14, 2018
2 parents f8e8cf4 + 2bc580b commit 81723c1
Show file tree
Hide file tree
Showing 18 changed files with 417 additions and 295 deletions.
234 changes: 21 additions & 213 deletions Gopkg.lock

Large diffs are not rendered by default.

52 changes: 27 additions & 25 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,36 @@ package app

import (
"encoding/json"
"io"
"os"

bam "github.com/irisnet/irishub/baseapp"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
tmtypes "github.com/tendermint/tendermint/types"

"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/irisnet/irishub/modules/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/irisnet/irishub/modules/iparams"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/stake"
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/upgrade"

"errors"
"fmt"
"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/viper"
abci "github.com/tendermint/tendermint/abci/types"
bc "github.com/tendermint/tendermint/blockchain"
tmcli "github.com/tendermint/tendermint/libs/cli"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/node"
sm "github.com/tendermint/tendermint/state"
bc "github.com/tendermint/tendermint/blockchain"
tmtypes "github.com/tendermint/tendermint/types"
"io"
"os"
"strings"
"github.com/cosmos/cosmos-sdk/x/params"
)

const (
Expand Down Expand Up @@ -72,11 +71,11 @@ type IrisApp struct {
slashingKeeper slashing.Keeper
paramsKeeper params.Keeper
govKeeper gov.Keeper
iparamsKeeper iparams.Keeper
iparamsKeeper iparams.Keeper
upgradeKeeper upgrade.Keeper

// fee manager
feeManager bam.FeeManager
feeManager bam.FeeManager
}

func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *IrisApp {
Expand All @@ -97,7 +96,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
keyGov: sdk.NewKVStoreKey("gov"),
keyFeeCollection: sdk.NewKVStoreKey("fee"),
keyParams: sdk.NewKVStoreKey("params"),
keyIparams: sdk.NewKVStoreKey("iparams"),
keyIparams: sdk.NewKVStoreKey("iparams"),
keyUpgrade: sdk.NewKVStoreKey("upgrade"),
}

Expand All @@ -114,7 +113,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
)

// add handlers
app.paramsKeeper = params.NewKeeper(cdc,app.keyParams)
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))
Expand Down Expand Up @@ -144,6 +143,7 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.SetFeePreprocessHandler(bam.NewFeePreprocessHandler(app.feeManager))
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyIBC, app.keyStake, app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams, app.keyIparams, app.keyUpgrade)
app.SetRunMsg(app.runMsgs)

var err error
if viper.GetBool(FlagReplay) {
err = app.LoadVersion(lastHeight, app.keyMain)
Expand All @@ -155,6 +155,8 @@ func NewIrisApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
}

upgrade.RegisterModuleList(app.Router())
parameter.SetParamReadWriter(app.paramsKeeper.Setter(), &govparams.DepositProcedureParameter)
parameter.RegisterGovParamMapping(&govparams.DepositProcedureParameter)

return app
}
Expand Down Expand Up @@ -219,14 +221,14 @@ func (app *IrisApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
panic(err)
}

minDeposit,err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s",10,denom))
minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 10, denom))
if err != nil {
panic(err)
}

gov.InitGenesis(ctx, app.govKeeper, gov.GenesisState{
StartingProposalID: 1,
DepositProcedure: gov.DepositProcedure{
DepositProcedure: govparams.DepositProcedure{
MinDeposit: sdk.Coins{minDeposit},
MaxDepositPeriod: 1440,
},
Expand Down Expand Up @@ -348,7 +350,7 @@ func (app *IrisApp) replay() int64 {
defer func() {
stateDB.Close()
blockStoreDB.Close()
} ()
}()

curState := sm.LoadState(stateDB)
preState := sm.LoadPreState(stateDB)
Expand Down
18 changes: 9 additions & 9 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import (
"github.com/tendermint/tendermint/crypto"
tmtypes "github.com/tendermint/tendermint/types"

"fmt"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/stake"
"time"
"github.com/irisnet/irishub/types"
"fmt"
"time"
)

// State to Unmarshal
Expand Down Expand Up @@ -54,13 +54,13 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) {
}

var (
flagName = "name"
flagClientHome = "home-client"
flagOWK = "owk"
denom = "iris-atto"
feeAmt = int64(100)
IrisCt = types.NewDefaultCoinType(denom)
freeFermionVal ,_ = IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s",feeAmt,denom))
flagName = "name"
flagClientHome = "home-client"
flagOWK = "owk"
denom = "iris-atto"
feeAmt = int64(100)
IrisCt = types.NewDefaultCoinType(denom)
freeFermionVal, _ = IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", feeAmt, denom))
)

const defaultUnbondingTime time.Duration = 60 * 10 * time.Second
Expand Down
4 changes: 4 additions & 0 deletions modules/gov/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const (
CodeInvalidVote sdk.CodeType = 9
CodeInvalidGenesis sdk.CodeType = 10
CodeInvalidProposalStatus sdk.CodeType = 11
CodeInvalidMinDeposit sdk.CodeType = 100
CodeInvalidMinDepositDenom sdk.CodeType = 101
CodeInvalidMinDepositAmount sdk.CodeType = 102
CodeInvalidDepositPeriod sdk.CodeType = 103
)

//----------------------------------------
Expand Down
10 changes: 7 additions & 3 deletions modules/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package gov

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irishub/modules/parameter"
"github.com/irisnet/irishub/modules/gov/params"
)

// GenesisState - all staking state that must be provided at genesis
type GenesisState struct {
StartingProposalID int64 `json:"starting_proposalID"`
DepositProcedure DepositProcedure `json:"deposit_period"`
DepositProcedure govparams.DepositProcedure `json:"deposit_period"`
VotingProcedure VotingProcedure `json:"voting_period"`
TallyingProcedure TallyingProcedure `json:"tallying_procedure"`
}

func NewGenesisState(startingProposalID int64, dp DepositProcedure, vp VotingProcedure, tp TallyingProcedure) GenesisState {
func NewGenesisState(startingProposalID int64, dp govparams.DepositProcedure, vp VotingProcedure, tp TallyingProcedure) GenesisState {
return GenesisState{
StartingProposalID: startingProposalID,
DepositProcedure: dp,
Expand All @@ -28,9 +30,11 @@ func InitGenesis(ctx sdk.Context, k Keeper,data GenesisState) {
// TODO: Handle this with #870
panic(err)
}
k.setDepositProcedure(ctx, data.DepositProcedure)
//k.setDepositProcedure(ctx, data.DepositProcedure)
parameter.InitGenesisParameter(&govparams.DepositProcedureParameter, ctx, data.DepositProcedure)
k.setVotingProcedure(ctx, data.VotingProcedure)
k.setTallyingProcedure(ctx, data.TallyingProcedure)

}

// WriteGenesis - output genesis parameters
Expand Down
49 changes: 16 additions & 33 deletions modules/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"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"
"strconv"
"strings"
)

// nolint


// Governance Keeper
type Keeper struct {
// The reference to the ParamSetter to get and set Global Params
Expand Down Expand Up @@ -57,12 +57,12 @@ func (keeper Keeper) WireCodec() *wire.Codec {
// =====================================================
// Proposals

func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind,params Params) Proposal{
func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, params Params) Proposal {
switch proposalType {
case ProposalTypeText:
return keeper.NewTextProposal(ctx, title, description, proposalType)
case ProposalTypeParameterChange:
return keeper.NewParametersProposal(ctx, title, description, proposalType,params)
return keeper.NewParametersProposal(ctx, title, description, proposalType, params)
case ProposalTypeSoftwareUpgrade:
return keeper.NewUpgradeProposal(ctx, title, description, proposalType)
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (keeper Keeper) NewTextProposal(ctx sdk.Context, title string, description
return proposal
}

func (keeper Keeper) NewParametersProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind,params Params) Proposal{
func (keeper Keeper) NewParametersProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, params Params) Proposal {
proposalID, err := keeper.getNewProposalID(ctx)
if err != nil {
return nil
Expand All @@ -115,7 +115,7 @@ func (keeper Keeper) NewParametersProposal(ctx sdk.Context, title string, descri
return proposal
}

func (keeper Keeper) NewUpgradeProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind) Proposal{
func (keeper Keeper) NewUpgradeProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind) Proposal {
proposalID, err := keeper.getNewProposalID(ctx)
if err != nil {
return nil
Expand Down Expand Up @@ -211,26 +211,9 @@ func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) {
// Procedures

// Returns the current Deposit Procedure from the global param store
func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) DepositProcedure {
return DepositProcedure{
MinDeposit: keeper.getDepositProcedureDeposit(ctx),
MaxDepositPeriod: keeper.getDepositProcedureMaxDepositPeriod(ctx),
}
}

func (keeper Keeper) getDepositProcedureMaxDepositPeriod(ctx sdk.Context) (MaxDepositPeriod int64) {
var maxDepositPeriod string
if keeper.ps.Get(ctx, ParamStoreKeyDepositProcedureMaxDepositPeriod, &maxDepositPeriod) == nil {
MaxDepositPeriod, _ = strconv.ParseInt(maxDepositPeriod, 10, 64)
}
return
}

func (keeper Keeper) getDepositProcedureDeposit(ctx sdk.Context) (Deposit sdk.Coins) {
var data string
keeper.ps.Get(ctx, ParamStoreKeyDepositProcedureDeposit, &data)
Deposit, _ = sdk.ParseCoins(data)
return
func (keeper Keeper) GetDepositProcedure(ctx sdk.Context) govparams.DepositProcedure {
govparams.DepositProcedureParameter.LoadValue(ctx)
return govparams.DepositProcedureParameter.Value
}

// Returns the current Voting Procedure from the global param store
Expand Down Expand Up @@ -267,14 +250,14 @@ func (keeper Keeper) getTallyingProcedure(ctx sdk.Context, key string) sdk.Rat {

}

func (keeper Keeper) setDepositProcedure(ctx sdk.Context, depositProcedure DepositProcedure) {
minDeposit := depositProcedure.MinDeposit.String()
keeper.ps.Set(ctx, ParamStoreKeyDepositProcedureDeposit, &minDeposit)

maxDepositPeriod := strconv.FormatInt(depositProcedure.MaxDepositPeriod, 10)
keeper.ps.Set(ctx, ParamStoreKeyDepositProcedureMaxDepositPeriod, &maxDepositPeriod)

}
//func (keeper Keeper) setDepositProcedure(ctx sdk.Context, depositProcedure DepositProcedure) {
// minDeposit := depositProcedure.MinDeposit.String()
// keeper.ps.Set(ctx, ParamStoreKeyDepositProcedureDeposit, &minDeposit)
//
// maxDepositPeriod := strconv.FormatInt(depositProcedure.MaxDepositPeriod, 10)
// keeper.ps.Set (ctx, ParamStoreKeyDepositProcedureMaxDepositPeriod, &maxDepositPeriod)
//
//}

func (keeper Keeper) setVotingProcedure(ctx sdk.Context, votingProcedure VotingProcedure) {
votingPeriod := strconv.FormatInt(votingProcedure.VotingPeriod, 10)
Expand Down
4 changes: 3 additions & 1 deletion modules/gov/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ func TestMsgSubmitProposal(t *testing.T) {
{"Test Proposal", "the purpose of this proposal is to test", ProposalTypeText, addrs[0], coinsMulti, true},
}

var params Params

for i, tc := range tests {
msg := NewMsgSubmitProposal(tc.title, tc.description, tc.proposalType, tc.proposerAddr, tc.initialDeposit)
msg := NewMsgSubmitProposal(tc.title, tc.description, tc.proposalType, tc.proposerAddr, tc.initialDeposit, params)
if tc.expectPass {
require.Nil(t, msg.ValidateBasic(), "test: %v", i)
} else {
Expand Down
13 changes: 13 additions & 0 deletions modules/gov/params/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package govparams

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

const (
DefaultCodespace sdk.CodespaceType = 5
CodeInvalidMinDeposit sdk.CodeType = 100
CodeInvalidMinDepositDenom sdk.CodeType = 101
CodeInvalidMinDepositAmount sdk.CodeType = 102
CodeInvalidDepositPeriod sdk.CodeType = 103
)
Loading

0 comments on commit 81723c1

Please sign in to comment.