Skip to content

Commit

Permalink
Merge pull request #2 from MrXJC/jiacheng/deps2
Browse files Browse the repository at this point in the history
add the iris begin and end  mark in code
  • Loading branch information
wukongcheng committed Oct 31, 2018
2 parents ea8ce42 + e6d6ea7 commit f2e31eb
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 7 deletions.
6 changes: 5 additions & 1 deletion modules/gov/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ const (
CodeInvalidVote sdk.CodeType = 9
CodeInvalidGenesis sdk.CodeType = 10
CodeInvalidProposalStatus sdk.CodeType = 11
//////////////////// iris begin ///////////////////////////
CodeInvalidParam sdk.CodeType = 12
CodeInvalidParamOp sdk.CodeType = 13
//////////////////// iris end /////////////////////////////
)

//----------------------------------------
Expand Down Expand Up @@ -68,10 +70,12 @@ func ErrInvalidGenesis(codespace sdk.CodespaceType, msg string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidVote, msg)
}

//////////////////// iris begin ///////////////////////////
func ErrInvalidParam(codespace sdk.CodespaceType) sdk.Error {
return sdk.NewError(codespace, CodeInvalidParam, fmt.Sprintf("Param is not valid"))
}

func ErrInvalidParamOp(codespace sdk.CodespaceType, opStr string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidParamOp, fmt.Sprintf("Op '%s' is not valid", opStr))
}
}
//////////////////// iris end /////////////////////////////
9 changes: 7 additions & 2 deletions modules/gov/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package gov
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/irisnet/irishub/modules/gov/params"
"github.com/irisnet/irishub/iparam"
"fmt"
"github.com/irisnet/irishub/types"
"time"
"github.com/irisnet/irishub/iparam"
)

// GenesisState - all gov state that must be provided at genesis
Expand Down Expand Up @@ -35,18 +35,23 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) {
panic(err)
}
//k.setDepositProcedure(ctx, data.DepositProcedure)
//////////////////// iris begin ///////////////////////////
iparam.InitGenesisParameter(&govparams.DepositProcedureParameter, ctx, data.DepositProcedure)
iparam.InitGenesisParameter(&govparams.VotingProcedureParameter, ctx, data.VotingProcedure)
iparam.InitGenesisParameter(&govparams.TallyingProcedureParameter, ctx, data.TallyingProcedure)

//////////////////// iris end /////////////////////////////
}

