No longer modify external userdata

This commit is contained in:
Greg Fitzgerald
2019-02-15 13:20:34 -07:00
parent 288645aeb7
commit 132c664e18
5 changed files with 39 additions and 20 deletions

View File

@ -46,6 +46,9 @@ pub enum VoteInstruction {
/// identified by keys[0] for voting
RegisterAccount,
Vote(Vote),
/// Clear the credits in the vote account
/// * Transaction::keys[0] - the "vote account"
ClearCredits,
}
#[derive(Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
@ -148,6 +151,18 @@ pub fn process_vote(keyed_accounts: &mut [KeyedAccount], vote: Vote) -> Result<(
Ok(())
}
pub fn clear_credits(keyed_accounts: &mut [KeyedAccount]) -> Result<(), ProgramError> {
if !check_id(&keyed_accounts[0].account.owner) {
error!("account[0] is not assigned to the VOTE_PROGRAM");
Err(ProgramError::InvalidArgument)?;
}
let mut vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata)?;
vote_state.clear_credits();
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
Ok(())
}
pub fn create_vote_account(tokens: u64) -> Account {
let space = get_max_size();
Account::new(tokens, space, id())