| Algorithms A2. Smart Contract 2: Product Purchase1 |
| Input: entity name, entity id, entity type, entity quantity, addr, seller, buyer |
| 1. if addr is valid && addr has adding authentication |
| 2. dairy_farm_details=getFarm(seller) |
| 3. x[]=getProduct_Adulteration_Info(entity id) |
| 4. y[]=getProduct_Contamination_Info(entity id) |
| 5. if x.quality ==1 && y.quality==1 |
| 6. Proceed with the purchase |
| 7. Initiate the payment to the farmer |
| 8. z=addBilling_Info(addr, dairy_farm_details, buyer, entity id, entity quantity, entity name, entity type, price) |
| 9. if z==1 |
| 10. Payment Successful |
| 11. updateProduct_Quantity(entity id, entity quantity, entity name, entity type) |
| 12. end |
| 13. else |
| 14. Payment Unsuccessful |
| 15. go to step 7 |
| 16. end |
| 17. else |
| 18. Product not fit for purchase due to lower quality standards |
| 19. end |
| 20. else |
| 21. Invalid or authorised address |
| 22. go to step 1 and enter a valid address |
| 23. end |
| 24. else |
| 25. Invalid or authorised address |
| 26. go to step 1 and enter a valid address |
| 27. end |