[Ethereum] Contract with mapping(address->bool) does not work as expected

contract-debuggingcontract-developmentcontract-invocationsolidity

I have a very simple Solidity contract:

contract AccessManager {

    mapping(address => bool) public registry;

    function grantAccess(address assetAddr) {
        registry[assetAddr] = true;
    }

    function isAuthorized(address assetAddr) constant returns (bool) {
        return registry[assetAddr];
    }
}

Logic is simple: whenever I call grantAccess(…) method an address (passed as an method argument) has to be added to mapping with "true" value.

The problem is that this simple code does not work. After I send a transaction to execute grantAccess("0x…..") method, I call isAuthorized("0x….) method and it always returns "false".
I've tried it with Chrome extension called "Sol" and with .NET Etherum API. The result is always same: isAuthorized(…) contract method returns "false" no matter what I do.

Here is how I call contact methods in Sol extension:

AccessManager Sol

I think the problem is in passing string as an address argument but I have another contract where I do a similar thing and it works just fine.

Did somebody experience similar issues?

Best Answer

Did you run your code locally or in memory(VM) or into the blockchain? I tried your code it seems working (0=false before granting access and 1=true after)

enter image description here

Try to add an event to your grantaccess function;

  event ev(bool is_granted)
  function grantAccess(address assetAddr) {
        registry[assetAddr] = true;
        ev(registry[assetAddr]);
    }
Related Topic