From 3e1b1b1b7207cb8fc7a42cc79519e7a178927b18 Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Wed, 4 Mar 2020 16:55:12 +0000 Subject: [PATCH] tidy up groupgov --- .../{gov-handler.go => proposal_handler.go} | 0 x/groupgov/handler.go | 4 -- x/groupgov/keeper/keeper.go | 8 ++++ x/groupgov/proposal_handler.go | 4 ++ x/groupgov/types/msg.go | 2 +- x/groupgov/types/permissions.go | 38 ++++++++++++++++--- x/groupgov/types/proposal.go | 12 ++++++ x/groupgov/types/types.go | 13 +------ 8 files changed, 59 insertions(+), 22 deletions(-) rename x/circuit-breaker/{gov-handler.go => proposal_handler.go} (100%) create mode 100644 x/groupgov/proposal_handler.go create mode 100644 x/groupgov/types/proposal.go diff --git a/x/circuit-breaker/gov-handler.go b/x/circuit-breaker/proposal_handler.go similarity index 100% rename from x/circuit-breaker/gov-handler.go rename to x/circuit-breaker/proposal_handler.go diff --git a/x/groupgov/handler.go b/x/groupgov/handler.go index 74d08933..5b1a959c 100644 --- a/x/groupgov/handler.go +++ b/x/groupgov/handler.go @@ -50,7 +50,3 @@ func handleMsgVote(ctx sdk.Context, k Keeper, msg types.MsgVote) sdk.Result { - store vote */ } - - - -// TODO create a GroupChangeProposalHandler \ No newline at end of file diff --git a/x/groupgov/keeper/keeper.go b/x/groupgov/keeper/keeper.go index f7e09804..909d53bd 100644 --- a/x/groupgov/keeper/keeper.go +++ b/x/groupgov/keeper/keeper.go @@ -8,3 +8,11 @@ type Keeper struct { // Proposal router router types.Router } + +/* TODO methods - should be similar to gov +- GetGroup +- SetGroup + +- AddVote + +*/ diff --git a/x/groupgov/proposal_handler.go b/x/groupgov/proposal_handler.go new file mode 100644 index 00000000..12598aea --- /dev/null +++ b/x/groupgov/proposal_handler.go @@ -0,0 +1,4 @@ +package groupgov + +// TODO create a GroupChangeProposalHandler, see params or distribution +// It will overwrite the Members of Permissions field of a group diff --git a/x/groupgov/types/msg.go b/x/groupgov/types/msg.go index d8fbb8b9..06cc211c 100644 --- a/x/groupgov/types/msg.go +++ b/x/groupgov/types/msg.go @@ -1,6 +1,6 @@ package types -// These msg types should be basically the same as for gov +// These msg types should be basically the same as for gov, but without deposits. // MsgSubmitProposal is used by group members to create a new proposal that they can vote on. type MsgSubmitProposal struct { diff --git a/x/groupgov/types/permissions.go b/x/groupgov/types/permissions.go index 6b2e286a..4024d8d3 100644 --- a/x/groupgov/types/permissions.go +++ b/x/groupgov/types/permissions.go @@ -1,11 +1,19 @@ package types +import ( + "github.com/cosmos/cosmos-sdk/x/gov" + "github.com/cosmos/cosmos-sdk/x/params" + cbtypes "github.com/kava-labs/kava/x/circuit-breaker/types" +) + // EXAMPLE PERMISSIONS ------------------------------ -type InflationRateChangePermission uint8 + +// Allow only changes to inflation_rate +type InflationRateChangePermission struct{} func (InflationRateChangePermission) Allows(p gov.Proposal) bool { pcp, _ := p.Content.(params.ParameterChangeProposal) - for pc, _ := range pcp.Changes { + for _, pc := range pcp.Changes { if pc.Key == "inflation_rate" { return true } @@ -13,12 +21,30 @@ func (InflationRateChangePermission) Allows(p gov.Proposal) bool { return false } -type CircuitBreakCDPDepsitPermission uint8 +// Allow only circuit breaking of the CDP Deposit msg +type CircuitBreakCDPDepsitPermission struct{} func (CircuitBreakCDPDepsitPermission) Allows(p gov.Proposal) bool { - cbp, _ := p.Content.(CircuitBreakProposal) - if cbp.Route == "cdp" && cbp.Msg == "MsgCDPDeposit" { - return true + cbp, _ := p.Content.(cbtypes.CircuitBreakProposal) + for _, r := range cbp.MsgRoutes { + if r.Route == "cdp" && r.Msg == "MsgCDPDeposit" { + return true + } + } + return false +} + +// Same as above but the route the permssion allows can be set +type CircuitBreakPermission struct { + MsgRoute cbtypes.MsgRoute +} + +func (perm CircuitBreakPermission) Allows(p gov.Proposal) bool { + cbp, _ := p.Content.(cbtypes.CircuitBreakProposal) + for _, r := range cbp.MsgRoutes { + if r == perm.MsgRoute { + return true + } } return false } diff --git a/x/groupgov/types/proposal.go b/x/groupgov/types/proposal.go new file mode 100644 index 00000000..611e5671 --- /dev/null +++ b/x/groupgov/types/proposal.go @@ -0,0 +1,12 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// A gov.Proposal to used to add/remove members from a group, or to add/remove permissions. +// Normally registered with standard gov. But could also be registed with groupgov to allow groups to be controlled by other groups. +type GroupChangeProposal struct { + Members []sdk.AccAddress + Permissions []Permission +} diff --git a/x/groupgov/types/types.go b/x/groupgov/types/types.go index 2ef2fd7f..50940abd 100644 --- a/x/groupgov/types/types.go +++ b/x/groupgov/types/types.go @@ -1,8 +1,8 @@ package types import ( + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov" - "github.com/cosmos/cosmos-sdk/x/params" ) // A Group is a collection of addresses that are allowed to vote and enact any governance proposal that passes their permissions. @@ -11,23 +11,14 @@ type Group struct { Permissions []Permission } -// handler for MsgSubmitProposal needs to loop apply all group permission Allows methods to the proposal and do a bit OR to see if it should be accepted - // Permission is anything with a method that validates whether a proposal is allowed by it or not. // Collectively, if one permission allows a proposal then the proposal is allowed through. type Permission interface { Allows(gov.Proposal) bool // maybe don't reuse gov's type here } -// A gov.Proposal to used to add/remove members from a group, or to add/remove permissions. -// Normally registered with standard gov. But could also be registed with groupgov to allow groups to be controlled by other groups. -type GroupChangeProposal struct { - Members []sdk.AccAddress - Permissions []Permission -} - // STANDARD GOV STUFF -------------------------- -// Should be much the same as in gov module. Either import gov types directly or do some copy n pasting. +// Should be much the same as in gov module, except Proposals are linked to a group ID. type Router struct { // TODO