From 09f449dac2211d8cba02660d4dde1f4dce166376 Mon Sep 17 00:00:00 2001 From: Omar Date: Fri, 11 Oct 2024 16:56:11 +0300 Subject: [PATCH 1/5] Add derivations for the package of direct caller --- .../src/common/non_fungible.rs | 28 +++++++++++-- .../src/derive/functions.rs | 42 +++++++++++++++++-- .../src/internal_prelude.rs | 2 + .../src/functions/derive.rs | 36 +++++++++------- 4 files changed, 87 insertions(+), 21 deletions(-) diff --git a/crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs b/crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs index c3a0a5ef..a33c41cc 100644 --- a/crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs +++ b/crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs @@ -92,6 +92,26 @@ impl NonFungibleGlobalId { ) } + #[uniffi::constructor] + pub fn global_caller_badge( + component_address: Arc
, + network_id: u8, + ) -> Result> { + derive_virtual_global_caller_non_fungible_global_id_from_component_address( + component_address, network_id, + ) + } + + #[uniffi::constructor] + pub fn package_of_direct_caller_badge( + package_address: Arc
, + network_id: u8, + ) -> Result> { + derive_virtual_package_of_direct_caller_non_fungible_global_id_from_component_address( + package_address, network_id, + ) + } + pub fn resource_address(&self) -> Arc
{ let address = self.0.resource_address(); Arc::new(Address::from_typed_node_id(address, self.1)) @@ -179,10 +199,10 @@ pub fn non_fungible_local_id_sbor_decode( bytes: Vec, ) -> Result { let native = match bytes.first().copied() { - Some(NATIVE_SCRYPTO_SBOR_V1_PAYLOAD_PREFIX) => native_scrypto_decode::< - NativeNonFungibleLocalId, - >(&bytes) - .map_err(Into::into), + Some(NATIVE_SCRYPTO_SBOR_V1_PAYLOAD_PREFIX) => { + native_scrypto_decode::(&bytes) + .map_err(Into::into) + } Some(NATIVE_MANIFEST_SBOR_V1_PAYLOAD_PREFIX) => { native_manifest_decode::(&bytes) .map_err(Into::into) diff --git a/crates/radix-engine-toolkit-uniffi/src/derive/functions.rs b/crates/radix-engine-toolkit-uniffi/src/derive/functions.rs index 26f9d9a3..1154cd33 100644 --- a/crates/radix-engine-toolkit-uniffi/src/derive/functions.rs +++ b/crates/radix-engine-toolkit-uniffi/src/derive/functions.rs @@ -49,7 +49,37 @@ pub fn derive_virtual_signature_non_fungible_global_id_from_public_key( core_virtual_signature_non_fungible_global_id_from_public_key( &public_key, ); - Ok(Arc::new(NonFungibleGlobalId(non_fungible_global_id, network_id))) + Ok(Arc::new(NonFungibleGlobalId( + non_fungible_global_id, + network_id, + ))) +} + +#[uniffi::export] +pub fn derive_virtual_global_caller_non_fungible_global_id_from_component_address( + component_address: Arc
, + network_id: u8, +) -> Result> { + let component_address = + NativeComponentAddress::try_from(*component_address)?; + let non_fungible_global_id = core_virtual_global_caller_non_fungible_global_id_from_component_address(component_address); + Ok(Arc::new(NonFungibleGlobalId( + non_fungible_global_id, + network_id, + ))) +} + +#[uniffi::export] +pub fn derive_virtual_package_of_direct_caller_non_fungible_global_id_from_component_address( + package_address: Arc
, + network_id: u8, +) -> Result> { + let package_address = NativePackageAddress::try_from(*package_address)?; + let non_fungible_global_id = core_virtual_package_of_direct_caller_non_fungible_global_id_from_component_address(package_address); + Ok(Arc::new(NonFungibleGlobalId( + non_fungible_global_id, + network_id, + ))) } #[uniffi::export] @@ -61,7 +91,10 @@ pub fn derive_virtual_account_address_from_olympia_account_address( core_virtual_account_address_from_olympia_account_address( &olympia_account_address.0, )?; - Ok(Arc::new(Address::from_typed_node_id(component_address, network_id))) + Ok(Arc::new(Address::from_typed_node_id( + component_address, + network_id, + ))) } #[uniffi::export] @@ -72,7 +105,10 @@ pub fn derive_resource_address_from_olympia_resource_address( let resource_address = core_resource_address_from_olympia_resource_address( &olympia_resource_address.0, )?; - Ok(Arc::new(Address::from_typed_node_id(resource_address, network_id))) + Ok(Arc::new(Address::from_typed_node_id( + resource_address, + network_id, + ))) } #[uniffi::export] diff --git a/crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs b/crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs index 4e810ea1..e107f0b8 100644 --- a/crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs +++ b/crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs @@ -40,6 +40,8 @@ mod core { virtual_account_address_from_public_key as core_virtual_account_address_from_public_key, virtual_identity_address_from_public_key as core_virtual_identity_address_from_public_key, virtual_signature_non_fungible_global_id_from_public_key as core_virtual_signature_non_fungible_global_id_from_public_key, + virtual_global_caller_non_fungible_global_id_from_component_address as core_virtual_global_caller_non_fungible_global_id_from_component_address, + virtual_package_of_direct_caller_non_fungible_global_id_from_component_address as core_virtual_package_of_direct_caller_non_fungible_global_id_from_component_address, virtual_account_address_from_olympia_account_address as core_virtual_account_address_from_olympia_account_address, resource_address_from_olympia_resource_address as core_resource_address_from_olympia_resource_address, public_key_from_olympia_account_address as core_public_key_from_olympia_account_address, diff --git a/crates/radix-engine-toolkit/src/functions/derive.rs b/crates/radix-engine-toolkit/src/functions/derive.rs index d8391f9d..d8000ca0 100644 --- a/crates/radix-engine-toolkit/src/functions/derive.rs +++ b/crates/radix-engine-toolkit/src/functions/derive.rs @@ -47,6 +47,18 @@ where NonFungibleGlobalId::from_public_key(public_key) } +pub fn virtual_global_caller_non_fungible_global_id_from_component_address( + component_address: ComponentAddress, +) -> NonFungibleGlobalId { + NonFungibleGlobalId::global_caller_badge(component_address) +} + +pub fn virtual_package_of_direct_caller_non_fungible_global_id_from_component_address( + package_address: PackageAddress, +) -> NonFungibleGlobalId { + NonFungibleGlobalId::package_of_direct_caller_badge(package_address) +} + pub fn virtual_account_address_from_olympia_account_address( olympia_account_address: S, ) -> Result @@ -117,14 +129,12 @@ where olympia_account_address.chars().nth(2), ) { (Some('d'), Some('x')) => Ok(()), - (Some(char1), Some(char2)) => { - Err( - DerivationError::InvalidCharsInOlympiaAddressEntitySpecifier { - expected: ('d', 'x'), - actual: (char1, char2), - }, - ) - } + (Some(char1), Some(char2)) => Err( + DerivationError::InvalidCharsInOlympiaAddressEntitySpecifier { + expected: ('d', 'x'), + actual: (char1, char2), + }, + ), _ => Err(DerivationError::InvalidOlympiaAddressLength { expected: 65, actual: olympia_account_address.len(), @@ -159,12 +169,10 @@ where } }) } - Some(prefix) => { - Err(DerivationError::InvalidOlympiaAddressPrefix { - expected: 0x04, - actual: *prefix, - }) - } + Some(prefix) => Err(DerivationError::InvalidOlympiaAddressPrefix { + expected: 0x04, + actual: *prefix, + }), None => Err(DerivationError::InvalidOlympiaAddressLength { expected: EXPECTED_LENGTH, actual: data.len(), From 66489864273fcb35a719130acae7ece20c1f4986 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 21 Oct 2024 21:54:17 +0300 Subject: [PATCH 2/5] Update build workflow --- .github/workflows/build.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 554bb092..ebd4ba44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -121,6 +121,8 @@ jobs: # uses: mozilla-actions/sccache-action@v0.0.3 # Installing Build Dependencies + - name: Adding Target + run: rustup target add ${{ matrix.build-target.target-triple }} - name: Build Dependencies (aarch64 linux) if: ${{ matrix.build-target.target-triple == 'aarch64-unknown-linux-gnu' }} run: | @@ -195,7 +197,7 @@ jobs: repository: radixdlt/uniffi-bindgen-cs path: uniffi-bindgen-cs submodules: 'recursive' - ref: bc78e828d86ffb2d0e674ddc990726c78299ff89 + ref: c2c9ab306cc8b8402b2a8ba76c632ad090435023 - name: Clone uniffi-bindgen-go uses: RDXWorks-actions/checkout@main with: @@ -372,7 +374,7 @@ jobs: path: "./artifacts/RadixEngineToolkit.xcframework" publish-kotlin-maven-github: needs: [build, generate-uniffi-bindings] - runs-on: macos-13 + runs-on: ubuntu-latest permissions: contents: read packages: write @@ -458,7 +460,7 @@ jobs: build-root-directory: interop/kotlin/ret-kotlin publish-android-maven: needs: [build, generate-uniffi-bindings] - runs-on: macos-13 + runs-on: ubuntu-latest permissions: contents: read packages: write From f484cd4aa2d4c42020dce4f9f314b0224a7bcb40 Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 21 Oct 2024 21:54:27 +0300 Subject: [PATCH 3/5] Update build workflow --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ebd4ba44..903029ff 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -197,7 +197,7 @@ jobs: repository: radixdlt/uniffi-bindgen-cs path: uniffi-bindgen-cs submodules: 'recursive' - ref: c2c9ab306cc8b8402b2a8ba76c632ad090435023 + ref: bc78e828d86ffb2d0e674ddc990726c78299ff89 - name: Clone uniffi-bindgen-go uses: RDXWorks-actions/checkout@main with: From b36e3d7cbfe0790a735710292d6007aa8e910b8d Mon Sep 17 00:00:00 2001 From: Omar Date: Mon, 28 Oct 2024 11:53:12 +0300 Subject: [PATCH 4/5] Remove account deposit settings from reserved instructons --- .../src/transaction/manifest.rs | 7 ------- .../traverser/auxiliary/reserved_instructions.rs | 13 ------------- .../src/transaction_types/types.rs | 1 - .../radix-engine-toolkit/tests/transaction_types.rs | 2 +- 4 files changed, 1 insertion(+), 22 deletions(-) diff --git a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs index da7520eb..0d21c24a 100644 --- a/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs +++ b/crates/radix-engine-toolkit-uniffi/src/transaction/manifest.rs @@ -423,7 +423,6 @@ pub enum ReservedInstruction { AccountLockFee, AccountSecurify, IdentitySecurify, - AccountUpdateSettings, AccessControllerMethod, } @@ -436,9 +435,6 @@ impl From for CoreReservedInstruction { ReservedInstruction::AccountLockFee => Self::AccountLockFee, ReservedInstruction::AccountSecurify => Self::AccountSecurify, ReservedInstruction::IdentitySecurify => Self::IdentitySecurify, - ReservedInstruction::AccountUpdateSettings => { - Self::AccountUpdateSettings - } } } } @@ -452,9 +448,6 @@ impl From for ReservedInstruction { CoreReservedInstruction::AccountLockFee => Self::AccountLockFee, CoreReservedInstruction::AccountSecurify => Self::AccountSecurify, CoreReservedInstruction::IdentitySecurify => Self::IdentitySecurify, - CoreReservedInstruction::AccountUpdateSettings => { - Self::AccountUpdateSettings - } } } } diff --git a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/reserved_instructions.rs b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/reserved_instructions.rs index db24f3f3..c14d8e32 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/reserved_instructions.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/traverser/auxiliary/reserved_instructions.rs @@ -65,19 +65,6 @@ impl ManifestSummaryCallback for ReservedInstructionsDetector { { self.reserved_instructions .insert(ReservedInstruction::AccountLockFee); - } else if is_account(address) - && contains!( - method_name => [ - ACCOUNT_ADD_AUTHORIZED_DEPOSITOR, - ACCOUNT_REMOVE_AUTHORIZED_DEPOSITOR, - ACCOUNT_SET_RESOURCE_PREFERENCE_IDENT, - ACCOUNT_REMOVE_RESOURCE_PREFERENCE_IDENT, - ACCOUNT_SET_DEFAULT_DEPOSIT_RULE_IDENT, - ] - ) - { - self.reserved_instructions - .insert(ReservedInstruction::AccountUpdateSettings); } else if is_access_controller(address) { self.reserved_instructions .insert(ReservedInstruction::AccessControllerMethod); diff --git a/crates/radix-engine-toolkit/src/transaction_types/types.rs b/crates/radix-engine-toolkit/src/transaction_types/types.rs index e06151a7..33a1681f 100644 --- a/crates/radix-engine-toolkit/src/transaction_types/types.rs +++ b/crates/radix-engine-toolkit/src/transaction_types/types.rs @@ -450,7 +450,6 @@ pub enum ReservedInstruction { AccountLockFee, AccountSecurify, IdentitySecurify, - AccountUpdateSettings, AccessControllerMethod, } diff --git a/crates/radix-engine-toolkit/tests/transaction_types.rs b/crates/radix-engine-toolkit/tests/transaction_types.rs index 010fcacc..cfe56b20 100644 --- a/crates/radix-engine-toolkit/tests/transaction_types.rs +++ b/crates/radix-engine-toolkit/tests/transaction_types.rs @@ -2261,7 +2261,7 @@ fn account_deposit_settings_changes_are_recognized() { assert_eq_three!( manifest_summary.reserved_instructions, execution_summary.reserved_instructions, - indexset![ReservedInstruction::AccountUpdateSettings] + indexset![] ); assert_eq_three!( manifest_summary.classification.len(), From 6300cb52c7d3168fd6cc306459592d7b24ef4299 Mon Sep 17 00:00:00 2001 From: Omar Date: Tue, 29 Oct 2024 13:40:40 +0300 Subject: [PATCH 5/5] Update the commit hash of uniffi bindgen CS --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 903029ff..ebd4ba44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -197,7 +197,7 @@ jobs: repository: radixdlt/uniffi-bindgen-cs path: uniffi-bindgen-cs submodules: 'recursive' - ref: bc78e828d86ffb2d0e674ddc990726c78299ff89 + ref: c2c9ab306cc8b8402b2a8ba76c632ad090435023 - name: Clone uniffi-bindgen-go uses: RDXWorks-actions/checkout@main with: