hashed-io / hashed-pallets

Hashed Network pallets
MIT License
0 stars 0 forks source link

Update set_afloat_balance extrinsic to allow all users with admin permissions to update asset balance #5

Closed tlacloc closed 1 year ago

tlacloc commented 1 year ago

Issue Description

Bug Fix

Update the extrinsic to allow all users with admin permissions to update the balance of the asset. This bug fix will enable users with admin privileges to modify the asset balance instead of restricting it to only the owner.

Description

The current implementation of the set_afloat_balance extrinsic in the substrate pallet restricts the ability to update the balance of the asset to only the owner. This issue aims to modify the code to allow all users with admin permissions to update the asset balance. Additionally, it may involve updating mapped assets to validate the signature of the origin.

#[pallet::call_index(9)]
    #[pallet::weight(Weight::from_ref_time(10_000) + T::DbWeight::get().reads_writes(2,1))]
    pub fn set_afloat_balance(
      origin: OriginFor<T>,
      beneficiary: T::AccountId,
      amount: T::Balance,
    ) -> DispatchResult {
      ensure_signed(origin.clone())?;

      // Only the owner can set afloat balance
      ensure!(Self::is_owner(ensure_signed(origin.clone())?), Error::<T>::Unauthorized);

      Self::do_set_afloat_balance(origin, beneficiary, amount)
    }

Changes Made

  1. Remove the ownership restriction from the ensure! statement that checks for the owner.
  2. Implement a mechanism to check if the user has admin permissions.
  3. Update the logic to validate the signature of the origin when updating mapped assets.
  4. Test the updated extrinsic to ensure proper functionality.

Overall Impact

Implications for Other Codebase

Acceptance Criteria