mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
add events
This commit is contained in:
parent
57f4ca7c9a
commit
e228aa6659
@ -1,6 +1,8 @@
|
|||||||
package committee
|
package committee
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
@ -13,7 +15,17 @@ func BeginBlocker(ctx sdk.Context, _ abci.RequestBeginBlock, k Keeper) {
|
|||||||
// Close all expired proposals
|
// Close all expired proposals
|
||||||
k.IterateProposals(ctx, func(proposal types.Proposal) bool {
|
k.IterateProposals(ctx, func(proposal types.Proposal) bool {
|
||||||
if proposal.HasExpiredBy(ctx.BlockTime()) {
|
if proposal.HasExpiredBy(ctx.BlockTime()) {
|
||||||
|
|
||||||
k.DeleteProposalAndVotes(ctx, proposal.ID)
|
k.DeleteProposalAndVotes(ctx, proposal.ID)
|
||||||
|
|
||||||
|
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, types.AttributeValueProposalTimeout),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
@ -9,27 +9,35 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AttributeKeyProposalID = types.AttributeKeyProposalID
|
AttributeKeyCommitteeID = types.AttributeKeyCommitteeID
|
||||||
DefaultCodespace = types.DefaultCodespace
|
AttributeKeyProposalCloseStatus = types.AttributeKeyProposalCloseStatus
|
||||||
DefaultNextProposalID = types.DefaultNextProposalID
|
AttributeKeyProposalID = types.AttributeKeyProposalID
|
||||||
DefaultParamspace = types.DefaultParamspace
|
AttributeValueCategory = types.AttributeValueCategory
|
||||||
EventTypeSubmitProposal = types.EventTypeSubmitProposal
|
AttributeValueProposalFailed = types.AttributeValueProposalFailed
|
||||||
MaxDescriptionLength = types.MaxDescriptionLength
|
AttributeValueProposalPassed = types.AttributeValueProposalPassed
|
||||||
ModuleName = types.ModuleName
|
AttributeValueProposalTimeout = types.AttributeValueProposalTimeout
|
||||||
ProposalTypeCommitteeChange = types.ProposalTypeCommitteeChange
|
DefaultCodespace = types.DefaultCodespace
|
||||||
ProposalTypeCommitteeDelete = types.ProposalTypeCommitteeDelete
|
DefaultNextProposalID = types.DefaultNextProposalID
|
||||||
QuerierRoute = types.QuerierRoute
|
DefaultParamspace = types.DefaultParamspace
|
||||||
QueryCommittee = types.QueryCommittee
|
EventTypeProposalClose = types.EventTypeProposalClose
|
||||||
QueryCommittees = types.QueryCommittees
|
EventTypeProposalSubmit = types.EventTypeProposalSubmit
|
||||||
QueryProposal = types.QueryProposal
|
EventTypeProposalVote = types.EventTypeProposalVote
|
||||||
QueryProposals = types.QueryProposals
|
MaxCommitteeDescriptionLength = types.MaxCommitteeDescriptionLength
|
||||||
QueryTally = types.QueryTally
|
ModuleName = types.ModuleName
|
||||||
QueryVote = types.QueryVote
|
ProposalTypeCommitteeChange = types.ProposalTypeCommitteeChange
|
||||||
QueryVotes = types.QueryVotes
|
ProposalTypeCommitteeDelete = types.ProposalTypeCommitteeDelete
|
||||||
RouterKey = types.RouterKey
|
QuerierRoute = types.QuerierRoute
|
||||||
StoreKey = types.StoreKey
|
QueryCommittee = types.QueryCommittee
|
||||||
TypeMsgSubmitProposal = types.TypeMsgSubmitProposal
|
QueryCommittees = types.QueryCommittees
|
||||||
TypeMsgVote = types.TypeMsgVote
|
QueryProposal = types.QueryProposal
|
||||||
|
QueryProposals = types.QueryProposals
|
||||||
|
QueryTally = types.QueryTally
|
||||||
|
QueryVote = types.QueryVote
|
||||||
|
QueryVotes = types.QueryVotes
|
||||||
|
RouterKey = types.RouterKey
|
||||||
|
StoreKey = types.StoreKey
|
||||||
|
TypeMsgSubmitProposal = types.TypeMsgSubmitProposal
|
||||||
|
TypeMsgVote = types.TypeMsgVote
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,7 +34,7 @@ func (p Proposer) String() string {
|
|||||||
func QueryProposer(cliCtx context.CLIContext, proposalID uint64) (Proposer, error) {
|
func QueryProposer(cliCtx context.CLIContext, proposalID uint64) (Proposer, error) {
|
||||||
events := []string{
|
events := []string{
|
||||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
|
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
|
||||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeSubmitProposal, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalSubmit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
// NOTE: SearchTxs is used to facilitate the txs query which does not currently
|
||||||
|
@ -35,7 +35,7 @@ func handleMsgSubmitProposal(ctx sdk.Context, k keeper.Keeper, msg types.MsgSubm
|
|||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
sdk.EventTypeMessage,
|
sdk.EventTypeMessage,
|
||||||
// TODO sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
||||||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Proposer.String()),
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.Proposer.String()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -47,6 +47,12 @@ func handleMsgSubmitProposal(ctx sdk.Context, k keeper.Keeper, msg types.MsgSubm
|
|||||||
}
|
}
|
||||||
|
|
||||||
func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) sdk.Result {
|
func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) sdk.Result {
|
||||||
|
// get the proposal just to add fields to the event
|
||||||
|
proposal, found := k.GetProposal(ctx, msg.ProposalID)
|
||||||
|
if !found {
|
||||||
|
return sdk.ErrInternal("proposal not found").Result()
|
||||||
|
}
|
||||||
|
|
||||||
err := k.AddVote(ctx, msg.ProposalID, msg.Voter)
|
err := k.AddVote(ctx, msg.ProposalID, msg.Voter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err.Result()
|
return err.Result()
|
||||||
@ -58,15 +64,27 @@ func handleMsgVote(ctx sdk.Context, k keeper.Keeper, msg types.MsgVote) sdk.Resu
|
|||||||
return err.Result()
|
return err.Result()
|
||||||
}
|
}
|
||||||
if passes {
|
if passes {
|
||||||
_ = k.EnactProposal(ctx, msg.ProposalID)
|
err = k.EnactProposal(ctx, msg.ProposalID)
|
||||||
// log err
|
outcome := types.AttributeValueProposalPassed
|
||||||
|
if err != nil {
|
||||||
|
outcome = types.AttributeValueProposalFailed
|
||||||
|
}
|
||||||
k.DeleteProposalAndVotes(ctx, msg.ProposalID)
|
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(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
sdk.EventTypeMessage,
|
sdk.EventTypeMessage,
|
||||||
// TODO sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
|
||||||
sdk.NewAttribute(sdk.AttributeKeySender, msg.Voter.String()),
|
sdk.NewAttribute(sdk.AttributeKeySender, msg.Voter.String()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -38,7 +38,8 @@ func (k Keeper) SubmitProposal(ctx sdk.Context, proposer sdk.AccAddress, committ
|
|||||||
|
|
||||||
ctx.EventManager().EmitEvent(
|
ctx.EventManager().EmitEvent(
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeSubmitProposal,
|
types.EventTypeProposalSubmit,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyCommitteeID, fmt.Sprintf("%d", com.ID)),
|
||||||
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)),
|
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", proposalID)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -66,6 +67,13 @@ func (k Keeper) AddVote(ctx sdk.Context, proposalID uint64, voter sdk.AccAddress
|
|||||||
// Store vote, overwriting any prior vote
|
// Store vote, overwriting any prior vote
|
||||||
k.SetVote(ctx, types.Vote{ProposalID: proposalID, Voter: voter})
|
k.SetVote(ctx, types.Vote{ProposalID: proposalID, Voter: voter})
|
||||||
|
|
||||||
|
ctx.EventManager().EmitEvent(
|
||||||
|
sdk.NewEvent(
|
||||||
|
types.EventTypeProposalVote,
|
||||||
|
sdk.NewAttribute(types.AttributeKeyCommitteeID, fmt.Sprintf("%d", com.ID)),
|
||||||
|
sdk.NewAttribute(types.AttributeKeyProposalID, fmt.Sprintf("%d", pr.ID)),
|
||||||
|
),
|
||||||
|
)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,18 +2,15 @@ package types
|
|||||||
|
|
||||||
// Module event types
|
// Module event types
|
||||||
const (
|
const (
|
||||||
EventTypeSubmitProposal = "submit_proposal"
|
EventTypeProposalSubmit = "proposal_submit"
|
||||||
// EventTypeProposalVote = "proposal_vote"
|
EventTypeProposalClose = "proposal_close"
|
||||||
// EventTypeInactiveProposal = "inactive_proposal"
|
EventTypeProposalVote = "proposal_vote"
|
||||||
// EventTypeActiveProposal = "active_proposal"
|
|
||||||
|
|
||||||
// AttributeKeyProposalResult = "proposal_result"
|
AttributeValueCategory = "committee"
|
||||||
// AttributeKeyOption = "option"
|
AttributeKeyCommitteeID = "committee_id"
|
||||||
AttributeKeyProposalID = "proposal_id"
|
AttributeKeyProposalID = "proposal_id"
|
||||||
// AttributeKeyVotingPeriodStart = "voting_period_start"
|
AttributeKeyProposalCloseStatus = "status"
|
||||||
// AttributeValueCategory = "governance"
|
AttributeValueProposalPassed = "proposal_passed"
|
||||||
// AttributeValueProposalDropped = "proposal_dropped" // didn't meet min deposit
|
AttributeValueProposalTimeout = "proposal_timeout"
|
||||||
// AttributeValueProposalPassed = "proposal_passed" // met vote quorum
|
AttributeValueProposalFailed = "proposal_failed"
|
||||||
// AttributeValueProposalRejected = "proposal_rejected" // didn't meet vote quorum
|
|
||||||
// AttributeValueProposalFailed = "proposal_failed" // error on proposal handler
|
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user