Skip to content

Commit

Permalink
move definition of public_tx/choice and public_tx/proof to the public…
Browse files Browse the repository at this point in the history
…_tx/vote mod
  • Loading branch information
Mr-Leshiy committed Dec 2, 2024
1 parent 6ed8202 commit bf461c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 53 deletions.
22 changes: 0 additions & 22 deletions rust/vote-tx-v2/src/public_tx/choice.rs

This file was deleted.

11 changes: 3 additions & 8 deletions rust/vote-tx-v2/src/public_tx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
//! A Catalyst public vote transaction v2 object, structured following this
//! [spec](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/catalyst_voting/v2/#public-vote)
mod choice;
mod proof;
mod vote;

use std::ops::{Deref, DerefMut};

pub use choice::Choice;
use minicbor::{Decode, Encode};
pub use proof::Proof;
pub use vote::{Choice, Proof, PropId};

use crate::{gen_tx::GeneralizedTx, uuid::Uuid, Cbor};

/// A public voting proposal id struct.
pub type PropId = Uuid;
use crate::{gen_tx::GeneralizedTx, Cbor};

/// A public vote tx struct.
#[derive(Debug, Clone, PartialEq)]
Expand Down
23 changes: 0 additions & 23 deletions rust/vote-tx-v2/src/public_tx/proof.rs

This file was deleted.

47 changes: 47 additions & 0 deletions rust/vote-tx-v2/src/public_tx/vote.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! A public vote tx vote objects.
use minicbor::{Decode, Encode};

use crate::uuid::Uuid;

/// A public voting choice struct.
#[derive(Debug, Clone, PartialEq)]
pub struct Choice(pub u64);

/// A public voting proof struct, CBOR `undefined`.
#[derive(Debug, Clone, PartialEq)]
pub struct Proof;

/// A public voting proposal id struct.
pub type PropId = Uuid;

impl Decode<'_, ()> for Choice {
fn decode(d: &mut minicbor::Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> {
let choice = d.u64()?;
Ok(Self(choice))
}
}

impl Encode<()> for Choice {
fn encode<W: minicbor::encode::Write>(
&self, e: &mut minicbor::Encoder<W>, (): &mut (),
) -> Result<(), minicbor::encode::Error<W::Error>> {
self.0.encode(e, &mut ())
}
}

impl Decode<'_, ()> for Proof {
fn decode(d: &mut minicbor::Decoder<'_>, (): &mut ()) -> Result<Self, minicbor::decode::Error> {
d.undefined()?;
Ok(Self)
}
}

impl Encode<()> for Proof {
fn encode<W: minicbor::encode::Write>(
&self, e: &mut minicbor::Encoder<W>, (): &mut (),
) -> Result<(), minicbor::encode::Error<W::Error>> {
e.undefined()?;
Ok(())
}
}

0 comments on commit bf461c3

Please sign in to comment.