-
Notifications
You must be signed in to change notification settings - Fork 0
/
veribuy.sol
57 lines (48 loc) · 1.49 KB
/
veribuy.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
51
52
53
54
55
56
57
pragma solidity >=0.5.0 <0.7.0;
contract VeriBuy {
struct User {
uint id;
string username;
}
struct Product {
uint id;
string name;
string description;
uint manufactuerID;
uint retailerID;
uint ownerID;
}
uint product_id = 0;
uint user_id = 1; // 0 for superuser
mapping(uint => Product) public productArr;
mapping(uint => User) public userArr;
function create_user(string memory _username) public payable returns (bool){
user_id++;
User memory newUser;
newUser.id = user_id;
newUser.username = _username;
userArr[user_id] = newUser;
return true;
}
function create_product(string memory _name, string memory _desc, uint _mID, uint _rID, uint _oID) public payable returns (bool){
product_id++;
Product memory newProduct;
newProduct.id = product_id;
newProduct.name = _name;
newProduct.description = _desc;
newProduct.manufactuerID = _mID;
newProduct.retailerID = _rID;
newProduct.ownerID = _oID;
productArr[product_id] = newProduct;
return true;
}
function get_users_count() public view returns (uint){
return user_id;
}
function get_products_count() public view returns (uint){
return product_id;
}
function change_owner(uint _pID, uint _uID) public payable {
productArr[_pID].ownerID = _uID;
}
}