-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathFBlock.sol
More file actions
158 lines (135 loc) · 5.34 KB
/
Copy pathFBlock.sol
File metadata and controls
158 lines (135 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* @title Storage
* @dev Store & retrieve value in a variable
*/
contract FBlocks {
/**
* @dev Define the structure for a basic product
// Need to define for Stakeholders, Product, TraceNTrack
*/
struct Stakeholder
{
string id;
string name;
string description;
string location;
string role;
uint256 inceptionDate;
uint256 walletShare;
bool exist;
}
struct Product
{
string prodId;
string prodName;
string productType;
string ProdDesc;
string ProductOrgin;
string farmerName;
uint256 salesPrice;
bool exist;
}
struct Traceability
{
string fertilizerInfo;
string seedOrgin;
uint256 temperature;
uint256 humidity;
uint TruckRunningTime;
uint256 shelfTime;
}
struct ProductStatus
{
string id;
bool inTrasit;
bool inSource;
bool inDestination;
}
/**
* @dev Mapping that define the storage of a product
*/
mapping(string => Product) private ProductStorage;
mapping(string => Stakeholder) private stakeholderStorage;
mapping(string => ProductStatus) private StatusStorage;
mapping(string => Traceability) private TraceStorage;
mapping(address => mapping(string => bool)) private foodWallet;
/**
* @dev Declare events according the Food Supply Chain:
*/
event CreateProduct(address addressProducer, string id, string Producer, uint256 CreationDate);
event TransferProduct(address fromStakeholder, address toStakeholder, string id);
event CreateStakeholder(address addressStakeholder, string id, string name, uint256 inceptionDate);
event StatusChange(string id,address statusDesc,string currentStatus);
event ActionTraceability( string fertilizerInfo, string seedOrigin, uint32 temperature,uint32 humidity,uint TruckRunningTime,uint shelfTime);
event setPrice(string id, uint32 salePrice);
event TransferReject(address from, address to, string id, string RejectMessage);
event CreationReject(address addressStakeholder, string id, string RejectMessage);
/**
* @dev Function that create the Product: Specific product eg., "strawberry"
*/
function CreateProduct1(address addressProducer, string memory id, string memory Producer, uint256 CreationDate, string memory prodType,string memory desc,uint salesPrice,string memory name) public {
if(ProductStorage[id].exist) {
emit CreationReject(msg.sender, id, "This product already exists");
return;
}
// ProductStorage[id] = Product(addressProducer,id,Producer,CreationDate,desc,prodType,name,true);
//ProductStorage[id] = Product(prodId,prodName,productType,ProdDesc,ProductOrgin,farmerName,salesPrice,true);
foodWallet[msg.sender][id] = true;
emit CreateProduct(msg.sender, id, Producer, block.timestamp);
}
/**
* @dev Function that makes the transfer of food product from one stakeholder to another
*/
function TransferProduct1(address toStakeholder, string memory id) public{
if(!ProductStorage[id].exist) {
emit TransferReject(msg.sender, toStakeholder, id, "No product id exists for this transaction");
return;
}
if(!foodWallet[msg.sender][id]) {
emit TransferReject(msg.sender, toStakeholder, id, "Transaction Rejected and no Wallet transfer");
return;
}
foodWallet[msg.sender][id] = false;
foodWallet[toStakeholder][id] = true;
emit TransferProduct (msg.sender, toStakeholder, id);
}
/**
* @dev Function that create the Stakeholder: Farmer/Supplier/Distributor/Retailer/Consumer
*/
function CreateStakeHolders1(address addressStakeholder, string memory id, string memory name, uint256 inceptionDate) public {
if(stakeholderStorage[id].exist) {
emit CreationReject(msg.sender, id, "The Stakeholder already exists");
return;
}
// stakeholderStorage[id] = Stakeholder(addressStakeholder, id, name,inceptionDate);
//stakeholderStorage[id] = Stakeholder(id, name, desc,loc,role,incDate,wShare,true);
foodWallet[msg.sender][id] = true;
emit CreateStakeholder(msg.sender, id, name, block.timestamp);
}
/**
* @dev Function that records status change: inTransit / inSource / inDestination
*/
function StatusChange1(string memory id,string memory statusDesc,string memory currentStatus) public {
if(StatusStorage[id].exist) {
emit CreationReject(msg.sender, id, "Status already upodated for this ID");
return;
}
StatusStorage[id] = StatusChange(id, statusDesc,currentStatus);
foodWallet[msg.sender][id] = true;
emit StatusChange(id, statusDesc,currentStatus);
}
/**
* @dev Function that records status change: inTransit / inSource / inDestination
*/
function ActionTraceability1(string memory id,string memory fertilizerInfo, string memory seedOrigin, uint32 temperature,uint32 humidity,uint TruckRunningTime,uint shelfTime) public {
if(TraceStorage[id].exist) {
emit CreationReject(msg.sender, id, "Tracking details already avaiable for this ID");
return;
}
TraceStorage[id] = ActionTraceability(id,fertilizerInfo, seedOrigin, temperature,humidity,TruckRunningTime,shelfTime);
foodWallet[msg.sender][id] = true;
emit ActionTraceability(id,fertilizerInfo, seedOrigin, temperature,humidity,TruckRunningTime,shelfTime);
}
}