0

How do I mutate a DoubleStorageMap with a Vec<T::AccountId> as a value using a struct?

Data::<T>::mutate(
  id.clone(),
  user_id.clone(),
  |params: &mut DataParams<T::AccountId>| {
    params.users.push(new_user);
    params.total_users += 1;
  }
);

total_users doesn't increase but users only ever has one user.


What's the best way to accomplish this? The mutate is within a for loop and needs to append multiple users.

7
  • are you mutating for every new_user in some vector/array users?
    – dastansam
    Commented Feb 15 at 16:36
  • it's new data that resets and needs to restore every so often. i just retested it and actually total_users doesn't increase.
    – bobby dy
    Commented Feb 15 at 16:42
  • Okay im not sure what's happening, if the build is not compiling correct. but now its pushing in the data. maybe i need to clean it up
    – bobby dy
    Commented Feb 15 at 17:01
  • Please include all the types that are involved in your question, most importantly DataParams.
    – kianenigma
    Commented Feb 15 at 19:50
  • Moreover, please be aware that iterating over a map, if the map keys can be unbounded is a dangerous operation.
    – kianenigma
    Commented Feb 15 at 19:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.