// WriteGenesis - output genesis parameters
func WriteGenesis(ctx sdk.Context, k Keeper) GenesisState {
startingProposalID, _ := k.getNewProposalID(ctx)

//////////////////// iris begin ///////////////////////////
depositProcedure := govparams.GetDepositProcedure(ctx)
votingProcedure := govparams.GetVotingProcedure(ctx)
tallyingProcedure := govparams.GetTallyingProcedure(ctx)
//////////////////// iris end /////////////////////////////


return GenesisState{
StartingProposalID: startingProposalID,
Expand Down
31 changes: 27 additions & 4 deletions modules/gov/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,30 @@ func NewHandler(keeper Keeper) sdk.Handler {
}

func handleMsgSubmitProposal(ctx sdk.Context, keeper Keeper, msg MsgSubmitProposal) sdk.Result {

//////////////////// iris begin ///////////////////////////
proposal := keeper.NewProposal(ctx, msg.Title, msg.Description, msg.ProposalType,msg.Param)
//////////////////// iris end /////////////////////////////


err, votingStarted := keeper.AddDeposit(ctx, proposal.GetProposalID(), msg.Proposer, msg.InitialDeposit)
if err != nil {
return err.Result()
}

//////////////////// iris begin ///////////////////////////
proposalIDBytes := []byte(strconv.FormatInt(proposal.GetProposalID(), 10))

var paramBytes []byte
if msg.ProposalType == ProposalTypeParameterChange {
paramBytes, _ = json.Marshal(proposal.(*ParameterProposal).Param)
}

//////////////////// iris end /////////////////////////////
resTags := sdk.NewTags(
tags.Action, tags.ActionSubmitProposal,
tags.Proposer, []byte(msg.Proposer.String()),
tags.ProposalID, proposalIDBytes,
//////////////////// iris begin ///////////////////////////
tags.Param, paramBytes,
//////////////////// iris end /////////////////////////////
)

if votingStarted {
Expand All @@ -67,7 +71,10 @@ func handleMsgDeposit(ctx sdk.Context, keeper Keeper, msg MsgDeposit) sdk.Result
return err.Result()
}

//////////////////// iris begin ///////////////////////////
proposalIDBytes := []byte(strconv.FormatInt(msg.ProposalID, 10))
//////////////////// iris end /////////////////////////////


// TODO: Add tag for if voting period started
resTags := sdk.NewTags(
Expand All @@ -92,7 +99,9 @@ func handleMsgVote(ctx sdk.Context, keeper Keeper, msg MsgVote) sdk.Result {
return err.Result()
}

//////////////////// iris begin ///////////////////////////
proposalIDBytes := []byte(strconv.FormatInt(msg.ProposalID, 10))
//////////////////// iris end /////////////////////////////

resTags := sdk.NewTags(
tags.Action, tags.ActionVote,
Expand All @@ -117,8 +126,9 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
if inactiveProposal.GetStatus() != StatusDepositPeriod {
continue
}

//////////////////// iris begin ///////////////////////////
proposalIDBytes := []byte(strconv.FormatInt(inactiveProposal.GetProposalID(), 10))
//////////////////// iris end /////////////////////////////
keeper.DeleteProposal(ctx, inactiveProposal)
resTags.AppendTag(tags.Action, tags.ActionProposalDropped)
resTags.AppendTag(tags.ProposalID, proposalIDBytes)
Expand All @@ -127,7 +137,9 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
fmt.Sprintf("proposal %d (%s) didn't meet minimum deposit of %v iris-atto (had only %v iris-atto); deleted",
inactiveProposal.GetProposalID(),
inactiveProposal.GetTitle(),
//////////////////// iris begin ///////////////////////////
govparams.GetDepositProcedure(ctx).MinDeposit.AmountOf("iris-atto"),
//////////////////// iris end /////////////////////////////
inactiveProposal.GetTotalDeposit().AmountOf("iris-atto"),
),
)
Expand All @@ -138,18 +150,25 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
activeProposal := keeper.ActiveProposalQueuePop(ctx)

proposalStartTime := activeProposal.GetVotingStartTime()
//////////////////// iris begin ///////////////////////////
votingPeriod := govparams.GetVotingProcedure(ctx).VotingPeriod
//////////////////// iris end /////////////////////////////
if ctx.BlockHeader().Time.Before(proposalStartTime.Add(votingPeriod)) {
continue
}

passes, tallyResults := tally(ctx, keeper, activeProposal)
//////////////////// iris begin ///////////////////////////
proposalIDBytes := []byte(strconv.FormatInt(activeProposal.GetProposalID(), 10))
//////////////////// iris end /////////////////////////////
var action []byte
if passes {
keeper.RefundDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusPassed)
action = tags.ActionProposalPassed
//////////////////// iris begin ///////////////////////////
activeProposal.Execute(ctx, keeper)
//////////////////// iris end /////////////////////////////
} else {
keeper.DeleteDeposits(ctx, activeProposal.GetProposalID())
activeProposal.SetStatus(StatusRejected)
Expand All @@ -168,7 +187,9 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
return resTags
}
func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
//////////////////// iris begin ///////////////////////////
depositProcedure := govparams.GetDepositProcedure(ctx)
//////////////////// iris end /////////////////////////////
peekProposal := keeper.InactiveProposalQueuePeek(ctx)

if peekProposal == nil {
Expand All @@ -182,7 +203,9 @@ func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
}

func shouldPopActiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
//////////////////// iris begin ///////////////////////////
votingProcedure := govparams.GetVotingProcedure(ctx)
//////////////////// iris end /////////////////////////////
peekProposal := keeper.ActiveProposalQueuePeek(ctx)

if peekProposal == nil {
Expand Down
8 changes: 8 additions & 0 deletions modules/gov/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func NewKeeper(cdc *codec.Codec, key sdk.StoreKey,ck bank.Keeper, ds sdk.Delegat
// =====================================================
// Proposals

//////////////////// iris begin ///////////////////////////
func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, param Param) Proposal {
switch proposalType {
case ProposalTypeText:
Expand All @@ -62,6 +63,8 @@ func (keeper Keeper) NewProposal(ctx sdk.Context, title string, description stri
}
return nil
}
//////////////////// iris end /////////////////////////////


// =====================================================
// Proposals
Expand All @@ -87,6 +90,7 @@ func (keeper Keeper) NewTextProposal(ctx sdk.Context, title string, description
return proposal
}

//////////////////// iris begin ///////////////////////////
func (keeper Keeper) NewParametersProposal(ctx sdk.Context, title string, description string, proposalType ProposalKind, param Param) Proposal {
proposalID, err := keeper.getNewProposalID(ctx)
if err != nil {
Expand Down Expand Up @@ -136,6 +140,8 @@ func (keeper Keeper) NewUpgradeProposal(ctx sdk.Context, title string, descripti
keeper.InactiveProposalQueuePush(ctx, proposal)
return proposal
}
//////////////////// iris end /////////////////////////////


// Get Proposal from store by ProposalID
func (keeper Keeper) GetProposal(ctx sdk.Context, proposalID int64) Proposal {
Expand Down Expand Up @@ -362,7 +368,9 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID int64, depositerAddr
// Check if deposit tipped proposal into voting period
// Active voting period if so
activatedVotingPeriod := false
//////////////////// iris begin ///////////////////////////
if proposal.GetStatus() == StatusDepositPeriod && proposal.GetTotalDeposit().IsGTE(govparams.GetDepositProcedure(ctx).MinDeposit) {
//////////////////// iris end /////////////////////////////
keeper.activateVotingPeriod(ctx, proposal)
activatedVotingPeriod = true
}
Expand Down
6 changes: 6 additions & 0 deletions modules/gov/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ type MsgSubmitProposal struct {
ProposalType ProposalKind `json:"proposal_type"` // Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
Proposer sdk.AccAddress `json:"proposer"` // Address of the proposer
InitialDeposit sdk.Coins `json:"initial_deposit"` // Initial deposit paid by sender. Must be strictly positive.
//////////////////// iris begin ///////////////////////////
Param Param
//////////////////// iris end /////////////////////////////
}

func NewMsgSubmitProposal(title string, description string, proposalType ProposalKind, proposer sdk.AccAddress, initialDeposit sdk.Coins, param Param) MsgSubmitProposal {
Expand All @@ -30,7 +32,9 @@ func NewMsgSubmitProposal(title string, description string, proposalType Proposa
ProposalType: proposalType,
Proposer: proposer,
InitialDeposit: initialDeposit,
//////////////////// iris begin ///////////////////////////
Param: param,
//////////////////// iris end /////////////////////////////
}
}

Expand Down Expand Up @@ -58,6 +62,7 @@ func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
if !msg.InitialDeposit.IsNotNegative() {
return sdk.ErrInvalidCoins(msg.InitialDeposit.String())
}
//////////////////// iris begin ///////////////////////////
if msg.ProposalType == ProposalTypeParameterChange {

if msg.Param.Op != Update && msg.Param.Op != Insert {
Expand All @@ -71,6 +76,7 @@ func (msg MsgSubmitProposal) ValidateBasic() sdk.Error {
}

}
//////////////////// iris end /////////////////////////////
return nil
}

Expand Down
8 changes: 8 additions & 0 deletions modules/gov/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ type Proposal interface {

GetVotingStartTime() time.Time
SetVotingStartTime(time.Time)

//////////////////// iris begin ///////////////////////////
Execute(ctx sdk.Context, k Keeper) error
//////////////////// iris end ///////////////////////////

}

// checks if two proposals are equal
Expand Down Expand Up @@ -98,6 +103,9 @@ func (tp TextProposal) GetVotingStartTime() time.Time { return tp.V
func (tp *TextProposal) SetVotingStartTime(votingStartTime time.Time) {
tp.VotingStartTime = votingStartTime
}
//////////////////// iris begin ///////////////////////////
func (pp *TextProposal) Execute(ctx sdk.Context, k Keeper) (err error) {return nil}
//////////////////// iris end /////////////////////////////

//-----------------------------------------------------------
// ProposalQueue
Expand Down
2 changes: 2 additions & 0 deletions modules/gov/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ var (
VotingPeriodStart = "voting-period-start"
Depositer = "depositer"
Voter = "voter"
//////////////////// iris begin ///////////////////////////
Param = "param"
//////////////////// iris end /////////////////////////////
)
2 changes: 2 additions & 0 deletions modules/gov/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ func tally(ctx sdk.Context, keeper Keeper, proposal Proposal) (passes bool, tall
totalVotingPower = totalVotingPower.Add(votingPower)
}

//////////////////// iris begin ///////////////////////////
tallyingProcedure := govparams.GetTallyingProcedure(ctx)
//////////////////// iris end /////////////////////////////

tallyResults = TallyResult{
Yes: results[OptionYes],
Expand Down

0 comments on commit f2e31eb

Please sign in to comment.