ItemManager()
struct & enum
First we create the item object with the struct item{}, need to reflect the following properties of id, price, address payable and the state.
State here refers to which stage in the supply-chain the item is currently at: Created, Paid, Delivered.
To achieve this we use enum itemState{Created, Paid, Delivered}
.
mapping
We would need a dataframe like structure to track out inventory of items, therefore a mapping from a uint
to struct Item
, where the uint is the index. We achieve this index capability with the creation of item_index -> we will increment this later and feed into the mapping. count starts at 0.
function createItem()
When we create an item, we are looking to update the mapping item_list
-> the mapping is initialized with default values of all 0. So we are updating each default struct in the mapping with proper values, sequentially starting from 0. Hence:
We do not bother with individually instantiating each item with a unique name and then subsequently populating the item_list. Instead we simply update the mapping with the relevant details.
Why? This saves gas and overheads and we do not have the need to outright declare each item as an object for further manipulation. Simply need to track state and existence.
Last updated