0g-chain/x/committee/keeper/keeper.go

85 lines
2.0 KiB
Go
Raw Normal View History

2020-03-10 21:41:10 +00:00
package keeper
2020-03-04 19:16:27 +00:00
import (
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/kava-labs/kava/x/committee/types"
)
type Keeper struct {
// TODO other stuff as needed
// Proposal router
router govtypes.Router
}
/* TODO keeper methods - very similar to gov
- SubmitProposal validate and store a proposal, additionally setting things like timeout
- GetProposal
- SetProposal
- AddVote - add a vote to a particular proposal from a member
- GetVote
- SetVote
- GetCommittee
- SetCommittee
*/
2020-03-10 21:41:10 +00:00
func (k Keeper) SubmitProposal(ctx sdk.Context, proposal types.Proposal) sdk.Error {
2020-03-04 19:16:27 +00:00
// TODO Limit proposals to only be submitted by group members
// Check group has permissions to enact proposal. As long as one permission allows the proposal then it goes through. Its the OR of all permissions.
2020-03-10 21:41:10 +00:00
committee, _ := k.GetCommittee(ctx, proposal.CommitteeID)
2020-03-04 19:16:27 +00:00
hasPermissions := false
for _, p := range committee.Permissions {
2020-03-10 21:41:10 +00:00
if p.Allows(proposal) {
2020-03-04 19:16:27 +00:00
hasPermissions = true
break
}
}
if !hasPermissions {
2020-03-10 21:41:10 +00:00
return sdk.ErrInternal("committee does not have permissions to enact proposal")
2020-03-04 19:16:27 +00:00
}
// TODO validate proposal by running it with cached context like how gov does it
// TODO store the proposal, probably put it in a queue
return nil
}
func (k Keeper) AddVote(ctx sdk.Context, msg types.MsgVote) sdk.Error {
/* TODO
- validate vote
- store vote
*/
return nil
}
2020-03-10 21:41:10 +00:00
// --------------------
func (k Keeper) GetCommittee(ctx sdk.Context, committeeID uint64) (types.Committee, bool) {
return types.Committee{}, false
}
func (k Keeper) SetCommittee(ctx sdk.Context, committee types.Committee) {
}
func (k Keeper) GetVote(ctx sdk.Context, voteID uint64) (types.Vote, bool) {
return types.Vote{}, false
}
func (k Keeper) SetVote(ctx sdk.Context, vote types.Vote) {
}
func (k Keeper) GetProposal(ctx sdk.Context, proposalID uint64) (types.Proposal, bool) {
return types.Proposal{}, false
}
func (k Keeper) SetProposal(ctx sdk.Context, proposal types.Proposal) {
}