Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pallets/worker-registration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
WorkerRegistered{ creator: T::AccountId },
WorkerUnRegistered{ creator: T::AccountId, cluster_id: ClusterId },
TaskScheduled {
worker: T::AccountId,
owner: T::AccountId,
Expand All @@ -221,7 +222,9 @@ pub mod pallet {
WorkerRegisterMissingIp,
WorkerRegisterMissingPort,
ClusterExists,
ClusterDoesNotExists,
NoWorkersAvailable,
InvalidOwnerOfCluster,
WorkerClusterNotRegistered,
UnassignedTaskId,
InvalidTaskOwner,
Expand Down Expand Up @@ -363,6 +366,7 @@ pub mod pallet {

//check cluster
ensure!(WorkerAccounts::<T>::contains_key(creator.clone()) == false,
//One work per account for now
Error::<T>::ClusterExists);

let cid = NextClusterId::<T>::get();
Expand Down Expand Up @@ -486,6 +490,30 @@ pub mod pallet {
// Return a successful DispatchResult
Ok(())
}

#[pallet::call_index(3)]
#[pallet::weight(10_000 + T::DbWeight::get().writes(1).ref_time())]
pub fn unregister_worker(
origin: OriginFor<T>,
cluster_id: ClusterId,
) -> DispatchResult {
let creator = ensure_signed(origin)?;

//check cluster
ensure!(WorkerAccounts::<T>::get(creator.clone()) == Some(cluster_id),
Error::<T>::InvalidOwnerOfCluster);
ensure!(WorkerClusters::<T>::get(cluster_id) != None,
Error::<T>::ClusterDoesNotExists);

// update storage
WorkerClusters::<T>::remove(cluster_id);
WorkerAccounts::<T>::remove(creator.clone());

// Emit an event.
Self::deposit_event(Event::WorkerUnRegistered { creator, cluster_id });

Ok(())
}
// //TODO: update implementation
// #[pallet::call_index(3)]
// #[pallet::weight({0})]
Expand Down