Skip to content

Commit

Permalink
Allow for other update_delegate authority types and remove unused fun…
Browse files Browse the repository at this point in the history
…ctions
  • Loading branch information
danenbm committed Jul 31, 2024
1 parent 3ce1104 commit 84068ec
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 71 deletions.
54 changes: 30 additions & 24 deletions programs/mpl-core/src/plugins/update_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ impl PluginValidation for UpdateDelegate {
ctx: &PluginValidationContext,
) -> Result<ValidationResult, ProgramError> {
if let Some(new_plugin) = ctx.target_plugin {
if (ctx.self_authority
== (&Authority::Address {
address: *ctx.authority_info.key,
})
if ((ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key))
&& new_plugin.manager() == Authority::UpdateAuthority
{
Expand All @@ -91,10 +92,11 @@ impl PluginValidation for UpdateDelegate {
ctx: &PluginValidationContext,
) -> Result<ValidationResult, ProgramError> {
if let Some(plugin_to_remove) = ctx.target_plugin {
if (ctx.self_authority
== (&Authority::Address {
address: *ctx.authority_info.key,
})
if ((ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key))
&& plugin_to_remove.manager() == Authority::UpdateAuthority
{
Expand All @@ -115,10 +117,11 @@ impl PluginValidation for UpdateDelegate {
let plugin = ctx.target_plugin.ok_or(MplCoreError::InvalidPlugin)?;

// If the plugin authority is the authority signing.
if (ctx.self_authority
== &(Authority::Address {
address: *ctx.authority_info.key,
})
if ((ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
// Or the authority is one of the additional delegates.
|| self.additional_delegates.contains(ctx.authority_info.key))
// And it's an authority-managed plugin.
Expand All @@ -141,10 +144,11 @@ impl PluginValidation for UpdateDelegate {
let plugin = ctx.target_plugin.ok_or(MplCoreError::InvalidPlugin)?;

// If the plugin authority is the authority signing.
if ctx.self_authority
== &(Authority::Address {
address: *ctx.authority_info.key,
})
if (ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
// Or the authority is one of the additional delegates.
|| (self.additional_delegates.contains(ctx.authority_info.key) && PluginType::from(plugin) != PluginType::UpdateDelegate)
// And it's an authority-managed plugin.
Expand All @@ -160,10 +164,11 @@ impl PluginValidation for UpdateDelegate {
&self,
ctx: &PluginValidationContext,
) -> Result<ValidationResult, ProgramError> {
if (ctx.self_authority
== (&Authority::Address {
address: *ctx.authority_info.key,
})
if ((ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key))
// We do not allow the root authority (either Collection or Address) to be changed by this delegate.
&& ctx.new_collection_authority.is_none() && ctx.new_asset_authority.is_none()
Expand All @@ -181,10 +186,11 @@ impl PluginValidation for UpdateDelegate {
let plugin = ctx.target_plugin.ok_or(MplCoreError::InvalidPlugin)?;

// If the plugin itself is being updated.
if ctx.self_authority
== (&Authority::Address {
address: *ctx.authority_info.key,
})
if (ctx.resolved_authorities.is_some()
&& ctx
.resolved_authorities
.unwrap()
.contains(ctx.self_authority))
|| self.additional_delegates.contains(ctx.authority_info.key)
{
if let Plugin::UpdateDelegate(update_delegate) = plugin {
Expand Down
48 changes: 1 addition & 47 deletions programs/mpl-core/src/state/update_authority.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::{program_error::ProgramError, pubkey::Pubkey};

use crate::{
instruction::accounts::{
BurnV1Accounts, CompressV1Accounts, DecompressV1Accounts, TransferV1Accounts,
},
plugins::{abstain, CheckResult, ValidationResult},
};
use solana_program::pubkey::Pubkey;

/// An enum representing the types of accounts that can update data on an asset.
#[derive(Clone, BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)]
Expand All @@ -28,43 +21,4 @@ impl UpdateAuthority {
Self::Collection(address) => *address,
}
}

/// Check permissions for the create lifecycle event.
pub fn check_create() -> CheckResult {
CheckResult::CanReject
}

/// Check permissions for the update lifecycle event.
pub fn check_update() -> CheckResult {
CheckResult::CanApprove
}

/// Validate the burn lifecycle event.
pub fn validate_burn(&self, _ctx: &BurnV1Accounts) -> Result<ValidationResult, ProgramError> {
abstain!()
}

/// Validate the transfer lifecycle event.
pub fn validate_transfer(
&self,
_ctx: &TransferV1Accounts,
) -> Result<ValidationResult, ProgramError> {
abstain!()
}

/// Validate the compress lifecycle event.
pub fn validate_compress(
&self,
_ctx: &CompressV1Accounts,
) -> Result<ValidationResult, ProgramError> {
abstain!()
}

/// Validate the decompress lifecycle event.
pub fn validate_decompress(
&self,
_ctx: &DecompressV1Accounts,
) -> Result<ValidationResult, ProgramError> {
abstain!()
}
}

0 comments on commit 84068ec

Please sign in to comment.