Skip to main content

dpp/voting/votes/resource_vote/v0/
mod.rs

1#[cfg(feature = "json-conversion")]
2use crate::serialization::json_safe_fields;
3use crate::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
4use crate::voting::vote_polls::VotePoll;
5use crate::ProtocolError;
6use bincode::{Decode, DecodeUntrusted, Encode};
7use platform_serialization_derive::{
8    PlatformDeserializeTrusted, PlatformDeserializeUntrusted, PlatformSerialize,
9};
10use platform_value::Identifier;
11#[cfg(feature = "serde-conversion")]
12use serde::{Deserialize, Serialize};
13
14#[cfg_attr(feature = "json-conversion", json_safe_fields)]
15#[derive(
16    Debug,
17    Clone,
18    Encode,
19    Decode,
20    PlatformDeserializeTrusted,
21    PlatformDeserializeUntrusted,
22    PlatformSerialize,
23    PartialEq,
24    DecodeUntrusted,
25)]
26#[cfg_attr(
27    feature = "serde-conversion",
28    derive(Serialize, Deserialize),
29    serde(rename_all = "camelCase")
30)]
31#[platform_serialize(unversioned)]
32pub struct ResourceVoteV0 {
33    pub vote_poll: VotePoll,
34    pub resource_vote_choice: ResourceVoteChoice,
35}
36
37impl Default for ResourceVoteV0 {
38    fn default() -> Self {
39        ResourceVoteV0 {
40            vote_poll: VotePoll::default(),
41            resource_vote_choice: ResourceVoteChoice::Abstain,
42        }
43    }
44}
45
46impl ResourceVoteV0 {
47    pub fn vote_poll_unique_id(&self) -> Result<Identifier, ProtocolError> {
48        self.vote_poll.unique_id()
49    }
50}