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.

slothbag
  • 433
  • 3
  • 10

2 Answers2

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.

Piper Merriam
  • 3,592
  • 3
  • 22
  • 34
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){}
slothbag
  • 433
  • 3
  • 10
  • I'm getting a similar error now. Is it possible this bug still exists? Is there a tracking issue in github somewhere? – carver Jun 08 '16 at 05:57