Skip to content

Commit

Permalink
Use validate_asset_permissions in compress/decompress
Browse files Browse the repository at this point in the history
Also remove args from validate methods
  • Loading branch information
danenbm committed Mar 8, 2024
1 parent 5f21cd4 commit bf046e0
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 200 deletions.
10 changes: 4 additions & 6 deletions programs/mpl-core/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,19 @@ pub(crate) enum MplAssetInstruction {
#[account(5, optional, name="log_wrapper", desc = "The SPL Noop Program")]
UpdateCollection(UpdateCollectionArgs),

/// Create a new mpl-core.
/// This function creates the initial mpl-core
/// Compress an mpl-core.
#[account(0, writable, name="asset", desc = "The address of the asset")]
#[account(1, optional, name="collection", desc = "The collection to which the asset belongs")]
#[account(2, signer, name="owner", desc = "The owner or delegate of the asset")]
#[account(2, signer, name="authority", desc = "The owner or delegate of the asset")]
#[account(3, optional, writable, signer, name="payer", desc = "The account receiving the storage fees")]
#[account(4, name="system_program", desc = "The system program")]
#[account(5, optional, name="log_wrapper", desc = "The SPL Noop Program")]
Compress(CompressArgs),

/// Create a new mpl-core.
/// This function creates the initial mpl-core
/// Decompress an mpl-core.
#[account(0, writable, name="asset", desc = "The address of the asset")]
#[account(1, optional, name="collection", desc = "The collection to which the asset belongs")]
#[account(2, signer, name="owner", desc = "The owner or delegate of the asset")]
#[account(2, signer, name="authority", desc = "The owner or delegate of the asset")]
#[account(3, optional, writable, signer, name="payer", desc = "The account paying for the storage fees")]
#[account(4, name="system_program", desc = "The system program")]
#[account(5, optional, name="log_wrapper", desc = "The SPL Noop Program")]
Expand Down
8 changes: 1 addition & 7 deletions programs/mpl-core/src/plugins/burn.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{account_info::AccountInfo, program_error::ProgramError};

use crate::{
processor::{CompressArgs, CreateArgs, DecompressArgs},
state::{Authority, DataBlob},
};
use crate::state::{Authority, DataBlob};

use super::{PluginValidation, ValidationResult};

Expand Down Expand Up @@ -41,7 +38,6 @@ impl PluginValidation for Burn {
fn validate_create(
&self,
_authority_info: &AccountInfo,
_args: &CreateArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down Expand Up @@ -83,7 +79,6 @@ impl PluginValidation for Burn {
fn validate_compress(
&self,
_authority_info: &AccountInfo,
_args: &CompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -92,7 +87,6 @@ impl PluginValidation for Burn {
fn validate_decompress(
&self,
_authority_info: &AccountInfo,
_args: &DecompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down
9 changes: 1 addition & 8 deletions programs/mpl-core/src/plugins/freeze.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{account_info::AccountInfo, program_error::ProgramError};

use crate::{
processor::{ApprovePluginAuthorityArgs, CompressArgs, CreateArgs, DecompressArgs},
state::{Asset, Authority, DataBlob},
};
use crate::state::{Asset, Authority, DataBlob};

use super::{PluginValidation, ValidationResult};

Expand Down Expand Up @@ -44,7 +41,6 @@ impl PluginValidation for Freeze {
fn validate_create(
&self,
_authority_info: &AccountInfo,
_args: &CreateArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down Expand Up @@ -109,7 +105,6 @@ impl PluginValidation for Freeze {
fn validate_compress(
&self,
_authority_info: &AccountInfo,
_args: &CompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -118,7 +113,6 @@ impl PluginValidation for Freeze {
fn validate_decompress(
&self,
_authority_info: &AccountInfo,
_args: &DecompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -127,7 +121,6 @@ impl PluginValidation for Freeze {
fn validate_add_authority(
&self,
_authority_info: &AccountInfo,
_args: &ApprovePluginAuthorityArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down
80 changes: 31 additions & 49 deletions programs/mpl-core/src/plugins/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ use solana_program::{account_info::AccountInfo, program_error::ProgramError};

use crate::{
error::MplCoreError,
processor::{
ApprovePluginAuthorityArgs, CompressArgs, CreateArgs, DecompressArgs,
RevokePluginAuthorityArgs,
},
state::{Asset, Authority, Key},
};

Expand Down Expand Up @@ -84,17 +80,17 @@ impl Plugin {
pub(crate) fn validate_create(
plugin: &Plugin,
authority: &AccountInfo,
args: &CreateArgs,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()),
Plugin::Royalties(royalties) => royalties.validate_create(authority, args, authorities),
Plugin::Freeze(freeze) => freeze.validate_create(authority, args, authorities),
Plugin::Burn(burn) => burn.validate_create(authority, args, authorities),
Plugin::Transfer(transfer) => transfer.validate_create(authority, args, authorities),
Plugin::Royalties(royalties) => royalties.validate_create(authority, authorities),
Plugin::Freeze(freeze) => freeze.validate_create(authority, authorities),
Plugin::Burn(burn) => burn.validate_create(authority, authorities),
Plugin::Transfer(transfer) => transfer.validate_create(authority, authorities),
Plugin::UpdateDelegate(update_delegate) => {
update_delegate.validate_create(authority, args, authorities)
update_delegate.validate_create(authority, authorities)
}
}
}
Expand Down Expand Up @@ -124,6 +120,7 @@ impl Plugin {
plugin: &Plugin,
asset: &Asset,
authority: &AccountInfo,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Expand Down Expand Up @@ -189,19 +186,17 @@ impl Plugin {
pub(crate) fn validate_compress(
plugin: &Plugin,
authority: &AccountInfo,
args: &CompressArgs,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()),
Plugin::Royalties(royalties) => {
royalties.validate_compress(authority, args, authorities)
}
Plugin::Freeze(freeze) => freeze.validate_compress(authority, args, authorities),
Plugin::Burn(burn) => burn.validate_compress(authority, args, authorities),
Plugin::Transfer(transfer) => transfer.validate_compress(authority, args, authorities),
Plugin::Royalties(royalties) => royalties.validate_compress(authority, authorities),
Plugin::Freeze(freeze) => freeze.validate_compress(authority, authorities),
Plugin::Burn(burn) => burn.validate_compress(authority, authorities),
Plugin::Transfer(transfer) => transfer.validate_compress(authority, authorities),
Plugin::UpdateDelegate(update_delegate) => {
update_delegate.validate_compress(authority, args, authorities)
update_delegate.validate_compress(authority, authorities)
}
}
}
Expand All @@ -210,21 +205,17 @@ impl Plugin {
pub(crate) fn validate_decompress(
plugin: &Plugin,
authority: &AccountInfo,
args: &DecompressArgs,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()),
Plugin::Royalties(royalties) => {
royalties.validate_decompress(authority, args, authorities)
}
Plugin::Freeze(freeze) => freeze.validate_decompress(authority, args, authorities),
Plugin::Burn(burn) => burn.validate_decompress(authority, args, authorities),
Plugin::Transfer(transfer) => {
transfer.validate_decompress(authority, args, authorities)
}
Plugin::Royalties(royalties) => royalties.validate_decompress(authority, authorities),
Plugin::Freeze(freeze) => freeze.validate_decompress(authority, authorities),
Plugin::Burn(burn) => burn.validate_decompress(authority, authorities),
Plugin::Transfer(transfer) => transfer.validate_decompress(authority, authorities),
Plugin::UpdateDelegate(update_delegate) => {
update_delegate.validate_decompress(authority, args, authorities)
update_delegate.validate_decompress(authority, authorities)
}
}
}
Expand All @@ -234,21 +225,19 @@ impl Plugin {
pub(crate) fn validate_add_plugin_authority(
plugin: &Plugin,
authority: &AccountInfo,
args: &ApprovePluginAuthorityArgs,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()),
Plugin::Royalties(royalties) => {
royalties.validate_add_authority(authority, args, authorities)
}
Plugin::Freeze(freeze) => freeze.validate_add_authority(authority, args, authorities),
Plugin::Burn(burn) => burn.validate_add_authority(authority, args, authorities),
Plugin::Transfer(transfer) => {
transfer.validate_add_authority(authority, args, authorities)
royalties.validate_add_authority(authority, authorities)
}
Plugin::Freeze(freeze) => freeze.validate_add_authority(authority, authorities),
Plugin::Burn(burn) => burn.validate_add_authority(authority, authorities),
Plugin::Transfer(transfer) => transfer.validate_add_authority(authority, authorities),
Plugin::UpdateDelegate(update_delegate) => {
update_delegate.validate_add_authority(authority, args, authorities)
update_delegate.validate_add_authority(authority, authorities)
}
}
}
Expand All @@ -258,23 +247,21 @@ impl Plugin {
pub(crate) fn validate_remove_plugin_authority(
plugin: &Plugin,
authority: &AccountInfo,
args: &RevokePluginAuthorityArgs,
_unused: Option<&AccountInfo>,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError> {
match plugin {
Plugin::Reserved => Err(MplCoreError::InvalidPlugin.into()),
Plugin::Royalties(royalties) => {
royalties.validate_remove_authority(authority, args, authorities)
}
Plugin::Freeze(freeze) => {
freeze.validate_remove_authority(authority, args, authorities)
royalties.validate_remove_authority(authority, authorities)
}
Plugin::Burn(burn) => burn.validate_remove_authority(authority, args, authorities),
Plugin::Freeze(freeze) => freeze.validate_remove_authority(authority, authorities),
Plugin::Burn(burn) => burn.validate_remove_authority(authority, authorities),
Plugin::Transfer(transfer) => {
transfer.validate_remove_authority(authority, args, authorities)
transfer.validate_remove_authority(authority, authorities)
}
Plugin::UpdateDelegate(update_delegate) => {
update_delegate.validate_remove_authority(authority, args, authorities)
update_delegate.validate_remove_authority(authority, authorities)
}
}
}
Expand All @@ -298,7 +285,6 @@ pub(crate) trait PluginValidation {
fn validate_create(
&self,
authority: &AccountInfo,
args: &CreateArgs,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError>;

Expand Down Expand Up @@ -349,23 +335,20 @@ pub(crate) trait PluginValidation {
fn validate_compress(
&self,
authority: &AccountInfo,
args: &CompressArgs,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError>;

/// Validate the decompress lifecycle action.
fn validate_decompress(
&self,
authority: &AccountInfo,
args: &DecompressArgs,
authorities: &Authority,
) -> Result<ValidationResult, ProgramError>;

/// Validate the add_authority lifecycle action.
fn validate_add_authority(
&self,
_authority: &AccountInfo,
_args: &ApprovePluginAuthorityArgs,
_authorities: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -375,7 +358,6 @@ pub(crate) trait PluginValidation {
fn validate_remove_authority(
&self,
_authority: &AccountInfo,
_args: &RevokePluginAuthorityArgs,
_authorities: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down
8 changes: 1 addition & 7 deletions programs/mpl-core/src/plugins/royalties.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{account_info::AccountInfo, program_error::ProgramError, pubkey::Pubkey};

use crate::{
processor::{CompressArgs, CreateArgs, DecompressArgs},
state::Authority,
};
use crate::state::Authority;

use super::{PluginValidation, ValidationResult};

Expand Down Expand Up @@ -41,7 +38,6 @@ impl PluginValidation for Royalties {
fn validate_create(
&self,
_authority_info: &AccountInfo,
_args: &CreateArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down Expand Up @@ -93,7 +89,6 @@ impl PluginValidation for Royalties {
fn validate_compress(
&self,
_authority_info: &AccountInfo,
_args: &CompressArgs,
_authority: &Authority,
) -> Result<ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -102,7 +97,6 @@ impl PluginValidation for Royalties {
fn validate_decompress(
&self,
_authority_info: &AccountInfo,
_args: &DecompressArgs,
_authority: &Authority,
) -> Result<ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down
8 changes: 1 addition & 7 deletions programs/mpl-core/src/plugins/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{account_info::AccountInfo, program_error::ProgramError};

use crate::{
processor::{CompressArgs, CreateArgs, DecompressArgs},
state::{Authority, DataBlob},
};
use crate::state::{Authority, DataBlob};

use super::{PluginValidation, ValidationResult};

Expand Down Expand Up @@ -41,7 +38,6 @@ impl PluginValidation for Transfer {
fn validate_create(
&self,
_authority_info: &AccountInfo,
_args: &CreateArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down Expand Up @@ -91,7 +87,6 @@ impl PluginValidation for Transfer {
fn validate_compress(
&self,
_authority_info: &AccountInfo,
_args: &CompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand All @@ -100,7 +95,6 @@ impl PluginValidation for Transfer {
fn validate_decompress(
&self,
_authority_info: &AccountInfo,
_args: &DecompressArgs,
_authority: &Authority,
) -> Result<super::ValidationResult, ProgramError> {
Ok(ValidationResult::Pass)
Expand Down
Loading

0 comments on commit bf046e0

Please sign in to comment.