Skip to content

Commit

Permalink
democracy: update democracy consumer v50 (#1358)
Browse files Browse the repository at this point in the history
* democracy: update x/staking

* democracy: update x/governance forbidden prop deletions

* democracy: update app.go, cmd

* app: fix app dir wrong references
  • Loading branch information
MSalopek authored Oct 13, 2023
1 parent 2794b9e commit c71521c
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 279 deletions.
84 changes: 84 additions & 0 deletions app/consumer-democracy/abci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package app

import (
"bytes"
"crypto/rand"
"encoding/json"
"fmt"

abci "github.com/cometbft/cometbft/abci/types"

"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type (
// VoteExtensionHandler defines a dummy vote extension handler for SimApp.
//
// NOTE: This implementation is solely used for testing purposes. DO NOT use
// in a production application!
VoteExtensionHandler struct{}

// VoteExtension defines the structure used to create a dummy vote extension.
VoteExtension struct {
Hash []byte
Height int64
Data []byte
}
)

func NewVoteExtensionHandler() *VoteExtensionHandler {
return &VoteExtensionHandler{}
}

func (h *VoteExtensionHandler) SetHandlers(bApp *baseapp.BaseApp) {
bApp.SetExtendVoteHandler(h.ExtendVote())
bApp.SetVerifyVoteExtensionHandler(h.VerifyVoteExtension())
}

func (h *VoteExtensionHandler) ExtendVote() sdk.ExtendVoteHandler {
return func(_ sdk.Context, req *abci.RequestExtendVote) (*abci.ResponseExtendVote, error) {
buf := make([]byte, 1024)

_, err := rand.Read(buf)
if err != nil {
return nil, fmt.Errorf("failed to generate random vote extension data: %w", err)
}

ve := VoteExtension{
Hash: req.Hash,
Height: req.Height,
Data: buf,
}

bz, err := json.Marshal(ve)
if err != nil {
return nil, fmt.Errorf("failed to encode vote extension: %w", err)
}

return &abci.ResponseExtendVote{VoteExtension: bz}, nil
}
}

func (h *VoteExtensionHandler) VerifyVoteExtension() sdk.VerifyVoteExtensionHandler {
return func(ctx sdk.Context, req *abci.RequestVerifyVoteExtension) (*abci.ResponseVerifyVoteExtension, error) {
var ve VoteExtension

if err := json.Unmarshal(req.VoteExtension, &ve); err != nil {
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}

switch {
case req.Height != ve.Height:
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil

case !bytes.Equal(req.Hash, ve.Hash):
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil

case len(ve.Data) != 1024:
return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_REJECT}, nil
}

return &abci.ResponseVerifyVoteExtension{Status: abci.ResponseVerifyVoteExtension_ACCEPT}, nil
}
}
4 changes: 2 additions & 2 deletions app/consumer-democracy/ante/forbidden_proposals_ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,11 @@ func newLegacyParamChangeProposalMsg(changes []proposal.ParamChange) *govv1.MsgS
if err != nil {
return nil
}
msg, _ := govv1.NewMsgSubmitProposal([]sdk.Msg{msgContent}, sdk.NewCoins(), sdk.AccAddress{}.String(), "", "", "")
msg, _ := govv1.NewMsgSubmitProposal([]sdk.Msg{msgContent}, sdk.NewCoins(), sdk.AccAddress{}.String(), "", "", "", false)
return msg
}

func newParamChangeProposalMsg(msgs []sdk.Msg) *govv1.MsgSubmitProposal {
msg, _ := govv1.NewMsgSubmitProposal(msgs, sdk.NewCoins(), sdk.AccAddress{}.String(), "", "", "")
msg, _ := govv1.NewMsgSubmitProposal(msgs, sdk.NewCoins(), sdk.AccAddress{}.String(), "", "", "", false)
return msg
}
Loading

0 comments on commit c71521c

Please sign in to comment.