0

I have a multisig contract where entities (represented by an address) can be activated or deactivated. These are the structures I created to represent an individual entity (_entityIdentity) and the list of entities (_entityStruct)

struct _entityIdentity{
    bool _activated;
    uint256 _addValidations;
    mapping(address => bool) _AddValidated;
    uint256 _removeValidations;
    mapping(address => bool) _RemoveValidated;
}

struct _entityStruct{
    mapping(address => _entityIdentity) _entities;
    address[] _activatedEntities;
}

The idea is:

  • in order to activate an entity "X" validations are required (from specific owners addresses).
  • _AddValidated keeps track of the addresses that have already validated the entity activation
  • _addvalidations keeps track of the number of validations received
  • When X is reached _activated is set to TRUE
  • Same idea for deactivating only using the other properties (_RemoveValidated, _removeValidations)

The problem I have is when I want to remove the entity, I simply do : delete(entity) (entity is of type _entityIdentity), and apparently that would properly set to false the boolean, to 0 the uint256, but the mappings will not be reset to false....

Is there a specific pattern/recommendation to deal with this?

2 Answers 2

0

The only solution I found was to replace mappings with arrays and make sure by code that addresses do not get replicated. Arrays can easily be deleted by using "delete" on them.

0

all vars in solidity have a default value as 0 and boolean key mappings have false values so instead of using delete you can just explicitly set them to default this will allow you to get a gas refund just like when you use delete but here you can reset your mappings too and you can use a subgraph on the UI to filter

2
  • problem I see with that solution is that I sould know which are the addresses for which boolean is set to true, otherwise I would have to iterate through the virtually infinite mapping Commented May 20, 2021 at 13:49
  • you can use a subgraph to filter o UI
    – viraj
    Commented May 24, 2021 at 14:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.