mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
tidy up groupgov
This commit is contained in:
parent
8a36e926e8
commit
3e1b1b1b72
@ -50,7 +50,3 @@ func handleMsgVote(ctx sdk.Context, k Keeper, msg types.MsgVote) sdk.Result {
|
||||
- store vote
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO create a GroupChangeProposalHandler
|
@ -8,3 +8,11 @@ type Keeper struct {
|
||||
// Proposal router
|
||||
router types.Router
|
||||
}
|
||||
|
||||
/* TODO methods - should be similar to gov
|
||||
- GetGroup
|
||||
- SetGroup
|
||||
|
||||
- AddVote
|
||||
|
||||
*/
|
||||
|
4
x/groupgov/proposal_handler.go
Normal file
4
x/groupgov/proposal_handler.go
Normal 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
|
@ -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 {
|
||||
|
@ -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" {
|
||||
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
|
||||
}
|
||||
|
12
x/groupgov/types/proposal.go
Normal file
12
x/groupgov/types/proposal.go
Normal 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
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user