From fb15886700abb6f20edac6bfa01a1fa272af1cc7 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Tue, 7 Nov 2023 10:28:30 +0100 Subject: [PATCH] merge create_bucket and allocate_bucket_to_cluster methods --- pallets/ddc-customers/src/lib.rs | 38 +++++++------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 4e41485a2..4adcee4b5 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -46,7 +46,6 @@ pub struct Bucket { bucket_id: BucketId, owner_id: AccountId, cluster_id: Option, - public_availability: bool, } #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] @@ -245,19 +244,23 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Create new bucket with provided public availability & reserved resources + /// Create new bucket with specified cluster id /// /// Anyone can create a bucket #[pallet::weight(10_000)] - pub fn create_bucket(origin: OriginFor, public_availability: bool) -> DispatchResult { + pub fn create_bucket(origin: OriginFor, cluster_id: ClusterId) -> DispatchResult { let bucket_owner = ensure_signed(origin)?; let cur_bucket_id = Self::buckets_count(); + ensure!( + ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), + Error::::ClusterDoesNotExist + ); + let bucket = Bucket { bucket_id: cur_bucket_id + 1, owner_id: bucket_owner, - cluster_id: None, - public_availability, + cluster_id: Some(cluster_id), }; >::set(cur_bucket_id + 1); @@ -265,31 +268,6 @@ pub mod pallet { Ok(()) } - /// Allocates specified bucket into specified cluster - /// - /// Only bucket owner can call this method - #[pallet::weight(10_000)] - pub fn allocate_bucket_to_cluster( - origin: OriginFor, - bucket_id: BucketId, - cluster_id: ClusterId, - ) -> DispatchResult { - let bucket_owner = ensure_signed(origin)?; - - let mut bucket = Self::buckets(bucket_id).ok_or(Error::::NoBucketWithId)?; - - ensure!(bucket.cluster_id == None, Error::::BucketAlreadyInCluster); - ensure!(bucket.owner_id == bucket_owner, Error::::NotBucketOwner); - - ensure!( - ddc_clusters::pallet::Clusters::::contains_key(&cluster_id), - Error::::ClusterDoesNotExist - ); - bucket.cluster_id = Some(cluster_id); - - Ok(()) - } - /// Take the origin account as a owner and lock up `value` of its balance. `Owner` will /// be the account that controls it. ///