pub fn serialize<W: Write>(self, writer: &mut W) -> Result<(), ProgramError> {
        if self.account_type == GovernanceAccountType::ProposalV2 {
            BorshSerialize::serialize(&self, writer)?
        } else if self.account_type == GovernanceAccountType::ProposalV1 {
            // V1 account can't be resized and we have to translate it back to the original format

            if self.abstain_vote_weight.is_some() {
                panic!("ProposalV1 doesn't support Abstain vote")
            }

            if self.veto_vote_weight.is_some() {
                panic!("ProposalV1 doesn't support Veto vote")
            }

            if self.start_voting_at.is_some() {
                panic!("ProposalV1 doesn't support start time")
            }

            if self.max_voting_time.is_some() {
                panic!("ProposalV1 doesn't support max voting time")
            }

            if self.options.len() != 1 {
                panic!("ProposalV1 doesn't support multiple options")
            }

            let proposal_data_v1 = ProposalV1 {
                account_type: self.account_type,
                governance: self.governance,
                governing_token_mint: self.governing_token_mint,
                state: self.state,
                token_owner_record: self.token_owner_record,
                signatories_count: self.signatories_count,
                signatories_signed_off_count: self.signatories_signed_off_count,
                yes_votes_count: self.options[0].vote_weight,
                no_votes_count: self.deny_vote_weight.unwrap(),
                instructions_executed_count: self.options[0].transactions_executed_count,
                instructions_count: self.options[0].transactions_count,
                instructions_next_index: self.options[0].transactions_next_index,
                draft_at: self.draft_at,
                signing_off_at: self.signing_off_at,
                voting_at: self.voting_at,
                voting_at_slot: self.voting_at_slot,
                voting_completed_at: self.voting_completed_at,
                executing_at: self.executing_at,
                closed_at: self.closed_at,
                execution_flags: self.execution_flags,
                max_vote_weight: self.max_vote_weight,
                vote_threshold_percentage: self.vote_threshold_percentage,
                name: self.name,
                description_link: self.description_link,
            };

            BorshSerialize::serialize(&proposal_data_v1, writer)?;
        }

        Ok(())
    }
/// Serializes account into the target buffer
Serializes account into the target buffer
Serializes account into the target buffer
pub fn serialize<W: Write>(self, writer: &mut W) -> Result<(), ProgramError> {
        if self.account_type == GovernanceAccountType::ProposalV2 {
            BorshSerialize::serialize(&self, writer)?
        } else if self.account_type == GovernanceAccountType::ProposalV1 {
            // V1 account can't be resized and we have to translate it back to the original format
            if self.abstain_vote_weight.is_some() {
                panic!("ProposalV1 doesn't support Abstain vote")
            }
            if self.veto_vote_weight.is_some() {
                panic!("ProposalV1 doesn't support Veto vote")
            }
            if self.start_voting_at.is_some() {
                panic!("ProposalV1 doesn't support start time")
            }
            if self.max_voting_time.is_some() {
                panic!("ProposalV1 doesn't support max voting time")
            }
            if self.options.len() != 1 {
                panic!("ProposalV1 doesn't support multiple options")
            }
            let proposal_data_v1 = ProposalV1 {
                account_type: self.account_type,
                governance: self.governance,
                governing_token_mint: self.governing_token_mint,
                state: self.state,
                token_owner_record: self.token_owner_record,
                signatories_count: self.signatories_count,
                signatories_signed_off_count: self.signatories_signed_off_count,
                yes_votes_count: self.options[0].vote_weight,
                no_votes_count: self.deny_vote_weight.unwrap(),
                instructions_executed_count: self.options[0].transactions_executed_count,
                instructions_count: self.options[0].transactions_count,
                instructions_next_index: self.options[0].transactions_next_index,
                draft_at: self.draft_at,
                signing_off_at: self.signing_off_at,
                voting_at: self.voting_at,
                voting_at_slot: self.voting_at_slot,
                voting_completed_at: self.voting_completed_at,
                executing_at: self.executing_at,
                closed_at: self.closed_at,
                execution_flags: self.execution_flags,
                max_vote_weight: self.max_vote_weight,
                vote_threshold_percentage: self.vote_threshold_percentage,
                name: self.name,
                description_link: self.description_link,
            };
            BorshSerialize::serialize(&proposal_data_v1, writer)?;
        }
        Ok(())
    }
pub fn serialize < W : Write > ( self , writer : & mut W ) -> Result < ( ) , ProgramError > { if self . account_type == GovernanceAccountType :: ProposalV2 { BorshSerialize :: serialize ( & self , writer ) ? } else if self . account_type == GovernanceAccountType :: ProposalV1 { // V1 account can't be resized and we have to translate it back to the original format if self . abstain_vote_weight . is_some ( ) { panic ! ( " " ) } if self . veto_vote_weight . is_some ( ) { panic ! ( " " ) } if self . start_voting_at . is_some ( ) { panic ! ( " " ) } if self . max_voting_time . is_some ( ) { panic ! ( " " ) } if self . options . len ( ) != 1 { panic ! ( " " ) } let proposal_data_v1 = ProposalV1 { account_type : self . account_type , governance : self . governance , governing_token_mint : self . governing_token_mint , state : self . state , token_owner_record : self . token_owner_record , signatories_count : self . signatories_count , signatories_signed_off_count : self . signatories_signed_off_count , yes_votes_count : self . options [ 0 ] . vote_weight , no_votes_count : self . deny_vote_weight . unwrap ( ) , instructions_executed_count : self . options [ 0 ] . transactions_executed_count , instructions_count : self . options [ 0 ] . transactions_count , instructions_next_index : self . options [ 0 ] . transactions_next_index , draft_at : self . draft_at , signing_off_at : self . signing_off_at , voting_at : self . voting_at , voting_at_slot : self . voting_at_slot , voting_completed_at : self . voting_completed_at , executing_at : self . executing_at , closed_at : self . closed_at , execution_flags : self . execution_flags , max_vote_weight : self . max_vote_weight , vote_threshold_percentage : self . vote_threshold_percentage , name : self . name , description_link : self . description_link , } ; BorshSerialize :: serialize ( & proposal_data_v1 , writer ) ? ; } Ok ( ( ) ) }
Serializes account into the target buffer
Serializes account into the target buffer
self
writer
&mut W
self
writer
&mut W