-
Notifications
You must be signed in to change notification settings - Fork 0
/
FactoryIKS.sol
126 lines (104 loc) · 4.23 KB
/
FactoryIKS.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
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
// host is the actual wallet that deploy this eventify
// owner is the factory contract that deploys this contract
import "./IKS.sol";
import "./FeaturedEvents.sol";
import "./interfaces/IFactoryIKS.sol";
import "./interfaces/IIKS.sol";
contract FactoryIKS is IFactoryIKS {
IKS[] public contracts;
address[] public addresses;
address public featuredEventsInstanceAddress;
FeaturedEvents public featuredEventsInstance;
mapping (address => string) public addressToUsername;
mapping (string => address) public usernameToAddress;
mapping (address => uint) public hostAddressToContractId;
mapping (string => bool) public usernameExist;
mapping (address => bool) public hasDeployed;
mapping (address => bool) public isWhitelisted;
mapping (address => bool) public isWhitelistOperator;
mapping (address => address[]) public userToHostPurchased;
struct FeaturedRequest {
address host;
uint ticketId;
bool isApproved;
}
uint public featuredRequestId;
mapping(uint => FeaturedRequest) public idToFeaturedRequest;
address owner;
constructor() {
isWhitelistOperator[msg.sender] = true;
featuredEventsInstance = new FeaturedEvents();
featuredEventsInstanceAddress = address(featuredEventsInstance);
owner = msg.sender;
}
modifier onlyOwner() {
require(owner == msg.sender);
_;
}
function setWhitelistOperator(address _user) public onlyOwner {
isWhitelistOperator[_user] = true;
}
function whitelistUser(address _user) public {
require(isWhitelistOperator[msg.sender] == true);
isWhitelisted[_user] = true;
emit UserWhitelisted(_user, msg.sender);
}
modifier isUserWhitelisted() {
require(isWhitelisted[msg.sender] == true, "You are not whitelisted");
_;
}
function deployIKS(string memory _username) public returns (address) {
require(hasDeployed[msg.sender] != true);
IKS t = new IKS(featuredEventsInstanceAddress, address(this));
contracts.push(t);
addressToUsername[msg.sender] =_username;
usernameToAddress[_username] = msg.sender;
usernameExist[_username] = true;
hostAddressToContractId[msg.sender] = contracts.length - 1;
hasDeployed[msg.sender] = true;
emit IKSDeployed(msg.sender, address(t));
return address(t);
}
function getHostsContractAddress(address _address) public view returns (address) {
uint id = hostAddressToContractId[_address];
return address(contracts[id]);
}
function buy(string memory _username, uint _ticketId) public payable {
address hostAddr = usernameToAddress[_username];
uint contractId = hostAddressToContractId[hostAddr];
contracts[contractId].buyTicket{value: msg.value}(_ticketId);
userToHostPurchased[msg.sender].push(hostAddr);
}
function raiseFeaturedRequest(uint256 _ticketId) public {
featuredRequestId++;
idToFeaturedRequest[featuredRequestId] = FeaturedRequest(msg.sender, _ticketId, false);
}
function approveFeaturedEvents(address host, uint _ticketId) public onlyOwner {
uint id = hostAddressToContractId[host];
contracts[id].pushFeaturedEvent(_ticketId);
idToFeaturedRequest[_ticketId].isApproved == false;
}
function fetchAllFeaturedRequest() public view returns (FeaturedRequest[] memory) {
uint counter = 0;
FeaturedRequest[] memory tickets = new FeaturedRequest[](featuredRequestId);
for (uint i = 0; i < featuredRequestId; i++) {
uint currentId = i + 1;
FeaturedRequest storage currentItem = idToFeaturedRequest[currentId];
tickets[counter] = currentItem;
counter++;
}
return tickets;
}
function userToHostPurchasedArray(address _address) public view returns (address[] memory) {
address[] memory arr;
arr = userToHostPurchased[_address];
return arr;
}
function contractsArray() public view returns (IKS[] memory) {
IKS[] memory arr = new IKS[](contracts.length-1);
arr = contracts;
return arr;
}
}