Skip to content

Commit

Permalink
Create object with permissioned signer
Browse files Browse the repository at this point in the history
  • Loading branch information
runtian-zhou committed Jan 10, 2025
1 parent dfa01cc commit a1bc425
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
33 changes: 33 additions & 0 deletions aptos-move/framework/aptos-framework/sources/object.move
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ module aptos_framework::object {
obj_owner
}

/// Master signer offers a transfer permission of an object to a permissioned signer.
public fun grant_permission<T>(
master: &signer,
permissioned_signer: &signer,
Expand All @@ -725,6 +726,17 @@ module aptos_framework::object {
)
}

/// Grant a transfer permission to the permissioned signer using TransferRef.
public fun grant_permission_with_transfer_ref(
permissioned_signer: &signer,
ref: &TransferRef,
) {
permissioned_signer::grant_unlimited_with_permissioned_signer(
permissioned_signer,
TransferPermission { object: ref.self }
)
}

#[test_only]
use std::option::{Self, Option};

Expand Down Expand Up @@ -1163,4 +1175,25 @@ module aptos_framework::object {

permissioned_signer::destroy_permissioned_handle(creator_permission_handle);
}

#[test(creator = @0x123)]
fun test_create_and_transfer(
creator: &signer,
) acquires ObjectCore {
let aptos_framework = account::create_signer_for_test(@0x1);
timestamp::set_time_has_started_for_testing(&aptos_framework);

let (_, hero) = create_hero(creator);
let (weapon_ref, weapon) = create_weapon(creator);
let t_ref = generate_transfer_ref(&weapon_ref);

// Create a permissioned signer
let creator_permission_handle = permissioned_signer::create_permissioned_handle(creator);
let creator_permission_signer = permissioned_signer::signer_from_permissioned_handle(&creator_permission_handle);

grant_permission_with_transfer_ref(&creator_permission_signer, &t_ref);
transfer_to_object(&creator_permission_signer, weapon, hero);

permissioned_signer::destroy_permissioned_handle(creator_permission_handle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,24 @@ module aptos_framework::permissioned_signer {
)
}

/// Grant an unlimited permission to a permissioned signer **without** master signer's approvoal.
public(package) fun grant_unlimited_with_permissioned_signer<PermKey: copy + drop + store>(
permissioned: &signer,
perm: PermKey
) acquires PermissionStorage {
if(!is_permissioned_signer(permissioned)) {
return;
};
insert_or(
permissioned,
perm,
|stored_permission| {
*stored_permission = StoredPermission::Unlimited;
},
StoredPermission::Unlimited,
)
}

/// Increase the `capacity` of a permissioned signer **without** master signer's approvoal.
///
/// The caller of the module will need to make sure the witness type `PermKey` can only be
Expand Down

0 comments on commit a1bc425

Please sign in to comment.