41 lines
1.4 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::native_program::ProgramError;
use solana_sdk::pubkey::Pubkey;
2018-12-14 20:39:10 -08:00
use solana_sdk::solana_entrypoint;
use solana_sdk::vote_program::{self, VoteInstruction};
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<(), ProgramError> {
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-01-21 15:45:30 -08:00
match deserialize(data).map_err(|_| ProgramError::InvalidUserdata)? {
VoteInstruction::InitializeAccount => vote_program::initialize_account(keyed_accounts),
VoteInstruction::DelegateStake(delegate_id) => {
vote_program::delegate_stake(keyed_accounts, delegate_id)
}
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(),
);
vote_program::process_vote(keyed_accounts, vote)
2019-01-21 15:45:30 -08:00
}
2019-02-15 13:20:34 -07:00
VoteInstruction::ClearCredits => vote_program::clear_credits(keyed_accounts),
2019-01-21 15:45:30 -08:00
}
}