Skip to content

Commit

Permalink
Add access controller methdods to the manifest builder
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Sep 6, 2023
1 parent f5cb1d1 commit ddf5371
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
105 changes: 105 additions & 0 deletions radix-engine-toolkit-uniffi/src/builder/manifest_builder/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,110 @@ impl ManifestBuilder {

/* Access Controller */

pub fn access_controller_initiate_recovery(
self: Arc<Self>,
access_controller_address: Arc<Address>,
proposer: Proposer,
proposed_primary_role: Arc<AccessRule>,
proposed_recovery_role: Arc<AccessRule>,
proposed_confirmation_role: Arc<AccessRule>,
proposed_timed_recovery_delay_in_minutes: Option<u32>,
) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let rule_set = NativeRuleSet {
primary_role: proposed_primary_role.0.clone(),
recovery_role: proposed_recovery_role.0.clone(),
confirmation_role: proposed_confirmation_role.0.clone(),
};

let (method_name, args) = match proposer {
Proposer::Primary => (
NATIVE_ACCESS_CONTROLLER_INITIATE_RECOVERY_AS_PRIMARY_IDENT,
native_to_manifest_value_and_unwrap!(
&NativeAccessControllerInitiateRecoveryAsPrimaryInput {
rule_set,
timed_recovery_delay_in_minutes:
proposed_timed_recovery_delay_in_minutes,
}
),
),
Proposer::Recovery => (
NATIVE_ACCESS_CONTROLLER_INITIATE_RECOVERY_AS_RECOVERY_IDENT,
native_to_manifest_value_and_unwrap!(
&NativeAccessControllerInitiateRecoveryAsRecoveryInput {
rule_set,
timed_recovery_delay_in_minutes:
proposed_timed_recovery_delay_in_minutes,
}
),
),
};

let instruction = NativeInstruction::CallMethod {
address: NativeDynamicGlobalAddress::Static(
(*access_controller_address).try_into()?,
),
method_name: method_name.to_owned(),
args,
};
builder.instructions.push(instruction);

Ok(())
})
}

pub fn access_controller_quick_confirm_recovery(
self: Arc<Self>,
access_controller_address: Arc<Address>,
proposer: Proposer,
proposed_primary_role: Arc<AccessRule>,
proposed_recovery_role: Arc<AccessRule>,
proposed_confirmation_role: Arc<AccessRule>,
proposed_timed_recovery_delay_in_minutes: Option<u32>,
) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let rule_set = NativeRuleSet {
primary_role: proposed_primary_role.0.clone(),
recovery_role: proposed_recovery_role.0.clone(),
confirmation_role: proposed_confirmation_role.0.clone(),
};

let (method_name, args) = match proposer {
Proposer::Primary => (
NATIVE_ACCESS_CONTROLLER_QUICK_CONFIRM_PRIMARY_ROLE_RECOVERY_PROPOSAL_IDENT,
native_to_manifest_value_and_unwrap!(
&NativeAccessControllerQuickConfirmPrimaryRoleRecoveryProposalInput {
rule_set,
timed_recovery_delay_in_minutes:
proposed_timed_recovery_delay_in_minutes,
}
),
),
Proposer::Recovery => (
NATIVE_ACCESS_CONTROLLER_QUICK_CONFIRM_RECOVERY_ROLE_RECOVERY_PROPOSAL_IDENT,
native_to_manifest_value_and_unwrap!(
&NativeAccessControllerQuickConfirmRecoveryRoleRecoveryProposalInput {
rule_set,
timed_recovery_delay_in_minutes:
proposed_timed_recovery_delay_in_minutes,
}
),
),
};

let instruction = NativeInstruction::CallMethod {
address: NativeDynamicGlobalAddress::Static(
(*access_controller_address).try_into()?,
),
method_name: method_name.to_owned(),
args,
};
builder.instructions.push(instruction);

Ok(())
})
}

pub fn create_signature_based_access_controller(
self: Arc<Self>,
controlled_asset: ManifestBuilderBucket,
Expand Down Expand Up @@ -941,3 +1045,4 @@ macro_rules! manifest_args {
}
use manifest_args;
use radix_engine::types::FromPublicKey;
use radix_engine_common::prelude::to_manifest_value;
1 change: 1 addition & 0 deletions radix-engine-toolkit-uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub mod prelude {
pub use crate::error::*;

/* Events */
pub use crate::events::functions::*;
pub use crate::events::*;

/* Cryptography */
Expand Down

0 comments on commit ddf5371

Please sign in to comment.