|
@@ -209,6 +209,12 @@ decl_event!(
|
|
|
/// - Role account id of the worker.
|
|
|
WorkerRoleAccountUpdated(WorkerId, AccountId),
|
|
|
|
|
|
+ /// Emits on updating the worker storage role.
|
|
|
+ /// Params:
|
|
|
+ /// - Id of the worker.
|
|
|
+ /// - Raw storage field.
|
|
|
+ WorkerStorageUpdated(WorkerId, Vec<u8>),
|
|
|
+
|
|
|
/// Emits on updating the reward account of the worker.
|
|
|
/// Params:
|
|
|
/// - Member id of the worker.
|
|
@@ -312,6 +318,10 @@ decl_storage! {
|
|
|
pub WorkerById get(fn worker_by_id) : map hasher(blake2_128_concat)
|
|
|
WorkerId<T> => WorkerOf<T>;
|
|
|
|
|
|
+ /// Maps identifier to corresponding worker storage.
|
|
|
+ pub WorkerStorage get(fn worker_storage): map hasher(blake2_128_concat)
|
|
|
+ WorkerId<T> => Vec<u8>;
|
|
|
+
|
|
|
/// Count of active workers.
|
|
|
pub ActiveWorkerCount get(fn active_worker_count): u32;
|
|
|
|
|
@@ -321,6 +331,9 @@ decl_storage! {
|
|
|
/// Worker exit rationale text length limits.
|
|
|
pub WorkerExitRationaleText get(fn worker_exit_rationale_text) : InputValidationLengthConstraint;
|
|
|
|
|
|
+ /// Worker storage size upper bound.
|
|
|
+ pub WorkerStorageSize get(fn worker_storage_size) : u16;
|
|
|
+
|
|
|
/// Map member id by hiring application id.
|
|
|
/// Required by StakingEventsHandler callback call to refund the balance on unstaking.
|
|
|
pub MemberIdByHiringApplicationId get(fn member_id_by_hiring_application_id):
|
|
@@ -332,11 +345,13 @@ decl_storage! {
|
|
|
config(opening_human_readable_text_constraint): InputValidationLengthConstraint;
|
|
|
config(worker_application_human_readable_text_constraint): InputValidationLengthConstraint;
|
|
|
config(worker_exit_rationale_text_constraint): InputValidationLengthConstraint;
|
|
|
+ config(worker_storage_size_constraint): u16;
|
|
|
build(|config: &GenesisConfig<T, I>| {
|
|
|
Module::<T, I>::initialize_working_group(
|
|
|
config.opening_human_readable_text_constraint,
|
|
|
config.worker_application_human_readable_text_constraint,
|
|
|
config.worker_exit_rationale_text_constraint,
|
|
|
+ config.worker_storage_size_constraint,
|
|
|
config.working_group_mint_capacity)
|
|
|
});
|
|
|
}
|
|
@@ -384,6 +399,30 @@ decl_module! {
|
|
|
Self::deposit_event(RawEvent::WorkerRoleAccountUpdated(worker_id, new_role_account_id));
|
|
|
}
|
|
|
|
|
|
+ /// Update the associated role storage.
|
|
|
+ #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ pub fn update_role_storage(
|
|
|
+ origin,
|
|
|
+ worker_id: WorkerId<T>,
|
|
|
+ storage: Vec<u8>
|
|
|
+ ) {
|
|
|
+
|
|
|
+ // Ensure there is a signer which matches role account of worker corresponding to provided id.
|
|
|
+ Self::ensure_worker_signed(origin, &worker_id)?;
|
|
|
+
|
|
|
+ Self::ensure_worker_role_storage_text_is_valid(&storage)?;
|
|
|
+
|
|
|
+ //
|
|
|
+ // == MUTATION SAFE ==
|
|
|
+ //
|
|
|
+
|
|
|
+ // Complete the role storage update
|
|
|
+ WorkerStorage::<T, I>::insert(worker_id, storage.clone());
|
|
|
+
|
|
|
+ // Trigger event
|
|
|
+ Self::deposit_event(RawEvent::WorkerStorageUpdated(worker_id, storage));
|
|
|
+ }
|
|
|
+
|
|
|
/// Update the reward account associated with a set reward relationship for the active worker.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn update_reward_account(
|
|
@@ -1329,6 +1368,14 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
|
|
)
|
|
|
.map_err(|e| DispatchError::Other(e))
|
|
|
}
|
|
|
+
|
|
|
+ fn ensure_worker_role_storage_text_is_valid(text: &[u8]) -> DispatchResult {
|
|
|
+ ensure!(
|
|
|
+ text.len() as u16 <= Self::worker_storage_size(),
|
|
|
+ Error::<T, I>::WorkerStorageValueTooLong
|
|
|
+ );
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// Creates default text constraint.
|
|
@@ -1336,6 +1383,11 @@ pub fn default_text_constraint() -> InputValidationLengthConstraint {
|
|
|
InputValidationLengthConstraint::new(1, 1024)
|
|
|
}
|
|
|
|
|
|
+/// Creates default storage size constraint.
|
|
|
+pub fn default_storage_size_constraint() -> u16 {
|
|
|
+ 2048
|
|
|
+}
|
|
|
+
|
|
|
impl<T: Trait<I>, I: Instance> Module<T, I> {
|
|
|
/// Callback from StakingEventsHandler. Refunds unstaked imbalance back to the source account.
|
|
|
pub fn refund_working_group_stake(
|
|
@@ -1488,6 +1540,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
|
|
opening_human_readable_text_constraint: InputValidationLengthConstraint,
|
|
|
worker_application_human_readable_text_constraint: InputValidationLengthConstraint,
|
|
|
worker_exit_rationale_text_constraint: InputValidationLengthConstraint,
|
|
|
+ worker_storage_size_constraint: u16,
|
|
|
working_group_mint_capacity: minting::BalanceOf<T>,
|
|
|
) {
|
|
|
// Create a mint.
|
|
@@ -1505,6 +1558,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
|
|
|
worker_application_human_readable_text_constraint,
|
|
|
);
|
|
|
<WorkerExitRationaleText<I>>::put(worker_exit_rationale_text_constraint);
|
|
|
+ <WorkerStorageSize<I>>::put(worker_storage_size_constraint);
|
|
|
}
|
|
|
|
|
|
// Set worker id as a leader id.
|