tidy up groupgov

This commit is contained in:
rhuairahrighairigh 2020-03-04 16:55:12 +00:00
parent 8a36e926e8
commit 3e1b1b1b72
8 changed files with 59 additions and 22 deletions

View File

@ -50,7 +50,3 @@ func handleMsgVote(ctx sdk.Context, k Keeper, msg types.MsgVote) sdk.Result {
- store vote - store vote
*/ */
} }
// TODO create a GroupChangeProposalHandler

View File

@ -8,3 +8,11 @@ type Keeper struct {
// Proposal router // Proposal router
router types.Router router types.Router
} }
/* TODO methods - should be similar to gov
- GetGroup
- SetGroup
- AddVote
*/

View File

@ -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

View File

@ -1,6 +1,6 @@
package types 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. // MsgSubmitProposal is used by group members to create a new proposal that they can vote on.
type MsgSubmitProposal struct { type MsgSubmitProposal struct {

View File

@ -1,11 +1,19 @@
package types 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 ------------------------------ // EXAMPLE PERMISSIONS ------------------------------
type InflationRateChangePermission uint8
// Allow only changes to inflation_rate
type InflationRateChangePermission struct{}
func (InflationRateChangePermission) Allows(p gov.Proposal) bool { func (InflationRateChangePermission) Allows(p gov.Proposal) bool {
pcp, _ := p.Content.(params.ParameterChangeProposal) pcp, _ := p.Content.(params.ParameterChangeProposal)
for pc, _ := range pcp.Changes { for _, pc := range pcp.Changes {
if pc.Key == "inflation_rate" { if pc.Key == "inflation_rate" {
return true return true
} }
@ -13,12 +21,30 @@ func (InflationRateChangePermission) Allows(p gov.Proposal) bool {
return false return false
} }
type CircuitBreakCDPDepsitPermission uint8 // Allow only circuit breaking of the CDP Deposit msg
type CircuitBreakCDPDepsitPermission struct{}
func (CircuitBreakCDPDepsitPermission) Allows(p gov.Proposal) bool { func (CircuitBreakCDPDepsitPermission) Allows(p gov.Proposal) bool {
cbp, _ := p.Content.(CircuitBreakProposal) cbp, _ := p.Content.(cbtypes.CircuitBreakProposal)
if cbp.Route == "cdp" && cbp.Msg == "MsgCDPDeposit" { for _, r := range cbp.MsgRoutes {
if r.Route == "cdp" && r.Msg == "MsgCDPDeposit" {
return true 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 return false
} }

View File

@ -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
}

View File

@ -1,8 +1,8 @@
package types package types
import ( import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov" "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. // 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 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. // 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. // Collectively, if one permission allows a proposal then the proposal is allowed through.
type Permission interface { type Permission interface {
Allows(gov.Proposal) bool // maybe don't reuse gov's type here 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 -------------------------- // 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 { type Router struct {
// TODO // TODO