Near-One / near-plugins

Implementation of common patterns used for NEAR smart contracts.
Creative Commons Zero v1.0 Universal
27 stars 12 forks source link

ACL: Add transfer super admin api #94

Closed karim-en closed 1 year ago

karim-en commented 1 year ago

Currently, the ACL plugin provides api to init single super admin by acl_init_super_admin. But to transfer the admin to another account, the developers need to write their own method, like this:

    pub fn transfer_super_admin(&mut self, account_id: AccountId) {
        let current_super_admin = env::predecessor_account_id();

        near_sdk::require!(
            self.acl_get_or_init()
                .revoke_super_admin_unchecked(&current_super_admin),
            "Failed to revoke super-admin."
        );

        near_sdk::require!(
            self.acl_get_or_init().init_super_admin(&account_id),
            "Failed to init super-admin."
        );
    }

This pull request adds a default implementation to transfer the super admin permissions to another account, this could be useful for transferring the super admin to DAO or another account, or on migration from one DAO to another.

Added pubic APIs:

fn acl_transfer_super_admin(&mut self, account_id: AccountId) -> Option<bool>;