diff --git a/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/account_interactions.rs b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/account_interactions.rs new file mode 100644 index 00000000..57cd4adc --- /dev/null +++ b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/account_interactions.rs @@ -0,0 +1,140 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use crate::internal_prelude::*; + +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct AccountInteractionsVisitor(AccountInteractionsOutput); + +impl AccountInteractionsVisitor { + pub fn new() -> Self { + Default::default() + } +} + +impl ManifestAnalysisVisitor for AccountInteractionsVisitor { + type Output = AccountInteractionsOutput; + type ValidityState = ConstVisitorValidityState; + + fn output(self) -> Self::Output { + self.0 + } + + fn validity_state(&self) -> &Self::ValidityState { + &ConstVisitorValidityState:: + } + + fn on_instruction( + &mut self, + _: &NamedAddressStore, + grouped_instruction: &GroupedInstruction, + _: &InstructionIndex, + maybe_typed_invocation: Option<&TypedManifestNativeInvocation>, + ) { + // We're interested in invocations and in the invoked address so we + // compute that. In the event that the instruction isn't an invocation + // or that it's not one to a global entity then we return from this + // method having done no work. + let Some(address) = grouped_instruction + .as_invocation_instructions() + .and_then(|invocation| invocation.invoked_global_entity()) + else { + return; + }; + + // We're only interested in account invocations and do not care about + // any other kind of invocations. + let Some(TypedManifestNativeInvocation::AccountBlueprintInvocation( + AccountBlueprintInvocation::Method(account_method), + )) = maybe_typed_invocation + else { + return; + }; + + let sets_to_add_to: &mut [_] = match account_method { + AccountBlueprintMethod::Securify(..) => { + &mut [&mut self.0.accounts_securified] + } + AccountBlueprintMethod::LockFee(..) + | AccountBlueprintMethod::LockContingentFee(..) => { + &mut [&mut self.0.accounts_locked_fees_from] + } + AccountBlueprintMethod::LockFeeAndWithdraw(..) + | AccountBlueprintMethod::LockFeeAndWithdrawNonFungibles(..) => { + &mut [ + &mut self.0.accounts_locked_fees_from, + &mut self.0.accounts_withdrawn_from, + ] + } + AccountBlueprintMethod::Withdraw(..) + | AccountBlueprintMethod::WithdrawNonFungibles(..) => { + &mut [&mut self.0.accounts_withdrawn_from] + } + AccountBlueprintMethod::Deposit(..) + | AccountBlueprintMethod::DepositBatch(..) + | AccountBlueprintMethod::TryDepositOrRefund(..) + | AccountBlueprintMethod::TryDepositBatchOrRefund(..) + | AccountBlueprintMethod::TryDepositOrAbort(..) + | AccountBlueprintMethod::TryDepositBatchOrAbort(..) => { + &mut [&mut self.0.accounts_deposited_into] + } + AccountBlueprintMethod::Burn(..) + | AccountBlueprintMethod::BurnNonFungibles(..) => { + &mut [&mut self.0.accounts_burned_from] + } + AccountBlueprintMethod::CreateProofOfAmount(..) + | AccountBlueprintMethod::CreateProofOfNonFungibles(..) => { + &mut [&mut self.0.accounts_created_proofs_from] + } + AccountBlueprintMethod::SetDefaultDepositRule(..) => { + &mut [&mut self.0.accounts_set_default_deposit_rule_of] + } + AccountBlueprintMethod::SetResourcePreference(..) => { + &mut [&mut self.0.accounts_set_resource_preference_into] + } + AccountBlueprintMethod::RemoveResourcePreference(..) => { + &mut [&mut self.0.accounts_remove_resource_preference_from] + } + AccountBlueprintMethod::AddAuthorizedDepositor(..) => { + &mut [&mut self.0.accounts_add_authorized_depositor_into] + } + AccountBlueprintMethod::RemoveAuthorizedDepositor(..) => { + &mut [&mut self.0.accounts_remove_authorized_depositor_from] + } + }; + for set in sets_to_add_to { + set.insert(address); + } + } +} + +#[derive(Clone, Debug, PartialEq, Eq, Default)] +pub struct AccountInteractionsOutput { + pub accounts_securified: IndexSet, + pub accounts_deposited_into: IndexSet, + pub accounts_withdrawn_from: IndexSet, + pub accounts_locked_fees_from: IndexSet, + pub accounts_created_proofs_from: IndexSet, + pub accounts_burned_from: IndexSet, + pub accounts_set_default_deposit_rule_of: IndexSet, + pub accounts_set_resource_preference_into: IndexSet, + pub accounts_remove_resource_preference_from: + IndexSet, + pub accounts_add_authorized_depositor_into: IndexSet, + pub accounts_remove_authorized_depositor_from: + IndexSet, +} diff --git a/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/mod.rs b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/mod.rs index f77bc68f..205c84ff 100644 --- a/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/mod.rs +++ b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/mod.rs @@ -15,11 +15,13 @@ // specific language governing permissions and limitations // under the License. +mod account_interactions; mod encountered_entities; mod entities_requiring_auth; mod presented_proofs; mod reserved_instructions; +pub use account_interactions::*; pub use encountered_entities::*; pub use entities_requiring_auth::*; pub use presented_proofs::*; diff --git a/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/reserved_instructions.rs b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/reserved_instructions.rs index 6187abc2..1ac1f7e4 100644 --- a/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/reserved_instructions.rs +++ b/crates/radix-engine-toolkit/src/manifest_analysis/data_retrieval/reserved_instructions.rs @@ -149,23 +149,21 @@ impl ManifestAnalysisVisitor for ReservedInstructionsVisitor { } _ => {} } - - todo!() } } #[derive(Clone, Debug, PartialEq, Eq, Default)] pub struct ReservedInstructionsOutput { - account_lock_fee_invocations: IndexSet, - account_securify_invocations: IndexSet, - account_lock_owner_keys_metadata_field_invocations: + pub account_lock_fee_invocations: IndexSet, + pub account_securify_invocations: IndexSet, + pub account_lock_owner_keys_metadata_field_invocations: IndexSet, - account_update_owner_keys_metadata_field_invocations: + pub account_update_owner_keys_metadata_field_invocations: IndexSet, - identity_securify_invocations: IndexSet, - identity_lock_owner_keys_metadata_field_invocations: + pub identity_securify_invocations: IndexSet, + pub identity_lock_owner_keys_metadata_field_invocations: IndexSet, - identity_update_owner_keys_metadata_field_invocations: + pub identity_update_owner_keys_metadata_field_invocations: IndexSet, - access_controller_invocations: IndexSet, + pub access_controller_invocations: IndexSet, }