File tree 1 file changed +50
-0
lines changed
1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ pragma solidity ^ 0.8.0 ;
2
+
3
+ contract fakeProdDetector {
4
+ mapping (bytes32 => Product) public productList;
5
+
6
+ struct Product {
7
+ bytes32 product_id;
8
+ string product_name;
9
+ uint product_price;
10
+ bool isFake;
11
+
12
+ }
13
+
14
+
15
+ // function toBytes(address x) returns (bytes b) {
16
+ // b = new bytes(20);
17
+ // for (uint i = 0; i < 20; i++)
18
+ // b[i] =byte(uint8(uint(x) / (2**(8*(19 - i)))));
19
+
20
+ // // return b;
21
+ // }
22
+
23
+ function uploadProduct (bytes32 id , string memory name , uint price ) public {
24
+
25
+ require (productList[id].product_id != 0 , "Product found and already Exists " );
26
+ productList[id] = Product ({
27
+ product_id: id,
28
+ product_name: name,
29
+ product_price: price,
30
+ isFake: false
31
+ });
32
+
33
+
34
+ }
35
+
36
+ function reportFakeProduct (bytes32 productId ) public {
37
+ require (productList[productId].product_id == 0 , "Product not found " );
38
+ productList[productId].isFake = true ;
39
+ }
40
+
41
+ function isFakeProduct (bytes32 productId ) public view returns (bool ) {
42
+ return productList[productId].isFake;
43
+ }
44
+
45
+ }
46
+
47
+
48
+ // This is Demo Code
49
+ // For full Project Code please reach out to us
50
+
You can’t perform that action at this time.
0 commit comments