0

Is it possible to add a modifier to the auto-generated getter for a given variable? My use case is I am marking a contract as being in-process for updating and setting a modifier flag; I'd like to prevent reading the contract state while it's updating, restricted by this modifier.

I understand I could create my own getter, but then I am returning a tuple with no keys. When I access one of the structs via the auto-generated getter via web3 for a mapping at a specific mapping key (of the form mapping(uint => SomeStruct), I get the SomeStruct instance along with the struct keys, which is nice but unexpected, since I'm not using the ABIEncoderV2 experimental encoder. I'd like to keep the ability to return this object, which as I've stated I don't think is possible if I define my own getter, without the experimental encoder.

6
  • 2
    Why don't you simply declare the variable private (or internal), and then implement a getter function explicitly? Apr 27, 2018 at 10:46
  • @goodvibration I explained this in the question. Currently unless you are using the experimental encoder, you cannot return a struct from a function. However, when I access the struct via the mapping, by mapping key, I get back an object with the struct keys, which as I mentioned is unexpected. If I were to implement my own getting, I can only return a tuple of the dereferenced values, there are no keys returned.
    – kasceled
    Apr 27, 2018 at 11:05
  • 1
    You can return a tuple, is that not good enough for your needs? Apr 27, 2018 at 11:56
  • For example, function func() external view returns (uint256, uint256, uint256) Apr 27, 2018 at 11:56
  • You can pass to this function the uint which you use in order to query the mapping, and inside the function return your structure as a tuple (list) of values. Apr 27, 2018 at 11:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.