Skip to content

Commit

Permalink
added proposal type to proposal tm events
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli committed Jan 5, 2024
1 parent 06e6172 commit fadba12
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
20 changes: 15 additions & 5 deletions apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ where
id,
proposal_code.is_some(),
result,
proposal_type,
)
.into()
}
Expand All @@ -118,8 +119,12 @@ where
id
);

ProposalEvent::pgf_steward_proposal_event(id, result)
.into()
ProposalEvent::pgf_steward_proposal_event(
id,
result,
proposal_type,
)
.into()
}
ProposalType::PGFPayment(payments) => {
let native_token =
Expand All @@ -136,8 +141,12 @@ where
id
);

ProposalEvent::pgf_payments_proposal_event(id, result)
.into()
ProposalEvent::pgf_payments_proposal_event(
id,
result,
proposal_type,
)
.into()
}
};
response.events.push(proposal_event);
Expand Down Expand Up @@ -165,7 +174,8 @@ where
}
}
let proposal_event =
ProposalEvent::rejected_proposal_event(id).into();
ProposalEvent::rejected_proposal_event(id, proposal_type)
.into();
response.events.push(proposal_event);
proposals_result.rejected.push(id);

Expand Down
35 changes: 29 additions & 6 deletions shared/src/ledger/governance/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use std::collections::HashMap;

use namada_core::ledger::governance::storage::proposal::ProposalType;
use namada_core::ledger::governance::utils::TallyResult;
use namada_sdk::events::{Event, EventLevel};
use thiserror::Error;
Expand Down Expand Up @@ -53,6 +54,7 @@ impl ProposalEvent {
id: u64,
has_proposal_code: bool,
proposal_code_exit_status: bool,
proposal_type: ProposalType,
) -> Self {
let attributes = HashMap::from([
("tally_result".to_string(), tally.to_string()),
Expand All @@ -65,6 +67,7 @@ impl ProposalEvent {
"proposal_code_exit_status".to_string(),
(!proposal_code_exit_status as u64).to_string(),
),
("proposal_type".to_string(), proposal_type.to_string()),
]);
Self {
event_type,
Expand All @@ -73,33 +76,43 @@ impl ProposalEvent {
}

/// Create a new proposal event for rejected proposal
pub fn rejected_proposal_event(proposal_id: u64) -> Self {
pub fn rejected_proposal_event(
proposal_id: u64,
proposal_type: ProposalType,
) -> Self {
ProposalEvent::new(
EventType::Proposal.to_string(),
TallyResult::Rejected,
proposal_id,
false,
false,
proposal_type,
)
}

/// Create a new proposal event for default proposal
pub fn default_proposal_event(
proposal_id: u64,
has_code: bool,
execution_status: bool,
result: bool,
proposal_type: ProposalType,
) -> Self {
ProposalEvent::new(
EventType::Proposal.to_string(),
TallyResult::Passed,
proposal_id,
has_code,
execution_status,
result,
proposal_type,
)
}

/// Create a new proposal event for pgf stewards proposal
pub fn pgf_steward_proposal_event(proposal_id: u64, result: bool) -> Self {
pub fn pgf_steward_proposal_event(
proposal_id: u64,
result: bool,
proposal_type: ProposalType,
) -> Self {
ProposalEvent::new(
EventType::Proposal.to_string(),
TallyResult::Passed,
Expand All @@ -110,24 +123,34 @@ impl ProposalEvent {
}

/// Create a new proposal event for pgf payments proposal
pub fn pgf_payments_proposal_event(proposal_id: u64, result: bool) -> Self {
pub fn pgf_payments_proposal_event(
proposal_id: u64,
result: bool,
proposal_type: ProposalType,
) -> Self {
ProposalEvent::new(
EventType::Proposal.to_string(),
TallyResult::Passed,
proposal_id,
false,
result,
proposal_type,
)
}

/// Create a new proposal event for eth proposal
pub fn eth_proposal_event(proposal_id: u64, result: bool) -> Self {
pub fn eth_proposal_event(
proposal_id: u64,
result: bool,
proposal_type: ProposalType,
) -> Self {
ProposalEvent::new(
EventType::Proposal.to_string(),
TallyResult::Passed,
proposal_id,
false,
result,
proposal_type,
)
}
}

0 comments on commit fadba12

Please sign in to comment.