Skip to content

Commit

Permalink
voting-body: add pre-vote queue and top-up method (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba authored Oct 19, 2023
1 parent b8224e7 commit 7ba4034
Show file tree
Hide file tree
Showing 5 changed files with 249 additions and 79 deletions.
17 changes: 17 additions & 0 deletions voting_body/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,30 @@ impl FunctionError for ExecError {
pub enum CreatePropError {
NotAuthorized,
Storage(String),
MinBond,
}

impl FunctionError for CreatePropError {
fn panic(&self) -> ! {
match self {
CreatePropError::NotAuthorized => panic_str("not authorized"),
CreatePropError::Storage(reason) => panic_str(reason),
CreatePropError::MinBond => panic_str("min pre_vote_bond is required"),
}
}
}

#[cfg_attr(not(target_arch = "wasm32"), derive(PartialEq, Debug))]
pub enum MovePropError {
NotFound,
MinBond,
}

impl FunctionError for MovePropError {
fn panic(&self) -> ! {
match self {
MovePropError::NotFound => panic_str("proposal not found"),
MovePropError::MinBond => panic_str("min active_queue_bond is required"),
}
}
}
25 changes: 21 additions & 4 deletions voting_body/src/events.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use near_sdk::serde::Serialize;
use near_sdk::{json_types::U128, serde::Serialize, Balance};
use serde_json::json;

use crate::{proposal::PropKind, ExecError};
Expand All @@ -14,10 +14,27 @@ fn emit_event<T: Serialize>(event: EventPayload<T>) {
.emit();
}

pub(crate) fn emit_prop_created(prop_id: u32, kind: &PropKind) {
/// * `active`: set to true if the prosal was added to an active queue directly.
pub(crate) fn emit_prop_created(prop_id: u32, kind: &PropKind, active: bool) {
emit_event(EventPayload {
event: "new-proposal",
data: json!({ "prop_id": prop_id, "kind": kind.to_name() }),
event: "proposal-create",
data: json!({ "prop_id": prop_id, "kind": kind.to_name(), "active": active}),
});
}

/// Emitted when moving proposal from pre-vote to active queue.
pub(crate) fn emit_prop_active(prop_id: u32) {
emit_event(EventPayload {
event: "proposal-activate",
data: json!({ "prop_id": prop_id}),
});
}

/// Emitted when removing prevote prop and slashing it for not getting enough support.
pub(crate) fn emit_prevote_prop_slashed(prop_id: u32, bond: Balance) {
emit_event(EventPayload {
event: "proposal-prevote-slash",
data: json!({ "prop_id": prop_id, "bond": U128(bond)}),
});
}

Expand Down
Loading

0 comments on commit 7ba4034

Please sign in to comment.