clawchain/x/governance/keeper/grpc_query_server.go
caelum0x 9e2746707a feat(governance): complete governance module with veto votes, cancel, queries, and execution log
- Task 1.1/1.2: Add no_with_veto vote option with 33.4% veto threshold
  - New VoteOptionNoWithVeto constant and DefaultVetoThresholdBps (3340)
  - VetoVotes field on Proposal struct (proto field 15)
  - CastVote handles no_with_veto; TallyProposal rejects if veto > 33.4%

- Task 1.3: Add MsgCancelProposal
  - New ErrUnauthorizedCancel (1411) and ErrProposalNotCancellable (1412)
  - ProposalStatusCancelled constant
  - CancelProposal keeper method: checks proposer, voting status, refunds deposit

- Task 1.4: Add QueryTallyResult and QueryVoterVotes
  - QueryTallyResult returns counts, percentages (bps), pass/veto status
  - QueryVoterVotes walks Votes collection filtered by voter address

- Task 1.5: ParamExecutor coverage for marketplace, reputation, messaging, modelregistry
  - All 4 modules tested via mock executor registration + ExecuteProposal

- Task 1.6: Execution log fields
  - ExecutionHeight (proto field 16) and ExecutionError (proto field 17) on Proposal
  - ExecuteProposal sets these on both success and failure paths

All 24 tests pass (5 existing + 19 new), go build ./... clean.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-16 14:24:34 +03:00

81 lines
2.1 KiB
Go

package keeper
import (
"context"
"clawchain/x/governance/types"
errorsmod "cosmossdk.io/errors"
)
type queryServer struct {
keeper Keeper
}
// NewQueryServerImpl returns an implementation of the QueryServer interface.
func NewQueryServerImpl(keeper Keeper) types.QueryServer {
return &queryServer{keeper: keeper}
}
var _ types.QueryServer = queryServer{}
func (q queryServer) Proposal(ctx context.Context, req *types.QueryProposalRequest) (*types.QueryProposalResponse, error) {
if req == nil {
return nil, errorsmod.Wrap(types.ErrInvalidProposal, "empty request")
}
proposal, err := q.keeper.GetProposal(ctx, req.ProposalId)
if err != nil {
return nil, err
}
return &types.QueryProposalResponse{Proposal: proposal}, nil
}
func (q queryServer) Proposals(ctx context.Context, req *types.QueryProposalsRequest) (*types.QueryProposalsResponse, error) {
if req == nil {
return nil, errorsmod.Wrap(types.ErrInvalidProposal, "empty request")
}
proposals, err := q.keeper.GetProposals(ctx, req.Status)
if err != nil {
return nil, err
}
// Convert value slice to pointer slice for pb compatibility
pbProposals := make([]*types.Proposal, len(proposals))
for i := range proposals {
pbProposals[i] = &proposals[i]
}
return &types.QueryProposalsResponse{Proposals: pbProposals}, nil
}
func (q queryServer) Votes(ctx context.Context, req *types.QueryVotesRequest) (*types.QueryVotesResponse, error) {
if req == nil {
return nil, errorsmod.Wrap(types.ErrInvalidProposal, "empty request")
}
votes, err := q.keeper.GetVotes(ctx, req.ProposalId)
if err != nil {
return nil, err
}
// Convert value slice to pointer slice for pb compatibility
pbVotes := make([]*types.Vote, len(votes))
for i := range votes {
pbVotes[i] = &votes[i]
}
return &types.QueryVotesResponse{Votes: pbVotes}, nil
}
func (q queryServer) Params(ctx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, errorsmod.Wrap(types.ErrInvalidProposal, "empty request")
}
// Return default params for now
return &types.QueryParamsResponse{}, nil
}