diff --git a/programs/mpl-core/src/plugins/lifecycle.rs b/programs/mpl-core/src/plugins/lifecycle.rs index d3810c16..d7598830 100644 --- a/programs/mpl-core/src/plugins/lifecycle.rs +++ b/programs/mpl-core/src/plugins/lifecycle.rs @@ -219,33 +219,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_add_plugin(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_add_plugin(ctx), - Plugin::BurnDelegate(burn) => burn.validate_add_plugin(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_add_plugin(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_add_plugin(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_add_plugin(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_add_plugin(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_add_plugin(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_add_plugin(ctx) - } - Plugin::Edition(edition) => edition.validate_add_plugin(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_add_plugin(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_add_plugin(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_add_plugin(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_add_plugin(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_add_plugin(ctx), - } + plugin.inner().validate_add_plugin(ctx) } /// Validate the remove plugin lifecycle event. @@ -260,33 +234,7 @@ impl Plugin { return reject!(); } - match plugin { - Plugin::Royalties(royalties) => royalties.validate_remove_plugin(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_remove_plugin(ctx), - Plugin::BurnDelegate(burn) => burn.validate_remove_plugin(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_remove_plugin(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_remove_plugin(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_remove_plugin(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_remove_plugin(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_remove_plugin(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_remove_plugin(ctx) - } - Plugin::Edition(edition) => edition.validate_remove_plugin(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_remove_plugin(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_remove_plugin(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_remove_plugin(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_remove_plugin(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_remove_plugin(ctx), - } + plugin.inner().validate_remove_plugin(ctx) } /// Validate the approve plugin authority lifecycle event. @@ -304,37 +252,7 @@ impl Plugin { return Err(MplCoreError::InvalidPlugin.into()); } - match plugin { - Plugin::Royalties(royalties) => royalties.validate_approve_plugin_authority(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_approve_plugin_authority(ctx), - Plugin::BurnDelegate(burn) => burn.validate_approve_plugin_authority(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_approve_plugin_authority(ctx), - Plugin::UpdateDelegate(update_delegate) => { - update_delegate.validate_approve_plugin_authority(ctx) - } - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_approve_plugin_authority(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_approve_plugin_authority(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_approve_plugin_authority(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_approve_plugin_authority(ctx) - } - Plugin::Edition(edition) => edition.validate_approve_plugin_authority(ctx), - Plugin::MasterEdition(master_edition) => { - master_edition.validate_approve_plugin_authority(ctx) - } - Plugin::AddBlocker(add_blocker) => add_blocker.validate_approve_plugin_authority(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_approve_plugin_authority(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_approve_plugin_authority(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_approve_plugin_authority(ctx), - } + plugin.inner().validate_approve_plugin_authority(ctx) } /// Validate the revoke plugin authority lifecycle event. @@ -364,37 +282,7 @@ impl Plugin { ValidationResult::Pass }; - let result = match plugin { - Plugin::Royalties(royalties) => royalties.validate_revoke_plugin_authority(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_revoke_plugin_authority(ctx), - Plugin::BurnDelegate(burn) => burn.validate_revoke_plugin_authority(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_revoke_plugin_authority(ctx), - Plugin::UpdateDelegate(update_delegate) => { - update_delegate.validate_revoke_plugin_authority(ctx) - } - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_revoke_plugin_authority(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_revoke_plugin_authority(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_revoke_plugin_authority(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_revoke_plugin_authority(ctx) - } - Plugin::Edition(edition) => edition.validate_revoke_plugin_authority(ctx), - Plugin::MasterEdition(master_edition) => { - master_edition.validate_revoke_plugin_authority(ctx) - } - Plugin::AddBlocker(add_blocker) => add_blocker.validate_revoke_plugin_authority(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_revoke_plugin_authority(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_revoke_plugin_authority(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_revoke_plugin_authority(ctx), - }?; + let result = plugin.inner().validate_revoke_plugin_authority(ctx)?; if result == ValidationResult::Pass { Ok(base_result) @@ -408,29 +296,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_create(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_create(ctx), - Plugin::BurnDelegate(burn) => burn.validate_create(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_create(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_create(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_create(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_create(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_create(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => permanent_burn.validate_create(ctx), - Plugin::Edition(edition) => edition.validate_create(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_create(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_create(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_create(ctx) - } - Plugin::VerifiedCreators(verified_creators) => verified_creators.validate_create(ctx), - Plugin::Autograph(autograph) => autograph.validate_create(ctx), - } + plugin.inner().validate_create(ctx) } /// Route the validation of the update action to the appropriate plugin. @@ -438,29 +304,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_update(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_update(ctx), - Plugin::BurnDelegate(burn) => burn.validate_update(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_update(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_update(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_update(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_update(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_update(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => permanent_burn.validate_update(ctx), - Plugin::Edition(edition) => edition.validate_update(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_update(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_update(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_update(ctx) - } - Plugin::VerifiedCreators(verified_creators) => verified_creators.validate_update(ctx), - Plugin::Autograph(autograph) => autograph.validate_update(ctx), - } + plugin.inner().validate_update(ctx) } /// Route the validation of the update_plugin action to the appropriate plugin. @@ -479,33 +323,7 @@ impl Plugin { ValidationResult::Pass }; - let result = match plugin { - Plugin::Royalties(royalties) => royalties.validate_update_plugin(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_update_plugin(ctx), - Plugin::BurnDelegate(burn) => burn.validate_update_plugin(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_update_plugin(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_update_plugin(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_update_plugin(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_update_plugin(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_update_plugin(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_update_plugin(ctx) - } - Plugin::Edition(edition) => edition.validate_update_plugin(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_update_plugin(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_update_plugin(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_update_plugin(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_update_plugin(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_update_plugin(ctx), - }?; + let result = plugin.inner().validate_update_plugin(ctx)?; match (&base_result, &result) { (ValidationResult::Approved, ValidationResult::Approved) => { @@ -532,27 +350,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_burn(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_burn(ctx), - Plugin::BurnDelegate(burn) => burn.validate_burn(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_burn(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_burn(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_burn(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_burn(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_burn(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => permanent_burn.validate_burn(ctx), - Plugin::Edition(edition) => edition.validate_burn(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_burn(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_burn(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => immutable_metadata.validate_burn(ctx), - Plugin::VerifiedCreators(verified_creators) => verified_creators.validate_burn(ctx), - Plugin::Autograph(autograph) => autograph.validate_burn(ctx), - } + plugin.inner().validate_burn(ctx) } /// Route the validation of the transfer action to the appropriate plugin. @@ -560,29 +358,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_transfer(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_transfer(ctx), - Plugin::BurnDelegate(burn) => burn.validate_transfer(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_transfer(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_transfer(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_transfer(ctx) - } - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_transfer(ctx) - } - Plugin::Attributes(attributes_transfer) => attributes_transfer.validate_transfer(ctx), - Plugin::PermanentBurnDelegate(burn_transfer) => burn_transfer.validate_transfer(ctx), - Plugin::Edition(edition) => edition.validate_transfer(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_transfer(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_transfer(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_transfer(ctx) - } - Plugin::VerifiedCreators(verified_creators) => verified_creators.validate_transfer(ctx), - Plugin::Autograph(autograph) => autograph.validate_transfer(ctx), - } + plugin.inner().validate_transfer(ctx) } /// Route the validation of the compress action to the appropriate plugin. @@ -590,29 +366,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_compress(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_compress(ctx), - Plugin::BurnDelegate(burn) => burn.validate_compress(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_compress(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_compress(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_compress(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_compress(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_compress(ctx) - } - Plugin::PermanentBurnDelegate(burn_transfer) => burn_transfer.validate_compress(ctx), - Plugin::Edition(edition) => edition.validate_compress(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_compress(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_compress(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_compress(ctx) - } - Plugin::VerifiedCreators(verified_creators) => verified_creators.validate_compress(ctx), - Plugin::Autograph(autograph) => autograph.validate_compress(ctx), - } + plugin.inner().validate_compress(ctx) } /// Route the validation of the decompress action to the appropriate plugin. @@ -620,33 +374,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_decompress(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_decompress(ctx), - Plugin::BurnDelegate(burn) => burn.validate_decompress(ctx), - Plugin::TransferDelegate(transfer) => transfer.validate_decompress(ctx), - Plugin::UpdateDelegate(update_delegate) => update_delegate.validate_decompress(ctx), - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_decompress(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_decompress(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_decompress(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_decompress(ctx) - } - Plugin::Edition(edition) => edition.validate_decompress(ctx), - Plugin::MasterEdition(master_edition) => master_edition.validate_decompress(ctx), - Plugin::AddBlocker(add_blocker) => add_blocker.validate_decompress(ctx), - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_decompress(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_decompress(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_decompress(ctx), - } + plugin.inner().validate_decompress(ctx) } /// Validate the add external plugin adapter lifecycle event. @@ -654,41 +382,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_add_external_plugin_adapter(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_add_external_plugin_adapter(ctx), - Plugin::BurnDelegate(burn) => burn.validate_add_external_plugin_adapter(ctx), - Plugin::TransferDelegate(transfer) => { - transfer.validate_add_external_plugin_adapter(ctx) - } - Plugin::UpdateDelegate(update_delegate) => { - update_delegate.validate_add_external_plugin_adapter(ctx) - } - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_add_external_plugin_adapter(ctx) - } - Plugin::Attributes(attributes) => attributes.validate_add_external_plugin_adapter(ctx), - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_add_external_plugin_adapter(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_add_external_plugin_adapter(ctx) - } - Plugin::Edition(edition) => edition.validate_add_external_plugin_adapter(ctx), - Plugin::MasterEdition(master_edition) => { - master_edition.validate_add_external_plugin_adapter(ctx) - } - Plugin::AddBlocker(add_blocker) => { - add_blocker.validate_add_external_plugin_adapter(ctx) - } - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_add_external_plugin_adapter(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_add_external_plugin_adapter(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_add_external_plugin_adapter(ctx), - } + plugin.inner().validate_add_external_plugin_adapter(ctx) } /// Validate the remove plugin lifecycle event. @@ -696,43 +390,7 @@ impl Plugin { plugin: &Plugin, ctx: &PluginValidationContext, ) -> Result { - match plugin { - Plugin::Royalties(royalties) => royalties.validate_remove_external_plugin_adapter(ctx), - Plugin::FreezeDelegate(freeze) => freeze.validate_remove_external_plugin_adapter(ctx), - Plugin::BurnDelegate(burn) => burn.validate_remove_external_plugin_adapter(ctx), - Plugin::TransferDelegate(transfer) => { - transfer.validate_remove_external_plugin_adapter(ctx) - } - Plugin::UpdateDelegate(update_delegate) => { - update_delegate.validate_remove_external_plugin_adapter(ctx) - } - Plugin::PermanentFreezeDelegate(permanent_freeze) => { - permanent_freeze.validate_remove_external_plugin_adapter(ctx) - } - Plugin::Attributes(attributes) => { - attributes.validate_remove_external_plugin_adapter(ctx) - } - Plugin::PermanentTransferDelegate(permanent_transfer) => { - permanent_transfer.validate_remove_external_plugin_adapter(ctx) - } - Plugin::PermanentBurnDelegate(permanent_burn) => { - permanent_burn.validate_remove_external_plugin_adapter(ctx) - } - Plugin::Edition(edition) => edition.validate_remove_external_plugin_adapter(ctx), - Plugin::MasterEdition(master_edition) => { - master_edition.validate_remove_external_plugin_adapter(ctx) - } - Plugin::AddBlocker(add_blocker) => { - add_blocker.validate_remove_external_plugin_adapter(ctx) - } - Plugin::ImmutableMetadata(immutable_metadata) => { - immutable_metadata.validate_remove_external_plugin_adapter(ctx) - } - Plugin::VerifiedCreators(verified_creators) => { - verified_creators.validate_remove_external_plugin_adapter(ctx) - } - Plugin::Autograph(autograph) => autograph.validate_remove_external_plugin_adapter(ctx), - } + plugin.inner().validate_remove_external_plugin_adapter(ctx) } } diff --git a/programs/mpl-core/src/plugins/mod.rs b/programs/mpl-core/src/plugins/mod.rs index f9c9e637..d42590d9 100644 --- a/programs/mpl-core/src/plugins/mod.rs +++ b/programs/mpl-core/src/plugins/mod.rs @@ -84,6 +84,27 @@ impl Plugin { MplCoreError::SerializationError.into() }) } + + /// Extract the inner plugin value from the plugin. + pub(crate) fn inner(&self) -> &dyn PluginValidation { + match &self { + Plugin::Royalties(inner) => inner, + Plugin::FreezeDelegate(inner) => inner, + Plugin::BurnDelegate(inner) => inner, + Plugin::TransferDelegate(inner) => inner, + Plugin::UpdateDelegate(inner) => inner, + Plugin::PermanentFreezeDelegate(inner) => inner, + Plugin::Attributes(inner) => inner, + Plugin::PermanentTransferDelegate(inner) => inner, + Plugin::PermanentBurnDelegate(inner) => inner, + Plugin::Edition(inner) => inner, + Plugin::MasterEdition(inner) => inner, + Plugin::AddBlocker(inner) => inner, + Plugin::ImmutableMetadata(inner) => inner, + Plugin::VerifiedCreators(inner) => inner, + Plugin::Autograph(inner) => inner, + } + } } impl Compressible for Plugin {}