45 lines
1.6 KiB
Rust
Raw Normal View History

2018-12-04 07:45:32 -08:00
//! Vote program
//! Receive and processes votes from validators
2019-01-21 15:45:30 -08:00
use bincode::deserialize;
2018-12-14 20:39:10 -08:00
use log::*;
use solana_sdk::account::KeyedAccount;
2018-12-04 07:45:32 -08:00
use solana_sdk::pubkey::Pubkey;
2018-12-14 20:39:10 -08:00
use solana_sdk::solana_entrypoint;
use solana_sdk::transaction::InstructionError;
2019-03-02 14:51:26 -07:00
use solana_vote_api::vote_instruction::VoteInstruction;
use solana_vote_api::vote_state;
2018-12-04 07:45:32 -08:00
solana_entrypoint!(entrypoint);
fn entrypoint(
_program_id: &Pubkey,
keyed_accounts: &mut [KeyedAccount],
data: &[u8],
_tick_height: u64,
) -> Result<(), InstructionError> {
solana_logger::setup();
2018-12-04 18:09:15 -08:00
2018-12-04 07:45:32 -08:00
trace!("process_instruction: {:?}", data);
trace!("keyed_accounts: {:?}", keyed_accounts);
match deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
2019-03-02 14:51:26 -07:00
VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts),
VoteInstruction::DelegateStake(delegate_id) => {
vote_state::delegate_stake(keyed_accounts, &delegate_id)
}
2019-03-06 14:28:21 -07:00
VoteInstruction::AuthorizeVoter(voter_id) => {
vote_state::authorize_voter(keyed_accounts, &voter_id)
2019-03-06 14:28:21 -07:00
}
2019-02-01 15:50:11 -07:00
VoteInstruction::Vote(vote) => {
2018-12-10 12:26:44 -08:00
debug!("{:?} by {}", vote, keyed_accounts[0].signer_key().unwrap());
solana_metrics::submit(
solana_metrics::influxdb::Point::new("vote-native")
.add_field("count", solana_metrics::influxdb::Value::Integer(1))
.to_owned(),
);
2019-03-02 14:51:26 -07:00
vote_state::process_vote(keyed_accounts, vote)
2019-01-21 15:45:30 -08:00
}
2019-03-02 14:51:26 -07:00
VoteInstruction::ClearCredits => vote_state::clear_credits(keyed_accounts),
2019-01-21 15:45:30 -08:00
}
}