pub fn vote(
        &mut self,
        settings: Settings,
        proposal: &Proposal,
        choice: Choice,
        valid_until: &BlockDate,
    ) -> Result<Box<[u8]>, Error> {
        let payload = if let Some(payload) = proposal.vote(choice) {
            payload
        } else {
            return Err(Error::wallet_vote_range());
        };

        let mut builder = wallet::TransactionBuilder::new(&settings, payload, *valid_until);

        let value = builder.estimate_fee_with(1, 0);

        let account_tx_builder = self
            .account
            .new_transaction(value)
            .map_err(|_| Error::not_enough_funds())?;

        let input = account_tx_builder.input();
        let witness_builder = account_tx_builder.witness_builder();

        builder.add_input(input, witness_builder);

        let tx = builder
            .finalize_tx(())
            .map_err(|e| Error::wallet_transaction().with(e))?;

        let fragment = Fragment::VoteCast(tx);
        let id = fragment.hash();

        account_tx_builder.add_fragment_id(id);

        Ok(fragment.serialize_as_vec().unwrap().into_boxed_slice())
    }
/// Cast a vote
///
/// This function outputs a fragment containing a voting transaction.
///
/// # Parameters
///
/// * `settings` - ledger settings.
/// * `proposal` - proposal information including the range of values
///   allowed in `choice`.
/// * `choice` - the option to vote for.
///
/// # Errors
///
/// The error is returned when `choice` does not fall withing the range of
/// available choices specified in `proposal`.
Cast a vote
This function outputs a fragment containing a voting transaction.
Cast a vote This function outputs a fragment containing a voting transaction .
pub fn vote(
        &mut self,
        settings: Settings,
        proposal: &Proposal,
        choice: Choice,
        valid_until: &BlockDate,
    ) -> Result<Box<[u8]>, Error> {
        let payload = if let Some(payload) = proposal.vote(choice) {
            payload
        } else {
            return Err(Error::wallet_vote_range());
        };
        let mut builder = wallet::TransactionBuilder::new(&settings, payload, *valid_until);
        let value = builder.estimate_fee_with(1, 0);
        let account_tx_builder = self
            .account
            .new_transaction(value)
            .map_err(|_| Error::not_enough_funds())?;
        let input = account_tx_builder.input();
        let witness_builder = account_tx_builder.witness_builder();
        builder.add_input(input, witness_builder);
        let tx = builder
            .finalize_tx(())
            .map_err(|e| Error::wallet_transaction().with(e))?;
        let fragment = Fragment::VoteCast(tx);
        let id = fragment.hash();
        account_tx_builder.add_fragment_id(id);
        Ok(fragment.serialize_as_vec().unwrap().into_boxed_slice())
    }
pub fn vote ( & mut self , settings : Settings , proposal : & Proposal , choice : Choice , valid_until : & BlockDate , ) -> Result < Box < [ u8 ] > , Error > { let payload = if let Some ( payload ) = proposal . vote ( choice ) { payload } else { return Err ( Error :: wallet_vote_range ( ) ) ; } ; let mut builder = wallet :: TransactionBuilder :: new ( & settings , payload , * valid_until ) ; let value = builder . estimate_fee_with ( 1 , 0 ) ; let account_tx_builder = self . account . new_transaction ( value ) . map_err ( | _ | Error :: not_enough_funds ( ) ) ? ; let input = account_tx_builder . input ( ) ; let witness_builder = account_tx_builder . witness_builder ( ) ; builder . add_input ( input , witness_builder ) ; let tx = builder . finalize_tx ( ( ) ) . map_err ( | e | Error :: wallet_transaction ( ) . with ( e ) ) ? ; let fragment = Fragment :: VoteCast ( tx ) ; let id = fragment . hash ( ) ; account_tx_builder . add_fragment_id ( id ) ; Ok ( fragment . serialize_as_vec ( ) . unwrap ( ) . into_boxed_slice ( ) ) }
Cast a vote
This function outputs a fragment containing a voting transaction.
Cast a vote This function outputs a fragment containing a voting transaction .
&mut self
settings
Settings
proposal
&Proposal
choice
Choice
valid_until
&BlockDate
&mut self
settings
Settings
proposal
&Proposal
choice
Choice
valid_until
&BlockDate
errors
The error is returned when `choice` does not fall withing the range of
available choices specified in `proposal`.
The error is returned when ` choice ` does not fall withing the range of available choices specified in ` proposal ` .