From ffbeced199cfc2adfa486b9bf1ec3df932dc546c Mon Sep 17 00:00:00 2001 From: rhuairahrighairigh Date: Tue, 28 Apr 2020 01:51:53 +0100 Subject: [PATCH] apply various pr suggestions --- x/committee/handler.go | 50 ++++++++++++++++++---------------- x/committee/types/committee.go | 2 +- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/x/committee/handler.go b/x/committee/handler.go index 9129d4e1..e46c0b6a 100644 --- a/x/committee/handler.go +++ b/x/committee/handler.go @@ -57,30 +57,6 @@ func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) (*sdk.Re if err != nil { return nil, err } - - // Enact a proposal if it has enough votes - passes, err := k.GetProposalResult(ctx, msg.ProposalID) - if err != nil { - return nil, err - } - if passes { - err = k.EnactProposal(ctx, msg.ProposalID) - outcome := types.AttributeValueProposalPassed - if err != nil { - outcome = types.AttributeValueProposalFailed - } - k.DeleteProposalAndVotes(ctx, msg.ProposalID) - - ctx.EventManager().EmitEvent( - sdk.NewEvent( - types.EventTypeProposalClose, - sdk.NewAttribute(types.AttributeKeyCommitteeID, fmt.Sprintf("%d", proposal.CommitteeID)), - sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.ID)), - sdk.NewAttribute(types.AttributeKeyProposalCloseStatus, outcome), - ), - ) - } - ctx.EventManager().EmitEvent( sdk.NewEvent( sdk.EventTypeMessage, @@ -89,5 +65,31 @@ func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) (*sdk.Re ), ) + // Enact a proposal if it has enough votes + passes, err := k.GetProposalResult(ctx, msg.ProposalID) + if err != nil { + return nil, err + } + if !passes { + return &sdk.Result{Events: ctx.EventManager().Events()}, nil + } + + err = k.EnactProposal(ctx, msg.ProposalID) + outcome := types.AttributeValueProposalPassed + if err != nil { + outcome = types.AttributeValueProposalFailed + } + + k.DeleteProposalAndVotes(ctx, msg.ProposalID) + + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.EventTypeProposalClose, + sdk.NewAttribute(types.AttributeKeyCommitteeID, fmt.Sprintf("%d", proposal.CommitteeID)), + sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposal.ID)), + sdk.NewAttribute(types.AttributeKeyProposalCloseStatus, outcome), + ), + ) + return &sdk.Result{Events: ctx.EventManager().Events()}, nil } diff --git a/x/committee/types/committee.go b/x/committee/types/committee.go index c516f2bb..c240ac52 100644 --- a/x/committee/types/committee.go +++ b/x/committee/types/committee.go @@ -9,7 +9,7 @@ import ( "gopkg.in/yaml.v2" ) -const MaxCommitteeDescriptionLength int = 5000 +const MaxCommitteeDescriptionLength int = 512 // ------------------------------------------ // Committees