Skip to content

Commit

Permalink
Merge pull request #133 from radixdlt/feature/extract-addresses-from-…
Browse files Browse the repository at this point in the history
…access-rules

Extract addresses from access rules
  • Loading branch information
0xOmarA authored Jan 27, 2025
2 parents 2ab5b35 + ecd509a commit 9423505
Show file tree
Hide file tree
Showing 52 changed files with 1,096 additions and 727 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Install Rust Toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: nightly-2024-02-01
toolchain: nightly-2025-01-26
default: true
profile: minimal
# - name: Run sccache-cache
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Install Rust Toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: nightly-2024-02-01
toolchain: nightly-2025-01-26
default: true
profile: minimal
target: ${{ matrix.build-target.target-triple }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/release-kotlin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ jobs:
uses: RDXWorks-actions/checkout@main
- name: Install Rust Target
run: |
# Install nightly-2024-02-01
rustup toolchain install nightly-2024-02-01
# Install nightly-2025-01-26
rustup toolchain install nightly-2025-01-26
# Update both toolchains
rustup update nightly-2024-07-30
rustup update nightly-2024-02-01
rustup update nightly-2025-01-26
rustup update nightly-2025-01-26
# Add target
rustup target install ${{ matrix.build-target.target-triple }}
rustup +nightly-2024-02-01 target install ${{ matrix.build-target.target-triple }}
rustup +nightly-2025-01-26 target install ${{ matrix.build-target.target-triple }}
# Install the nightly-2024-02-01 toolchain of the target of this machine.
# Install the nightly-2025-01-26 toolchain of the target of this machine.
DEFAULT_TARGET=$(rustc -vV | sed -n 's|host: ||p')
rustup component add rust-src --toolchain nightly-2024-02-01-$DEFAULT_TARGET
rustup component add rust-src --toolchain nightly-2025-01-26-$DEFAULT_TARGET
- name: Build dependencies (x86_64-pc-windows-gnu)
if: ${{ matrix.build-target.target-triple == 'x86_64-pc-windows-gnu' }}
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Install Rust Toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: nightly-2024-07-30
toolchain: nightly-2025-01-26
default: true
components: rustfmt, clippy
- name: Install cargo nextest
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Install Rust Toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: nightly-2024-07-30
toolchain: nightly-2025-01-26
default: true
profile: minimal
- name: Cargo Check
Expand All @@ -91,7 +91,7 @@ jobs:
- name: Install Rust Toolchain
uses: RDXWorks-actions/toolchain@master
with:
toolchain: nightly-2024-07-30
toolchain: nightly-2025-01-26
default: true
components: rustfmt, clippy
- name: Clippy Check
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/generator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "generator"
version = "2.2.0-dev2"
version = "2.2.2"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/radix-engine-toolkit-json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-engine-toolkit-json"
version = "2.2.0-dev2"
version = "2.2.2"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/radix-engine-toolkit-uniffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-engine-toolkit-uniffi"
version = "2.2.0-dev2"
version = "2.2.2"
edition = "2021"
build = "build.rs"

Expand Down
11 changes: 7 additions & 4 deletions crates/radix-engine-toolkit-uniffi/src/blueprints/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ impl ToNative for MetadataInit {
None => None,
};

Ok((key, NativeKeyValueStoreInitEntry::<NativeMetadataValue> {
lock: value.lock,
value: metadata,
}))
Ok((
key,
NativeKeyValueStoreInitEntry::<NativeMetadataValue> {
lock: value.lock,
value: metadata,
},
))
})
.collect::<Result<
IndexMap<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![allow(clippy::too_many_arguments)]

use crate::prelude::*;
use radix_common::prelude::{FromPublicKey, to_manifest_value};
use radix_common::prelude::{to_manifest_value, FromPublicKey};

#[derive(Debug, Clone, Object, Default)]
pub struct ManifestV1Builder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#![allow(clippy::too_many_arguments)]

use crate::prelude::*;
use radix_common::prelude::{FromPublicKey, to_manifest_value};
use radix_common::prelude::{to_manifest_value, FromPublicKey};

