Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

voting-body: add pre-vote queue and top-up method #108

Merged
merged 9 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading