9

I have two mappings (uint => customStruct) called listA and listB. I want to run both through a single function to perform operations on the contents.

How do I pass this type into a function so that I can call someFunction(listA) and someFunction(listB)?

I get errors like Type is required to live outside storage.

  • Ok, so I have found this which sounds related.. data-storage – slothbag Feb 4 '16 at 10:20
  • 1
    Feel free to write your own answer (instead of a comment) and include details, not just a link. – eth Feb 4 '16 at 11:04
  • Thanks, I haven't found a solution yet. The link was just a "might help" addition. – slothbag Feb 4 '16 at 11:36
  • It's worth noting that you cannot iterate over a mapping nor can you check whether a key exists in a mapping. In solidity, mappings exist as if every key was present and had zero's as all of it's values. – Piper Merriam Feb 7 '16 at 6:17
4

All storage variables declared in a contract are available within the scope of all of the functions of that contract. You do not need to pass them into your contracts functions to access them.

4

I got confirmation from Chriseth that this is probably a bug in Solidity that is not allowing a mapping to be sent as a parameter.

I worked around the problem by wrapping the parameter in a struct, and of course you need to use the storage keywork.

someFunction(myStruct storage myInstance){}
  • I'm getting a similar error now. Is it possible this bug still exists? Is there a tracking issue in github somewhere? – carver Jun 8 '16 at 5:57

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.