|
| 1 | +//! A public vote tx vote objects. |
| 2 | +
|
| 3 | +use minicbor::{Decode, Encode}; |
| 4 | + |
| 5 | +use crate::uuid::Uuid; |
| 6 | + |
| 7 | +/// A public voting choice struct. |
| 8 | +#[derive(Debug, Clone, PartialEq)] |
| 9 | +pub struct Choice(pub u64); |
| 10 | + |
| 11 | +/// A public voting proof struct, CBOR `undefined`. |
| 12 | +#[derive(Debug, Clone, PartialEq)] |
| 13 | +pub struct Proof; |
| 14 | + |
| 15 | +/// A public voting proposal id struct. |
| 16 | +pub type PropId = Uuid; |
| 17 | + |
| 18 | +impl Decode<'_, ()> for Choice { |
| 19 | + fn decode(d: &mut minicbor::Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> { |
| 20 | + let choice = d.u64()?; |
| 21 | + Ok(Self(choice)) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +impl Encode<()> for Choice { |
| 26 | + fn encode<W: minicbor::encode::Write>( |
| 27 | + &self, e: &mut minicbor::Encoder<W>, (): &mut (), |
| 28 | + ) -> Result<(), minicbor::encode::Error<W::Error>> { |
| 29 | + self.0.encode(e, &mut ()) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +impl Decode<'_, ()> for Proof { |
| 34 | + fn decode(d: &mut minicbor::Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> { |
| 35 | + d.undefined()?; |
| 36 | + Ok(Self) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +impl Encode<()> for Proof { |
| 41 | + fn encode<W: minicbor::encode::Write>( |
| 42 | + &self, e: &mut minicbor::Encoder<W>, (): &mut (), |
| 43 | + ) -> Result<(), minicbor::encode::Error<W::Error>> { |
| 44 | + e.undefined()?; |
| 45 | + Ok(()) |
| 46 | + } |
| 47 | +} |
0 commit comments