generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 31
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
fc002b5
commit 3479261
Showing
12 changed files
with
114 additions
and
124 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
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 |
---|---|---|
|
@@ -14,4 +14,5 @@ pub enum PluginType { | |
Reserved, | ||
Royalties, | ||
Delegate, | ||
Collection, | ||
} |
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,8 +1,8 @@ | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use solana_program::pubkey::Pubkey; | ||
|
||
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug)] | ||
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)] | ||
pub struct Collection { | ||
collection_address: Pubkey, | ||
required: bool, | ||
managed: bool, | ||
} |
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,109 +1,83 @@ | ||
use solana_program::{entrypoint::ProgramResult, program_error::ProgramError, slot_history::Check}; | ||
use solana_program::program_error::ProgramError; | ||
|
||
use super::{Plugin, PluginType}; | ||
|
||
// Lifecycle permissions | ||
pub enum CheckResult { | ||
CanApprove, | ||
CanReject, | ||
None, | ||
} | ||
|
||
pub enum ValidationResult { | ||
Approved, | ||
Rejected, | ||
Pass, | ||
} | ||
|
||
// Lifecycle validations | ||
pub fn check_create(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
_ => Ok(CheckResult::No), | ||
} | ||
} | ||
|
||
pub fn check_update(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
_ => Ok(CheckResult::No), | ||
} | ||
} | ||
|
||
pub fn check_burn(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
PluginType::Delegate => { | ||
// If the delegate plugin authority is the signer, then approve the burn. | ||
Ok(CheckResult::Yes) | ||
// Otherwise pass. | ||
pub trait CheckLifecyclePermission { | ||
fn check_create(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
#[allow(clippy::match_single_binding)] | ||
match plugin_type { | ||
_ => Ok(CheckResult::None), | ||
} | ||
_ => Ok(CheckResult::No), | ||
} | ||
} | ||
|
||
pub fn check_transfer(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
PluginType::Delegate => { | ||
// If the delegate plugin authority is the signer, then approve the burn. | ||
Ok(CheckResult::Yes) | ||
// Otherwise pass. | ||
fn check_update(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
#[allow(clippy::match_single_binding)] | ||
match plugin_type { | ||
_ => Ok(CheckResult::None), | ||
} | ||
PluginType::Royalties => { | ||
// If the auth rules passes, pass. | ||
Ok(CheckResult::Yes) | ||
// Otherwise fail. | ||
} | ||
_ => Ok(CheckResult::No), | ||
} | ||
} | ||
|
||
pub fn check_compress(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
_ => Ok(CheckResult::No), | ||
fn check_burn(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
PluginType::Delegate => { | ||
// If the delegate plugin authority is the signer, then approve the burn. | ||
Ok(CheckResult::CanApprove) | ||
// Otherwise pass. | ||
} | ||
_ => Ok(CheckResult::None), | ||
} | ||
} | ||
} | ||
|
||
pub fn check_decompress(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
_ => Ok(CheckResult::No), | ||
fn check_transfer(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
match plugin_type { | ||
PluginType::Delegate => { | ||
// If the delegate plugin authority is the signer, then approve the burn. | ||
Ok(CheckResult::CanApprove) | ||
// Otherwise pass. | ||
} | ||
PluginType::Royalties => { | ||
// If the auth rules passes, pass. | ||
Ok(CheckResult::CanReject) | ||
// Otherwise fail. | ||
} | ||
_ => Ok(CheckResult::None), | ||
} | ||
} | ||
} | ||
|
||
// Lifecycle hooks | ||
pub fn on_create(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
} | ||
pub fn on_update(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
} | ||
pub fn on_burn(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
Plugin::Delegate(_) => { | ||
// If the delegate plugin authority is the signer, then approve the burn. | ||
Ok(ValidationResult::Pass) | ||
// Otherwise fail. | ||
fn check_compress(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
#[allow(clippy::match_single_binding)] | ||
match plugin_type { | ||
_ => Ok(CheckResult::None), | ||
} | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
} | ||
pub fn on_transfer(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
Plugin::Delegate(_) => { | ||
// If the delegate plugin authority is the signer, then approve the Transfer. | ||
Ok(ValidationResult::Pass) | ||
// Otherwise fail. | ||
|
||
fn check_decompress(plugin_type: PluginType) -> Result<CheckResult, ProgramError> { | ||
#[allow(clippy::match_single_binding)] | ||
match plugin_type { | ||
_ => Ok(CheckResult::None), | ||
} | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
} | ||
pub fn on_compress(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
|
||
// Lifecycle validations | ||
pub enum ValidationResult { | ||
Approved, | ||
Rejected, | ||
Pass, | ||
} | ||
pub fn on_decompress(plugin: Plugin) -> Result<ValidationResult, ProgramError> { | ||
match plugin { | ||
_ => Ok(ValidationResult::Pass), | ||
} | ||
|
||
pub trait ValidateLifecycle { | ||
fn validate_create(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
fn validate_update(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
fn validate_burn(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
fn validate_transfer(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
fn validate_compress(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
fn validate_decompress(plugin: &Plugin) -> Result<ValidationResult, ProgramError>; | ||
} |
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
Oops, something went wrong.