Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge with develop #219

Merged
merged 24 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4c30b28
IRISHUB-311:finish the parameter interface definition
MrXJC Sep 12, 2018
73cd02f
Merge pull request #207 from MrXJC/jiacheng/gov
wukongcheng Sep 12, 2018
26cf64d
Merge branch 'develop' of https://github.com/irisnet/irishub into jia…
MrXJC Sep 12, 2018
f2974dd
Merge pull request #208 from MrXJC/jiacheng/gov
wukongcheng Sep 12, 2018
4db5c8f
IRISHUB-317,IRISHUB-318: realize the depositProcedureParameter and it…
MrXJC Sep 13, 2018
c9eda4b
IRISHUB-317: add the input parameter to the InitGenesis()
MrXJC Sep 13, 2018
9f1d11a
IRISHUB-317:refactor the structure of gov_params
MrXJC Sep 14, 2018
29e37cb
IRISHUB-317:make the errors readable
MrXJC Sep 14, 2018
72c8e4d
IRISHUB-317:change the package name
MrXJC Sep 14, 2018
f462548
Merge pull request #210 from MrXJC/jiacheng/gov
wukongcheng Sep 14, 2018
f73843f
IRISHUB-398:finish the InitGenesisParameter()
MrXJC Sep 14, 2018
47c2003
IRISHUB-398:finish the InitGenesisParameter() UnitTest
MrXJC Sep 14, 2018
5333212
IRISHUB-398:add the genesisData to InitGenesisParameter
MrXJC Sep 14, 2018
c42bead
IRISHUB-398:add a judgement of whether the parameter address is null …
MrXJC Sep 14, 2018
d475d82
Merge pull request #211 from MrXJC/jiacheng/gov
wukongcheng Sep 14, 2018
c7b10ff
IRISHUB-399: finish the GovParameterMap register function
MrXJC Sep 14, 2018
0ee194e
IRISHUB-399: finish the UnitTest of the GovParameterMap register func…
MrXJC Sep 14, 2018
f7dba86
Merge pull request #212 from MrXJC/jiacheng/gov
wukongcheng Sep 14, 2018
550d27b
IRISHUB-404:fix the cycle import
MrXJC Sep 14, 2018
2fcb0f7
IRISHUB-404:make the code clean
MrXJC Sep 14, 2018
2bc580b
Merge pull request #216 from MrXJC/jiacheng/gov
wukongcheng Sep 14, 2018
81723c1
Merge pull request #217 from irisnet/feature/gov
wukongcheng Sep 14, 2018
b45f810
IRISHUB-358: merge with irishub develop
Sep 14, 2018
a46354c
IRISHUB-358:go fmt app.go and genesis.go
Sep 14, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -73,11 +72,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 @@ -98,7 +97,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 @@ -115,7 +114,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 @@ -145,6 +144,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 @@ -156,6 +156,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 @@ -220,14 +222,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 @@ -349,7 +351,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"
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"
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: 2 additions & 2 deletions client/lcd/swaggerui/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"tags": [
"Version"
],
"summary": "Get connected full node executable binary version",
"description": "Get connected full node executable binary version",
"summary": "Get the version of connected full node",
"description": "Get the version of connected full node",
"consumes": [
"application/json"
],
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