From 21bd626e24aa56b28c6ec041890b310378918665 Mon Sep 17 00:00:00 2001 From: Omar Date: Thu, 6 Jul 2023 18:14:55 +0300 Subject: [PATCH] Update Scrypto dependency --- .github/workflows/build.yml | 2 +- Changelog.md | 4 +- generate_manifest_inputs.py | 86 - generator/Cargo.toml | 14 +- generator/src/function_examples/execution.rs | 29 +- .../function_examples/manifest_provider.rs | 2 +- .../src/serializable_models/instruction.rs | 358 ---- radix-engine-toolkit-core/Cargo.toml | 18 +- .../src/functions/execution.rs | 2 +- .../src/functions/manifest.rs | 2 +- .../src/instruction_visitor/core/traits.rs | 24 +- .../src/instruction_visitor/core/traverser.rs | 16 +- .../general_transaction_visitor.rs | 3 +- .../simple_transfer_visitor.rs | 18 - .../transaction_type/transfer_visitor.rs | 3 +- radix-engine-toolkit-core/src/statics.rs | 1 - radix-engine-toolkit-core/src/utils.rs | 3 +- .../tests/account_interactions.rs | 21 +- .../tests/account_proofs.rs | 8 +- radix-engine-toolkit-core/tests/execution.rs | 35 +- .../manifests/access_rule/access_rule.rtm | 15 - .../tests/manifests/package/publish.rtm | 10 +- .../tests/manifests/resources/auth_zone.rtm | 8 +- .../creation/fungible/no_initial_supply.rtm | 80 +- .../creation/fungible/with_initial_supply.rtm | 82 +- .../non_fungible/no_initial_supply.rtm | 77 +- .../non_fungible/with_initial_supply.rtm | 79 +- .../tests/manifests/resources/recall.rtm | 2 +- .../resources/recall_non_fungibles.rtm | 1 + .../tests/manifests/resources/worktop.rtm | 1 + .../tests/manifests/values/values.rtm | 2 +- .../tests/schema_visitor.rs | 6 +- .../tests/simple_transfer_visitor.rs | 15 +- radix-engine-toolkit-core/tests/test_data.rs | 2 +- .../tests/transfer_visitor.rs | 29 +- radix-engine-toolkit-core/tests/utils.rs | 20 +- radix-engine-toolkit-uniffi/Cargo.toml | 10 +- .../src/common/decimal.rs | 59 +- .../src/transaction/instruction.rs | 44 +- radix-engine-toolkit/Cargo.toml | 10 +- .../src/models/manifest/inputs.rs | 135 -- .../src/models/manifest/mod.rs | 1 - .../src/models/transaction/instruction.rs | 1666 ++--------------- radix-engine-toolkit/src/prelude.rs | 1 - .../manifests/access_rule/access_rule.rtm | 15 - .../tests/manifests/package/publish.rtm | 10 +- .../tests/manifests/resources/auth_zone.rtm | 8 +- .../creation/fungible/no_initial_supply.rtm | 80 +- .../creation/fungible/with_initial_supply.rtm | 82 +- .../non_fungible/no_initial_supply.rtm | 77 +- .../non_fungible/with_initial_supply.rtm | 79 +- .../tests/manifests/resources/recall.rtm | 2 +- .../resources/recall_non_fungibles.rtm | 1 + .../tests/manifests/resources/worktop.rtm | 1 + .../tests/manifests/values/values.rtm | 2 +- 55 files changed, 562 insertions(+), 2799 deletions(-) delete mode 100644 generate_manifest_inputs.py create mode 100644 radix-engine-toolkit-core/tests/manifests/resources/recall_non_fungibles.rtm delete mode 100644 radix-engine-toolkit/src/models/manifest/inputs.rs create mode 100644 radix-engine-toolkit/tests/manifests/resources/recall_non_fungibles.rtm diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8da0d623..15597930 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -246,7 +246,7 @@ jobs: - name: Clone uniffi-bindgen-cs uses: actions/checkout@v3 with: - repository: 0xOmarA/uniffi-bindgen-cs + repository: radixdlt/uniffi-bindgen-cs path: uniffi-bindgen-cs submodules: 'recursive' - uses: actions/download-artifact@v3 diff --git a/Changelog.md b/Changelog.md index 175a890c..0dec4d6e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,6 @@ -# 0.10.0-elm.1 (WIP) +# 0.10.0 (6 July 2023) -Still a work in progress +* The instruction model of the `radix-engine-toolkit` crate no longer performs any aliasing of instructions. All aliasing is to be handled by transaction manifest builders. # 0.10.0-damson.1 (26-June-2023) diff --git a/generate_manifest_inputs.py b/generate_manifest_inputs.py deleted file mode 100644 index dc1d50da..00000000 --- a/generate_manifest_inputs.py +++ /dev/null @@ -1,86 +0,0 @@ -import os -import shutil -import re - -SCRIPT_DIRECTORY: str = os.path.dirname(os.path.realpath(__file__)) -REPOSITORY_URL: str = "https://github.com/radixdlt/radixdlt-scrypto" -OUTPUT_PATH: str = os.path.join(SCRIPT_DIRECTORY, "radix-engine-toolkit", "src", "models", "manifest", "inputs.rs") - -def main() -> None: - # Get the tag or branch of the Scrypto dependency being used. - path_of_cargo_toml_manifest: str = os.path.join(SCRIPT_DIRECTORY, 'radix-engine-toolkit-core', 'Cargo.toml') - branch_or_tag: str = read_tag_or_version(path_of_cargo_toml_manifest) - - # Remove the radixdlt-scrypto if it exists - radixdlt_scrypto_directory: str = os.path.join(SCRIPT_DIRECTORY, 'radixdlt-scrypto') - if os.path.exists(radixdlt_scrypto_directory): - shutil.rmtree(radixdlt_scrypto_directory) - - # Clone the repository - os.system(f'git clone {REPOSITORY_URL} -b {branch_or_tag} "{radixdlt_scrypto_directory}"') - - # Obtain the struct definitions that match the Regex pattern - structs: list[str] = [] - for (root_directory, _, file_names) in os.walk(radixdlt_scrypto_directory): - for file_name in file_names: - if not file_name.endswith('rs'): - continue - - path: str = os.path.join(root_directory, file_name) - with open(path, 'r') as file: - content: str = file.read() - - new_structs: list[str] = re.findall(r'struct\s*.*Input\s*\{[\n\s\w\t_:(),<>#\[\]\(\)="]*BTreeMap[\n\s\w\t_:(),<>#\[\]\(\)="]*\}', content) - structs.extend(new_structs) - - replacements: dict[str, str] = {} - imports: list[str] = [ - "use radix_engine::blueprints::package::*;", - "use radix_engine_common::prelude::*;", - "use scrypto::api::node_modules::metadata::*;", - "use scrypto::prelude::*;", - ] - with open(OUTPUT_PATH, 'w') as file: - file.write("\n".join(imports) + '\n\n') - - for struct in structs: - derives: str = "#[derive(ManifestSbor, Clone, Debug)]" if "ManifestInput" in struct else "#[derive(ScryptoSbor, Clone, Debug)]" - struct: str = struct.replace("BTreeMap", "IndexMap") - struct_ident: str = re.findall(r'struct\s*(.*)Input', struct)[0] - struct = "pub " + struct.replace(struct_ident, f'{struct_ident}IndexMap') - - replacements[struct_ident + "Input"] = f'{struct_ident}IndexMapInput' - - file.write(derives + '\n' + struct + '\n\n') - - # Remove the radixdlt-scrypto repo after we're finished with it. - shutil.rmtree(radixdlt_scrypto_directory) - - # Use the new types in code. - for (root_dir, _, file_names) in os.walk(SCRIPT_DIRECTORY): - for file_name in file_names: - if not file_name.endswith(".rs"): - continue; - - path: str = os.path.join(root_dir, file_name) - with open(path, 'r') as file: - content: str = file.read() - - for (old, new) in replacements.items(): - content = content.replace(old, new) - - with open(path, 'w') as file: - file.write(content) - -def read_tag_or_version(manifest_path: str) -> str: - if not manifest_path.endswith('.toml'): - raise Exception("Invalid file extension") - - with open(manifest_path, 'r') as file: - contents: str = file.read() - - pattern: str = r'scrypto\s?=\s?\{.*[branch|tag]\s?=\s?"([\w\d\/-]*)".*\}' - return re.findall(pattern, contents)[0] - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/generator/Cargo.toml b/generator/Cargo.toml index cbb7d0e9..fe208e09 100644 --- a/generator/Cargo.toml +++ b/generator/Cargo.toml @@ -5,13 +5,13 @@ edition = "2021" [dependencies] # radixdlt-scrypto dependencies. -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features = false, features = ["lru", "std"] } -transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features= false, features = ["std", "lru"] } -radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } +sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features = false, features = ["lru", "std"] } +transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } +radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features= false, features = ["std", "lru"] } +radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } # Core Radix Engine Toolkit and Toolkit Native Library radix-engine-toolkit-core = { path = "../radix-engine-toolkit-core" } diff --git a/generator/src/function_examples/execution.rs b/generator/src/function_examples/execution.rs index 1fbb3c84..4159cb1e 100644 --- a/generator/src/function_examples/execution.rs +++ b/generator/src/function_examples/execution.rs @@ -31,9 +31,10 @@ impl<'f> HasExamples<'f, 3> for ExecutionAnalyze { let (public_key2, _, account2) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, "10") + .withdraw_from_account(account1, RADIX_TOKEN, "10") + .take_from_worktop(RADIX_TOKEN, "10", "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, @@ -59,16 +60,18 @@ impl<'f> HasExamples<'f, 3> for ExecutionAnalyze { let (public_key3, _, account3) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 20.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, "10") + .withdraw_from_account(account1, RADIX_TOKEN, "20") + .take_from_worktop(RADIX_TOKEN, "10", "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, manifest_args!(bucket), ) }) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, "10", "bucket1") + .with_bucket("bucket1", |builder, bucket| { builder.call_method( account3, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, @@ -94,17 +97,19 @@ impl<'f> HasExamples<'f, 3> for ExecutionAnalyze { let (public_key3, _, account3) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .withdraw_from_account(account2, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, "10") + .withdraw_from_account(account1, RADIX_TOKEN, "10") + .withdraw_from_account(account2, RADIX_TOKEN, "10") + .take_from_worktop(RADIX_TOKEN, "10", "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, manifest_args!(bucket), ) }) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, "10", "bucket1") + .with_bucket("bucket1", |builder, bucket| { builder.call_method( account3, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, diff --git a/generator/src/function_examples/manifest_provider.rs b/generator/src/function_examples/manifest_provider.rs index a56d0785..f4f7d29d 100644 --- a/generator/src/function_examples/manifest_provider.rs +++ b/generator/src/function_examples/manifest_provider.rs @@ -20,7 +20,7 @@ use radix_engine_toolkit::prelude::*; use transaction::manifest::*; use walkdir::WalkDir; -pub const NUMBER_OF_MANIFESTS: usize = 25; +pub const NUMBER_OF_MANIFESTS: usize = 26; pub const NUMBER_OF_MANIFESTS_DOUBLE: usize = NUMBER_OF_MANIFESTS * 2; pub fn get_serializable_instructions() -> [SerializableInstructions; NUMBER_OF_MANIFESTS_DOUBLE] { diff --git a/generator/src/serializable_models/instruction.rs b/generator/src/serializable_models/instruction.rs index 71b51aed..8d90b936 100644 --- a/generator/src/serializable_models/instruction.rs +++ b/generator/src/serializable_models/instruction.rs @@ -17,288 +17,15 @@ use super::traits::HasExamples; use crate::function_examples::notarized_transaction::*; -use radix_engine::system::bootstrap::*; -use radix_engine_interface::blueprints::account::*; -use radix_engine_interface::blueprints::consensus_manager::*; -use radix_engine_interface::blueprints::package::*; use radix_engine_toolkit::prelude::*; use scrypto::api::node_modules::metadata::*; -use scrypto::api::node_modules::royalty::*; use scrypto::prelude::*; use transaction::prelude::*; use transaction::validation::*; impl<'f> HasExamples<'f> for SerializableInstruction { fn examples() -> Vec { - let (code, setup) = example_package(); - ExamplesBuilder::new() - .add_example(|mut builder| { - builder - .call_function( - FAUCET_PACKAGE, - "blueprint", - "function_name", - manifest_args!(dec!("10"), "hello world!", RADIX_TOKEN), - ) - .call_function( - FAUCET_PACKAGE, - "blueprint", - "function_name", - manifest_args!(), - ) - .call_method(FAUCET, "free", manifest_args!(dec!("100"))) - .call_method(FAUCET, "free", manifest_args!()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, _| builder) - .take_all_from_worktop(RADIX_TOKEN, |builder, bucket| { - builder - .create_proof_from_bucket(&bucket, |builder, _| builder) - .create_proof_from_bucket_of_all(&bucket, |builder, _| builder) - .create_proof_from_bucket_of_amount(&bucket, 10.into(), |builder, _| { - builder - }) - .create_proof_from_bucket_of_non_fungibles( - &bucket, - BTreeSet::from([ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2), - ]), - |builder, _| builder, - ) - }) - .take_non_fungibles_from_worktop( - RADIX_TOKEN, - &BTreeSet::from([ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2), - ]), - |builder, bucket| builder.return_to_worktop(bucket), - ) - .assert_worktop_contains(RADIX_TOKEN, 10.into()) - .assert_worktop_contains_non_fungibles( - RADIX_TOKEN, - &BTreeSet::from([ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2), - ]), - ) - .pop_from_auth_zone(|builder, proof| { - builder - .push_to_auth_zone(proof) - .clone_proof(&proof, |builder, proof2| builder.drop_proof(proof2)) - }) - .clear_auth_zone() - .create_proof_from_auth_zone(RADIX_TOKEN, |builder, _| builder) - .create_proof_from_auth_zone_of_all(RADIX_TOKEN, |builder, _| builder) - .create_proof_from_auth_zone_of_amount(RADIX_TOKEN, 10.into(), |builder, _| { - builder - }) - .create_proof_from_auth_zone_of_non_fungibles( - RADIX_TOKEN, - &BTreeSet::from([ - NonFungibleLocalId::integer(1), - NonFungibleLocalId::integer(2), - ]), - |builder, _| builder, - ) - .clear_signature_proofs() - .burn_from_worktop(10.into(), RADIX_TOKEN) - .add_instruction(InstructionV1::CallRoyaltyMethod { - address: DynamicGlobalAddress::Static(FAUCET.into()), - method_name: COMPONENT_ROYALTY_CLAIM_ROYALTIES_IDENT.to_string(), - args: to_manifest_value(&ComponentClaimRoyaltiesInput {}).unwrap(), - }) - .0 - .add_instruction(InstructionV1::CallMetadataMethod { - address: DynamicGlobalAddress::Static(FAUCET.into()), - method_name: METADATA_SET_IDENT.to_string(), - args: to_manifest_value(&MetadataSetInput { - key: "key".into(), - value: MetadataValue::Bool(true), - }) - .unwrap(), - }) - .0 - .add_instruction(InstructionV1::CallAccessRulesMethod { - address: DynamicGlobalAddress::Static(FAUCET.into()), - method_name: ACCESS_RULES_SET_ROLE_IDENT.to_string(), - args: to_manifest_value(&AccessRulesSetRoleInput { - module: scrypto::api::ObjectModuleId::Main, - role_key: RoleKey { - key: "free".to_string(), - }, - rule: rule!(allow_all), - }) - .unwrap(), - }) - .0 - .drop_all_proofs() - .recall(vault_id(), 10.into()) - .freeze_withdraw(vault_id()) - .freeze_deposit(vault_id()) - .freeze_burn(vault_id()) - .unfreeze_withdraw(vault_id()) - .unfreeze_deposit(vault_id()) - .unfreeze_burn(vault_id()) - .create_identity() - .create_identity_advanced(OwnerRole::None) - .call_function( - ACCOUNT_PACKAGE, - ACCOUNT_BLUEPRINT, - ACCOUNT_CREATE_IDENT, - to_manifest_value(&AccountCreateInput {}).unwrap(), - ) - .call_function( - ACCOUNT_PACKAGE, - ACCOUNT_BLUEPRINT, - ACCOUNT_CREATE_ADVANCED_IDENT, - to_manifest_value(&AccountCreateAdvancedInput { - owner_role: OwnerRole::None, - }) - .unwrap(), - ) - .create_validator( - Secp256k1PrivateKey::from_u64(1).unwrap().public_key(), - 10.into(), - ManifestBucket(1), - ) - .mint_ruid_non_fungible( - RADIX_TOKEN, - vec![ - Human { - name: "Jack".into(), - age: 30, - height: (6, 11, 2), - }, - Human { - name: "Not Jack".into(), - age: 60, - height: (5, 11, 2), - }, - ], - ) - .mint_non_fungible( - RADIX_TOKEN, - btreemap! { - NonFungibleLocalId::integer(1) => Human { - name: "Jack".into(), - age: 30, - height: (6, 11, 2), - }, - NonFungibleLocalId::integer(2) => Human { - name: "Not Jack".into(), - age: 60, - height: (5, 11, 2), - }, - }, - ) - .mint_fungible(RADIX_TOKEN, 10.into()) - .claim_package_royalties(ACCOUNT_PACKAGE) - .claim_component_royalties(FAUCET) - .set_component_royalty(FAUCET, "free", RoyaltyAmount::Free) - .add_instruction(InstructionV1::CallMetadataMethod { - address: DynamicGlobalAddress::Static(FAUCET.into()), - method_name: METADATA_REMOVE_IDENT.into(), - args: to_manifest_value(&MetadataRemoveInput { - key: "free".to_string(), - }) - .unwrap(), - }) - .0 - .set_metadata( - FAUCET.into(), - "free".to_string(), - MetadataValue::Decimal(10.into()), - ) - .create_access_controller( - ManifestBucket(10), - rule!(allow_all), - rule!(allow_all), - rule!(allow_all), - Some(10), - ) - .create_fungible_resource::( - OwnerRole::None, - true, - 18, - ModuleConfig { - init: metadata_init!( - "name" => true, locked; - ), - roles: RolesInit::default(), - }, - BTreeMap::new(), - Some(10.into()), - ) - .create_fungible_resource::( - OwnerRole::None, - true, - 18, - ModuleConfig { - init: metadata_init!( - "name" => true, locked; - ), - roles: RolesInit::default(), - }, - BTreeMap::new(), - None, - ) - .create_non_fungible_resource( - OwnerRole::None, - NonFungibleIdType::Integer, - true, - ModuleConfig { - init: metadata_init!( - "name" => true, locked; - ), - roles: RolesInit::default(), - }, - BTreeMap::::new(), - None::>, - ) - .create_non_fungible_resource( - OwnerRole::None, - NonFungibleIdType::Integer, - true, - ModuleConfig { - init: metadata_init!( - "name" => true, locked; - ), - roles: RolesInit::default(), - }, - BTreeMap::::new(), - Some(btreemap! { - NonFungibleLocalId::integer(1) => Human { - name: "Jack".into(), - age: 30, - height: (6, 11, 2), - }, - NonFungibleLocalId::integer(2) => Human { - name: "Not Jack".into(), - age: 60, - height: (5, 11, 2), - }, - }), - ) - .allocate_global_address( - BlueprintId { - package_address: ACCOUNT_PACKAGE, - blueprint_name: ACCOUNT_BLUEPRINT.to_string(), - }, - |builder, _, _| builder, - ) - .publish_package(code.clone(), setup.clone()) - .publish_package_advanced( - None, - code.clone(), - setup.clone(), - metadata_init!( - "name" => true, locked; - ), - OwnerRole::None, - ) - .build() - }) .add_instructions( notarized_transactions() .into_iter() @@ -323,14 +50,6 @@ impl ExamplesBuilder { Default::default() } - pub fn add_example(self, callback: F) -> Self - where - F: FnOnce(ManifestBuilder) -> TransactionManifestV1, - { - let TransactionManifestV1 { instructions, .. } = callback(ManifestBuilder::new()); - self.add_instructions(instructions) - } - pub fn add_instructions(self, instructions: Vec) -> Self { self.add_serializable_instructions( instructions @@ -364,83 +83,6 @@ impl ExamplesBuilder { } } -fn vault_id() -> InternalAddress { - let mut address = RADIX_TOKEN.as_node_id().0; - address[0] = EntityType::InternalFungibleVault as u8; - InternalAddress::new_or_panic(address) -} - -fn example_package() -> (Vec, PackageDefinition) { - let SystemTransactionV1 { - instructions, - blobs, - .. - } = create_system_bootstrap_transaction( - Epoch::of(0), - ConsensusManagerConfig { - max_validators: 0, - epoch_change_condition: EpochChangeCondition::default(), - num_unstake_epochs: 0, - total_emission_xrd_per_epoch: 0.into(), - min_validator_reliability: 0.into(), - num_owner_stake_units_unlock_epochs: 0, - num_fee_increase_delay_epochs: 0, - validator_creation_xrd_cost: 0.into(), - }, - 0, - None, - 0.into(), - ); - - for instruction in instructions.0.into_iter() { - let (code, setup) = match instruction { - InstructionV1::CallFunction { - package_address, - blueprint_name, - function_name, - args, - } if package_address == DynamicPackageAddress::Static(PACKAGE_PACKAGE) - && blueprint_name == PACKAGE_BLUEPRINT - && function_name == PACKAGE_PUBLISH_WASM_IDENT => - { - let PackagePublishWasmManifestInput { code, setup, .. } = - manifest_decode(&manifest_encode(&args).unwrap()).unwrap(); - - (code, setup) - } - InstructionV1::CallFunction { - package_address, - blueprint_name, - function_name, - args, - } if package_address == DynamicPackageAddress::Static(PACKAGE_PACKAGE) - && blueprint_name == PACKAGE_BLUEPRINT - && function_name == PACKAGE_PUBLISH_WASM_ADVANCED_IDENT => - { - let PackagePublishWasmAdvancedManifestInput { code, setup, .. } = - manifest_decode(&manifest_encode(&args).unwrap()).unwrap(); - - (code, setup) - } - _ => continue, - }; - - let code = blobs - .blobs - .into_iter() - .find_map(|BlobV1(value)| { - if hash(&value).0 == code.0 { - Some(value) - } else { - None - } - }) - .unwrap(); - return (code, setup); - } - panic!("Can't get here") -} - #[derive(NonFungibleData, ScryptoSbor, ManifestSbor)] pub struct Human { name: String, diff --git a/radix-engine-toolkit-core/Cargo.toml b/radix-engine-toolkit-core/Cargo.toml index 35daa270..bdae660c 100644 --- a/radix-engine-toolkit-core/Cargo.toml +++ b/radix-engine-toolkit-core/Cargo.toml @@ -6,14 +6,14 @@ build = "build.rs" [dependencies] # radixdlt-scrypto dependencies. -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features= false, features = ["std", "lru"] } -radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } -radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features= false, features = ["std", "lru"] } -radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } +sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } +radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features= false, features = ["std", "lru"] } +radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +radix-engine-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } +radix-engine-queries = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features= false, features = ["std", "lru"] } +radix-engine-store-interface = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } # Bech32 encoding and decoding of addresses. Used for the Olympia <-> Babylon address derivations. bech32 = { version = "0.9.1" } @@ -31,7 +31,7 @@ regex = "1.8.4" cargo_toml = { version = "0.15.3" } [dev-dependencies] -scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features = false, features = ["lru", "std", "resource_tracker"] } +scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features = false, features = ["lru", "std", "resource_tracker"] } [lib] crate-type = ["staticlib", "cdylib", "rlib"] diff --git a/radix-engine-toolkit-core/src/functions/execution.rs b/radix-engine-toolkit-core/src/functions/execution.rs index ed133132..3d2e41df 100644 --- a/radix-engine-toolkit-core/src/functions/execution.rs +++ b/radix-engine-toolkit-core/src/functions/execution.rs @@ -197,5 +197,5 @@ impl From for ExecutionModuleError { } fn cost_units_to_xrd(cost_units: u128) -> Decimal { - Decimal::from_str(DEFAULT_COST_UNIT_PRICE).unwrap() * cost_units + Decimal::from_str(DEFAULT_COST_UNIT_PRICE_IN_XRD).unwrap() * cost_units } diff --git a/radix-engine-toolkit-core/src/functions/manifest.rs b/radix-engine-toolkit-core/src/functions/manifest.rs index 577ea112..7499402c 100644 --- a/radix-engine-toolkit-core/src/functions/manifest.rs +++ b/radix-engine-toolkit-core/src/functions/manifest.rs @@ -17,8 +17,8 @@ use sbor::*; use scrypto::prelude::*; -use transaction::builder::*; use transaction::errors::*; +use transaction::prelude::*; use transaction::validation::*; pub fn hash(manifest: &TransactionManifestV1) -> Result { diff --git a/radix-engine-toolkit-core/src/instruction_visitor/core/traits.rs b/radix-engine-toolkit-core/src/instruction_visitor/core/traits.rs index 120ecb85..b2619fb2 100644 --- a/radix-engine-toolkit-core/src/instruction_visitor/core/traits.rs +++ b/radix-engine-toolkit-core/src/instruction_visitor/core/traits.rs @@ -81,6 +81,14 @@ pub trait InstructionVisitor { Ok(()) } + #[inline] + fn visit_assert_worktop_contains_any( + &mut self, + resource_address: &ResourceAddress, + ) -> Result<(), InstructionVisitorError> { + Ok(()) + } + #[inline] fn visit_assert_worktop_contains_non_fungibles( &mut self, @@ -108,14 +116,6 @@ pub trait InstructionVisitor { Ok(()) } - #[inline] - fn visit_create_proof_from_auth_zone( - &mut self, - resource_address: &ResourceAddress, - ) -> Result<(), InstructionVisitorError> { - Ok(()) - } - #[inline] fn visit_create_proof_from_auth_zone_of_amount( &mut self, @@ -147,14 +147,6 @@ pub trait InstructionVisitor { Ok(()) } - #[inline] - fn visit_create_proof_from_bucket( - &mut self, - bucket_id: &ManifestBucket, - ) -> Result<(), InstructionVisitorError> { - Ok(()) - } - #[inline] fn visit_create_proof_from_bucket_of_amount( &mut self, diff --git a/radix-engine-toolkit-core/src/instruction_visitor/core/traverser.rs b/radix-engine-toolkit-core/src/instruction_visitor/core/traverser.rs index 5d54ef22..af612161 100644 --- a/radix-engine-toolkit-core/src/instruction_visitor/core/traverser.rs +++ b/radix-engine-toolkit-core/src/instruction_visitor/core/traverser.rs @@ -50,6 +50,12 @@ pub fn traverse( InstructionV1::ReturnToWorktop { bucket_id } => { for_each_enabled_visitor!(visitors, visit_return_to_worktop(bucket_id)) } + InstructionV1::AssertWorktopContainsAny { resource_address } => { + for_each_enabled_visitor!( + visitors, + visit_assert_worktop_contains_any(resource_address) + ) + } InstructionV1::AssertWorktopContains { resource_address, amount, @@ -77,12 +83,7 @@ pub fn traverse( InstructionV1::ClearAuthZone => { for_each_enabled_visitor!(visitors, visit_clear_auth_zone()) } - InstructionV1::CreateProofFromAuthZone { resource_address } => { - for_each_enabled_visitor!( - visitors, - visit_create_proof_from_auth_zone(resource_address) - ) - } + InstructionV1::CreateProofFromAuthZoneOfAmount { resource_address, amount, @@ -110,9 +111,6 @@ pub fn traverse( InstructionV1::ClearSignatureProofs {} => { for_each_enabled_visitor!(visitors, visit_clear_signature_proofs()) } - InstructionV1::CreateProofFromBucket { bucket_id } => { - for_each_enabled_visitor!(visitors, visit_create_proof_from_bucket(bucket_id)) - } InstructionV1::CreateProofFromBucketOfAmount { bucket_id, amount } => { for_each_enabled_visitor!( visitors, diff --git a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/general_transaction_visitor.rs b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/general_transaction_visitor.rs index 3ff40e2f..d5150c8b 100644 --- a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/general_transaction_visitor.rs +++ b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/general_transaction_visitor.rs @@ -151,16 +151,15 @@ impl<'r> InstructionVisitor for GeneralTransactionTypeVisitor<'r> { /* Allowed Instructions */ InstructionV1::AssertWorktopContains { .. } + | InstructionV1::AssertWorktopContainsAny { .. } | InstructionV1::AssertWorktopContainsNonFungibles { .. } | InstructionV1::PopFromAuthZone | InstructionV1::PushToAuthZone { .. } | InstructionV1::ClearAuthZone - | InstructionV1::CreateProofFromAuthZone { .. } | InstructionV1::CreateProofFromAuthZoneOfAmount { .. } | InstructionV1::CreateProofFromAuthZoneOfNonFungibles { .. } | InstructionV1::CreateProofFromAuthZoneOfAll { .. } | InstructionV1::ClearSignatureProofs - | InstructionV1::CreateProofFromBucket { .. } | InstructionV1::CreateProofFromBucketOfAmount { .. } | InstructionV1::CreateProofFromBucketOfNonFungibles { .. } | InstructionV1::CreateProofFromBucketOfAll { .. } diff --git a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/simple_transfer_visitor.rs b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/simple_transfer_visitor.rs index 91741405..3662413a 100644 --- a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/simple_transfer_visitor.rs +++ b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/simple_transfer_visitor.rs @@ -253,15 +253,6 @@ impl InstructionVisitor for SimpleTransactionTypeVisitor { Ok(()) } - #[inline] - fn visit_create_proof_from_auth_zone( - &mut self, - _: &ResourceAddress, - ) -> Result<(), InstructionVisitorError> { - self.illegal_instruction_encountered = true; - Ok(()) - } - #[inline] fn visit_create_proof_from_auth_zone_of_amount( &mut self, @@ -297,15 +288,6 @@ impl InstructionVisitor for SimpleTransactionTypeVisitor { Ok(()) } - #[inline] - fn visit_create_proof_from_bucket( - &mut self, - _: &ManifestBucket, - ) -> Result<(), InstructionVisitorError> { - self.illegal_instruction_encountered = true; - Ok(()) - } - #[inline] fn visit_create_proof_from_bucket_of_amount( &mut self, diff --git a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/transfer_visitor.rs b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/transfer_visitor.rs index 40690d43..f3c0e24c 100644 --- a/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/transfer_visitor.rs +++ b/radix-engine-toolkit-core/src/instruction_visitor/visitors/transaction_type/transfer_visitor.rs @@ -164,18 +164,17 @@ impl InstructionVisitor for TransferTransactionTypeVisitor { } /* Allowed Instructions */ InstructionV1::AssertWorktopContains { .. } + | InstructionV1::AssertWorktopContainsAny { .. } | InstructionV1::AssertWorktopContainsNonFungibles { .. } => {} /* Illegal Instructions */ InstructionV1::CallMethod { .. } | InstructionV1::PopFromAuthZone | InstructionV1::PushToAuthZone { .. } | InstructionV1::ClearAuthZone - | InstructionV1::CreateProofFromAuthZone { .. } | InstructionV1::CreateProofFromAuthZoneOfAmount { .. } | InstructionV1::CreateProofFromAuthZoneOfNonFungibles { .. } | InstructionV1::CreateProofFromAuthZoneOfAll { .. } | InstructionV1::ClearSignatureProofs - | InstructionV1::CreateProofFromBucket { .. } | InstructionV1::CreateProofFromBucketOfAmount { .. } | InstructionV1::CreateProofFromBucketOfNonFungibles { .. } | InstructionV1::CreateProofFromBucketOfAll { .. } diff --git a/radix-engine-toolkit-core/src/statics.rs b/radix-engine-toolkit-core/src/statics.rs index 19d14ddd..0e4d4efa 100644 --- a/radix-engine-toolkit-core/src/statics.rs +++ b/radix-engine-toolkit-core/src/statics.rs @@ -20,7 +20,6 @@ use radix_engine::blueprints::native_schema::*; use radix_engine::blueprints::package::*; use radix_engine::types::*; use scrypto::api::node_modules::auth::*; -use scrypto::api::node_modules::metadata::*; use scrypto::api::node_modules::royalty::*; use scrypto::blueprints::account::*; use scrypto::blueprints::identity::*; diff --git a/radix-engine-toolkit-core/src/utils.rs b/radix-engine-toolkit-core/src/utils.rs index 9d959c90..5945b518 100644 --- a/radix-engine-toolkit-core/src/utils.rs +++ b/radix-engine-toolkit-core/src/utils.rs @@ -27,7 +27,8 @@ use radix_engine_store_interface::interface::DatabaseUpdate; use regex::Regex; use sbor::{generate_full_schema_from_single_type, validate_payload_against_schema}; use scrypto::{api::node_modules::metadata::MetadataValue, prelude::*}; -use transaction::{builder::TransactionManifestV1, model::IntentV1, prelude::DynamicGlobalAddress}; +use transaction::model::IntentV1; +use transaction::prelude::{DynamicGlobalAddress, TransactionManifestV1}; pub fn manifest_from_intent(intent: &IntentV1) -> TransactionManifestV1 { let IntentV1 { diff --git a/radix-engine-toolkit-core/tests/account_interactions.rs b/radix-engine-toolkit-core/tests/account_interactions.rs index 9ef84b18..c45dc5da 100644 --- a/radix-engine-toolkit-core/tests/account_interactions.rs +++ b/radix-engine-toolkit-core/tests/account_interactions.rs @@ -26,7 +26,7 @@ fn account_withdraw_fungibles_interactions_count_as_withdraws_and_auth_requiring // Arrange let account = account(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account, RADIX_TOKEN, 1.into()) + .withdraw_from_account(account, RADIX_TOKEN, dec!("1")) .build(); // Act @@ -71,7 +71,7 @@ fn account_lock_fee_and_withdraw_fungibles_interactions_count_as_withdraws_and_a // Arrange let account = account(); let manifest = ManifestBuilder::new() - .lock_fee_and_withdraw(account, 1.into(), RADIX_TOKEN, 1.into()) + .lock_fee_and_withdraw(account, dec!("1"), RADIX_TOKEN, dec!("1")) .build(); // Act @@ -94,7 +94,7 @@ fn account_lock_fee_and_withdraw_non_fungibles_interactions_count_as_withdraws_a let account = account(); let ids = non_fungible_ids(); let manifest = ManifestBuilder::new() - .lock_fee_and_withdraw_non_fungibles(account, 1.into(), RADIX_TOKEN, ids) + .lock_fee_and_withdraw_non_fungibles(account, dec!("1"), RADIX_TOKEN, &ids) .build(); // Act @@ -114,7 +114,7 @@ fn account_lock_fee_and_withdraw_non_fungibles_interactions_count_as_withdraws_a fn account_lock_fee_interactions_count_as_auth_requiring_interactions() { // Arrange let account = account(); - let manifest = ManifestBuilder::new().lock_fee(account, 1.into()).build(); + let manifest = ManifestBuilder::new().lock_fee(account, dec!("1")).build(); // Act let (accounts_requiring_auth, accounts_withdrawn_from, accounts_deposited_into) = @@ -133,7 +133,7 @@ fn account_lock_contingent_fee_interactions_count_as_auth_requiring_interactions // Arrange let account = account(); let manifest = ManifestBuilder::new() - .lock_contingent_fee(account, 1.into()) + .lock_contingent_fee(account, dec!("1")) .build(); // Act @@ -153,7 +153,7 @@ fn account_create_proof_interactions_count_as_auth_requiring_interactions() { // Arrange let account = account(); let manifest = ManifestBuilder::new() - .create_proof_from_account(account, RADIX_TOKEN) + .create_proof_from_account_of_amount(account, RADIX_TOKEN, dec!("10")) .build(); // Act @@ -173,7 +173,7 @@ fn account_create_proof_by_amount_interactions_count_as_auth_requiring_interacti // Arrange let account = account(); let manifest = ManifestBuilder::new() - .create_proof_from_account_of_amount(account, RADIX_TOKEN, 1.into()) + .create_proof_from_account_of_amount(account, RADIX_TOKEN, dec!("1")) .build(); // Act @@ -214,7 +214,8 @@ fn account_deposit_interactions_count_as_deposit_interactions() { // Arrange let account = account(); let manifest = ManifestBuilder::new() - .take_all_from_worktop(RADIX_TOKEN, |builder, bucket| { + .take_all_from_worktop(RADIX_TOKEN, "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account, "deposit", manifest_args!(bucket)) }) .build(); @@ -260,7 +261,7 @@ fn account_set_metadata_interactions_count_as_auth_requiring_interactions() { // Arrange let account = account(); let manifest = ManifestBuilder::new() - .set_metadata(account.into(), "x", MetadataValue::Bool(true)) + .set_metadata(account, "x", MetadataValue::Bool(true)) .build(); // Act @@ -296,7 +297,7 @@ fn identity_set_metadata_interactions_count_as_auth_requiring_interactions() { // Arrange let identity = identity(); let manifest = ManifestBuilder::new() - .set_metadata(identity.into(), "x", MetadataValue::Bool(true)) + .set_metadata(identity, "x", MetadataValue::Bool(true)) .build(); // Act diff --git a/radix-engine-toolkit-core/tests/account_proofs.rs b/radix-engine-toolkit-core/tests/account_proofs.rs index 5ccfddcb..661e0737 100644 --- a/radix-engine-toolkit-core/tests/account_proofs.rs +++ b/radix-engine-toolkit-core/tests/account_proofs.rs @@ -24,8 +24,8 @@ use transaction::prelude::*; fn account_proofs_visitor_picks_up_on_calls_to_create_proof() { // Arrange let manifest = ManifestBuilder::new() - .create_proof_from_account(account(), RADIX_TOKEN) - .create_proof_from_account(account(), ACCOUNT_OWNER_BADGE) + .create_proof_from_account_of_amount(account(), RADIX_TOKEN, dec!("1")) + .create_proof_from_account_of_amount(account(), ACCOUNT_OWNER_BADGE, dec!("1")) .build(); // Act @@ -42,8 +42,8 @@ fn account_proofs_visitor_picks_up_on_calls_to_create_proof() { fn account_proofs_visitor_picks_up_on_calls_to_create_proof_of_amount() { // Arrange let manifest = ManifestBuilder::new() - .create_proof_from_account_of_amount(account(), RADIX_TOKEN, 10.into()) - .create_proof_from_account_of_amount(account(), ACCOUNT_OWNER_BADGE, 10.into()) + .create_proof_from_account_of_amount(account(), RADIX_TOKEN, dec!("10")) + .create_proof_from_account_of_amount(account(), ACCOUNT_OWNER_BADGE, dec!("10")) .build(); // Act diff --git a/radix-engine-toolkit-core/tests/execution.rs b/radix-engine-toolkit-core/tests/execution.rs index e0771b43..2cfade22 100644 --- a/radix-engine-toolkit-core/tests/execution.rs +++ b/radix-engine-toolkit-core/tests/execution.rs @@ -32,9 +32,10 @@ fn simple_transfer_is_picked_up_as_a_simple_account_transfer_transaction() { let (public_key2, _, account2) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, dec!("10")) + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, @@ -59,7 +60,7 @@ fn simple_transfer_is_picked_up_as_a_simple_account_transfer_transaction() { TransactionType::SimpleTransfer(Box::new(SimpleTransferTransactionType { from: account1, to: account2, - transferred: ResourceSpecifier::Amount(RADIX_TOKEN, 10.into()) + transferred: ResourceSpecifier::Amount(RADIX_TOKEN, dec!("10")) })) ) } @@ -73,16 +74,18 @@ fn transfer_is_picked_up_as_an_account_transfer_transaction() { let (public_key3, _, account3) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 20.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, dec!("10")) + .withdraw_from_account(account1, RADIX_TOKEN, dec!("20")) + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, manifest_args!(bucket), ) }) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket2") + .with_bucket("bucket2", |builder, bucket| { builder.call_method( account3, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, @@ -108,10 +111,10 @@ fn transfer_is_picked_up_as_an_account_transfer_transaction() { from: account1, transfers: hashmap! { account2 => hashmap! { - RADIX_TOKEN => Resources::Amount(10.into()), + RADIX_TOKEN => Resources::Amount(dec!("10")), }, account3 => hashmap! { - RADIX_TOKEN => Resources::Amount(10.into()), + RADIX_TOKEN => Resources::Amount(dec!("10")), } } })) @@ -127,17 +130,19 @@ fn complex_transfer_is_picked_up_as_an_general_transaction() { let (public_key3, _, account3) = test_runner.new_account(true); let manifest = ManifestBuilder::new() - .lock_fee(account1, 10.into()) - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .withdraw_from_account(account2, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .lock_fee(account1, dec!("10")) + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) + .withdraw_from_account(account2, RADIX_TOKEN, dec!("10")) + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method( account2, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, manifest_args!(bucket), ) }) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket1") + .with_bucket("bucket1", |builder, bucket| { builder.call_method( account3, ACCOUNT_TRY_DEPOSIT_OR_ABORT_IDENT, diff --git a/radix-engine-toolkit-core/tests/manifests/access_rule/access_rule.rtm b/radix-engine-toolkit-core/tests/manifests/access_rule/access_rule.rtm index a2833d36..07401614 100644 --- a/radix-engine-toolkit-core/tests/manifests/access_rule/access_rule.rtm +++ b/radix-engine-toolkit-core/tests/manifests/access_rule/access_rule.rtm @@ -5,22 +5,7 @@ SET_OWNER_ROLE LOCK_OWNER_ROLE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez"); -SET_AND_LOCK_OWNER_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>(); # The rule associated with the role - SET_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>() - "hello" # The name of the role to update the access rule for. - Enum<0u8>(); # The rule associated with the role - -LOCK_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>() - "hello"; # The name of the role to update the access rule for. - -SET_AND_LOCK_ROLE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Enum<0u8>() "hello" # The name of the role to update the access rule for. diff --git a/radix-engine-toolkit-core/tests/manifests/package/publish.rtm b/radix-engine-toolkit-core/tests/manifests/package/publish.rtm index bda169b4..672e746d 100644 --- a/radix-engine-toolkit-core/tests/manifests/package/publish.rtm +++ b/radix-engine-toolkit-core/tests/manifests/package/publish.rtm @@ -14,10 +14,10 @@ CALL_METHOD # Publishing a new package and setting some of its royalty and access rules. PUBLISH_PACKAGE_ADVANCED - None - Blob("a710f0959d8e139b3c1ca74ac4fcb9a95ada2c82e7f563304c5487e0117095c0") - Tuple( + Enum() # Owner AccessRule + Tuple( # Package Definition Map() ) - Map() # Metadata - Enum<0u8>(); # Owner AccessRule + Blob("a710f0959d8e139b3c1ca74ac4fcb9a95ada2c82e7f563304c5487e0117095c0") # Package Code + Map() # Metadata + None; # Address Reservation diff --git a/radix-engine-toolkit-core/tests/manifests/resources/auth_zone.rtm b/radix-engine-toolkit-core/tests/manifests/resources/auth_zone.rtm index 89ffdf51..bc7b86f6 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/auth_zone.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/auth_zone.rtm @@ -6,13 +6,12 @@ CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cv # Create a proof from bucket, clone it and drop both TAKE_ALL_FROM_WORKTOP Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3") Bucket("some_xrd"); -CREATE_PROOF_FROM_BUCKET Bucket("some_xrd") Proof("proof1"); CREATE_PROOF_FROM_BUCKET_OF_AMOUNT Bucket("some_xrd") Decimal("1") Proof("proof1a"); CREATE_PROOF_FROM_BUCKET_OF_NON_FUNGIBLES Bucket("some_xrd") Array(NonFungibleLocalId("#123#")) Proof("proof1b"); CREATE_PROOF_FROM_BUCKET_OF_ALL Bucket("some_xrd") Proof("proof1c"); -CLONE_PROOF Proof("proof1") Proof("proof2"); -DROP_PROOF Proof("proof1"); -DROP_PROOF Proof("proof2"); +CLONE_PROOF Proof("proof1c") Proof("proof1d"); +DROP_PROOF Proof("proof1d"); +DROP_PROOF Proof("proof1c"); CLEAR_AUTH_ZONE; # Create a proof from account and drop it @@ -22,7 +21,6 @@ DROP_PROOF Proof("proof3"); # Compose proofs CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q") "create_proof_of_amount" Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("5.0"); -CREATE_PROOF_FROM_AUTH_ZONE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Proof("Proof Name"); CREATE_PROOF_FROM_AUTH_ZONE_OF_AMOUNT Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("1") Proof("proof4"); CREATE_PROOF_FROM_AUTH_ZONE_OF_NON_FUNGIBLES Address("resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha") Array(NonFungibleLocalId("#123#")) Proof("proof5"); CREATE_PROOF_FROM_AUTH_ZONE_OF_ALL Address("resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha") Proof("proof6"); diff --git a/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/no_initial_supply.rtm b/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/no_initial_supply.rtm index 7446545b..e0cc8369 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/no_initial_supply.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/no_initial_supply.rtm @@ -16,60 +16,36 @@ CALL_METHOD # Creating a new resource with a divisibility of 18 and a name of `MyResource`. The resource has # default resource behavior where it can be withdrawn and deposited by anybody. CREATE_FUNGIBLE_RESOURCE - Enum<0u8>() - false # Track Total Supply - 18u8 - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + 18u8 # Divisibility (between 0u8 and 18u8) Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None # Deposit Roles (if None: defaults to AllowAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "symbol" => Tuple( - Enum( - Enum("RSRC"), # Resource Symbol - ), - true # Locked Resource Symbol - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - true # Locked Resource Description + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); # No Address Reservation \ No newline at end of file + None; # No Address Reservation \ No newline at end of file diff --git a/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/with_initial_supply.rtm b/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/with_initial_supply.rtm index c4d42a8a..93df44e9 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/with_initial_supply.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/creation/fungible/with_initial_supply.rtm @@ -16,64 +16,40 @@ CALL_METHOD # Creating a new resource with a divisibility of 18 and a name of `MyResource`. The resource has # default resource behavior where it can be withdrawn and deposited by anybody. CREATE_FUNGIBLE_RESOURCE_WITH_INITIAL_SUPPLY - Enum<0u8>() - false # Track Total Supply - 18u8 - Decimal("12") - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + 18u8 # Divisibility (between 0u8 and 18u8) + Decimal("12") # Initial supply Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None # Deposit Roles (if None: defaults to AllowAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "symbol" => Tuple( - Enum( - Enum("RSRC"), # Resource Symbol - ), - true # Locked Resource Symbol - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - true # Locked Resource Description + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); # No Address Reservation + None; # No Address Reservation # Depositing the entirety of the initial supply of the newly created resource into our account # component. diff --git a/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm b/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm index c2a771f3..c496d829 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm @@ -15,55 +15,38 @@ CALL_METHOD # Creating a new resource CREATE_NON_FUNGIBLE_RESOURCE - Enum<0u8>() - Enum() - false # Track Total Supply - Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + Enum() # The type of NonFungible Id + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) # Non Fungible Data Schema Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None, # Deposit Roles (if None: defaults to AllowAll, DenyAll) + None # Non Fungible Data Update Roles (if None: defaults to DenyAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - false + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); \ No newline at end of file + None; # No Address Reservation \ No newline at end of file diff --git a/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm b/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm index 5d8aa3ce..d4e1ef67 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm @@ -15,61 +15,44 @@ CALL_METHOD # Creating a new resource CREATE_NON_FUNGIBLE_RESOURCE_WITH_INITIAL_SUPPLY - Enum<0u8>() - Enum() - false # Track Total Supply - Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) - Map( + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + Enum() # The type of NonFungible Id + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) # Non Fungible Data Schema + Map( # Initial supply to mint NonFungibleLocalId("#12#") => Tuple(Tuple("Hello World", Decimal("12"))) ) - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None, # Deposit Roles (if None: defaults to AllowAll, DenyAll) + None # Non Fungible Data Update Roles (if None: defaults to DenyAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - false + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); + None; # No Address Reservation # Depositing the entirety of the initial supply of the newly created resource into our account # component. diff --git a/radix-engine-toolkit-core/tests/manifests/resources/recall.rtm b/radix-engine-toolkit-core/tests/manifests/resources/recall.rtm index 4634ac66..ff1f1d3a 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/recall.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/recall.rtm @@ -1 +1 @@ -RECALL_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Decimal("1.2"); +RECALL_FROM_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Decimal("1.2"); diff --git a/radix-engine-toolkit-core/tests/manifests/resources/recall_non_fungibles.rtm b/radix-engine-toolkit-core/tests/manifests/resources/recall_non_fungibles.rtm new file mode 100644 index 00000000..8b8b7e0b --- /dev/null +++ b/radix-engine-toolkit-core/tests/manifests/resources/recall_non_fungibles.rtm @@ -0,0 +1 @@ +RECALL_NON_FUNGIBLES_FROM_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Array(NonFungibleLocalId("#123#"), NonFungibleLocalId("#456#")); diff --git a/radix-engine-toolkit-core/tests/manifests/resources/worktop.rtm b/radix-engine-toolkit-core/tests/manifests/resources/worktop.rtm index fcbc906e..cafdd9a9 100644 --- a/radix-engine-toolkit-core/tests/manifests/resources/worktop.rtm +++ b/radix-engine-toolkit-core/tests/manifests/resources/worktop.rtm @@ -7,6 +7,7 @@ CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cv # Buy GUM with XRD TAKE_FROM_WORKTOP Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3") Decimal("2.0") Bucket("xrd"); CALL_METHOD Address("component_sim1cqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvemygpmu") "buy_gumball" Bucket("xrd"); +ASSERT_WORKTOP_CONTAINS_ANY Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez"); ASSERT_WORKTOP_CONTAINS Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("3.0"); # Create a proof from bucket, clone it and drop both diff --git a/radix-engine-toolkit-core/tests/manifests/values/values.rtm b/radix-engine-toolkit-core/tests/manifests/values/values.rtm index e659340d..08e5f377 100644 --- a/radix-engine-toolkit-core/tests/manifests/values/values.rtm +++ b/radix-engine-toolkit-core/tests/manifests/values/values.rtm @@ -1,7 +1,7 @@ TAKE_ALL_FROM_WORKTOP Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Bucket("temp1"); -CREATE_PROOF_FROM_AUTH_ZONE +CREATE_PROOF_FROM_AUTH_ZONE_OF_ALL Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Proof("temp2"); diff --git a/radix-engine-toolkit-core/tests/schema_visitor.rs b/radix-engine-toolkit-core/tests/schema_visitor.rs index 8be971bc..f8cfb937 100644 --- a/radix-engine-toolkit-core/tests/schema_visitor.rs +++ b/radix-engine-toolkit-core/tests/schema_visitor.rs @@ -75,8 +75,10 @@ fn bucket_in_path_visitor_does_not_detect_non_existent_buckets() { #[test] fn proof_in_path_visitor_can_detect_a_proof_in_the_schema() { // Arrange - let (local_type_index, schema) = - generate_full_schema_from_single_type::(); + let (local_type_index, schema) = generate_full_schema_from_single_type::< + AccountCreateProofOfAmountOutput, + ScryptoCustomSchema, + >(); // Act let mut visitor = ProofInPathVisitor::default(); diff --git a/radix-engine-toolkit-core/tests/simple_transfer_visitor.rs b/radix-engine-toolkit-core/tests/simple_transfer_visitor.rs index dde0d7c7..7742d22c 100644 --- a/radix-engine-toolkit-core/tests/simple_transfer_visitor.rs +++ b/radix-engine-toolkit-core/tests/simple_transfer_visitor.rs @@ -32,8 +32,9 @@ pub fn simple_transfer_visitor_can_pick_up_fungible_transfer() { let account2 = test_data::account2(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); @@ -50,7 +51,7 @@ pub fn simple_transfer_visitor_can_pick_up_fungible_transfer() { assert_eq!(to_account, account2); assert_eq!( resource_specifier, - ResourceSpecifier::Amount(RADIX_TOKEN, 10.into()) + ResourceSpecifier::Amount(RADIX_TOKEN, dec!("10")) ); } @@ -69,7 +70,8 @@ pub fn simple_transfer_visitor_can_pick_up_non_fungible_transfer() { NonFungibleLocalId::integer(2), ]), ) - .take_from_worktop(RADIX_TOKEN, 2.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("2"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); @@ -103,7 +105,7 @@ pub fn simple_transfer_visitor_invalidated_transfer_with_an_additional_withdraw( let account2 = test_data::account2(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) .withdraw_non_fungibles_from_account( account1, RADIX_TOKEN, @@ -112,7 +114,8 @@ pub fn simple_transfer_visitor_invalidated_transfer_with_an_additional_withdraw( NonFungibleLocalId::integer(2), ]), ) - .take_from_worktop(RADIX_TOKEN, 2.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("2"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); diff --git a/radix-engine-toolkit-core/tests/test_data.rs b/radix-engine-toolkit-core/tests/test_data.rs index 130ccbf1..f6cf05ca 100644 --- a/radix-engine-toolkit-core/tests/test_data.rs +++ b/radix-engine-toolkit-core/tests/test_data.rs @@ -31,7 +31,7 @@ pub fn notarized_transaction() -> NotarizedTransactionV1 { TransactionBuilder::new() .manifest( ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) .try_deposit_batch_or_abort(account2) .build(), ) diff --git a/radix-engine-toolkit-core/tests/transfer_visitor.rs b/radix-engine-toolkit-core/tests/transfer_visitor.rs index ed62b75a..68608fb7 100644 --- a/radix-engine-toolkit-core/tests/transfer_visitor.rs +++ b/radix-engine-toolkit-core/tests/transfer_visitor.rs @@ -31,8 +31,9 @@ pub fn transfer_visitor_can_pick_up_fungible_transfer() { let account2 = test_data::account2(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 10.into(), |builder, bucket| { + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) + .take_from_worktop(RADIX_TOKEN, dec!("10"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); @@ -50,7 +51,7 @@ pub fn transfer_visitor_can_pick_up_fungible_transfer() { deposits, hashmap!( account2 => hashmap! { - RADIX_TOKEN => Resources::Amount(10.into()) + RADIX_TOKEN => Resources::Amount(dec!("10")) } ) ); @@ -65,11 +66,13 @@ pub fn transfer_visitor_can_pick_up_fungible_transfer_from_a_single_source_to_mu let account3 = test_data::account3(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 20.into()) - .take_from_worktop(RADIX_TOKEN, 15.into(), |builder, bucket| { + .withdraw_from_account(account1, RADIX_TOKEN, dec!("20")) + .take_from_worktop(RADIX_TOKEN, dec!("15"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) - .take_from_worktop(RADIX_TOKEN, 5.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("5"), "bucket1") + .with_bucket("bucket1", |builder, bucket| { builder.call_method(account3, "deposit", manifest_args!(bucket)) }) .build(); @@ -87,10 +90,10 @@ pub fn transfer_visitor_can_pick_up_fungible_transfer_from_a_single_source_to_mu deposits, hashmap!( account2 => hashmap! { - RADIX_TOKEN => Resources::Amount(15.into()) + RADIX_TOKEN => Resources::Amount(dec!("15")) }, account3 => hashmap! { - RADIX_TOKEN => Resources::Amount(5.into()) + RADIX_TOKEN => Resources::Amount(dec!("5")) } ) ); @@ -103,9 +106,10 @@ pub fn transfer_visitor_invalidated_transfer_from_multiple_accounts() { let account2 = test_data::account2(); let manifest = ManifestBuilder::new() - .withdraw_from_account(account1, RADIX_TOKEN, 10.into()) - .withdraw_from_account(account2, RADIX_TOKEN, 10.into()) - .take_from_worktop(RADIX_TOKEN, 20.into(), |builder, bucket| { + .withdraw_from_account(account1, RADIX_TOKEN, dec!("10")) + .withdraw_from_account(account2, RADIX_TOKEN, dec!("10")) + .take_from_worktop(RADIX_TOKEN, dec!("20"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); @@ -133,7 +137,8 @@ pub fn transfer_visitor_can_pick_up_non_fungible_transfer() { NonFungibleLocalId::integer(2), ]), ) - .take_from_worktop(RADIX_TOKEN, 2.into(), |builder, bucket| { + .take_from_worktop(RADIX_TOKEN, dec!("2"), "bucket") + .with_bucket("bucket", |builder, bucket| { builder.call_method(account2, "deposit", manifest_args!(bucket)) }) .build(); diff --git a/radix-engine-toolkit-core/tests/utils.rs b/radix-engine-toolkit-core/tests/utils.rs index 30676c27..694b13ca 100644 --- a/radix-engine-toolkit-core/tests/utils.rs +++ b/radix-engine-toolkit-core/tests/utils.rs @@ -30,17 +30,16 @@ fn extraction_of_metadata_from_receipts_succeeds() { // Act let manifest = ManifestBuilder::new() - .create_fungible_resource::( + .create_fungible_resource( OwnerRole::None, true, 18, - ModuleConfig { - init: metadata_init!( + FungibleResourceRoles::default(), + metadata! { + init { "name" => true, locked; - ), - roles: RolesInit::default(), + } }, - BTreeMap::new(), None, ) .build(); @@ -78,13 +77,12 @@ fn extraction_of_non_fungible_data_from_receipts_succeeds() { OwnerRole::None, NonFungibleIdType::Integer, true, - ModuleConfig { - init: metadata_init!( + NonFungibleResourceRoles::default(), + metadata! { + init { "name" => true, locked; - ), - roles: RolesInit::default(), + } }, - BTreeMap::::new(), Some(btreemap!( NonFungibleLocalId::integer(1) => Owl { name: "an example name".to_string(), diff --git a/radix-engine-toolkit-uniffi/Cargo.toml b/radix-engine-toolkit-uniffi/Cargo.toml index 19ce8980..329931f7 100644 --- a/radix-engine-toolkit-uniffi/Cargo.toml +++ b/radix-engine-toolkit-uniffi/Cargo.toml @@ -6,11 +6,11 @@ build = "build.rs" [dependencies] # radixdlt-scrypto dependencies. -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features= false, features = ["std", "lru"] } -radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } +sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } +radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features= false, features = ["std", "lru"] } +radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } # Core Radix Engine Toolkit radix-engine-toolkit-core = { path = "../radix-engine-toolkit-core" } diff --git a/radix-engine-toolkit-uniffi/src/common/decimal.rs b/radix-engine-toolkit-uniffi/src/common/decimal.rs index f8a08cf8..9e6273d3 100644 --- a/radix-engine-toolkit-uniffi/src/common/decimal.rs +++ b/radix-engine-toolkit-uniffi/src/common/decimal.rs @@ -99,7 +99,7 @@ macro_rules! define_uniffi_decimal { $crate::prelude::Arc::new(Self(self.0.ceiling())) } - pub fn round(&self, decimal_places: u32, rounding_mode: crate::prelude::RoundingMode) -> $crate::prelude::Arc { + pub fn round(&self, decimal_places: i32, rounding_mode: crate::prelude::RoundingMode) -> $crate::prelude::Arc { $crate::prelude::Arc::new(Self(self.0.round(decimal_places, rounding_mode.into()))) } @@ -151,26 +151,34 @@ define_uniffi_decimal!(PreciseDecimal); #[derive(Clone, Debug, crate::prelude::Enum)] pub enum RoundingMode { - TowardsPositiveInfinity, - TowardsNegativeInfinity, - TowardsZero, + ToPositiveInfinity, + ToNegativeInfinity, + ToZero, AwayFromZero, - TowardsNearestAndHalfTowardsZero, - TowardsNearestAndHalfAwayFromZero, + ToNearestMidpointTowardZero, + ToNearestMidpointAwayFromZero, + ToNearestMidpointToEven, } impl From for crate::prelude::NativeRoundingMode { fn from(value: RoundingMode) -> Self { match value { - RoundingMode::TowardsPositiveInfinity => Self::TowardsPositiveInfinity, - RoundingMode::TowardsNegativeInfinity => Self::TowardsNegativeInfinity, - RoundingMode::TowardsZero => Self::TowardsZero, - RoundingMode::AwayFromZero => Self::AwayFromZero, - RoundingMode::TowardsNearestAndHalfTowardsZero => { - Self::TowardsNearestAndHalfTowardsZero + RoundingMode::ToPositiveInfinity => { + crate::prelude::NativeRoundingMode::ToPositiveInfinity } - RoundingMode::TowardsNearestAndHalfAwayFromZero => { - Self::TowardsNearestAndHalfAwayFromZero + RoundingMode::ToNegativeInfinity => { + crate::prelude::NativeRoundingMode::ToNegativeInfinity + } + RoundingMode::ToZero => crate::prelude::NativeRoundingMode::ToZero, + RoundingMode::AwayFromZero => crate::prelude::NativeRoundingMode::AwayFromZero, + RoundingMode::ToNearestMidpointTowardZero => { + crate::prelude::NativeRoundingMode::ToNearestMidpointTowardZero + } + RoundingMode::ToNearestMidpointAwayFromZero => { + crate::prelude::NativeRoundingMode::ToNearestMidpointAwayFromZero + } + RoundingMode::ToNearestMidpointToEven => { + crate::prelude::NativeRoundingMode::ToNearestMidpointToEven } } } @@ -179,19 +187,22 @@ impl From for crate::prelude::NativeRoundingMode { impl From for RoundingMode { fn from(value: crate::prelude::NativeRoundingMode) -> Self { match value { - crate::prelude::NativeRoundingMode::TowardsPositiveInfinity => { - Self::TowardsPositiveInfinity + crate::prelude::NativeRoundingMode::ToPositiveInfinity => { + RoundingMode::ToPositiveInfinity + } + crate::prelude::NativeRoundingMode::ToNegativeInfinity => { + RoundingMode::ToNegativeInfinity } - crate::prelude::NativeRoundingMode::TowardsNegativeInfinity => { - Self::TowardsNegativeInfinity + crate::prelude::NativeRoundingMode::ToZero => RoundingMode::ToZero, + crate::prelude::NativeRoundingMode::AwayFromZero => RoundingMode::AwayFromZero, + crate::prelude::NativeRoundingMode::ToNearestMidpointTowardZero => { + RoundingMode::ToNearestMidpointTowardZero } - crate::prelude::NativeRoundingMode::TowardsZero => Self::TowardsZero, - crate::prelude::NativeRoundingMode::AwayFromZero => Self::AwayFromZero, - crate::prelude::NativeRoundingMode::TowardsNearestAndHalfTowardsZero => { - Self::TowardsNearestAndHalfTowardsZero + crate::prelude::NativeRoundingMode::ToNearestMidpointAwayFromZero => { + RoundingMode::ToNearestMidpointAwayFromZero } - crate::prelude::NativeRoundingMode::TowardsNearestAndHalfAwayFromZero => { - Self::TowardsNearestAndHalfAwayFromZero + crate::prelude::NativeRoundingMode::ToNearestMidpointToEven => { + RoundingMode::ToNearestMidpointToEven } } } diff --git a/radix-engine-toolkit-uniffi/src/transaction/instruction.rs b/radix-engine-toolkit-uniffi/src/transaction/instruction.rs index 91aeddc1..7e7e54d7 100644 --- a/radix-engine-toolkit-uniffi/src/transaction/instruction.rs +++ b/radix-engine-toolkit-uniffi/src/transaction/instruction.rs @@ -42,6 +42,10 @@ pub enum Instruction { amount: Arc, }, + AssertWorktopContainsAny { + resource_address: Arc
, + }, + AssertWorktopContainsNonFungibles { resource_address: Arc
, ids: Vec, @@ -55,10 +59,6 @@ pub enum Instruction { ClearAuthZone, - CreateProofFromAuthZone { - resource_address: Arc
, - }, - CreateProofFromAuthZoneOfAmount { resource_address: Arc
, amount: Arc, @@ -75,10 +75,6 @@ pub enum Instruction { ClearSignatureProofs, - CreateProofFromBucket { - bucket_id: ManifestBucket, - }, - CreateProofFromBucketOfAmount { bucket_id: ManifestBucket, amount: Arc, @@ -187,6 +183,14 @@ impl Instruction { resource_address: Arc::new(Address::from_node_id(*resource_address, network_id)), amount: Arc::new(Decimal(*amount)), }, + NativeInstruction::AssertWorktopContainsAny { resource_address } => { + Self::AssertWorktopContainsAny { + resource_address: Arc::new(Address::from_node_id( + *resource_address, + network_id, + )), + } + } NativeInstruction::AssertWorktopContainsNonFungibles { resource_address, ids, @@ -200,14 +204,6 @@ impl Instruction { }, NativeInstruction::ClearAuthZone => Self::ClearAuthZone, NativeInstruction::ClearSignatureProofs => Self::ClearSignatureProofs, - NativeInstruction::CreateProofFromAuthZone { resource_address } => { - Self::CreateProofFromAuthZone { - resource_address: Arc::new(Address::from_node_id( - *resource_address, - network_id, - )), - } - } NativeInstruction::CreateProofFromAuthZoneOfAll { resource_address } => { Self::CreateProofFromAuthZoneOfAll { resource_address: Arc::new(Address::from_node_id( @@ -230,9 +226,6 @@ impl Instruction { resource_address: Arc::new(Address::from_node_id(*resource_address, network_id)), ids: ids.iter().cloned().map(Into::into).collect(), }, - NativeInstruction::CreateProofFromBucket { bucket_id } => Self::CreateProofFromBucket { - bucket_id: (*bucket_id).into(), - }, NativeInstruction::CreateProofFromBucketOfAll { bucket_id } => { Self::CreateProofFromBucketOfAll { bucket_id: (*bucket_id).into(), @@ -364,6 +357,11 @@ impl Instruction { resource_address: (*resource_address.as_ref()).try_into()?, amount: amount.0, }, + Self::AssertWorktopContainsAny { resource_address } => { + NativeInstruction::AssertWorktopContainsAny { + resource_address: (*resource_address.as_ref()).try_into()?, + } + } Self::AssertWorktopContainsNonFungibles { resource_address, ids, @@ -380,11 +378,6 @@ impl Instruction { proof_id: (*proof_id).into(), }, Self::ClearAuthZone => NativeInstruction::ClearAuthZone, - Self::CreateProofFromAuthZone { resource_address } => { - NativeInstruction::CreateProofFromAuthZone { - resource_address: (*resource_address.as_ref()).try_into()?, - } - } Self::CreateProofFromAuthZoneOfAll { resource_address } => { NativeInstruction::CreateProofFromAuthZoneOfAll { resource_address: (*resource_address.as_ref()).try_into()?, @@ -409,9 +402,6 @@ impl Instruction { .collect::>()?, }, Self::ClearSignatureProofs => NativeInstruction::ClearSignatureProofs, - Self::CreateProofFromBucket { bucket_id } => NativeInstruction::CreateProofFromBucket { - bucket_id: (*bucket_id).into(), - }, Self::CreateProofFromBucketOfAll { bucket_id } => { NativeInstruction::CreateProofFromBucketOfAll { bucket_id: (*bucket_id).into(), diff --git a/radix-engine-toolkit/Cargo.toml b/radix-engine-toolkit/Cargo.toml index f5ed8418..371712bb 100644 --- a/radix-engine-toolkit/Cargo.toml +++ b/radix-engine-toolkit/Cargo.toml @@ -5,11 +5,11 @@ edition = "2021" [dependencies] # radixdlt-scrypto dependencies. -sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } -transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3" } -radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", default-features= false, features = ["std", "lru"] } -radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "elm-970ed2bf3", features = ["serde"] } +sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } +transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e" } +radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", default-features= false, features = ["std", "lru"] } +radix-engine-common = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "rcnet-v2-8fdd53b3e", features = ["serde"] } # Core Radix Engine Toolkit radix-engine-toolkit-core = { path = "../radix-engine-toolkit-core" } diff --git a/radix-engine-toolkit/src/models/manifest/inputs.rs b/radix-engine-toolkit/src/models/manifest/inputs.rs deleted file mode 100644 index 0ddf3620..00000000 --- a/radix-engine-toolkit/src/models/manifest/inputs.rs +++ /dev/null @@ -1,135 +0,0 @@ -// 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 radix_engine_common::prelude::*; -use scrypto::api::node_modules::metadata::*; -use scrypto::prelude::*; - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerCreateIndexMapInput { - pub owner_role: OwnerRole, - pub id_type: NonFungibleIdType, - pub track_total_supply: bool, - pub non_fungible_schema: NonFungibleDataSchema, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ManifestSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerCreateManifestIndexMapInput { - pub owner_role: OwnerRole, - pub id_type: NonFungibleIdType, - pub track_total_supply: bool, - pub non_fungible_schema: NonFungibleDataSchema, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerCreateWithInitialSupplyIndexMapInput { - pub owner_role: OwnerRole, - pub id_type: NonFungibleIdType, - pub track_total_supply: bool, - pub non_fungible_schema: NonFungibleDataSchema, - pub entries: IndexMap, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ManifestSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - pub owner_role: OwnerRole, - pub id_type: NonFungibleIdType, - pub track_total_supply: bool, - pub non_fungible_schema: NonFungibleDataSchema, - pub entries: IndexMap, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerCreateRuidWithInitialSupplyIndexMapInput { - pub owner_role: OwnerRole, - pub track_total_supply: bool, - pub non_fungible_schema: NonFungibleDataSchema, - pub entries: Vec<(ScryptoValue,)>, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ManifestSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerMintManifestIndexMapInput { - pub entries: IndexMap, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct NonFungibleResourceManagerMintIndexMapInput { - pub entries: IndexMap, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct FungibleResourceManagerCreateIndexMapInput { - pub owner_role: OwnerRole, - pub track_total_supply: bool, - pub divisibility: u8, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ManifestSbor, Clone, Debug)] -pub struct FungibleResourceManagerCreateManifestIndexMapInput { - pub owner_role: OwnerRole, - pub track_total_supply: bool, - pub divisibility: u8, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct FungibleResourceManagerCreateWithInitialSupplyIndexMapInput { - pub owner_role: OwnerRole, - pub track_total_supply: bool, - pub divisibility: u8, - pub initial_supply: Decimal, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ManifestSbor, Clone, Debug)] -pub struct FungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - pub owner_role: OwnerRole, - pub track_total_supply: bool, - pub divisibility: u8, - pub initial_supply: Decimal, - pub access_rules: IndexMap, - pub metadata: ModuleConfig, - pub address_reservation: Option, -} - -#[derive(ScryptoSbor, Clone, Debug)] -pub struct AccessRulesCreateIndexMapInput { - pub owner_role: OwnerRole, - pub roles: IndexMap, -} diff --git a/radix-engine-toolkit/src/models/manifest/mod.rs b/radix-engine-toolkit/src/models/manifest/mod.rs index 15c39b6a..a8cdbc5a 100644 --- a/radix-engine-toolkit/src/models/manifest/mod.rs +++ b/radix-engine-toolkit/src/models/manifest/mod.rs @@ -15,5 +15,4 @@ // specific language governing permissions and limitations // under the License. -pub mod inputs; pub mod runtime; diff --git a/radix-engine-toolkit/src/models/transaction/instruction.rs b/radix-engine-toolkit/src/models/transaction/instruction.rs index 94ce03f3..291ac1dd 100644 --- a/radix-engine-toolkit/src/models/transaction/instruction.rs +++ b/radix-engine-toolkit/src/models/transaction/instruction.rs @@ -17,18 +17,8 @@ use crate::prelude::*; -use radix_engine::blueprints::package::*; use radix_engine::types::*; -use radix_engine_toolkit_core::utils::*; use schemars::*; -use scrypto::api::node_modules::auth::*; -use scrypto::api::node_modules::metadata::*; -use scrypto::api::node_modules::royalty::*; -use scrypto::api::ObjectModuleId; -use scrypto::blueprints::access_controller::*; -use scrypto::blueprints::account::*; -use scrypto::blueprints::consensus_manager::*; -use scrypto::blueprints::identity::*; use serde::*; use transaction::prelude::*; use transaction::validation::*; @@ -36,25 +26,29 @@ use transaction::validation::*; #[derive(Serialize, Deserialize, JsonSchema, Clone, Debug, PartialEq, Eq, Hash)] #[serde(tag = "kind")] pub enum SerializableInstruction { - TakeFromWorktop { + TakeAllFromWorktop { resource_address: SerializableManifestValue, - amount: SerializableManifestValue, new_bucket: SerializableManifestValue, }, - TakeNonFungiblesFromWorktop { - ids: SerializableManifestValue, + TakeFromWorktop { resource_address: SerializableManifestValue, + amount: SerializableManifestValue, new_bucket: SerializableManifestValue, }, - TakeAllFromWorktop { + TakeNonFungiblesFromWorktop { resource_address: SerializableManifestValue, + ids: SerializableManifestValue, new_bucket: SerializableManifestValue, }, ReturnToWorktop { - bucket: SerializableManifestValue, + bucket_id: SerializableManifestValue, + }, + + AssertWorktopContainsAny { + resource_address: SerializableManifestValue, }, AssertWorktopContains { @@ -72,16 +66,11 @@ pub enum SerializableInstruction { }, PushToAuthZone { - proof: SerializableManifestValue, + proof_id: SerializableManifestValue, }, ClearAuthZone, - CreateProofFromAuthZone { - resource_address: SerializableManifestValue, - new_proof: SerializableManifestValue, - }, - CreateProofFromAuthZoneOfAmount { resource_address: SerializableManifestValue, amount: SerializableManifestValue, @@ -101,39 +90,34 @@ pub enum SerializableInstruction { ClearSignatureProofs, - CreateProofFromBucket { - bucket: SerializableManifestValue, - new_proof: SerializableManifestValue, - }, - CreateProofFromBucketOfAmount { - bucket: SerializableManifestValue, + bucket_id: SerializableManifestValue, amount: SerializableManifestValue, new_proof: SerializableManifestValue, }, CreateProofFromBucketOfNonFungibles { - bucket: SerializableManifestValue, + bucket_id: SerializableManifestValue, ids: SerializableManifestValue, new_proof: SerializableManifestValue, }, CreateProofFromBucketOfAll { - bucket: SerializableManifestValue, + bucket_id: SerializableManifestValue, new_proof: SerializableManifestValue, }, BurnResource { - bucket: SerializableManifestValue, + bucket_id: SerializableManifestValue, }, CloneProof { - proof: SerializableManifestValue, + proof_id: SerializableManifestValue, new_proof: SerializableManifestValue, }, DropProof { - proof: SerializableManifestValue, + proof_id: SerializableManifestValue, }, CallFunction { @@ -167,6 +151,12 @@ pub enum SerializableInstruction { args: SerializableManifestValue, }, + CallDirectVaultMethod { + address: SerializableManifestValue, + method_name: SerializableManifestValue, + args: SerializableManifestValue, + }, + DropAllProofs, AllocateGlobalAddress { @@ -175,126 +165,6 @@ pub enum SerializableInstruction { address_reservation: SerializableManifestValue, named_address: SerializableManifestValue, }, - - RecallVault { - vault_id: SerializableManifestValue, - amount: SerializableManifestValue, - }, - FreezeVault { - vault_id: SerializableManifestValue, - to_freeze: SerializableManifestValue, - }, - UnfreezeVault { - vault_id: SerializableManifestValue, - to_unfreeze: SerializableManifestValue, - }, - - PublishPackage { - code: SerializableManifestValue, - setup: SerializableManifestValue, - metadata: SerializableManifestValue, - }, - PublishPackageAdvanced { - package_address: SerializableManifestValue, - code: SerializableManifestValue, - setup: SerializableManifestValue, - metadata: SerializableManifestValue, - owner_role: SerializableManifestValue, - }, - CreateFungibleResource { - owner_role: SerializableManifestValue, - address_reservation: SerializableManifestValue, - track_total_supply: SerializableManifestValue, - divisibility: SerializableManifestValue, - metadata: SerializableManifestValue, - access_rules: SerializableManifestValue, - }, - CreateFungibleResourceWithInitialSupply { - owner_role: SerializableManifestValue, - address_reservation: SerializableManifestValue, - track_total_supply: SerializableManifestValue, - divisibility: SerializableManifestValue, - metadata: SerializableManifestValue, - access_rules: SerializableManifestValue, - initial_supply: SerializableManifestValue, - }, - CreateNonFungibleResource { - owner_role: SerializableManifestValue, - address_reservation: SerializableManifestValue, - id_type: SerializableManifestValue, - track_total_supply: SerializableManifestValue, - non_fungible_schema: SerializableManifestValue, - metadata: SerializableManifestValue, - access_rules: SerializableManifestValue, - }, - CreateNonFungibleResourceWithInitialSupply { - owner_role: SerializableManifestValue, - address_reservation: SerializableManifestValue, - id_type: SerializableManifestValue, - track_total_supply: SerializableManifestValue, - non_fungible_schema: SerializableManifestValue, - metadata: SerializableManifestValue, - access_rules: SerializableManifestValue, - entries: SerializableManifestValue, - }, - CreateAccessController { - controlled_asset: SerializableManifestValue, - rule_set: SerializableManifestValue, - timed_recovery_delay_in_minutes: SerializableManifestValue, - }, - CreateIdentity {}, - CreateIdentityAdvanced { - owner_rule: SerializableManifestValue, - }, - CreateAccount {}, - CreateAccountAdvanced { - owner_role: SerializableManifestValue, - }, - - SetMetadata { - address: SerializableManifestValue, - key: SerializableManifestValue, - value: SerializableManifestValue, - }, - RemoveMetadata { - address: SerializableManifestValue, - key: SerializableManifestValue, - }, - SetComponentRoyaltyConfig { - address: SerializableManifestValue, - method: SerializableManifestValue, - amount: SerializableManifestValue, - }, - ClaimComponentRoyalty { - address: SerializableManifestValue, - }, - SetRole { - address: SerializableManifestValue, - module: SerializableManifestValue, - role_key: SerializableManifestValue, - rule: SerializableManifestValue, - }, - - ClaimPackageRoyalty { - address: SerializableManifestValue, - }, - MintFungible { - address: SerializableManifestValue, - amount: SerializableManifestValue, - }, - MintNonFungible { - address: SerializableManifestValue, - entries: SerializableManifestValue, - }, - MintRuidNonFungible { - address: SerializableManifestValue, - entries: SerializableManifestValue, - }, - CreateValidator { - key: SerializableManifestValue, - fee_factor: SerializableManifestValue, - xrd_payment: SerializableManifestValue, - }, } impl SerializableInstruction { @@ -346,7 +216,7 @@ impl SerializableInstruction { } } InstructionV1::ReturnToWorktop { bucket_id } => Self::ReturnToWorktop { - bucket: SerializableManifestValue::from_typed(&bucket_id, network_id)?, + bucket_id: SerializableManifestValue::from_typed(&bucket_id, network_id)?, }, InstructionV1::AssertWorktopContains { resource_address, @@ -358,6 +228,14 @@ impl SerializableInstruction { )?, amount: SerializableManifestValue::from_typed(amount, network_id)?, }, + InstructionV1::AssertWorktopContainsAny { resource_address } => { + Self::AssertWorktopContainsAny { + resource_address: SerializableManifestValue::from_typed( + resource_address, + network_id, + )?, + } + } InstructionV1::AssertWorktopContainsNonFungibles { resource_address, ids, @@ -376,20 +254,9 @@ impl SerializableInstruction { } } InstructionV1::PushToAuthZone { proof_id } => Self::PushToAuthZone { - proof: SerializableManifestValue::from_typed(&proof_id, network_id)?, + proof_id: SerializableManifestValue::from_typed(&proof_id, network_id)?, }, InstructionV1::ClearAuthZone => Self::ClearAuthZone, - InstructionV1::CreateProofFromAuthZone { resource_address } => { - let proof = id_allocator.new_proof_id(); - - Self::CreateProofFromAuthZone { - resource_address: SerializableManifestValue::from_typed( - resource_address, - network_id, - )?, - new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, - } - } InstructionV1::CreateProofFromAuthZoneOfAll { resource_address } => { let proof = id_allocator.new_proof_id(); @@ -432,19 +299,11 @@ impl SerializableInstruction { } } InstructionV1::ClearSignatureProofs => Self::ClearSignatureProofs, - InstructionV1::CreateProofFromBucket { bucket_id } => { - let proof = id_allocator.new_proof_id(); - - Self::CreateProofFromBucket { - bucket: SerializableManifestValue::from_typed(bucket_id, network_id)?, - new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, - } - } InstructionV1::CreateProofFromBucketOfAll { bucket_id } => { let proof = id_allocator.new_proof_id(); Self::CreateProofFromBucketOfAll { - bucket: SerializableManifestValue::from_typed(bucket_id, network_id)?, + bucket_id: SerializableManifestValue::from_typed(bucket_id, network_id)?, new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, } } @@ -452,7 +311,7 @@ impl SerializableInstruction { let proof = id_allocator.new_proof_id(); Self::CreateProofFromBucketOfAmount { - bucket: SerializableManifestValue::from_typed(bucket_id, network_id)?, + bucket_id: SerializableManifestValue::from_typed(bucket_id, network_id)?, amount: SerializableManifestValue::from_typed(amount, network_id)?, new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, } @@ -461,24 +320,24 @@ impl SerializableInstruction { let proof = id_allocator.new_proof_id(); Self::CreateProofFromBucketOfNonFungibles { - bucket: SerializableManifestValue::from_typed(bucket_id, network_id)?, + bucket_id: SerializableManifestValue::from_typed(bucket_id, network_id)?, ids: SerializableManifestValue::from_typed(ids, network_id)?, new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, } } InstructionV1::BurnResource { bucket_id } => Self::BurnResource { - bucket: SerializableManifestValue::from_typed(bucket_id, network_id)?, + bucket_id: SerializableManifestValue::from_typed(bucket_id, network_id)?, }, InstructionV1::CloneProof { proof_id } => { let proof = id_allocator.new_proof_id(); Self::CloneProof { - proof: SerializableManifestValue::from_typed(proof_id, network_id)?, + proof_id: SerializableManifestValue::from_typed(proof_id, network_id)?, new_proof: SerializableManifestValue::from_typed(&proof, network_id)?, } } InstructionV1::DropProof { proof_id } => Self::DropProof { - proof: SerializableManifestValue::from_typed(proof_id, network_id)?, + proof_id: SerializableManifestValue::from_typed(proof_id, network_id)?, }, InstructionV1::DropAllProofs => Self::DropAllProofs, InstructionV1::CallFunction { @@ -486,198 +345,60 @@ impl SerializableInstruction { blueprint_name, function_name, args, - } => { - let instruction = if let DynamicPackageAddress::Static(address) = package_address { - alias_call_function!( - address.as_node_id(), - blueprint_name, - function_name, - args, - network_id, - [ - PublishPackageAlias, - PublishPackageAdvancedAlias, - CreateFungibleResourceAlias, - CreateFungibleResourceWithInitialSupplyAlias, - CreateNonFungibleResourceAlias, - CreateNonFungibleResourceWithInitialSupplyAlias, - CreateAccessControllerAlias, - CreateIdentityAlias, - CreateIdentityAdvancedAlias, - CreateAccountAlias, - CreateAccountAdvancedAlias, - ] - ) - } else { - None - }; - - if let Some(instruction) = instruction { - instruction - } else { - Self::CallFunction { - package_address: SerializableManifestValue::from_typed( - package_address, - network_id, - )?, - blueprint_name: SerializableManifestValue::from_typed( - blueprint_name, - network_id, - )?, - function_name: SerializableManifestValue::from_typed( - function_name, - network_id, - )?, - args: SerializableManifestValue::from_typed(args, network_id)?, - } - } - } + } => Self::CallFunction { + package_address: SerializableManifestValue::from_typed( + package_address, + network_id, + )?, + blueprint_name: SerializableManifestValue::from_typed(blueprint_name, network_id)?, + function_name: SerializableManifestValue::from_typed(function_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::CallMethod { address, method_name, args, - } => { - let instruction = if let DynamicGlobalAddress::Static(address) = address { - alias_call_method!( - address.as_node_id(), - ObjectModuleId::Main, - method_name, - args, - network_id, - [ - ClaimPackageRoyaltyAlias, - MintFungibleAlias, - MintNonFungibleAlias, - MintRuidNonFungibleAlias, - CreateValidatorAlias, - ] - ) - } else { - None - }; - - if let Some(instruction) = instruction { - instruction - } else { - Self::CallMethod { - address: SerializableManifestValue::from_typed(address, network_id)?, - method_name: SerializableManifestValue::from_typed( - method_name, - network_id, - )?, - args: SerializableManifestValue::from_typed(args, network_id)?, - } - } - } + } => Self::CallMethod { + address: SerializableManifestValue::from_typed(address, network_id)?, + method_name: SerializableManifestValue::from_typed(method_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::CallRoyaltyMethod { address, method_name, args, - } => { - let instruction = if let DynamicGlobalAddress::Static(address) = address { - alias_call_method!( - address.as_node_id(), - ObjectModuleId::Royalty, - method_name, - args, - network_id, - [SetComponentRoyaltyConfigAlias, ClaimComponentRoyaltyAlias] - ) - } else { - None - }; - - if let Some(instruction) = instruction { - instruction - } else { - Self::CallRoyaltyMethod { - address: SerializableManifestValue::from_typed(address, network_id)?, - method_name: SerializableManifestValue::from_typed( - method_name, - network_id, - )?, - args: SerializableManifestValue::from_typed(args, network_id)?, - } - } - } + } => Self::CallRoyaltyMethod { + address: SerializableManifestValue::from_typed(address, network_id)?, + method_name: SerializableManifestValue::from_typed(method_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::CallMetadataMethod { address, method_name, args, - } => { - let instruction = if let DynamicGlobalAddress::Static(address) = address { - alias_call_method!( - address.as_node_id(), - ObjectModuleId::Metadata, - method_name, - args, - network_id, - [SetMetadataAlias, RemoveMetadataAlias] - ) - } else { - None - }; - - if let Some(instruction) = instruction { - instruction - } else { - Self::CallMetadataMethod { - address: SerializableManifestValue::from_typed(address, network_id)?, - method_name: SerializableManifestValue::from_typed( - method_name, - network_id, - )?, - args: SerializableManifestValue::from_typed(args, network_id)?, - } - } - } + } => Self::CallMetadataMethod { + address: SerializableManifestValue::from_typed(address, network_id)?, + method_name: SerializableManifestValue::from_typed(method_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::CallAccessRulesMethod { address, method_name, args, - } => { - let instruction = if let DynamicGlobalAddress::Static(address) = address { - alias_call_method!( - address.as_node_id(), - ObjectModuleId::Metadata, - method_name, - args, - network_id, - [SetRoleAlias] - ) - } else { - None - }; - - if let Some(instruction) = instruction { - instruction - } else { - Self::CallAccessRulesMethod { - address: SerializableManifestValue::from_typed(address, network_id)?, - method_name: SerializableManifestValue::from_typed( - method_name, - network_id, - )?, - args: SerializableManifestValue::from_typed(args, network_id)?, - } - } - } + } => Self::CallAccessRulesMethod { + address: SerializableManifestValue::from_typed(address, network_id)?, + method_name: SerializableManifestValue::from_typed(method_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::CallDirectVaultMethod { address, method_name, args, - } => { - // TODO: seems to be special cased in Scrypto, why? - alias_call_method!( - address.as_node_id(), - ObjectModuleId::Main, - method_name, - args, - network_id, - [FreezeVaultAlias, UnfreezeVaultAlias, RecallVaultAlias] - ) - .unwrap() - } + } => Self::CallDirectVaultMethod { + address: SerializableManifestValue::from_typed(address, network_id)?, + method_name: SerializableManifestValue::from_typed(method_name, network_id)?, + args: SerializableManifestValue::from_typed(args, network_id)?, + }, InstructionV1::AllocateGlobalAddress { package_address, blueprint_name, @@ -731,8 +452,8 @@ impl SerializableInstruction { } => InstructionV1::TakeAllFromWorktop { resource_address: resource_address.to_typed()?, }, - Self::ReturnToWorktop { bucket } => InstructionV1::ReturnToWorktop { - bucket_id: bucket.to_typed()?, + Self::ReturnToWorktop { bucket_id } => InstructionV1::ReturnToWorktop { + bucket_id: bucket_id.to_typed()?, }, Self::AssertWorktopContains { resource_address, @@ -741,6 +462,11 @@ impl SerializableInstruction { resource_address: resource_address.to_typed()?, amount: amount.to_typed()?, }, + Self::AssertWorktopContainsAny { resource_address } => { + InstructionV1::AssertWorktopContainsAny { + resource_address: resource_address.to_typed()?, + } + } Self::AssertWorktopContainsNonFungibles { resource_address, ids, @@ -749,16 +475,11 @@ impl SerializableInstruction { ids: ids.to_typed()?, }, Self::PopFromAuthZone { .. } => InstructionV1::PopFromAuthZone {}, - Self::PushToAuthZone { proof } => InstructionV1::PushToAuthZone { - proof_id: proof.to_typed()?, + Self::PushToAuthZone { proof_id } => InstructionV1::PushToAuthZone { + proof_id: proof_id.to_typed()?, }, Self::ClearAuthZone => InstructionV1::ClearAuthZone, Self::ClearSignatureProofs => InstructionV1::ClearSignatureProofs, - Self::CreateProofFromAuthZone { - resource_address, .. - } => InstructionV1::CreateProofFromAuthZone { - resource_address: resource_address.to_typed()?, - }, Self::CreateProofFromAuthZoneOfAll { resource_address, .. } => InstructionV1::CreateProofFromAuthZoneOfAll { @@ -780,34 +501,31 @@ impl SerializableInstruction { resource_address: resource_address.to_typed()?, ids: ids.to_typed()?, }, - Self::CreateProofFromBucket { bucket, .. } => InstructionV1::CreateProofFromBucket { - bucket_id: bucket.to_typed()?, - }, - Self::CreateProofFromBucketOfAll { bucket, .. } => { + Self::CreateProofFromBucketOfAll { bucket_id, .. } => { InstructionV1::CreateProofFromBucketOfAll { - bucket_id: bucket.to_typed()?, - } - } - Self::CreateProofFromBucketOfAmount { bucket, amount, .. } => { - InstructionV1::CreateProofFromBucketOfAmount { - bucket_id: bucket.to_typed()?, - amount: amount.to_typed()?, + bucket_id: bucket_id.to_typed()?, } } - Self::CreateProofFromBucketOfNonFungibles { bucket, ids, .. } => { + Self::CreateProofFromBucketOfAmount { + bucket_id, amount, .. + } => InstructionV1::CreateProofFromBucketOfAmount { + bucket_id: bucket_id.to_typed()?, + amount: amount.to_typed()?, + }, + Self::CreateProofFromBucketOfNonFungibles { bucket_id, ids, .. } => { InstructionV1::CreateProofFromBucketOfNonFungibles { - bucket_id: bucket.to_typed()?, + bucket_id: bucket_id.to_typed()?, ids: ids.to_typed()?, } } - Self::BurnResource { bucket } => InstructionV1::BurnResource { - bucket_id: bucket.to_typed()?, + Self::BurnResource { bucket_id } => InstructionV1::BurnResource { + bucket_id: bucket_id.to_typed()?, }, - Self::CloneProof { proof, .. } => InstructionV1::CloneProof { - proof_id: proof.to_typed()?, + Self::CloneProof { proof_id, .. } => InstructionV1::CloneProof { + proof_id: proof_id.to_typed()?, }, - Self::DropProof { proof, .. } => InstructionV1::DropProof { - proof_id: proof.to_typed()?, + Self::DropProof { proof_id, .. } => InstructionV1::DropProof { + proof_id: proof_id.to_typed()?, }, Self::DropAllProofs {} => InstructionV1::DropAllProofs {}, Self::CallFunction { @@ -857,6 +575,15 @@ impl SerializableInstruction { method_name: method_name.to_typed()?, args: args.to_typed()?, }, + Self::CallDirectVaultMethod { + address, + method_name, + args, + } => InstructionV1::CallDirectVaultMethod { + address: address.to_typed()?, + method_name: method_name.to_typed()?, + args: args.to_typed()?, + }, Self::AllocateGlobalAddress { package_address, blueprint_name, @@ -865,298 +592,6 @@ impl SerializableInstruction { package_address: package_address.to_typed()?, blueprint_name: blueprint_name.to_typed()?, }, - Self::RecallVault { vault_id, amount } => InstructionV1::CallDirectVaultMethod { - address: vault_id.to_typed()?, - method_name: VAULT_RECALL_IDENT.to_string(), - args: manifest_args!(amount.to_manifest_value()?), - }, - Self::FreezeVault { - vault_id, - to_freeze, - } => InstructionV1::CallDirectVaultMethod { - address: vault_id.to_typed()?, - method_name: VAULT_FREEZE_IDENT.to_string(), - args: to_manifest_value_or_panic(&VaultFreezeInput { - to_freeze: to_freeze.to_typed()?, - }), - }, - Self::UnfreezeVault { - vault_id, - to_unfreeze, - } => InstructionV1::CallDirectVaultMethod { - address: vault_id.to_typed()?, - method_name: VAULT_UNFREEZE_IDENT.to_string(), - args: to_manifest_value_or_panic(&VaultUnfreezeInput { - to_unfreeze: to_unfreeze.to_typed()?, - }), - }, - Self::PublishPackage { - code, - setup, - metadata, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(PACKAGE_PACKAGE), - blueprint_name: PACKAGE_BLUEPRINT.to_string(), - function_name: PACKAGE_PUBLISH_WASM_IDENT.to_string(), - args: to_manifest_value_or_panic(&PackagePublishWasmManifestInput { - code: code.to_typed()?, - metadata: metadata.to_typed()?, - setup: resolve_encoded_type(setup) - .ok_or(InstructionConversionError::FailedToResolveSetup)?, - }), - }, - Self::PublishPackageAdvanced { - code, - setup, - metadata, - owner_role, - package_address, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(PACKAGE_PACKAGE), - blueprint_name: PACKAGE_BLUEPRINT.to_string(), - function_name: PACKAGE_PUBLISH_WASM_ADVANCED_IDENT.to_string(), - args: to_manifest_value_or_panic(&PackagePublishWasmAdvancedManifestInput { - code: code.to_typed()?, - metadata: metadata.to_typed()?, - setup: resolve_encoded_type(setup) - .ok_or(InstructionConversionError::FailedToResolveSetup)?, - owner_role: owner_role.to_typed()?, - package_address: package_address.to_typed()?, - }), - }, - Self::CreateFungibleResource { - access_rules, - divisibility, - metadata, - track_total_supply, - address_reservation, - owner_role, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(RESOURCE_PACKAGE), - blueprint_name: FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT.to_string(), - function_name: FUNGIBLE_RESOURCE_MANAGER_CREATE_IDENT.to_string(), - args: to_manifest_value_or_panic( - &FungibleResourceManagerCreateManifestIndexMapInput { - access_rules: access_rules.to_typed()?, - divisibility: divisibility.to_typed()?, - metadata: metadata.to_typed()?, - track_total_supply: track_total_supply.to_typed()?, - address_reservation: address_reservation.to_typed()?, - owner_role: owner_role.to_typed()?, - }, - ), - }, - Self::CreateFungibleResourceWithInitialSupply { - access_rules, - divisibility, - metadata, - track_total_supply, - initial_supply, - owner_role, - address_reservation, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(RESOURCE_PACKAGE), - blueprint_name: FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT.to_string(), - function_name: FUNGIBLE_RESOURCE_MANAGER_CREATE_WITH_INITIAL_SUPPLY_IDENT - .to_string(), - args: to_manifest_value_or_panic( - &FungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - access_rules: access_rules.to_typed()?, - divisibility: divisibility.to_typed()?, - metadata: metadata.to_typed()?, - track_total_supply: track_total_supply.to_typed()?, - initial_supply: initial_supply.to_typed()?, - owner_role: owner_role.to_typed()?, - address_reservation: address_reservation.to_typed()?, - }, - ), - }, - Self::CreateNonFungibleResource { - access_rules, - id_type, - metadata, - non_fungible_schema, - track_total_supply, - owner_role, - address_reservation, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(RESOURCE_PACKAGE), - blueprint_name: NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT.to_string(), - function_name: NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_IDENT.to_string(), - args: to_manifest_value_or_panic( - &NonFungibleResourceManagerCreateManifestIndexMapInput { - access_rules: access_rules.to_typed()?, - metadata: metadata.to_typed()?, - track_total_supply: track_total_supply.to_typed()?, - id_type: id_type.to_typed()?, - non_fungible_schema: non_fungible_schema.to_typed()?, - owner_role: owner_role.to_typed()?, - address_reservation: address_reservation.to_typed()?, - }, - ), - }, - Self::CreateNonFungibleResourceWithInitialSupply { - access_rules, - id_type, - metadata, - non_fungible_schema, - track_total_supply, - entries, - owner_role, - address_reservation, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(RESOURCE_PACKAGE), - blueprint_name: NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT.to_string(), - function_name: NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_WITH_INITIAL_SUPPLY_IDENT - .to_string(), - args: to_manifest_value_or_panic( - &NonFungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - access_rules: access_rules.to_typed()?, - metadata: metadata.to_typed()?, - track_total_supply: track_total_supply.to_typed()?, - id_type: id_type.to_typed()?, - non_fungible_schema: non_fungible_schema.to_typed()?, - entries: entries.to_typed()?, - owner_role: owner_role.to_typed()?, - address_reservation: address_reservation.to_typed()?, - }, - ), - }, - Self::CreateAccessController { - controlled_asset, - rule_set, - timed_recovery_delay_in_minutes, - } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(ACCESS_CONTROLLER_PACKAGE), - blueprint_name: ACCESS_CONTROLLER_BLUEPRINT.to_string(), - function_name: ACCESS_CONTROLLER_CREATE_GLOBAL_IDENT.to_string(), - args: to_manifest_value_or_panic(&AccessControllerCreateGlobalManifestInput { - controlled_asset: controlled_asset.to_typed()?, - rule_set: rule_set.to_typed()?, - timed_recovery_delay_in_minutes: timed_recovery_delay_in_minutes.to_typed()?, - }), - }, - Self::CreateIdentity {} => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(IDENTITY_PACKAGE), - blueprint_name: IDENTITY_BLUEPRINT.to_string(), - function_name: IDENTITY_CREATE_IDENT.to_string(), - args: to_manifest_value_or_panic(&IdentityCreateInput {}), - }, - Self::CreateIdentityAdvanced { owner_rule } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(IDENTITY_PACKAGE), - blueprint_name: IDENTITY_BLUEPRINT.to_string(), - function_name: IDENTITY_CREATE_ADVANCED_IDENT.to_string(), - args: to_manifest_value_or_panic(&IdentityCreateAdvancedInput { - owner_rule: owner_rule.to_typed()?, - }), - }, - Self::CreateAccount {} => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(ACCOUNT_PACKAGE), - blueprint_name: ACCOUNT_BLUEPRINT.to_string(), - function_name: ACCOUNT_CREATE_IDENT.to_string(), - args: to_manifest_value_or_panic(&AccountCreateInput {}), - }, - Self::CreateAccountAdvanced { owner_role } => InstructionV1::CallFunction { - package_address: DynamicPackageAddress::Static(ACCOUNT_PACKAGE), - blueprint_name: ACCOUNT_BLUEPRINT.to_string(), - function_name: ACCOUNT_CREATE_ADVANCED_IDENT.to_string(), - args: to_manifest_value_or_panic(&AccountCreateAdvancedInput { - owner_role: owner_role.to_typed()?, - }), - }, - Self::SetMetadata { - address, - key, - value, - } => InstructionV1::CallMetadataMethod { - address: address.to_typed()?, - method_name: METADATA_SET_IDENT.to_string(), - args: to_manifest_value_or_panic(&MetadataSetInput { - key: key.to_typed()?, - value: value.to_typed()?, - }), - }, - Self::RemoveMetadata { address, key } => InstructionV1::CallMetadataMethod { - address: address.to_typed()?, - method_name: METADATA_REMOVE_IDENT.to_string(), - args: to_manifest_value_or_panic(&MetadataRemoveInput { - key: key.to_typed()?, - }), - }, - Self::SetComponentRoyaltyConfig { - address, - method, - amount, - } => InstructionV1::CallRoyaltyMethod { - address: address.to_typed()?, - method_name: COMPONENT_ROYALTY_SET_ROYALTY_IDENT.to_string(), - args: to_manifest_value_or_panic(&ComponentSetRoyaltyInput { - method: method.to_typed()?, - amount: amount.to_typed()?, - }), - }, - Self::ClaimComponentRoyalty { address } => InstructionV1::CallRoyaltyMethod { - address: address.to_typed()?, - method_name: COMPONENT_ROYALTY_CLAIM_ROYALTIES_IDENT.to_string(), - args: to_manifest_value_or_panic(&ComponentClaimRoyaltiesInput {}), - }, - Self::SetRole { - address, - module, - role_key, - rule, - } => InstructionV1::CallAccessRulesMethod { - address: address.to_typed()?, - method_name: ACCESS_RULES_SET_ROLE_IDENT.to_string(), - args: to_manifest_value_or_panic(&AccessRulesSetRoleInput { - module: module.to_typed()?, - role_key: role_key.to_typed()?, - rule: rule.to_typed()?, - }), - }, - Self::ClaimPackageRoyalty { address } => InstructionV1::CallMethod { - address: address.to_typed()?, - method_name: PACKAGE_CLAIM_ROYALTIES_IDENT.to_string(), - args: to_manifest_value_or_panic(&PackageClaimRoyaltiesInput {}), - }, - Self::MintFungible { address, amount } => InstructionV1::CallMethod { - address: address.to_typed()?, - method_name: FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT.to_string(), - args: to_manifest_value_or_panic(&FungibleResourceManagerMintInput { - amount: amount.to_typed()?, - }), - }, - Self::MintNonFungible { address, entries } => InstructionV1::CallMethod { - address: address.to_typed()?, - method_name: NON_FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT.to_string(), - args: to_manifest_value_or_panic( - &NonFungibleResourceManagerMintManifestIndexMapInput { - entries: entries.to_typed()?, - }, - ), - }, - Self::MintRuidNonFungible { address, entries } => InstructionV1::CallMethod { - address: address.to_typed()?, - method_name: NON_FUNGIBLE_RESOURCE_MANAGER_MINT_RUID_IDENT.to_string(), - args: to_manifest_value_or_panic( - &NonFungibleResourceManagerMintRuidManifestInput { - entries: entries.to_typed()?, - }, - ), - }, - Self::CreateValidator { - key, - fee_factor, - xrd_payment, - } => InstructionV1::CallMethod { - address: DynamicGlobalAddress::Static(CONSENSUS_MANAGER.into()), - method_name: CONSENSUS_MANAGER_CREATE_VALIDATOR_IDENT.to_string(), - args: to_manifest_value_or_panic(&ConsensusManagerCreateValidatorManifestInput { - key: key.to_typed()?, - fee_factor: fee_factor.to_typed()?, - xrd_payment: xrd_payment.to_typed()?, - }), - }, }; Ok(instruction) } @@ -1166,7 +601,6 @@ impl SerializableInstruction { #[serde(tag = "kind", content = "error")] pub enum InstructionConversionError { ValueConversionError(ValueConversionError), - FailedToResolveSetup, } impl From for InstructionConversionError { @@ -1175,868 +609,6 @@ impl From for InstructionConversionError { } } -trait CallMethodAlias { - type ScryptoInput: ScryptoDescribe; - type ManifestInput: ManifestDecode; - const METHOD_NAME: &'static str; - const MODULE: ObjectModuleId; - - fn is_valid_address(node_id: &NodeId) -> bool; - - fn handle_aliasing( - node_id: &NodeId, - args: &Self::ManifestInput, - network_id: u8, - ) -> Result; - - fn alias( - node_id: &NodeId, - object_module_id: ObjectModuleId, - method_name: &str, - args: &ManifestValue, - network_id: u8, - ) -> Option { - if Self::is_valid_address(node_id) - && object_module_id == Self::MODULE - && method_name == Self::METHOD_NAME - { - let encoded_value = manifest_encode(&args).unwrap(); - let (local_type_index, schema) = - generate_full_schema_from_single_type::(); - if validate_payload_against_schema::( - &encoded_value, - &schema, - local_type_index, - &(), - ) - .is_ok() - { - Self::handle_aliasing(node_id, &to_manifest_type(args).unwrap(), network_id).ok() - } else { - None - } - } else { - None - } - } -} - -struct RecallVaultAlias; -impl CallMethodAlias for RecallVaultAlias { - type ScryptoInput = VaultRecallInput; - type ManifestInput = VaultRecallInput; - const METHOD_NAME: &'static str = VAULT_RECALL_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_internal_vault() - } - - fn handle_aliasing( - node_id: &NodeId, - VaultRecallInput { amount }: &VaultRecallInput, - network_id: u8, - ) -> Result { - let vault_address = InternalAddress::new_or_panic(node_id.0); - let instruction = SerializableInstruction::RecallVault { - vault_id: SerializableManifestValue::from_typed(&vault_address, network_id)?, - amount: SerializableManifestValue::from_typed(&amount, network_id)?, - }; - Ok(instruction) - } -} - -struct FreezeVaultAlias; -impl CallMethodAlias for FreezeVaultAlias { - type ScryptoInput = VaultFreezeInput; - type ManifestInput = VaultFreezeInput; - const METHOD_NAME: &'static str = VAULT_FREEZE_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_internal_vault() - } - - fn handle_aliasing( - node_id: &NodeId, - VaultFreezeInput { to_freeze }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let vault_address = InternalAddress::new_or_panic(node_id.0); - let instruction = SerializableInstruction::FreezeVault { - vault_id: SerializableManifestValue::from_typed(&vault_address, network_id)?, - to_freeze: SerializableManifestValue::from_typed(&to_freeze, network_id)?, - }; - Ok(instruction) - } -} - -struct UnfreezeVaultAlias; -impl CallMethodAlias for UnfreezeVaultAlias { - type ScryptoInput = VaultUnfreezeInput; - type ManifestInput = VaultUnfreezeInput; - const METHOD_NAME: &'static str = VAULT_UNFREEZE_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_internal_vault() - } - - fn handle_aliasing( - node_id: &NodeId, - VaultUnfreezeInput { to_unfreeze }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let vault_address = InternalAddress::new_or_panic(node_id.0); - let instruction = SerializableInstruction::UnfreezeVault { - vault_id: SerializableManifestValue::from_typed(&vault_address, network_id)?, - to_unfreeze: SerializableManifestValue::from_typed(&to_unfreeze, network_id)?, - }; - Ok(instruction) - } -} - -struct SetMetadataAlias; -impl CallMethodAlias for SetMetadataAlias { - type ScryptoInput = MetadataSetInput; - type ManifestInput = MetadataSetInput; - const METHOD_NAME: &'static str = METADATA_SET_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Metadata; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global() - } - - fn handle_aliasing( - node_id: &NodeId, - MetadataSetInput { key, value }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::SetMetadata { - address: SerializableManifestValue::from_typed(&address, network_id)?, - key: SerializableManifestValue::from_typed(&key, network_id)?, - value: SerializableManifestValue::from_typed(&value, network_id)?, - }; - Ok(instruction) - } -} - -struct RemoveMetadataAlias; -impl CallMethodAlias for RemoveMetadataAlias { - type ScryptoInput = MetadataRemoveInput; - type ManifestInput = MetadataRemoveInput; - const METHOD_NAME: &'static str = METADATA_REMOVE_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Metadata; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global() - } - - fn handle_aliasing( - node_id: &NodeId, - MetadataRemoveInput { key }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::RemoveMetadata { - address: SerializableManifestValue::from_typed(&address, network_id)?, - key: SerializableManifestValue::from_typed(&key, network_id)?, - }; - Ok(instruction) - } -} - -struct SetComponentRoyaltyConfigAlias; -impl CallMethodAlias for SetComponentRoyaltyConfigAlias { - type ScryptoInput = ComponentSetRoyaltyInput; - type ManifestInput = ComponentSetRoyaltyInput; - const METHOD_NAME: &'static str = COMPONENT_ROYALTY_SET_ROYALTY_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Royalty; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global() - } - - fn handle_aliasing( - node_id: &NodeId, - ComponentSetRoyaltyInput { amount, method }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::SetComponentRoyaltyConfig { - address: SerializableManifestValue::from_typed(&address, network_id)?, - method: SerializableManifestValue::from_typed(&method, network_id)?, - amount: SerializableManifestValue::from_typed(&amount, network_id)?, - }; - Ok(instruction) - } -} - -struct ClaimComponentRoyaltyAlias; -impl CallMethodAlias for ClaimComponentRoyaltyAlias { - type ScryptoInput = ComponentClaimRoyaltiesInput; - type ManifestInput = ComponentClaimRoyaltiesInput; - const METHOD_NAME: &'static str = COMPONENT_ROYALTY_CLAIM_ROYALTIES_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Royalty; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global() - } - - fn handle_aliasing( - node_id: &NodeId, - ComponentClaimRoyaltiesInput {}: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::ClaimComponentRoyalty { - address: SerializableManifestValue::from_typed(&address, network_id)?, - }; - Ok(instruction) - } -} - -struct SetRoleAlias; -impl CallMethodAlias for SetRoleAlias { - type ScryptoInput = AccessRulesSetRoleInput; - type ManifestInput = AccessRulesSetRoleInput; - const METHOD_NAME: &'static str = ACCESS_RULES_SET_ROLE_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::AccessRules; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global() - } - - fn handle_aliasing( - node_id: &NodeId, - AccessRulesSetRoleInput { - module, - role_key, - rule, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::SetRole { - address: SerializableManifestValue::from_typed(&address, network_id)?, - module: SerializableManifestValue::from_typed(&module, network_id)?, - role_key: SerializableManifestValue::from_typed(&role_key, network_id)?, - rule: SerializableManifestValue::from_typed(&rule, network_id)?, - }; - Ok(instruction) - } -} - -struct ClaimPackageRoyaltyAlias; -impl CallMethodAlias for ClaimPackageRoyaltyAlias { - type ScryptoInput = PackageClaimRoyaltiesInput; - type ManifestInput = PackageClaimRoyaltiesInput; - const METHOD_NAME: &'static str = PACKAGE_CLAIM_ROYALTIES_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global_package() - } - - fn handle_aliasing( - node_id: &NodeId, - PackageClaimRoyaltiesInput {}: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::ClaimPackageRoyalty { - address: SerializableManifestValue::from_typed(&address, network_id)?, - }; - Ok(instruction) - } -} - -struct MintFungibleAlias; -impl CallMethodAlias for MintFungibleAlias { - type ScryptoInput = FungibleResourceManagerMintInput; - type ManifestInput = FungibleResourceManagerMintInput; - const METHOD_NAME: &'static str = FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global_fungible_resource_manager() - } - - fn handle_aliasing( - node_id: &NodeId, - FungibleResourceManagerMintInput { amount }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::MintFungible { - address: SerializableManifestValue::from_typed(&address, network_id)?, - amount: SerializableManifestValue::from_typed(&amount, network_id)?, - }; - Ok(instruction) - } -} - -struct MintNonFungibleAlias; -impl CallMethodAlias for MintNonFungibleAlias { - type ScryptoInput = NonFungibleResourceManagerMintIndexMapInput; - type ManifestInput = NonFungibleResourceManagerMintManifestIndexMapInput; - const METHOD_NAME: &'static str = NON_FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global_non_fungible_resource_manager() - } - - fn handle_aliasing( - node_id: &NodeId, - NonFungibleResourceManagerMintManifestIndexMapInput { entries }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::MintNonFungible { - address: SerializableManifestValue::from_typed(&address, network_id)?, - entries: SerializableManifestValue::from_typed(&entries, network_id)?, - }; - Ok(instruction) - } -} - -struct MintRuidNonFungibleAlias; -impl CallMethodAlias for MintRuidNonFungibleAlias { - type ScryptoInput = NonFungibleResourceManagerMintRuidInput; - type ManifestInput = NonFungibleResourceManagerMintRuidManifestInput; - const METHOD_NAME: &'static str = NON_FUNGIBLE_RESOURCE_MANAGER_MINT_RUID_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global_non_fungible_resource_manager() - } - - fn handle_aliasing( - node_id: &NodeId, - Self::ManifestInput { entries }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let address = DynamicGlobalAddress::Static(GlobalAddress::new_or_panic(node_id.0)); - let instruction = SerializableInstruction::MintRuidNonFungible { - address: SerializableManifestValue::from_typed(&address, network_id)?, - entries: SerializableManifestValue::from_typed(&entries, network_id)?, - }; - Ok(instruction) - } -} - -struct CreateValidatorAlias; -impl CallMethodAlias for CreateValidatorAlias { - type ScryptoInput = ConsensusManagerCreateValidatorInput; - type ManifestInput = ConsensusManagerCreateValidatorManifestInput; - const METHOD_NAME: &'static str = CONSENSUS_MANAGER_CREATE_VALIDATOR_IDENT; - const MODULE: ObjectModuleId = ObjectModuleId::Main; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id.is_global_consensus_manager() - } - - fn handle_aliasing( - _: &NodeId, - Self::ManifestInput { - key, - fee_factor, - xrd_payment, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateValidator { - key: SerializableManifestValue::from_typed(&key, network_id)?, - fee_factor: SerializableManifestValue::from_typed(&fee_factor, network_id)?, - xrd_payment: SerializableManifestValue::from_typed(&xrd_payment, network_id)?, - }; - Ok(instruction) - } -} - -trait CallFunctionAlias { - type ScryptoInput: ScryptoDescribe; - type ManifestInput: ManifestDecode; - const FUNCTION_NAME: &'static str; - const BLUEPRINT_NAME: &'static str; - - fn is_valid_address(node_id: &NodeId) -> bool; - - fn handle_aliasing( - node_id: &NodeId, - args: &Self::ManifestInput, - network_id: u8, - ) -> Result; - - fn alias( - node_id: &NodeId, - blueprint_name: &str, - function_name: &str, - args: &ManifestValue, - network_id: u8, - ) -> Option { - if Self::is_valid_address(node_id) - && blueprint_name == Self::BLUEPRINT_NAME - && function_name == Self::FUNCTION_NAME - { - let encoded_value = manifest_encode(&args).unwrap(); - let (local_type_index, schema) = - generate_full_schema_from_single_type::(); - if validate_payload_against_schema::( - &encoded_value, - &schema, - local_type_index, - &(), - ) - .is_ok() - { - // Self::handle_aliasing(node_id, &to_manifest_type(args).unwrap_or_else(|| - // panic!("Failed to perform the conversion for: {blueprint_name} - // {function_name}")), network_id).ok() - Self::handle_aliasing( - node_id, - &manifest_decode(&manifest_encode(args).unwrap()).unwrap_or_else(|error| panic!("{error:?} => Failed to perform the conversion for: {blueprint_name} {function_name}")), - network_id - ).ok() - } else { - None - } - } else { - None - } - } -} - -struct PublishPackageAlias; -impl CallFunctionAlias for PublishPackageAlias { - type ScryptoInput = PackagePublishWasmInput; - type ManifestInput = PackagePublishWasmManifestInput; - const FUNCTION_NAME: &'static str = PACKAGE_PUBLISH_WASM_IDENT; - const BLUEPRINT_NAME: &'static str = PACKAGE_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == PACKAGE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - PackagePublishWasmManifestInput { - code, - setup, - metadata, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::PublishPackage { - code: SerializableManifestValue::from_typed(&code, network_id)?, - setup: SerializableManifestValue::from_typed( - &manifest_encode(&setup).unwrap(), - network_id, - )?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - }; - Ok(instruction) - } -} - -struct PublishPackageAdvancedAlias; -impl CallFunctionAlias for PublishPackageAdvancedAlias { - type ScryptoInput = PackagePublishWasmAdvancedInput; - type ManifestInput = PackagePublishWasmAdvancedManifestInput; - const FUNCTION_NAME: &'static str = PACKAGE_PUBLISH_WASM_ADVANCED_IDENT; - const BLUEPRINT_NAME: &'static str = PACKAGE_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == PACKAGE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - PackagePublishWasmAdvancedManifestInput { - code, - metadata, - owner_role, - package_address, - setup, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::PublishPackageAdvanced { - package_address: SerializableManifestValue::from_typed(&package_address, network_id)?, - code: SerializableManifestValue::from_typed(&code, network_id)?, - setup: SerializableManifestValue::from_typed( - &manifest_encode(&setup).unwrap(), - network_id, - )?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - }; - Ok(instruction) - } -} - -struct CreateFungibleResourceAlias; -impl CallFunctionAlias for CreateFungibleResourceAlias { - type ScryptoInput = FungibleResourceManagerCreateIndexMapInput; - type ManifestInput = FungibleResourceManagerCreateManifestIndexMapInput; - const FUNCTION_NAME: &'static str = FUNGIBLE_RESOURCE_MANAGER_CREATE_IDENT; - const BLUEPRINT_NAME: &'static str = FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == RESOURCE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - FungibleResourceManagerCreateManifestIndexMapInput { - access_rules, - divisibility, - metadata, - track_total_supply, - owner_role, - address_reservation, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateFungibleResource { - track_total_supply: SerializableManifestValue::from_typed( - &track_total_supply, - network_id, - )?, - divisibility: SerializableManifestValue::from_typed(&divisibility, network_id)?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - access_rules: SerializableManifestValue::from_typed(&access_rules, network_id)?, - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - address_reservation: SerializableManifestValue::from_typed( - &address_reservation, - network_id, - )?, - }; - Ok(instruction) - } -} - -struct CreateFungibleResourceWithInitialSupplyAlias; -impl CallFunctionAlias for CreateFungibleResourceWithInitialSupplyAlias { - type ScryptoInput = FungibleResourceManagerCreateWithInitialSupplyIndexMapInput; - type ManifestInput = FungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput; - const FUNCTION_NAME: &'static str = FUNGIBLE_RESOURCE_MANAGER_CREATE_WITH_INITIAL_SUPPLY_IDENT; - const BLUEPRINT_NAME: &'static str = FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == RESOURCE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - FungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - access_rules, - divisibility, - initial_supply, - metadata, - track_total_supply, - owner_role, - address_reservation, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateFungibleResourceWithInitialSupply { - track_total_supply: SerializableManifestValue::from_typed( - &track_total_supply, - network_id, - )?, - divisibility: SerializableManifestValue::from_typed(&divisibility, network_id)?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - access_rules: SerializableManifestValue::from_typed(&access_rules, network_id)?, - initial_supply: SerializableManifestValue::from_typed(&initial_supply, network_id)?, - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - address_reservation: SerializableManifestValue::from_typed( - &address_reservation, - network_id, - )?, - }; - Ok(instruction) - } -} - -struct CreateNonFungibleResourceAlias; -impl CallFunctionAlias for CreateNonFungibleResourceAlias { - type ScryptoInput = NonFungibleResourceManagerCreateIndexMapInput; - type ManifestInput = NonFungibleResourceManagerCreateManifestIndexMapInput; - const FUNCTION_NAME: &'static str = NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_IDENT; - const BLUEPRINT_NAME: &'static str = NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == RESOURCE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - NonFungibleResourceManagerCreateManifestIndexMapInput { - access_rules, - metadata, - track_total_supply, - id_type, - non_fungible_schema, - owner_role, - address_reservation, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateNonFungibleResource { - track_total_supply: SerializableManifestValue::from_typed( - &track_total_supply, - network_id, - )?, - id_type: SerializableManifestValue::from_typed(&id_type, network_id)?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - access_rules: SerializableManifestValue::from_typed(&access_rules, network_id)?, - non_fungible_schema: SerializableManifestValue::from_typed( - &non_fungible_schema, - network_id, - )?, - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - address_reservation: SerializableManifestValue::from_typed( - &address_reservation, - network_id, - )?, - }; - Ok(instruction) - } -} - -struct CreateNonFungibleResourceWithInitialSupplyAlias; -impl CallFunctionAlias for CreateNonFungibleResourceWithInitialSupplyAlias { - type ScryptoInput = NonFungibleResourceManagerCreateWithInitialSupplyIndexMapInput; - type ManifestInput = NonFungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput; - const FUNCTION_NAME: &'static str = - NON_FUNGIBLE_RESOURCE_MANAGER_CREATE_WITH_INITIAL_SUPPLY_IDENT; - const BLUEPRINT_NAME: &'static str = NON_FUNGIBLE_RESOURCE_MANAGER_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == RESOURCE_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - NonFungibleResourceManagerCreateWithInitialSupplyManifestIndexMapInput { - access_rules, - metadata, - track_total_supply, - id_type, - non_fungible_schema, - entries, - owner_role, - address_reservation, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateNonFungibleResourceWithInitialSupply { - track_total_supply: SerializableManifestValue::from_typed( - &track_total_supply, - network_id, - )?, - id_type: SerializableManifestValue::from_typed(&id_type, network_id)?, - metadata: SerializableManifestValue::from_typed(&metadata, network_id)?, - access_rules: SerializableManifestValue::from_typed(&access_rules, network_id)?, - non_fungible_schema: SerializableManifestValue::from_typed( - &non_fungible_schema, - network_id, - )?, - entries: SerializableManifestValue::from_typed(&entries, network_id)?, - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - address_reservation: SerializableManifestValue::from_typed( - &address_reservation, - network_id, - )?, - }; - Ok(instruction) - } -} - -struct CreateAccessControllerAlias; -impl CallFunctionAlias for CreateAccessControllerAlias { - type ScryptoInput = AccessControllerCreateGlobalInput; - type ManifestInput = AccessControllerCreateGlobalManifestInput; - const FUNCTION_NAME: &'static str = ACCESS_CONTROLLER_CREATE_GLOBAL_IDENT; - const BLUEPRINT_NAME: &'static str = ACCESS_CONTROLLER_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == ACCESS_CONTROLLER_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - AccessControllerCreateGlobalManifestInput { - controlled_asset, - rule_set, - timed_recovery_delay_in_minutes, - }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateAccessController { - controlled_asset: SerializableManifestValue::from_typed(&controlled_asset, network_id)?, - rule_set: SerializableManifestValue::from_typed(&rule_set, network_id)?, - timed_recovery_delay_in_minutes: SerializableManifestValue::from_typed( - &timed_recovery_delay_in_minutes, - network_id, - )?, - }; - Ok(instruction) - } -} - -struct CreateIdentityAlias; -impl CallFunctionAlias for CreateIdentityAlias { - type ScryptoInput = IdentityCreateInput; - type ManifestInput = IdentityCreateInput; - const FUNCTION_NAME: &'static str = IDENTITY_CREATE_IDENT; - const BLUEPRINT_NAME: &'static str = IDENTITY_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == IDENTITY_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - IdentityCreateInput {}: &Self::ManifestInput, - _: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateIdentity {}; - Ok(instruction) - } -} - -struct CreateIdentityAdvancedAlias; -impl CallFunctionAlias for CreateIdentityAdvancedAlias { - type ScryptoInput = IdentityCreateAdvancedInput; - type ManifestInput = IdentityCreateAdvancedInput; - const FUNCTION_NAME: &'static str = IDENTITY_CREATE_ADVANCED_IDENT; - const BLUEPRINT_NAME: &'static str = IDENTITY_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == IDENTITY_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - IdentityCreateAdvancedInput { owner_rule }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateIdentityAdvanced { - owner_rule: SerializableManifestValue::from_typed(&owner_rule, network_id)?, - }; - Ok(instruction) - } -} - -struct CreateAccountAlias; -impl CallFunctionAlias for CreateAccountAlias { - type ScryptoInput = AccountCreateInput; - type ManifestInput = AccountCreateInput; - const FUNCTION_NAME: &'static str = ACCOUNT_CREATE_IDENT; - const BLUEPRINT_NAME: &'static str = ACCOUNT_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == ACCOUNT_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - AccountCreateInput {}: &Self::ManifestInput, - _: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateAccount {}; - Ok(instruction) - } -} - -struct CreateAccountAdvancedAlias; -impl CallFunctionAlias for CreateAccountAdvancedAlias { - type ScryptoInput = AccountCreateAdvancedInput; - type ManifestInput = AccountCreateAdvancedInput; - const FUNCTION_NAME: &'static str = ACCOUNT_CREATE_ADVANCED_IDENT; - const BLUEPRINT_NAME: &'static str = ACCOUNT_BLUEPRINT; - - fn is_valid_address(node_id: &NodeId) -> bool { - node_id == ACCOUNT_PACKAGE.as_node_id() - } - - fn handle_aliasing( - _: &NodeId, - AccountCreateAdvancedInput { owner_role }: &Self::ManifestInput, - network_id: u8, - ) -> Result { - let instruction = SerializableInstruction::CreateAccountAdvanced { - owner_role: SerializableManifestValue::from_typed(&owner_role, network_id)?, - }; - Ok(instruction) - } -} - -macro_rules! alias_call_method { - ( - $node_id: expr, - $object_module_id: expr, - $method_name: expr, - $args: expr, - $network_id: expr, - [ - $($aliasing_handler: ty),* $(,)? - ] - ) => { - [ - $( - <$aliasing_handler>::alias( - $node_id, - $object_module_id, - $method_name, - $args, - $network_id, - ) - ),* - ].into_iter().find_map(|instruction| instruction) - }; -} - -macro_rules! alias_call_function { - ( - $node_id: expr, - $blueprint_name: expr, - $function_name: expr, - $args: expr, - $network_id: expr, - [ - $($aliasing_handler: ty),* $(,)? - ] - ) => { - [ - $( - <$aliasing_handler>::alias( - $node_id, - $blueprint_name, - $function_name, - $args, - $network_id, - ) - ),* - ].into_iter().find_map(|instruction| instruction) - }; -} - -use alias_call_function; -use alias_call_method; - -// TODO: Temporary, add to Scrypto and then remove from here. -#[derive(Debug, Eq, PartialEq, ManifestSbor)] -pub struct AccessControllerCreateGlobalManifestInput { - pub controlled_asset: ManifestBucket, - pub rule_set: RuleSet, - pub timed_recovery_delay_in_minutes: Option, -} - pub fn to_serializable_instructions( instructions: &[InstructionV1], network_id: u8, @@ -2078,27 +650,3 @@ pub struct LocatedInstructionConversionError { pub instruction_index: usize, pub error: InstructionConversionError, } - -fn resolve_encoded_type(value: &SerializableManifestValue) -> Option -where - T: ManifestDecode, -{ - match value { - SerializableManifestValue::Array { - element_value_kind: SerializableManifestValueKind::U8, - elements, - } => elements - .iter() - .map(|element| match element { - SerializableManifestValue::U8 { value } => Some(**value), - _ => None, - }) - .collect::>>() - .and_then(|bytes| manifest_decode(&bytes).ok()), - _ => None, - } -} - -fn to_manifest_value_or_panic(value: &T) -> ManifestValue { - to_manifest_value(value).unwrap() -} diff --git a/radix-engine-toolkit/src/prelude.rs b/radix-engine-toolkit/src/prelude.rs index 2b23c86b..b2d3b6d3 100644 --- a/radix-engine-toolkit/src/prelude.rs +++ b/radix-engine-toolkit/src/prelude.rs @@ -42,7 +42,6 @@ pub use crate::models::cryptographic::public_key_hash::*; pub use crate::models::cryptographic::signature::*; pub use crate::models::cryptographic::signature_with_public_key::*; pub use crate::models::macros::*; -pub use crate::models::manifest::inputs::*; pub use crate::models::manifest::runtime::*; pub use crate::models::olympia::network::*; pub use crate::models::sbor::local_type_index::*; diff --git a/radix-engine-toolkit/tests/manifests/access_rule/access_rule.rtm b/radix-engine-toolkit/tests/manifests/access_rule/access_rule.rtm index a2833d36..07401614 100644 --- a/radix-engine-toolkit/tests/manifests/access_rule/access_rule.rtm +++ b/radix-engine-toolkit/tests/manifests/access_rule/access_rule.rtm @@ -5,22 +5,7 @@ SET_OWNER_ROLE LOCK_OWNER_ROLE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez"); -SET_AND_LOCK_OWNER_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>(); # The rule associated with the role - SET_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>() - "hello" # The name of the role to update the access rule for. - Enum<0u8>(); # The rule associated with the role - -LOCK_ROLE - Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") - Enum<0u8>() - "hello"; # The name of the role to update the access rule for. - -SET_AND_LOCK_ROLE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Enum<0u8>() "hello" # The name of the role to update the access rule for. diff --git a/radix-engine-toolkit/tests/manifests/package/publish.rtm b/radix-engine-toolkit/tests/manifests/package/publish.rtm index bda169b4..672e746d 100644 --- a/radix-engine-toolkit/tests/manifests/package/publish.rtm +++ b/radix-engine-toolkit/tests/manifests/package/publish.rtm @@ -14,10 +14,10 @@ CALL_METHOD # Publishing a new package and setting some of its royalty and access rules. PUBLISH_PACKAGE_ADVANCED - None - Blob("a710f0959d8e139b3c1ca74ac4fcb9a95ada2c82e7f563304c5487e0117095c0") - Tuple( + Enum() # Owner AccessRule + Tuple( # Package Definition Map() ) - Map() # Metadata - Enum<0u8>(); # Owner AccessRule + Blob("a710f0959d8e139b3c1ca74ac4fcb9a95ada2c82e7f563304c5487e0117095c0") # Package Code + Map() # Metadata + None; # Address Reservation diff --git a/radix-engine-toolkit/tests/manifests/resources/auth_zone.rtm b/radix-engine-toolkit/tests/manifests/resources/auth_zone.rtm index 89ffdf51..bc7b86f6 100644 --- a/radix-engine-toolkit/tests/manifests/resources/auth_zone.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/auth_zone.rtm @@ -6,13 +6,12 @@ CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cv # Create a proof from bucket, clone it and drop both TAKE_ALL_FROM_WORKTOP Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3") Bucket("some_xrd"); -CREATE_PROOF_FROM_BUCKET Bucket("some_xrd") Proof("proof1"); CREATE_PROOF_FROM_BUCKET_OF_AMOUNT Bucket("some_xrd") Decimal("1") Proof("proof1a"); CREATE_PROOF_FROM_BUCKET_OF_NON_FUNGIBLES Bucket("some_xrd") Array(NonFungibleLocalId("#123#")) Proof("proof1b"); CREATE_PROOF_FROM_BUCKET_OF_ALL Bucket("some_xrd") Proof("proof1c"); -CLONE_PROOF Proof("proof1") Proof("proof2"); -DROP_PROOF Proof("proof1"); -DROP_PROOF Proof("proof2"); +CLONE_PROOF Proof("proof1c") Proof("proof1d"); +DROP_PROOF Proof("proof1d"); +DROP_PROOF Proof("proof1c"); CLEAR_AUTH_ZONE; # Create a proof from account and drop it @@ -22,7 +21,6 @@ DROP_PROOF Proof("proof3"); # Compose proofs CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cve475w0q") "create_proof_of_amount" Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("5.0"); -CREATE_PROOF_FROM_AUTH_ZONE Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Proof("Proof Name"); CREATE_PROOF_FROM_AUTH_ZONE_OF_AMOUNT Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("1") Proof("proof4"); CREATE_PROOF_FROM_AUTH_ZONE_OF_NON_FUNGIBLES Address("resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha") Array(NonFungibleLocalId("#123#")) Proof("proof5"); CREATE_PROOF_FROM_AUTH_ZONE_OF_ALL Address("resource_sim1ngktvyeenvvqetnqwysevcx5fyvl6hqe36y3rkhdfdn6uzvt5366ha") Proof("proof6"); diff --git a/radix-engine-toolkit/tests/manifests/resources/creation/fungible/no_initial_supply.rtm b/radix-engine-toolkit/tests/manifests/resources/creation/fungible/no_initial_supply.rtm index 7446545b..e0cc8369 100644 --- a/radix-engine-toolkit/tests/manifests/resources/creation/fungible/no_initial_supply.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/creation/fungible/no_initial_supply.rtm @@ -16,60 +16,36 @@ CALL_METHOD # Creating a new resource with a divisibility of 18 and a name of `MyResource`. The resource has # default resource behavior where it can be withdrawn and deposited by anybody. CREATE_FUNGIBLE_RESOURCE - Enum<0u8>() - false # Track Total Supply - 18u8 - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + 18u8 # Divisibility (between 0u8 and 18u8) Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None # Deposit Roles (if None: defaults to AllowAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "symbol" => Tuple( - Enum( - Enum("RSRC"), # Resource Symbol - ), - true # Locked Resource Symbol - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - true # Locked Resource Description + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); # No Address Reservation \ No newline at end of file + None; # No Address Reservation \ No newline at end of file diff --git a/radix-engine-toolkit/tests/manifests/resources/creation/fungible/with_initial_supply.rtm b/radix-engine-toolkit/tests/manifests/resources/creation/fungible/with_initial_supply.rtm index c4d42a8a..93df44e9 100644 --- a/radix-engine-toolkit/tests/manifests/resources/creation/fungible/with_initial_supply.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/creation/fungible/with_initial_supply.rtm @@ -16,64 +16,40 @@ CALL_METHOD # Creating a new resource with a divisibility of 18 and a name of `MyResource`. The resource has # default resource behavior where it can be withdrawn and deposited by anybody. CREATE_FUNGIBLE_RESOURCE_WITH_INITIAL_SUPPLY - Enum<0u8>() - false # Track Total Supply - 18u8 - Decimal("12") - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + 18u8 # Divisibility (between 0u8 and 18u8) + Decimal("12") # Initial supply Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None # Deposit Roles (if None: defaults to AllowAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "symbol" => Tuple( - Enum( - Enum("RSRC"), # Resource Symbol - ), - true # Locked Resource Symbol - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - true # Locked Resource Description + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); # No Address Reservation + None; # No Address Reservation # Depositing the entirety of the initial supply of the newly created resource into our account # component. diff --git a/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm b/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm index c2a771f3..c496d829 100644 --- a/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/no_initial_supply.rtm @@ -15,55 +15,38 @@ CALL_METHOD # Creating a new resource CREATE_NON_FUNGIBLE_RESOURCE - Enum<0u8>() - Enum() - false # Track Total Supply - Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + Enum() # The type of NonFungible Id + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) # Non Fungible Data Schema Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None, # Deposit Roles (if None: defaults to AllowAll, DenyAll) + None # Non Fungible Data Update Roles (if None: defaults to DenyAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - false + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); \ No newline at end of file + None; # No Address Reservation \ No newline at end of file diff --git a/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm b/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm index 5d8aa3ce..d4e1ef67 100644 --- a/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/creation/non_fungible/with_initial_supply.rtm @@ -15,61 +15,44 @@ CALL_METHOD # Creating a new resource CREATE_NON_FUNGIBLE_RESOURCE_WITH_INITIAL_SUPPLY - Enum<0u8>() - Enum() - false # Track Total Supply - Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) - Map( + # Owner role - This gets metadata permissions, and is the default for other permissions + # Can set as Enum(access_rule) or Enum(access_rule) + Enum() + Enum() # The type of NonFungible Id + true # Whether the engine should track supply (avoid for massively parallelizable tokens) + Tuple(Tuple(Array(), Array(), Array()), Enum<0u8>(64u8), Array()) # Non Fungible Data Schema + Map( # Initial supply to mint NonFungibleLocalId("#12#") => Tuple(Tuple("Hello World", Decimal("12"))) ) - Map( - # This array of tuples defines the behavior of the resource. Each element in the array - # defines different resource behaviors. As an example, the first element in this array - # defines the withdraw behavior while the second element in the array defines the deposit - # behavior. - # - # Each tuple of the array is made up of two elements: - # 1. An enum of the `ResourceAction` or the method that we would like to define the - # behavior of. - # 2. A tuple of two elements: - # a. The current behaviour. - # b. The mutability of the behaviour. As in, who can change the current behavior in - # the future. - # - # Lets take `Tuple(Enum(), Tuple(Enum(), Enum()))` as an - # example. This means that anybody who is in possession of the resource may withdraw it from - # a vault that they control. This behavior is permanent and can not be changed by anybody - # as the mutability is a `Enum()`. - # - # ┌ We Are customizing the "Withdraw" behavior of the resource - # │ - # │ ┌ The resource may be withdrawn by anybody who has it - # │ │ - # │ │ ┌ The withdraw behavior (the resource is withdrawable by - # │ │ │ by anybody who has the resource) is permanent and can't - # │ │ │ be changed in the future. - # │ │ │ - Enum() => Tuple(Enum(), Enum()), - Enum() => Tuple(Enum(), Enum()) - ) Tuple( - Map( + Some( # Mint Roles (if None: defaults to DenyAll, DenyAll) + Tuple( + Some(Enum()), # Minter (if None: defaults to Owner) + Some(Enum()) # Minter Updater (if None: defaults to Owner) + ) + ), + None, # Burn Roles (if None: defaults to DenyAll, DenyAll) + None, # Freeze Roles (if None: defaults to DenyAll, DenyAll) + None, # Recall Roles (if None: defaults to DenyAll, DenyAll) + None, # Withdraw Roles (if None: defaults to AllowAll, DenyAll) + None, # Deposit Roles (if None: defaults to AllowAll, DenyAll) + None # Non Fungible Data Update Roles (if None: defaults to DenyAll, DenyAll) + ) + Tuple( # Metadata initialization + Map( # Initial metadata values "name" => Tuple( - Enum( - Enum("MyResource") # Resource Name - ), - true # Locked Resource Name - ), - "description" => Tuple( - Enum( - Enum("A very innovative and important resource") # Resource Description - ), - false + Some(Enum("MyResource")), # Resource Name + true # Locked ) ), - Map() + Map( # Metadata roles + "metadata_setter" => Some(Enum()), # Metadata setter role + "metadata_setter_updater" => None, # Metadata setter updater role as None defaults to OWNER + "metadata_locker" => Some(Enum()), # Metadata locker role + "metadata_locker_updater" => None # Metadata locker updater role as None defaults to OWNER + ) ) - Enum<0u8>(); + None; # No Address Reservation # Depositing the entirety of the initial supply of the newly created resource into our account # component. diff --git a/radix-engine-toolkit/tests/manifests/resources/recall.rtm b/radix-engine-toolkit/tests/manifests/resources/recall.rtm index 4634ac66..ff1f1d3a 100644 --- a/radix-engine-toolkit/tests/manifests/resources/recall.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/recall.rtm @@ -1 +1 @@ -RECALL_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Decimal("1.2"); +RECALL_FROM_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Decimal("1.2"); diff --git a/radix-engine-toolkit/tests/manifests/resources/recall_non_fungibles.rtm b/radix-engine-toolkit/tests/manifests/resources/recall_non_fungibles.rtm new file mode 100644 index 00000000..8b8b7e0b --- /dev/null +++ b/radix-engine-toolkit/tests/manifests/resources/recall_non_fungibles.rtm @@ -0,0 +1 @@ +RECALL_NON_FUNGIBLES_FROM_VAULT Address("internal_vault_sim1tqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvevp72ff") Array(NonFungibleLocalId("#123#"), NonFungibleLocalId("#456#")); diff --git a/radix-engine-toolkit/tests/manifests/resources/worktop.rtm b/radix-engine-toolkit/tests/manifests/resources/worktop.rtm index fcbc906e..cafdd9a9 100644 --- a/radix-engine-toolkit/tests/manifests/resources/worktop.rtm +++ b/radix-engine-toolkit/tests/manifests/resources/worktop.rtm @@ -7,6 +7,7 @@ CALL_METHOD Address("account_sim1cyvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cv # Buy GUM with XRD TAKE_FROM_WORKTOP Address("resource_sim1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxakj8n3") Decimal("2.0") Bucket("xrd"); CALL_METHOD Address("component_sim1cqvgx33089ukm2pl97pv4max0x40ruvfy4lt60yvya744cvemygpmu") "buy_gumball" Bucket("xrd"); +ASSERT_WORKTOP_CONTAINS_ANY Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez"); ASSERT_WORKTOP_CONTAINS Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Decimal("3.0"); # Create a proof from bucket, clone it and drop both diff --git a/radix-engine-toolkit/tests/manifests/values/values.rtm b/radix-engine-toolkit/tests/manifests/values/values.rtm index e659340d..08e5f377 100644 --- a/radix-engine-toolkit/tests/manifests/values/values.rtm +++ b/radix-engine-toolkit/tests/manifests/values/values.rtm @@ -1,7 +1,7 @@ TAKE_ALL_FROM_WORKTOP Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Bucket("temp1"); -CREATE_PROOF_FROM_AUTH_ZONE +CREATE_PROOF_FROM_AUTH_ZONE_OF_ALL Address("resource_sim1thvwu8dh6lk4y9mntemkvj25wllq8adq42skzufp4m8wxxuemugnez") Proof("temp2");