Skip to main content

amaru_kernel/cardano/
proposal_state.rs

1// Copyright 2025 PRAGMA
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::collections::BTreeMap;
16
17use crate::{Epoch, PoolId, Proposal, ProposalId, StakeCredential, Vote, cbor};
18
19#[derive(Debug)]
20pub struct ProposalState {
21    pub id: ProposalId,
22    pub procedure: Proposal,
23    pub proposed_in: Epoch,
24    pub expires_after: Epoch,
25    pub committee_votes: BTreeMap<StakeCredential, Vote>,
26    pub dreps_votes: BTreeMap<StakeCredential, Vote>,
27    pub pools_votes: BTreeMap<PoolId, Vote>,
28}
29
30impl<'b, C> cbor::decode::Decode<'b, C> for ProposalState {
31    fn decode(d: &mut cbor::Decoder<'b>, ctx: &mut C) -> Result<Self, cbor::decode::Error> {
32        d.array()?;
33        let id = d.decode_with(ctx)?;
34        let committee_votes = d.decode_with(ctx)?;
35        let dreps_votes = d.decode_with(ctx)?;
36        let pools_votes = d.decode_with(ctx)?;
37        let procedure = d.decode_with(ctx)?;
38        let proposed_in = d.decode_with(ctx)?;
39        let expires_after = d.decode_with(ctx)?;
40
41        Ok(ProposalState { id, procedure, proposed_in, expires_after, dreps_votes, pools_votes, committee_votes })
42    }
43}