#[derive(Debug, Clone, Object)]
pub struct ManifestV2Builder {
Expand Down
19 changes: 19 additions & 0 deletions crates/radix-engine-toolkit-uniffi/src/common/access_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ pub struct AccessRule(pub NativeAccessRule);

#[uniffi::export]
impl AccessRule {
#[uniffi::constructor]
pub fn from_scrypto_sbor_payload(payload: Vec<u8>) -> Result<Arc<Self>> {
native_scrypto_decode(&payload)
.map_err(RadixEngineToolkitError::from)
.map(Self)
.map(Arc::new)
}

#[uniffi::constructor]
pub fn require(
resource_or_non_fungible: ResourceOrNonFungible,
Expand Down Expand Up @@ -158,6 +166,17 @@ impl AccessRule {
};
Arc::new(AccessRule(access_rule))
}

pub fn extract_entities(
&self,
network_id: u8,
) -> Vec<ResourceOrNonFungible> {
let extraced_entities = core_extract_entities(&self.0);
extraced_entities
.into_iter()
.map(|item| ResourceOrNonFungible::from_native(item, network_id))
.collect()
}
}

#[derive(Clone, Debug, Enum, Hash, PartialEq, Eq)]
Expand Down
27 changes: 24 additions & 3 deletions crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,35 @@ impl NonFungibleGlobalId {
}

#[uniffi::constructor]
pub fn global_caller_badge(
pub fn global_caller_badge_from_global_address(
component_address: Arc<Address>,
network_id: u8,
) -> Result<Arc<Self>> {
derive_global_caller_non_fungible_global_id_from_component_address(
derive_global_caller_non_fungible_global_id_from_global_address(
component_address,
network_id,
)
}

#[uniffi::constructor]
pub fn global_caller_badge_from_blueprint_id(
package_address: Arc<Address>,
blueprint_name: String,
network_id: u8,
) -> Result<Arc<Self>> {
derive_global_caller_non_fungible_global_id_from_blueprint_id(
package_address,
blueprint_name,
network_id,
)
}

#[uniffi::constructor]
pub fn package_of_direct_caller_badge(
package_address: Arc<Address>,
network_id: u8,
) -> Result<Arc<Self>> {
derive_package_of_direct_caller_non_fungible_global_id_from_component_address(
derive_package_of_direct_caller_non_fungible_global_id_from_package_address(
package_address, network_id,
)
}
Expand All @@ -130,6 +143,14 @@ impl NonFungibleGlobalId {
NativeAddressBech32Encoder::new(&network_definition);
self.0.to_canonical_string(&bech32_encoder)
}

pub fn is_global_caller_badge(&self) -> bool {
self.0.resource_address() == NATIVE_GLOBAL_CALLER_RESOURCE
}

pub fn is_package_of_direct_caller_badge(&self) -> bool {
self.0.resource_address() == NATIVE_PACKAGE_OF_DIRECT_CALLER_RESOURCE
}
}

#[derive(Clone, Debug, Enum, Hash, PartialEq, Eq)]
Expand Down
45 changes: 37 additions & 8 deletions crates/radix-engine-toolkit-uniffi/src/derive/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@ pub fn derive_signature_badge_non_fungible_global_id_from_public_key(
}

#[uniffi::export]
pub fn derive_global_caller_non_fungible_global_id_from_component_address(
component_address: Arc<Address>,
pub fn derive_global_caller_non_fungible_global_id_from_global_address(
global_address: Arc<Address>,
network_id: u8,
) -> Result<Arc<NonFungibleGlobalId>> {
let component_address =
NativeComponentAddress::try_from(*component_address)?;
let global_address = NativeGlobalAddress::try_from(*global_address)?;
let non_fungible_global_id =
core_global_caller_non_fungible_global_id_from_component_address(
component_address,
core_global_caller_non_fungible_global_id_from_global_address(
global_address,
);
Ok(Arc::new(NonFungibleGlobalId(
non_fungible_global_id,
Expand All @@ -75,12 +74,33 @@ pub fn derive_global_caller_non_fungible_global_id_from_component_address(
}

#[uniffi::export]
pub fn derive_package_of_direct_caller_non_fungible_global_id_from_component_address(
pub fn derive_global_caller_non_fungible_global_id_from_blueprint_id(
package_address: Arc<Address>,
blueprint_name: String,
network_id: u8,
) -> Result<Arc<NonFungibleGlobalId>> {
let package_address = NativePackageAddress::try_from(*package_address)?;
let non_fungible_global_id = core_package_of_direct_caller_non_fungible_global_id_from_component_address(package_address);
let blueprint_id = NativeBlueprintId {
package_address,
blueprint_name,
};
let non_fungible_global_id =
core_global_caller_non_fungible_global_id_from_blueprint_id(
blueprint_id,
);
Ok(Arc::new(NonFungibleGlobalId(
non_fungible_global_id,
network_id,
)))
}

#[uniffi::export]
pub fn derive_package_of_direct_caller_non_fungible_global_id_from_package_address(
package_address: Arc<Address>,
network_id: u8,
) -> Result<Arc<NonFungibleGlobalId>> {
let package_address = NativePackageAddress::try_from(*package_address)?;
let non_fungible_global_id = core_package_of_direct_caller_non_fungible_global_id_from_package_address(package_address);
Ok(Arc::new(NonFungibleGlobalId(
non_fungible_global_id,
network_id,
Expand Down Expand Up @@ -146,3 +166,12 @@ pub fn derive_olympia_account_address_from_public_key(
);
Ok(Arc::new(OlympiaAddress(address)))
}

#[uniffi::export]
pub fn public_key_hash_from_public_key(
public_key: PublicKey,
) -> Result<PublicKeyHash> {
let public_key = NativePublicKey::try_from(public_key)?;
let public_key_hash = core_public_key_hash_from_public_key(&public_key);
Ok(public_key_hash.into())
}
4 changes: 3 additions & 1 deletion crates/radix-engine-toolkit-uniffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ pub enum RadixEngineToolkitError {
#[error("The static analysis of the manifest failed: {error}")]
StaticAnalysisFailed { error: String },

#[error("Not all of the builder items were specified, progressing failed.")]
#[error(
"Not all of the builder items were specified, progressing failed."
)]
NotAllBuilderItemsWereSpecified,

#[error("Validation of manifest failed: {error}")]
Expand Down
11 changes: 9 additions & 2 deletions crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ mod core {
preallocated_account_address_from_public_key as core_preallocated_account_address_from_public_key,
preallocated_identity_address_from_public_key as core_preallocated_identity_address_from_public_key,
preallocated_signature_non_fungible_global_id_from_public_key as core_preallocated_signature_non_fungible_global_id_from_public_key,
global_caller_non_fungible_global_id_from_component_address as core_global_caller_non_fungible_global_id_from_component_address,
package_of_direct_caller_non_fungible_global_id_from_component_address as core_package_of_direct_caller_non_fungible_global_id_from_component_address,
global_caller_non_fungible_global_id_from_global_address as core_global_caller_non_fungible_global_id_from_global_address,
global_caller_non_fungible_global_id_from_blueprint_id as core_global_caller_non_fungible_global_id_from_blueprint_id,
public_key_hash_from_public_key as core_public_key_hash_from_public_key,
package_of_direct_caller_non_fungible_global_id_from_package_address as core_package_of_direct_caller_non_fungible_global_id_from_package_address,
preallocated_account_address_from_olympia_account_address as core_preallocated_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,
Expand All @@ -58,6 +60,9 @@ mod core {
pub use radix_engine_toolkit::functions::utils::{
decode_transaction_id as core_decode_transaction_id
};
pub use radix_engine_toolkit::functions::access_rule::{
extract_entities as core_extract_entities
};
pub use radix_engine_toolkit::functions::transaction_v1::manifest::{
to_payload_bytes as core_transaction_v1_manifest_to_payload_bytes,
from_payload_bytes as core_transaction_v1_manifest_from_payload_bytes,
Expand All @@ -83,6 +88,7 @@ mod core {
to_payload_bytes as core_transaction_v1_notarized_transaction_to_payload_bytes,
from_payload_bytes as core_transaction_v1_notarized_transaction_from_payload_bytes,
statically_validate as core_transaction_v1_notarized_transaction_statically_validate,
extract_signer_public_keys as core_transaction_v1_notarized_transaction_extract_signer_public_keys,
};
pub use radix_engine_toolkit::functions::transaction_v2::instructions::{
extract_addresses as core_transaction_v2_instructions_extract_addresses,
Expand Down Expand Up @@ -123,6 +129,7 @@ mod core {
to_payload_bytes as core_transaction_v2_notarized_transaction_to_payload_bytes,
from_payload_bytes as core_transaction_v2_notarized_transaction_from_payload_bytes,
statically_validate as core_transaction_v2_notarized_transaction_statically_validate,
extract_signer_public_keys as core_transaction_v2_notarized_transaction_extract_signer_public_keys,
};
pub use radix_engine_toolkit::functions::transaction_v2::partial_transaction::{
hash as core_transaction_v2_partial_transaction_hash,
Expand Down
2 changes: 1 addition & 1 deletion crates/radix-engine-toolkit-uniffi/src/manifest/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ impl From<NativeManifestBlobRef> for ManifestBlobRef {

impl From<ManifestBlobRef> for NativeManifestBlobRef {
fn from(value: ManifestBlobRef) -> Self {
Self(value.value.0.0)
Self(value.value.0 .0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ impl NotarizedTransactionV1 {
)
.map_err(Into::into)
}

pub fn signer_public_keys(&self) -> Result<Vec<PublicKey>> {
core_transaction_v1_notarized_transaction_extract_signer_public_keys(
&self.clone().try_into()?,
)
.map_err(Into::into)
.map(|value| value.into_iter().map(Into::into).collect())
}
}

impl From<NativeNotarizedTransactionV1> for NotarizedTransactionV1 {
Expand Down
Loading

0 comments on commit 9423505

Please sign in to comment.