Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mpl-core account parsing #41

Merged
merged 2 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
}
Loading