generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 32
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
1 parent
e77c53c
commit c2ff054
Showing
7 changed files
with
142 additions
and
23 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 |
---|---|---|
@@ -1,16 +1,77 @@ | ||
use super::Plugin; | ||
use borsh::BorshDeserialize; | ||
use solana_program::{ | ||
account_info::AccountInfo, entrypoint::ProgramResult, program_error::ProgramError, | ||
pubkey::Pubkey, | ||
}; | ||
|
||
//TODO: Implement this function | ||
pub fn create_idempotent() { | ||
// Create plugin header and registry if it doesn't exist | ||
use crate::{ | ||
error::MplAssetError, | ||
state::{Asset, Key, PluginHeader}, | ||
utils::DataBlob, | ||
}; | ||
|
||
use super::{Plugin, PluginRegistry}; | ||
|
||
//TODO:keith: Implement this function | ||
/// Create plugin header and registry if it doesn't exist | ||
pub fn create_idempotent(account: &AccountInfo) -> ProgramResult { | ||
let mut bytes: &[u8] = &(*account.data).borrow(); | ||
let asset = Asset::deserialize(&mut bytes)?; | ||
|
||
// Check if the plugin header and registry exist. | ||
if asset.get_size() == account.data_len() { | ||
// They don't exist, so create them. | ||
let header = PluginHeader { | ||
version: 1, | ||
plugin_map_offset: asset.get_size() + PluginHeader::get_initial_size(), | ||
}; | ||
let registry = PluginRegistry { registry: vec![] }; | ||
|
||
header.save(account, asset.get_size())?; | ||
registry.save(account, header.plugin_map_offset)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
//TODO: Implement this function | ||
pub fn fetch_plugin(plugin: u8) -> Plugin { | ||
// Create plugin header and registry if it doesn't exist | ||
pub fn assert_plugins_initialized(account: &AccountInfo) -> ProgramResult { | ||
let mut bytes: &[u8] = &(*account.data).borrow(); | ||
let asset = Asset::deserialize(&mut bytes).unwrap(); | ||
|
||
if asset.get_size() == account.data_len() { | ||
return Err(MplAssetError::PluginsNotInitialized.into()); | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
//TODO:keith: Implement this function | ||
pub fn fetch_plugin( | ||
account: &AccountInfo, | ||
plugin: Key, | ||
) -> Result<((Vec<Pubkey>, Plugin)), ProgramError> { | ||
// Fetch the plugin from the registry. | ||
let mut bytes: &[u8] = &(*account.data).borrow(); | ||
let asset = Asset::deserialize(&mut bytes)?; | ||
|
||
let header = PluginHeader::load(account, asset.get_size())?; | ||
let PluginRegistry { registry } = PluginRegistry::load(account, header.plugin_map_offset)?; | ||
|
||
let plugin_data = registry | ||
.iter() | ||
.find(|(key, _)| *key == plugin) | ||
.map(|(_, data)| data) | ||
.ok_or(MplAssetError::PluginNotFound)?; | ||
|
||
let authorities = plugin_data | ||
.authorities | ||
.iter() | ||
.map(|authority| authority.key) | ||
.collect(); | ||
} | ||
|
||
//TODO: Implement this function | ||
//TODO:keith: Implement this function | ||
pub fn list_plugins() -> Vec<u8> { | ||
// Create plugin header and registry if it doesn't exist | ||
vec![] | ||
} |
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