-
Notifications
You must be signed in to change notification settings - Fork 0
/
Whitelist-product.sol
78 lines (61 loc) · 2.23 KB
/
Whitelist-product.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0;
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0));
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
}
contract extraFunctions is Ownable {
mapping(uint256 => productStruct) _product;
struct productStruct {
bool whitelistEnabled;
mapping (address => bool) isWhitelisted;
}
//mapping(address => bool) isWhitelisted;
function whitelist(uint256 productId, address[] memory _addresses) public onlyOwner {
for(uint256 i = 0; i < _addresses.length; i++) {
_product[productId].isWhitelisted[_addresses[i]] = true;
}
}
function removeWhitelist(uint256 productId, address[] memory _addresses) public onlyOwner {
for(uint256 i = 0; i < _addresses.length; i++) {
_product[productId].isWhitelisted[_addresses[i]] = false;
}
}
function setProductWhitelistEnabled(uint256 productId, bool _state) public onlyOwner {
_product[productId].whitelistEnabled = _state;
}
function isProductWhitelistEnabled(uint256 productId) public view returns(bool) {
return _product[productId].whitelistEnabled;
}
function getProductAddressIsWhitelisted(uint256 productId, address _address) public view returns(bool) {
return _product[productId].isWhitelisted[_address];
}
}