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::*;
|
2019-02-15 08:42:09 -07:00
|
|
|
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;
|
2019-03-18 10:05:03 -06:00
|
|
|
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,
|
2019-03-18 10:05:03 -06:00
|
|
|
) -> Result<(), InstructionError> {
|
2018-12-14 12:36:50 -08:00
|
|
|
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);
|
|
|
|
|
2019-03-18 10:05:03 -06:00
|
|
|
match deserialize(data).map_err(|_| InstructionError::InvalidInstructionData)? {
|
2019-03-02 14:51:26 -07:00
|
|
|
VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts),
|
2019-02-28 17:08:45 -08:00
|
|
|
VoteInstruction::DelegateStake(delegate_id) => {
|
2019-03-09 19:28:43 -08:00
|
|
|
vote_state::delegate_stake(keyed_accounts, &delegate_id)
|
2019-02-28 17:08:45 -08:00
|
|
|
}
|
2019-03-06 14:28:21 -07:00
|
|
|
VoteInstruction::AuthorizeVoter(voter_id) => {
|
2019-03-09 19:28:43 -08:00
|
|
|
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());
|
2018-12-14 12:36:50 -08:00
|
|
|
solana_metrics::submit(
|
|
|
|
solana_metrics::influxdb::Point::new("vote-native")
|
|
|
|
.add_field("count", solana_metrics::influxdb::Value::Integer(1))
|
2018-12-11 15:43:41 -08:00
|
|
|
.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
|
|
|
}
|
|
|
|
}
|