-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
77 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::{ | ||
error::BlockbusterError, | ||
instruction::InstructionBundle, | ||
program_handler::{NotUsed, ParseResult, ProgramParser}, | ||
programs::ProgramParseResult, | ||
}; | ||
use borsh::BorshDeserialize; | ||
use mpl_candy_machine_core::CandyMachine; | ||
use plerkle_serialization::AccountInfo; | ||
use solana_sdk::{pubkey::Pubkey, pubkeys}; | ||
use std::convert::TryInto; | ||
|
||
pubkeys!( | ||
candy_machine_core_id, | ||
"CndyV3LdqHUfDLmE5naZjVN8rBZz4tqhdefbAnjHG3JR" | ||
); | ||
|
||
// Anchor account discriminators. | ||
const CANDY_MACHINE_DISCRIMINATOR: [u8; 8] = [51, 173, 177, 113, 25, 241, 109, 189]; | ||
|
||
pub enum CandyMachineCoreAccountData { | ||
CandyMachineCore(CandyMachine), | ||
} | ||
|
||
impl ParseResult for CandyMachineCoreAccountData { | ||
fn result_type(&self) -> ProgramParseResult { | ||
ProgramParseResult::CandyMachineCore(self) | ||
} | ||
} | ||
|
||
pub struct CandyMachineParser; | ||
|
||
impl ProgramParser for CandyMachineParser { | ||
fn key(&self) -> Pubkey { | ||
candy_machine_core_id() | ||
} | ||
|
||
fn key_match(&self, key: &Pubkey) -> bool { | ||
key == &candy_machine_core_id() | ||
} | ||
|
||
fn handle_account( | ||
&self, | ||
account_info: &AccountInfo, | ||
) -> Result<Box<dyn ParseResult>, BlockbusterError> { | ||
let account_data = if let Some(account_info) = account_info.data() { | ||
account_info | ||
} else { | ||
return Err(BlockbusterError::DeserializationError); | ||
}; | ||
|
||
let discriminator: [u8; 8] = account_data[0..8].try_into().unwrap(); | ||
|
||
let account_type = match discriminator { | ||
CANDY_MACHINE_DISCRIMINATOR => { | ||
let candy_machine = CandyMachine::try_from_slice(&account_data[8..])?; | ||
CandyMachineCoreAccountData::CandyMachineCore(candy_machine) | ||
} | ||
_ => return Err(BlockbusterError::UnknownAccountDiscriminator), | ||
}; | ||
|
||
Ok(Box::new(account_type)) | ||
} | ||
|
||
fn handle_instruction( | ||
&self, | ||
_bundle: &InstructionBundle, | ||
) -> Result<Box<dyn ParseResult>, BlockbusterError> { | ||
Ok(Box::new(NotUsed::new())) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
use bubblegum::BubblegumInstruction; | ||
use candy_machine::CandyMachineAccountData; | ||
use token_metadata::TokenMetadataAccountState; | ||
use candy_machine_core::CandyMachineCoreAccountData; | ||
use token_account::TokenProgramAccount; | ||
use token_metadata::TokenMetadataAccountState; | ||
|
||
pub mod bubblegum; | ||
pub mod candy_machine; | ||
pub mod token_metadata; | ||
pub mod candy_machine_core; | ||
pub mod token_account; | ||
pub mod token_metadata; | ||
// pub mod gummyroll; | ||
|
||
pub enum ProgramParseResult<'a> { | ||
Bubblegum(&'a BubblegumInstruction), | ||
TokenMetadata(&'a TokenMetadataAccountState), | ||
TokenProgramAccount(&'a TokenProgramAccount), | ||
CandyMachine(&'a CandyMachineAccountData), | ||
CandyMachineCore(&'a CandyMachineCoreAccountData), | ||
Unknown, | ||
} |