From 1babe298b8f61aff9fcef1d38e8c9a1dd122f9e1 Mon Sep 17 00:00:00 2001 From: Raid Ateir Date: Sun, 27 Nov 2022 23:59:38 +0100 Subject: [PATCH] return bucket list by account --- bucket/ddc_bucket/bucket/messages.rs | 8 ++++++++ bucket/lib.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/bucket/ddc_bucket/bucket/messages.rs b/bucket/ddc_bucket/bucket/messages.rs index db8d2bce..ffda3c48 100644 --- a/bucket/ddc_bucket/bucket/messages.rs +++ b/bucket/ddc_bucket/bucket/messages.rs @@ -96,6 +96,14 @@ impl DdcBucket { (bucket_statuses, self.buckets.0.len()) } + pub fn message_bucket_list_for_account(&self, owner_id: AccountId) -> Vec { + self.buckets.0 + .iter() + .filter(|bucket| bucket.owner_id == owner_id) + .cloned() + .collect() + } + pub fn bucket_calculate_status(&self, bucket_id: BucketId, bucket: Bucket) -> Result { let mut writer_ids = self.buckets_perms.get_bucket_readers(bucket_id); writer_ids.push(bucket.owner_id); diff --git a/bucket/lib.rs b/bucket/lib.rs index a559e00a..5e49b3fe 100755 --- a/bucket/lib.rs +++ b/bucket/lib.rs @@ -208,6 +208,14 @@ pub mod ddc_bucket { self.message_bucket_list(offset, limit, filter_owner_id) } + /// Iterate through all buckets and return only those owned by owner + /// + /// This method returns bucket struct, not the status + #[ink(message)] + pub fn bucket_list_for_account(&self, owner_id: AccountId) -> Vec { + self.message_bucket_list_for_account(owner_id) + } + /// Set availiablity of the bucket #[ink(message)] pub fn bucket_set_availability(&mut self, bucket_id: BucketId, public_availability: bool) -> () {