From aa96ec3338e5ca4c176e7ba62c748007a7a05f04 Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Sat, 28 Dec 2024 13:59:09 +0000 Subject: [PATCH] Expose the queue of votes to process (#42) --- canister/can.did | 11 +++++++++++ canister/src/lib.rs | 6 +++--- canister/src/queries/mod.rs | 1 + canister/src/queries/votes_to_process.rs | 7 +++++++ canister/src/state.rs | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 canister/src/queries/votes_to_process.rs diff --git a/canister/can.did b/canister/can.did index 0fbb50d..e7ac7cf 100644 --- a/canister/can.did +++ b/canister/can.did @@ -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; @@ -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; } \ No newline at end of file diff --git a/canister/src/lib.rs b/canister/src/lib.rs index 2bfe651..8fb8e02 100644 --- a/canister/src/lib.rs +++ b/canister/src/lib.rs @@ -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, diff --git a/canister/src/queries/mod.rs b/canister/src/queries/mod.rs index 3d5a5bb..dcb83e2 100644 --- a/canister/src/queries/mod.rs +++ b/canister/src/queries/mod.rs @@ -1,2 +1,3 @@ mod list_neuron_pairs; mod logs; +mod votes_to_process; diff --git a/canister/src/queries/votes_to_process.rs b/canister/src/queries/votes_to_process.rs new file mode 100644 index 0000000..b616f03 --- /dev/null +++ b/canister/src/queries/votes_to_process.rs @@ -0,0 +1,7 @@ +use crate::{state, VoteToProcess}; +use ic_cdk::query; + +#[query] +fn votes_to_process() -> Vec { + state::read(|s| s.votes_to_process()) +} diff --git a/canister/src/state.rs b/canister/src/state.rs index 9b5e478..50b140c 100644 --- a/canister/src/state.rs +++ b/canister/src/state.rs @@ -145,6 +145,10 @@ impl State { self.votes_to_process.pop_front() } + pub fn votes_to_process(&self) -> Vec { + self.votes_to_process.iter().cloned().collect() + } + pub fn votes_to_process_count(&self) -> usize { self.votes_to_process.len() }