2

My use case: I have to keep track of all "submitted quotations" from one person to another.

My solution: For this I am keeping a mapping of uint and struct mapping (uint => quotation) allQuoatations. I am appending inside this method on addQuoatation method.

My doubts:

  1. Is it the correct way to model arrays.
  2. Should I only keep last quotation inside contract, remove the array and emit an event after addition of quotation.
  • Could you post some more code? I'm having a hard time understanding what you're trying to accomplish – flygoing Jun 26 '18 at 2:29
2

The two choices of whether to store all quotations in the smart contract and whether to emit events are independent:

  1. You should keep all quotations in the smart contract if you need to access them in the smart contract, e.g. if there is another method that needs to read quotations for its logic.

    • You can either model them as a Solidity array. In this case you will know the total number of quotations and will be able to access them by index.
    • Or you can model them as a Solidity mapping. In this case you won't know the total number of quotations (unless you keep them in a separate variable) and will be able to access quotations by id.
  2. You should emit events on quotations if you need to be notified of new quotations in your Dapp.

| improve this answer | |

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.