generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify Rust client to ignore unknown plugins (#52)
* Modify Rust client to ignore unknown plugins * Add full collection deserialization. * Remove fetch_plugins function. * Add fetching plugins tests * Add create collection tests * Add back updated fetch_plugins and tests * Rename deserialize_collection
- Loading branch information
Showing
10 changed files
with
916 additions
and
178 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,47 @@ | ||
use borsh::BorshSerialize; | ||
|
||
use crate::{ | ||
accounts::{BaseCollectionV1, PluginHeaderV1}, | ||
registry_records_to_plugin_list, Collection, PluginRegistryV1Safe, | ||
}; | ||
|
||
impl Collection { | ||
pub fn deserialize(data: &[u8]) -> Result<Self, std::io::Error> { | ||
let base = BaseCollectionV1::from_bytes(data)?; | ||
let base_data = base.try_to_vec()?; | ||
let (plugin_header, plugin_list) = if base_data.len() != data.len() { | ||
let plugin_header = PluginHeaderV1::from_bytes(&data[base_data.len()..])?; | ||
let plugin_registry = PluginRegistryV1Safe::from_bytes( | ||
&data[plugin_header.plugin_registry_offset as usize..], | ||
)?; | ||
|
||
let plugin_list = registry_records_to_plugin_list(&plugin_registry.registry, data)?; | ||
|
||
(Some(plugin_header), Some(plugin_list)) | ||
} else { | ||
(None, None) | ||
}; | ||
|
||
Ok(Self { | ||
base, | ||
plugin_list: plugin_list.unwrap_or_default(), | ||
plugin_header, | ||
}) | ||
} | ||
|
||
#[inline(always)] | ||
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> { | ||
Self::deserialize(data) | ||
} | ||
} | ||
|
||
impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Collection { | ||
type Error = std::io::Error; | ||
|
||
fn try_from( | ||
account_info: &solana_program::account_info::AccountInfo<'a>, | ||
) -> Result<Self, Self::Error> { | ||
let data: &[u8] = &(*account_info.data).borrow(); | ||
Self::deserialize(data) | ||
} | ||
} |
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
Oops, something went wrong.