forked from neonevm/neon-spl-governance
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow missing TokenOwnerRecord for Withdraw and ChangeOwner instructi…
…ons neonevm#23 (neonevm#24) Co-authored-by: Semen Medvedev <sm@neonlabs.org>
- Loading branch information
1 parent
c58f4cf
commit c0c3732
Showing
5 changed files
with
92 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::error::VestingError; | ||
use solana_program::{ | ||
account_info::AccountInfo, | ||
program_error::ProgramError, | ||
pubkey::Pubkey, | ||
system_program, | ||
}; | ||
|
||
use spl_governance::state::{ | ||
token_owner_record::{ | ||
TokenOwnerRecordV2, | ||
get_token_owner_record_data_for_seeds, | ||
}, | ||
}; | ||
|
||
pub fn get_token_owner_record_data_if_exists( | ||
program_id: &Pubkey, | ||
token_owner_record_info: &AccountInfo, | ||
token_owner_record_seeds: &[&[u8]], | ||
) -> Result<Option<TokenOwnerRecordV2>, ProgramError> { | ||
let (token_owner_record_address, _) = | ||
Pubkey::find_program_address(token_owner_record_seeds, program_id); | ||
|
||
if token_owner_record_address != *token_owner_record_info.key { | ||
return Err(VestingError::InvalidTokenOwnerRecord.into()); | ||
} | ||
|
||
if token_owner_record_info.data_is_empty() { | ||
if *token_owner_record_info.owner != system_program::id() { | ||
return Err(VestingError::InvalidTokenOwnerRecord.into()); | ||
} | ||
|
||
Ok(None) | ||
} else { | ||
Ok(Some(get_token_owner_record_data_for_seeds( | ||
program_id, | ||
token_owner_record_info, | ||
token_owner_record_seeds)? | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters