Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing double validation #220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions programs/mpl-core/src/plugins/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,6 @@ pub(crate) trait PluginValidation {
/// The STRONGEST result is returned.
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
pub(crate) fn validate_plugin_checks<'a>(
key: Key,
accounts: &'a [AccountInfo<'a>],
checks: &BTreeMap<PluginType, (Key, CheckResult, RegistryRecord)>,
authority: &'a AccountInfo<'a>,
Expand All @@ -683,13 +682,11 @@ pub(crate) fn validate_plugin_checks<'a>(
let mut approved = false;
let mut rejected = false;
for (check_key, check_result, registry_record) in checks.values() {
if *check_key == key
&& matches!(
check_result,
CheckResult::CanApprove | CheckResult::CanReject
)
{
let account = match key {
if matches!(
check_result,
CheckResult::CanApprove | CheckResult::CanReject
) {
let account = match check_key {
Key::CollectionV1 => collection.ok_or(MplCoreError::InvalidCollection)?,
Key::AssetV1 => asset.ok_or(MplCoreError::InvalidAsset)?,
_ => unreachable!(),
Expand Down Expand Up @@ -738,7 +735,6 @@ pub(crate) fn validate_plugin_checks<'a>(
/// The STRONGEST result is returned.
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
pub(crate) fn validate_external_plugin_adapter_checks<'a>(
key: Key,
accounts: &'a [AccountInfo<'a>],
external_checks: &BTreeMap<
ExternalPluginAdapterKey,
Expand All @@ -762,12 +758,8 @@ pub(crate) fn validate_external_plugin_adapter_checks<'a>(
) -> Result<ValidationResult, ProgramError> {
let mut approved = false;
for (check_key, check_result, external_registry_record) in external_checks.values() {
if *check_key == key
&& (check_result.can_listen()
|| check_result.can_approve()
|| check_result.can_reject())
{
let account = match key {
if check_result.can_listen() || check_result.can_approve() || check_result.can_reject() {
let account = match check_key {
Key::CollectionV1 => collection.ok_or(MplCoreError::InvalidCollection)?,
Key::AssetV1 => asset.ok_or(MplCoreError::InvalidAsset)?,
_ => unreachable!(),
Expand Down
53 changes: 0 additions & 53 deletions programs/mpl-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,32 +243,6 @@ pub(crate) fn validate_asset_permissions<'a>(
};

match validate_plugin_checks(
Key::CollectionV1,
accounts,
&checks,
authority_info,
new_owner,
new_authority,
None,
new_plugin,
new_plugin_authority,
new_external_plugin_adapter,
new_external_plugin_adapter_authority,
Some(asset),
collection,
&resolved_authorities,
plugin_validate_fp,
)? {
ValidationResult::Approved => approved = true,
ValidationResult::Rejected => rejected = true,
ValidationResult::Pass => (),
ValidationResult::ForceApproved => {
return Ok((deserialized_asset, plugin_header, plugin_registry))
}
};

match validate_plugin_checks(
Key::AssetV1,
accounts,
&checks,
authority_info,
Expand All @@ -294,31 +268,6 @@ pub(crate) fn validate_asset_permissions<'a>(

if let Some(external_plugin_adapter_validate_fp) = external_plugin_adapter_validate_fp {
match validate_external_plugin_adapter_checks(
Key::CollectionV1,
accounts,
&external_checks,
authority_info,
new_owner,
new_authority,
None,
new_plugin,
new_plugin_authority,
new_external_plugin_adapter,
new_external_plugin_adapter_authority,
Some(asset),
collection,
&resolved_authorities,
external_plugin_adapter_validate_fp,
)? {
ValidationResult::Approved => approved = true,
ValidationResult::Rejected => rejected = true,
ValidationResult::Pass => (),
// Force approved will not be possible from external plugin adapters.
ValidationResult::ForceApproved => unreachable!(),
};

match validate_external_plugin_adapter_checks(
Key::AssetV1,
accounts,
&external_checks,
authority_info,
Expand Down Expand Up @@ -450,7 +399,6 @@ pub(crate) fn validate_collection_permissions<'a>(
};

match validate_plugin_checks(
Key::CollectionV1,
accounts,
&checks,
authority_info,
Expand All @@ -476,7 +424,6 @@ pub(crate) fn validate_collection_permissions<'a>(

if let Some(external_plugin_adapter_validate_fp) = external_plugin_adapter_validate_fp {
match validate_external_plugin_adapter_checks(
Key::CollectionV1,
accounts,
&external_checks,
authority_info,
Expand Down