solana_vote_program/
vote_transaction.rs

1use {
2    crate::{vote_instruction, vote_state::Vote},
3    solana_sdk::{
4        clock::Slot,
5        hash::Hash,
6        signature::{Keypair, Signer},
7        transaction::Transaction,
8    },
9};
10
11pub fn new_vote_transaction(
12    slots: Vec<Slot>,
13    bank_hash: Hash,
14    blockhash: Hash,
15    node_keypair: &Keypair,
16    vote_keypair: &Keypair,
17    authorized_voter_keypair: &Keypair,
18    switch_proof_hash: Option<Hash>,
19) -> Transaction {
20    let votes = Vote::new(slots, bank_hash);
21    let vote_ix = if let Some(switch_proof_hash) = switch_proof_hash {
22        vote_instruction::vote_switch(
23            &vote_keypair.pubkey(),
24            &authorized_voter_keypair.pubkey(),
25            votes,
26            switch_proof_hash,
27        )
28    } else {
29        vote_instruction::vote(
30            &vote_keypair.pubkey(),
31            &authorized_voter_keypair.pubkey(),
32            votes,
33        )
34    };
35
36    let mut vote_tx = Transaction::new_with_payer(&[vote_ix], Some(&node_keypair.pubkey()));
37
38    vote_tx.partial_sign(&[node_keypair], blockhash);
39    vote_tx.partial_sign(&[authorized_voter_keypair], blockhash);
40    vote_tx
41}