Skip to content

Commit

Permalink
Add mpl-core account parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed Mar 25, 2024
1 parent b06ad27 commit 66ca5f5
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blockbuster/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bs58 = "0.4.0"
lazy_static = "1.4.0"
log = "0.4.17"
mpl-bubblegum = "1.2.0"
mpl-core = { version = "0.1.0", features = ["serde"] }
mpl-token-metadata = { version = "4.1.1", features = ["serde"] }
solana-sdk = "~1.17"
solana-transaction-status = "~1.17"
Expand Down
1 change: 1 addition & 0 deletions blockbuster/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pub mod instruction;
pub mod program_handler;
pub mod programs;

pub use mpl_core;
pub use mpl_token_metadata as token_metadata;
3 changes: 3 additions & 0 deletions blockbuster/src/programs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use bubblegum::BubblegumInstruction;
use mpl_core_program::MplCoreAccountState;
use token_account::TokenProgramAccount;
use token_metadata::TokenMetadataAccountState;

pub mod bubblegum;
pub mod mpl_core_program;
pub mod token_account;
pub mod token_metadata;

Expand All @@ -22,6 +24,7 @@ pub mod token_metadata;
// though it did not depend on the `mpl-candy-machine` crate, it was also not being used by DAS.
pub enum ProgramParseResult<'a> {
Bubblegum(&'a BubblegumInstruction),
MplCore(&'a MplCoreAccountState),
TokenMetadata(&'a TokenMetadataAccountState),
TokenProgramAccount(&'a TokenProgramAccount),
Unknown,
Expand Down
91 changes: 91 additions & 0 deletions blockbuster/src/programs/mpl_core_program/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
use crate::{
error::BlockbusterError,
program_handler::{ParseResult, ProgramParser},
programs::ProgramParseResult,
};
use borsh::BorshDeserialize;
use mpl_core::{types::Key, IndexableAsset};
use solana_sdk::{pubkey::Pubkey, pubkeys};

pubkeys!(mpl_core_id, "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d");

pub enum MplCoreAccountData {
Asset(IndexableAsset),
Collection(IndexableAsset),
HashedAsset,
EmptyAccount,
}

pub struct MplCoreAccountState {
pub key: Key,
pub data: MplCoreAccountData,
}

impl ParseResult for MplCoreAccountState {
fn result(&self) -> &Self
where
Self: Sized,
{
self
}
fn result_type(&self) -> ProgramParseResult {
ProgramParseResult::MplCore(self)
}
}

pub struct MplCoreParser;

impl ProgramParser for MplCoreParser {
fn key(&self) -> Pubkey {
mpl_core_id()
}
fn key_match(&self, key: &Pubkey) -> bool {
key == &mpl_core_id()
}

fn handles_account_updates(&self) -> bool {
true
}

fn handles_instructions(&self) -> bool {
false
}

fn handle_account(
&self,
account_data: &[u8],
) -> Result<Box<(dyn ParseResult + 'static)>, BlockbusterError> {
if account_data.is_empty() {
return Ok(Box::new(MplCoreAccountState {
key: Key::Uninitialized,
data: MplCoreAccountData::EmptyAccount,
}));
}
let key = Key::try_from_slice(&account_data[0..1])?;
let mpl_core_account_state = match key {
Key::AssetV1 => {
let indexable_asset = IndexableAsset::fetch(key, account_data)?;
MplCoreAccountState {
key,
data: MplCoreAccountData::Asset(indexable_asset),
}
}
Key::CollectionV1 => {
let indexable_asset = IndexableAsset::fetch(key, account_data)?;
MplCoreAccountState {
key,
data: MplCoreAccountData::Collection(indexable_asset),
}
}
Key::Uninitialized => MplCoreAccountState {
key: Key::Uninitialized,
data: MplCoreAccountData::EmptyAccount,
},
_ => {
return Err(BlockbusterError::AccountTypeNotImplemented);
}
};

Ok(Box::new(mpl_core_account_state))
}
}

0 comments on commit 66ca5f5

Please sign in to comment.