0

I have following variable in decl_storage:

Candidate get(fn candidate_name): map hasher(blake2_128_concat) T::AccountId => Vec<u8>;

This is my decl_module function:

    #[weight = 10_000 + T::DbWeight::get().reads_writes(2,2)]
    pub fn add_peers_to_deparment(origin, departmentid: u128) -> dispatch::DispatchResult {
        let who = ensure_signed(origin)?;
        let mut approved_peer_dep = PeerDepartments::<T>::get(&who);

        match approved_peer_dep.binary_search(&departmentid) {

            Ok(_) => Err(Error::<T>::DepartmentExists.into()),
            Err(index) => {
                approved_peer_dep.insert(index, departmentid.clone());
                PeerDepartments::<T>::insert(&who,approved_peer_dep);
                Self::deposit_event(RawEvent::PeerDepartment(departmentid, who));
                Ok(())
             }

        }
     }

Here I am writing two statements, first inserting departmentid to approved_peer_dep and then again inserting approved_peer_dep to the blockchain storage PeerDepartments.

approved_peer_dep.insert(index, departmentid.clone());
PeerDepartments::<T>::insert(&who,approved_peer_dep);

The doubt is if approved_peer_dep contains a very large Vec, will the blockchain (PeerDepartments) insert the complete Vec containing all the departments using more resources, or will used use resource of adding a single department? If it will use more resource what will be the better way to write the code.

How to have a data structure, so that I can access the Vec through a key and update it?

Amiya Behera
  • 2,210
  • 19
  • 32

1 Answers1

0

As a start, here are a few resources to help you decide the path forward:

Nuke
  • 1,032
  • 7
  • 13
  • I am unable to be sure. It says, it hashes only the storage name, instead of storage value. So the code should work fine? – Amiya Behera Mar 18 '21 at 07:47