## 3 Methodology and Implementation
### Functions
OnlyManufacturer(): This function is for checking whether the contract caller has the role of the manufacturer or not. This function is used for limiting access to some features in the network, such as adding products. As a main smart contract, Handler.sol can be countable as the main entry point. Handler.sol basically imports both products and parties' smart contracts and prepares them for interactions with smart contracts. All of the functions in this contract are public functions since the main purpose of this function is to enable user interaction with the network. This function includes a constructor that defaults to the contract creator as the manufacturer on the contract deployment. The functional diagram of Handler.sol and its interactions with other contracts can be seen in Figure 8, and the UML diagram for the contract can be seen in Figure 9.  
Figure 8: Relation Map of functions of Handler.sol. View functions: The following functions use a view modifier, which indicates that the function is only limited to read rights and has no means to alter the network. Public functions:  
1. contractBalance(): Returns the contract's total balance. This function can only be invoked by the contract owner. 2. getAllProducts(): Function for retrieving all products. Returns product struct. 3. getPartyProducts(): Function for retrieving all the products linked to a particular party; invokes getPartyProductsInternal function from product contract and returns product struct. 4. getSingleProduct(): Function for retrieving a specific product; takes productId as a parameter and invokes getSpecificProduct function from product contract. Returns product history struct. 5. getPartyDetailsHandler(): Function for retrieving details of a party in the network; takes party address identifier as a parameter and invokes getPartyDetails function using address identifier parameter. Returns party details struct. 6. getPartyDetails(): Function for retrieving details of the contract caller's party; takes no parameter and instead uses msg.sender as a parameter when calling getPartyDetails function. Returns party details struct. 7. getPartiesList(): Function for retrieving list of parties added by a specific party; takes no parameter and instead uses msg.sender as a parameter and invokes getMyPartyList function using address identifier parameter. Returns party details struct. Functions that are altering network state:  
1. addProduct(): Returns invoker's Ethereum balance in the network. 2. addParty(): Function for retrieving all products. Returns product struct. Figure 9: UML diagram of Handler.sol. transferProduct(): Function for retrieving a specific product; takes productId as a parameter and invokes getSpecificProduct function from product contract. Returns product history struct. 4. returnTransferProduct(): Function for retrieving details of a party in the network; takes party address identifier as a parameter and invokes getPartyDetails function using address identifier parameter. Returns party details struct. 5. removeParty(): Publicly accessible wrapper for removing a party. Calls removePartyInternal from Parties.sol before calling. It performs a condition check to determine whether the due party has a product in its inventory. 6. setProductForReturn(): Publicly accessible wrapper for setting a product for return flow. Calls addPartyInternal from Products.sol. 7. deposit(): Function for depositing Ether to the contract for the caller's wallet. 8. withdraw(): Function for withdrawing Ether from the contract for the caller's wallet. The party is only able to withdraw the amount in its wallet.