0

I am passing an array of addresses into a contract from a parent contract. Using that I am generating a mapping with those address to quickly verify the msg.sender is part of the set mappings.

To check if a msg.sender is part of the mappings I am using the restricted modifier.

contract Upload{

    mapping(address => bool) managerAddresses;
    string public ownerName;
    string public location;

    modifier restricted(){
        require(managerAddresses[msg.sender]);
        _;
    }


    constructor(address[] _managerAddressesArr,string _ownerName,string _location)  public {
        for(uint i = 0;i<_managerAddressesArr.length;i++){
            managerAddresses[_managerAddressesArr[i]] = true;
        }
        ownerName = _ownerName;
    }

    function setLocation(string _location) restricted public{
        location = _location;
    }



}

But the setLocation function is unable to change the location when the restricted modifier is on and the transaction is mined but doesn't execte. Even though the address passed by the managerAddressesArr are correct and without the modifier I can execute the functions.

Also solidity gives a

Gas requirement of function Upload.setLocation(string) high: infinite

Does anyone have any idea whats wrong with the restricted modifier?

  • Don't really know for your problem, but in your for loop, shouldn't it be i<=_manager instead of just <? – Florian Castelain May 4 '18 at 9:19
  • @Andromelus No because it's zero-based. OP: The warning is caused by your array - Solidity has no way of knowing how many elements are in it so it warns about possible gas requirement problems – Lauri Peltonen May 4 '18 at 10:00
0

It seems to work just fine here. Try this: https://ethfiddle.com/1e8OhY-Czd

I deployed it with the first available address in the list (which is the sender) and, then called setLocation and then checked the getter of location - it had the right value.

  • @OP: Same for me. Everything works as expected. – Tobias Mar 21 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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