-
Notifications
You must be signed in to change notification settings - Fork 0
/
organising.sol
42 lines (37 loc) · 1.55 KB
/
organising.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
// SPDX-License-Identifier: MIT
pragma solidity >= 0.5.0 < 0.9.0;
contract EventContract{
struct Event{
address organiser;
string name;
uint date;
uint price;
uint ticketCount;
uint ticketRemain;
}
mapping(uint=>Event) public events;
mapping(address=>mapping(uint=>uint)) public tickets;
uint public nextId;
function createEvent(string memory name,uint date,uint price,uint ticketCount) external{
require(date>block.timestamp,"you can organize event for future date");
require(ticketCount>0,"you can organise only if you create more than 0 tickets");
events[nextId]=Event(msg.sender,name,date,price,ticketCount,ticketCount);
nextId++;
}
function buyTicket(uint id,uint quantity) external payable{
require(events[id].date!=0,"no event exist");
require(events[id].date>block.timestamp,"event has already occured");
Event storage _event=events[id];
require(msg.value==(_event.price*quantity),"ether is not enough");
require(_event.ticketRemain>=quantity,"not enough tickets");
_event.ticketRemain-=quantity;
tickets[msg.sender][id]+=quantity;
}
function transferTicket(uint id,uint quantity,address to) external{
require(events[id].date!=0,"no event exist");
require(events[id].date>block.timestamp,"event has already occured");
require(tickets[msg.sender][id]>=quantity,"you don't have enough tickets");
tickets[msg.sender][id]-=quantity;
tickets[to][id]+=quantity;
}
}