-
Notifications
You must be signed in to change notification settings - Fork 7
/
code.sol
50 lines (35 loc) · 1.2 KB
/
code.sol
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
pragma solidity ^0.8.0;
contract fakeProdDetector {
mapping(bytes32 => Product) public productList;
struct Product {
bytes32 product_id;
string product_name;
uint product_price;
bool isFake;
}
// function toBytes(address x) returns (bytes b) {
// b = new bytes(20);
// for (uint i = 0; i < 20; i++)
// b[i] =byte(uint8(uint(x) / (2**(8*(19 - i)))));
// // return b;
// }
function uploadProduct(bytes32 id, string memory name, uint price) public {
require(productList[id].product_id != 0, "Product found and already Exists");
productList[id] = Product({
product_id: id,
product_name: name,
product_price: price,
isFake: false
});
}
function reportFakeProduct(bytes32 productId) public {
require(productList[productId].product_id == 0, "Product not found");
productList[productId].isFake = true;
}
function isFakeProduct(bytes32 productId) public view returns (bool) {
return productList[productId].isFake;
}
}
// This is Demo Code
// For full Project Code please reach out to us
// Mail : [email protected]