Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Oct 29, 2024
2 parents 494d108 + 6300cb5 commit fc1da69
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ impl AccessRule {
}

#[uniffi::constructor]
pub fn require_virtual_signature(
public_key: PublicKey,
) -> Result<Arc<Self>> {
pub fn require_signature(public_key: PublicKey) -> Result<Arc<Self>> {
let public_key = NativePublicKey::try_from(public_key)?;
let non_fungible_global_id =
NativeNonFungibleGlobalId::from_public_key(&public_key);
Expand Down
23 changes: 22 additions & 1 deletion crates/radix-engine-toolkit-uniffi/src/common/non_fungible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl NonFungibleGlobalId {
}

#[uniffi::constructor]
pub fn virtual_signature_badge(
pub fn signature_badge(
public_key: PublicKey,
network_id: u8,
) -> Result<Arc<Self>> {
Expand All @@ -92,6 +92,27 @@ impl NonFungibleGlobalId {
)
}

#[uniffi::constructor]
pub fn global_caller_badge(
component_address: Arc<Address>,
network_id: u8,
) -> Result<Arc<Self>> {
derive_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<Address>,
network_id: u8,
) -> Result<Arc<Self>> {
derive_package_of_direct_caller_non_fungible_global_id_from_component_address(
package_address, network_id,
)
}

pub fn resource_address(&self) -> Arc<Address> {
let address = self.0.resource_address();
Arc::new(Address::from_typed_node_id(address, self.1))
Expand Down
30 changes: 30 additions & 0 deletions crates/radix-engine-toolkit-uniffi/src/derive/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,36 @@ 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>,
network_id: u8,
) -> Result<Arc<NonFungibleGlobalId>> {
let component_address =
NativeComponentAddress::try_from(*component_address)?;
let non_fungible_global_id =
core_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_package_of_direct_caller_non_fungible_global_id_from_component_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_component_address(package_address);
Ok(Arc::new(NonFungibleGlobalId(
non_fungible_global_id,
network_id,
)))
}

#[uniffi::export]
pub fn derive_preallocated_account_address_from_olympia_account_address(
olympia_account_address: Arc<OlympiaAddress>,
Expand Down
2 changes: 2 additions & 0 deletions crates/radix-engine-toolkit-uniffi/src/internal_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ 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,
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 Down
12 changes: 12 additions & 0 deletions crates/radix-engine-toolkit/src/functions/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ where
NonFungibleGlobalId::from_public_key(public_key)
}

pub fn global_caller_non_fungible_global_id_from_component_address(
component_address: ComponentAddress,
) -> NonFungibleGlobalId {
NonFungibleGlobalId::global_caller_badge(component_address)
}

pub fn 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 preallocated_account_address_from_olympia_account_address<S>(
olympia_account_address: S,
) -> Result<ComponentAddress, DerivationError>
Expand Down

0 comments on commit fc1da69

Please sign in to comment.