Skip to content

Commit

Permalink
Expose the queue of votes to process (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 28, 2024
1 parent 7a81d7f commit aa96ec3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions canister/can.did
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type NeuronPairPublic = record {
nns_neuron_id : nat64;
wtn_neuron_id : blob;
};
type NnsVote = record { adopt : bool; proposal_id : nat64 };
type QueryStats = record {
response_payload_bytes_total : nat;
num_instructions_total : nat;
Expand All @@ -56,10 +57,20 @@ type RegisterNeuronPairError = variant {
GovernanceError : record { int32; text };
};
type Result = variant { Ok : nat64; Err : RegisterNeuronPairError };
type VoteToProcess = variant {
NnsVote : record { nat64; NnsVote };
PendingWtnVote : record { nat64; WtnVote };
};
type WtnVote = record {
nns_proposal_id : nat64;
adopt : bool;
wtn_proposal_id : nat64;
};
service : (InitOrUpgradeArgs) -> {
deregister_neuron_pair : (DeregisterNeuronPairArgs) -> (bool);
list_neuron_pairs : () -> (vec NeuronPairPublic) query;
logs : () -> (vec text) query;
register_neuron_pair : (RegisterNeuronPairArgs) -> (Result);
status : () -> (CanisterStatusResponse);
votes_to_process : () -> (vec VoteToProcess) query;
}
6 changes: 3 additions & 3 deletions canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ impl InitOrUpgradeArgs {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
enum VoteToProcess {
NnsVote(u64, NnsVote),
PendingWtnVote(u64, WtnVote),
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
struct NnsVote {
proposal_id: u64,
adopt: bool,
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(CandidType, Serialize, Deserialize, Clone, Debug)]
struct WtnVote {
nns_proposal_id: u64,
wtn_proposal_id: u64,
Expand Down
1 change: 1 addition & 0 deletions canister/src/queries/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod list_neuron_pairs;
mod logs;
mod votes_to_process;
7 changes: 7 additions & 0 deletions canister/src/queries/votes_to_process.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use crate::{state, VoteToProcess};
use ic_cdk::query;

#[query]
fn votes_to_process() -> Vec<VoteToProcess> {
state::read(|s| s.votes_to_process())
}
4 changes: 4 additions & 0 deletions canister/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl State {
self.votes_to_process.pop_front()
}

pub fn votes_to_process(&self) -> Vec<VoteToProcess> {
self.votes_to_process.iter().cloned().collect()
}

pub fn votes_to_process_count(&self) -> usize {
self.votes_to_process.len()
}
Expand Down

0 comments on commit aa96ec3

Please sign in to comment.