Summary
The focus of this chapter was to understand data modeling with regard to smart contracts. Smart contracts contain state variables, and they are costly in terms of their usage. This chapter introduced concepts related to nested or embedded structures viz-a-viz reference structures and concepts related to the use of references versus nested structures. However, modeling structures and storing them in mappings viz-a-viz arrays can make big differences in terms of access and write patterns. Looping plays a big role in deciding whether arrays or mappings should be used.
We also saw a complete example of a smart contract with multiple structures used in various operations, such as reading, writing, and looping. In this chapter, two other important patterns were discussed. The first set of patterns was related to establishing and transferring ownership of both assets and contracts, and the next pattern was to stop executing functions in a contract in the event of an emergency....