-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCertification.sol
More file actions
133 lines (102 loc) · 4.61 KB
/
Certification.sol
File metadata and controls
133 lines (102 loc) · 4.61 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
pragma solidity ^0.5.2;
contract myCertification{
struct product{
bool stored;
address sender;
string ownerFullName;
string ownerGender;
string ownerState;
string ownerCountry;
string productType;
string productFormat;
uint numOfTracks;
}
mapping(string => product) internal products;
event productEvent(string hash);
///@dev Adds a new record to the blockchain containing all product attributes.
///@param hash An unique hash based on all product attributes. Should be encrypted externally.
///@param ownerFullName The full name of the product owner.
///@param ownerGender The Gender of owner.
///@param ownerState The state of owner.
///@param ownerCountry The country of owner lives in.
///@param productType Type of the product owner wants to register.
///@param productFormat Format of the product owner wants to reister.
// ///@param numOfTracks number of tracks in the owners product.
function addProduct(string storage hash,
string storage ownerFullName,
string storage ownerGender,
string storage ownerState,
string storage ownerCountry,
string storage productType,
string storage productFormat,
uint numOfTracks)
internal{
require(bytes(hash).length > 0);
require(bytes(ownerFullName).length > 0);
require(numOfTracks > 0);
products[hash].stored = true;
products[hash].sender = msg.sender;
products[hash].ownerFullName = ownerFullName;
products[hash].ownerGender = ownerGender;
products[hash].ownerState = ownerState;
products[hash].ownerCountry = ownerCountry;
products[hash].productType = productType;
products[hash].productFormat = productFormat;
products[hash].numOfTracks = numOfTracks;
}
///@dev Checks if the product has already been added to the blockchain.
///@param hash An unique hash based on all product attributes. Should be encrypted externally.
///@param ownerFullName The full name of the product owner.
///@param ownerGender Gender of product owner
///@param ownerState State where product owner lives.
///@param ownerCountry Country where product owner lives.
///@param productType Type of the prduct owner want to register.
///@param productFormat Format of the product owner want to register.
///@param numOfTracks number of tracks in the product.
function newProduct(string calldata hash,
string calldata ownerFullName,
string calldata ownerGender,
string calldata ownerState,
string calldata ownerCountry,
string calldata productType,
string calldata productFormat,
uint numOfTracks)
external
returns(string memory result){
if(products[hash].stored){
result = "Hash is already registered.";
} else {
addProduct(hash, ownerFullName, ownerGender, ownerState, ownerCountry, productType, productFormat, numOfTracks);
emit productEvent(hash);
result = "Product registered successfully";
}
return result;
}
///@dev Displays product data based on their unique hash.
///@param hash An unique hash based on all product attributes. Should be encrypted externally.
function getProduct(string calldata hash)
external
view
returns(string memory result,
string memory ownerFullName,
string memory ownerGender,
string memory ownerState,
string memory ownerCountry,
string memory productType,
string memory productFormat,
uint numOfTracks){
if(products[hash].stored){
result = "Product record found.";
}else{
result = "Product not found.";
}
return(result,
products[hash].ownerFullName,
products[hash].ownerGender,
products[hash].ownerState,
products[hash].ownerCountry,
products[hash].productType,
products[hash].productFormat,
products[hash].numOfTracks);
}
}