Last active
October 3, 2022 22:30
-
-
Save ac12644/1333e6d44f142d3672ec74f479515c1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.0; | |
... | |
// 1st step in supply chain process | |
function produceItemByFarmer( | |
uint256 _productCode, | |
string memory _originFarmName, | |
string memory _originFarmInformation, | |
string memory _originFarmLatitude, | |
string memory _originFarmLongitude, | |
string memory _productNotes, | |
uint256 _price | |
) | |
public | |
onlyFarmer // check address belongs to farmerRole | |
{ | |
address distributorID; // Empty distributorID address | |
address retailerID; // Empty retailerID address | |
address consumerID; // Empty consumerID address | |
Item memory newProduce; // Create a new struct Item in memory | |
newProduce.stockUnit = stockUnit; // Stock Keeping Unit (stockUnit) | |
newProduce.productCode = _productCode; // Product Codegenerated by the Farmer, goes on the package, can be verified by the Consumer | |
newProduce.ownerID = _msgSender(); // Metamask-Ethereum address of the current owner as the product moves through 8 stages | |
newProduce.originFarmerID = _msgSender(); // Metamask-Ethereum address of the Farmer | |
newProduce.originFarmName = _originFarmName; // Farmer Name | |
newProduce.originFarmInformation = _originFarmInformation; // Farmer Information | |
newProduce.originFarmLatitude = _originFarmLatitude; // Farm Latitude | |
newProduce.originFarmLongitude = _originFarmLongitude; // Farm Longitude | |
newProduce.productID = _productCode + stockUnit; // Product ID | |
newProduce.productNotes = _productNotes; // Product Notes | |
newProduce.productPrice = _price; // Product Price | |
newProduce.productDate = block.timestamp; | |
newProduce.productSliced = 0; | |
newProduce.itemState = defaultState; // Product State as represented in the enum above | |
newProduce.distributorID = distributorID; // Metamask-Ethereum address of the Distributor | |
newProduce.retailerID = retailerID; // Metamask-Ethereum address of the Retailer | |
newProduce.consumerID = consumerID; // Metamask-Ethereum address of the Consumer // ADDED payable | |
items[_productCode] = newProduce; // Add newProduce to items struct by productCode | |
uint256 placeholder; // Block number place holder | |
Txblocks memory txBlock; // create new txBlock struct | |
txBlock.FTD = placeholder; // assign placeholder values | |
txBlock.DTR = placeholder; | |
txBlock.RTC = placeholder; | |
itemsHistory[_productCode] = txBlock; // add txBlock to itemsHistory mapping by productCode | |
// Increment stockUnit | |
stockUnit = stockUnit + 1; | |
// Emit the appropriate event | |
emit ProduceByFarmer(_productCode); | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment