Skip to content

Commit

Permalink
Add more methods to the manifest builder
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Aug 2, 2023
1 parent 31a8e57 commit fb108d8
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ impl ManifestBuilder {
//=====================

/* Faucet */
pub fn free_xrd_from_faucet(self: Arc<Self>) -> Result<Arc<Self>> {

pub fn faucet_free_xrd(self: Arc<Self>) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let instruction = NativeInstruction::CallMethod {
address: NativeDynamicGlobalAddress::Static(NATIVE_FAUCET.into()),
Expand All @@ -575,6 +576,18 @@ impl ManifestBuilder {
})
}

pub fn faucet_lock_fee(self: Arc<Self>) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let instruction = NativeInstruction::CallMethod {
address: NativeDynamicGlobalAddress::Static(NATIVE_FAUCET.into()),
method_name: "lock_fee".to_owned(),
args: manifest_args!(NativeDecimal::from_str("100").unwrap()).into(),
};
builder.instructions.push(instruction);
Ok(())
})
}

/* Account */

pub fn create_account_advanced(self: Arc<Self>, owner_role: OwnerRole) -> Result<Arc<Self>> {
Expand Down Expand Up @@ -839,6 +852,57 @@ impl ManifestBuilder {
})
}

pub fn mint_fungible(
self: Arc<Self>,
resource_address: Arc<Address>,
amount: Arc<Decimal>,
) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let resource_address = NativeResourceAddress::try_from(*resource_address)?;
let amount = amount.0;

let instruction = NativeInstruction::CallMethod {
address: NativeDynamicGlobalAddress::Static(resource_address.into()),
method_name: NATIVE_FUNGIBLE_RESOURCE_MANAGER_MINT_IDENT.to_owned(),
args: native_to_manifest_value_and_unwrap!(
&NativeFungibleResourceManagerMintInput { amount }
),
};
builder.instructions.push(instruction);

Ok(())
})
}

/* Access Rule */

pub fn set_role(
self: Arc<Self>,
address: Arc<Address>,
module: ObjectModuleId,
role_key: String,
rule: Arc<AccessRule>,
) -> Result<Arc<Self>> {
builder_arc_map(self, |builder| {
let address = NativeGlobalAddress::try_from(*address)?;
let module = NativeObjectModuleId::from(module);
let rule = rule.0.clone();

let instruction = NativeInstruction::CallAccessRulesMethod {
address: NativeDynamicGlobalAddress::Static(address),
method_name: NATIVE_ACCESS_RULES_SET_ROLE_IDENT.to_owned(),
args: native_to_manifest_value_and_unwrap!(&NativeAccessRulesSetRoleInput {
module,
role_key: NativeRoleKey { key: role_key },
rule
}),
};
builder.instructions.push(instruction);

Ok(())
})
}

//=================
// Builder Methods
//=================
Expand Down
20 changes: 20 additions & 0 deletions radix-engine-toolkit-uniffi/src/common/access_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// specific language governing permissions and limitations
// under the License.

use radix_engine::types::FromPublicKey;

use crate::prelude::*;

#[derive(Clone, Debug, Object)]
Expand Down Expand Up @@ -63,6 +65,24 @@ impl AccessRule {
Ok(Arc::new(Self(access_rule)))
}

#[uniffi::constructor]
pub fn require_virtual_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);
let access_rule = native_rule!(native_require(non_fungible_global_id));
Ok(Arc::new(Self(access_rule)))
}

#[uniffi::constructor]
pub fn allow_all() -> Arc<Self> {
Arc::new(Self(NativeAccessRule::AllowAll))
}

#[uniffi::constructor]
pub fn deny_all() -> Arc<Self> {
Arc::new(Self(NativeAccessRule::DenyAll))
}

pub fn or(&self, other: Arc<Self>) -> Arc<Self> {
let access_rule = match (&self.0, &other.0) {
(NativeAccessRule::AllowAll, _) | (_, NativeAccessRule::AllowAll) => {
Expand Down
15 changes: 14 additions & 1 deletion radix-engine-toolkit-uniffi/src/internal_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ mod native {
RoleDefinition as NativeRoleDefinition,
manifest_args as native_manifest_args,
rule as native_rule,
require as native_require
require as native_require,
};
pub use scrypto::address::{
AddressBech32Decoder as NativeAddressBech32Decoder,
Expand Down Expand Up @@ -460,6 +460,19 @@ mod native {
pub use radix_engine_interface::types::{
KeyValueStoreInitEntry as NativeKeyValueStoreInitEntry,
};
pub use radix_engine_interface::api::node_modules::auth::{
AccessRulesCreateInput as NativeAccessRulesCreateInput,
AccessRulesSetRoleInput as NativeAccessRulesSetRoleInput,
AccessRulesSetOwnerRoleInput as NativeAccessRulesSetOwnerRoleInput,
AccessRulesLockOwnerRoleInput as NativeAccessRulesLockOwnerRoleInput,
AccessRulesGetRoleInput as NativeAccessRulesGetRoleInput,
ACCESS_RULES_BLUEPRINT as NATIVE_ACCESS_RULES_BLUEPRINT,
ACCESS_RULES_CREATE_IDENT as NATIVE_ACCESS_RULES_CREATE_IDENT,
ACCESS_RULES_SET_ROLE_IDENT as NATIVE_ACCESS_RULES_SET_ROLE_IDENT,
ACCESS_RULES_SET_OWNER_ROLE_IDENT as NATIVE_ACCESS_RULES_SET_OWNER_ROLE_IDENT,
ACCESS_RULES_LOCK_OWNER_ROLE_IDENT as NATIVE_ACCESS_RULES_LOCK_OWNER_ROLE_IDENT,
ACCESS_RULES_GET_ROLE_IDENT as NATIVE_ACCESS_RULES_GET_ROLE_IDENT,
};
pub use radix_engine_interface::blueprints::access_controller::{
AccessControllerCreateGlobalInput as NativeAccessControllerCreateGlobalInput,
AccessControllerCreateProofInput as NativeAccessControllerCreateProofInput,
Expand Down
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 @@ -115,6 +115,7 @@ pub mod prelude {

/* Often needed */
pub(crate) use std::collections::{BTreeMap, HashMap};
pub(crate) use std::str::FromStr;
pub(crate) use std::sync::Arc;
pub(crate) use thiserror::Error as ThisError;
pub(crate) use uniffi::{Enum, Error, Object, Record};
Expand Down

0 comments on commit fb108d8

Please sign in to comment.