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

usarskyyusarskyy Posts: 4Member
That's copy-paste of my question on SE: http://ethereum.stackexchange.com/questions/8445/contract-with-mappingaddress-bool-does-not-work-as-expected

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:



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?

Comments

  • usarskyyusarskyy Posts: 4Member
    One important thing: this code works as expected on local machine but fails on blockchain (see comments to SE question)
  • usarskyyusarskyy Posts: 4Member
    Another update on this problem: when I took latest browser-solidity sources and used it instead of "Sol" Chrome extension, I was able to see correct results. So, I suspect "Sol" extension has a bug in response decodding code and has to be updated.

    Unfortunately C# API wrapper (Nethereum) continues returning wrong results.
    I was able to grant access to an account throught C# code and verify that blockchain contains correct results using browser-solidity.
  • usarskyyusarskyy Posts: 4Member
    OK, now I found why Netherum (C# API) did not work: I copy-pasted code that calls a contract method from another place and forgot to remove "gas" parameter (in original code "gas" is required).
    But as "isAuthorized" method is constant, it does not require any gas for its execution. Normally I would have to get an exception but I didn't, instead I was receiving "false" (default value) all the time.
  • twitsakthitwitsakthi Posts: 2Member
    hi usarskyy, i am facing a similar problem. it would be great if you share the code snippet of nethereum code callasync or dto method.
Sign In or Register to comment.