diff --git a/aptos-move/framework/aptos-framework/sources/object.move b/aptos-move/framework/aptos-framework/sources/object.move index 7f94c73b2ac90..09e724318e942 100644 --- a/aptos-move/framework/aptos-framework/sources/object.move +++ b/aptos-move/framework/aptos-framework/sources/object.move @@ -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( master: &signer, permissioned_signer: &signer, @@ -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}; @@ -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); + } } diff --git a/aptos-move/framework/aptos-framework/sources/permissioned_signer.move b/aptos-move/framework/aptos-framework/sources/permissioned_signer.move index f951f01bfa333..9c090c8e5ae4d 100644 --- a/aptos-move/framework/aptos-framework/sources/permissioned_signer.move +++ b/aptos-move/framework/aptos-framework/sources/permissioned_signer.move @@ -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( + 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