whisky_pallas/wrapper/transaction_body/
voting_procedure.rs1use pallas::ledger::primitives::{conway::VotingProcedure as PallasVotingProcedure, Fragment};
2
3use crate::wrapper::transaction_body::{Anchor, Vote};
4
5#[derive(Debug, PartialEq, Eq, Clone)]
6pub struct VotingProdecedure {
7 pub inner: PallasVotingProcedure,
8}
9
10impl VotingProdecedure {
11 pub fn new(vote: Vote, anchor: Option<Anchor>) -> Self {
12 let pallas_vote = vote.inner;
13 let pallas_anchor = anchor.map(|a| a.inner);
14 let pallas_vote_procedure = PallasVotingProcedure {
15 vote: pallas_vote,
16 anchor: pallas_anchor,
17 };
18 Self {
19 inner: pallas_vote_procedure,
20 }
21 }
22
23 pub fn encode(&self) -> String {
24 hex::encode(
25 self.inner
26 .encode_fragment()
27 .expect("encoding failed at VotingProcedure"),
28 )
29 }
30 pub fn decode_bytes(bytes: &[u8]) -> Result<Self, String> {
31 let inner = PallasVotingProcedure::decode_fragment(&bytes)
32 .map_err(|e| format!("Fragment decode error: {}", e.to_string()))?;
33 Ok(Self { inner })
34 }
35}