pragma solidity ^0.5.7;
contract Randomness{
mapping(uint => ticket) public tickets;
struct ticket{
uint id;
address buyer;
bytes32 hashed;
}
uint public time;
address public userInput;
bytes32 public hashed;
function hashIt(string memory hashMe) public returns (bytes32){
hashed = sha256(bytes(hashMe));
return hashed;
}
function getStuff() public{
time = now;
userInput = msg.sender;
}
uint ticketId;
function addTicket() public returns(uint _id){
_id = ticketId++;
tickets[_id] = ticket({
id:_id,
buyer : msg.sender,
hashed: hashed});
return tickets[_id].id;
}
}
Last active
May 16, 2019 16:47
-
-
Save theowlsden/55ddac79d0eec8ffc6f9475473fa75e0 to your computer and use it in GitHub Desktop.
pragma solidity ^0.5.7;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract TicketingDapp is Ownable {
struct Event {
uint eventId;
string name;
string date;
string eventType;
uint ticketPrice;
uint ticketSupply;
bool eventEnded;
address payable organizer;
}
struct Ticket{
uint id;
uint eventId;
address owner;
bytes32 hashed;
}
uint ID;
uint ticketId;
bytes32 public hashed;
string[] eventArr;
mapping(uint => Event) public events;
mapping(address => bool) public admins;
mapping(uint => Ticket) public tickets;
modifier onlyAdmin() {
require(admins[msg.sender] == true);
_;
}
function addAdmin(address newAdmin) public onlyOwner {
admins[newAdmin] = true;
}
function createEvent(
string memory _name,
string memory _date,
string memory _eventType,
uint _price,
uint _ticketAmount
) public onlyAdmin returns(uint _ID) {
_ID = ID++;
events[_ID] = Event ({
eventId: _ID,
name: _name,
date: _date,
eventType: _eventType,
ticketPrice: _price * 1 wei,
ticketSupply: _ticketAmount,
eventEnded: false,
organizer: msg.sender
});
eventArr.push(events[_ID].name);
return events[_ID].eventId;
}
function getAllEvents() public view returns (uint){
return eventArr.length;
}
function getEventDetails(uint _id) public view returns(string memory, string memory, string memory, uint, uint) {
//get event details
require(events[_id].eventId == _id);
return (events[_id].name,
events[_id].date,
events[_id].eventType,
events[_id].ticketPrice,
events[_id].ticketSupply);
}
function endEvent(uint _id) public onlyOwner returns(bool) {
//sets eventEnded to true
return events[_id].eventEnded = true;
}
function hashIt(string memory hashMe) public returns (bytes32) {
hashed = sha256(bytes(hashMe));
return hashed;
}
function addTicket(uint _eventId) public returns(uint _id) {
_id = ticketId++;
tickets[_id] = Ticket({
id:_id,
eventId: events[_eventId].eventId,
owner : msg.sender,
hashed: hashed});
return tickets[_id].id;
}
function buyTicket(uint _eventId, uint _ticketAmount) public payable{
uint paid = msg.value;
events[_eventId].organizer.transfer(paid);
uint i;
while(i<= _ticketAmount){
addTicket(_eventId);
i++;
}
}
function kill(address payable _owner) public onlyOwner {
selfdestruct(_owner);
}
function() external payable {
revert();
}
}
pragma solidity ^0.5.7;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
contract TicketingDapp is Ownable, ERC721 {
mapping(address => Event) public ownerToEvent;
struct Event {
string name;
string description;
uint date;
string eventType;
uint ticketPrice;
uint ticketSupply;
bool eventEnded;
}
struct eventToken{
string eventName;
uint eventDate;
uint ticketPrice;
uint ticketId;
}
function createEvent(
string memory _name,
string memory _desc,
uint _date,
string memory _eventType,
uint _price,
uint _ticketAmount
) public onlyOwner {
ownerToEvent[msg.sender] = Event ({
name: _name,
description: _desc,
date: _date,
eventType: _eventType,
ticketPrice: _price,
ticketSupply: _ticketAmount,
eventEnded: false
});
}
function getEventDetails() public {
//get event details
}
function endEvent() public onlyOwner {
//sets eventEnded to true
}
function kill(address payable _owner) public onlyOwner {
selfdestruct(_owner);
}
function() external payable {
revert();
}
// Token dingens
string public name = "Test Event";
string public symbol = 'ETE';
address public ownerby;
eventToken[] public tickets;
constructor() public{
ownerby = msg.sender;
}
function mintTickets(uint _ticketAmount, string memory _name, uint _date, uint _tPrice) public{
require(ownerby == msg.sender);
while(tickets.length < _ticketAmount){
uint _id = tickets.length;
tickets.push(eventToken(_name, _date, _tPrice, _id));
_mint(ownerby, _id);
}
}
}
pragma solidity ^0.5.7;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
contract TicketingDapp is Ownable, ERC721 {
struct Event {
uint eventId;
string name;
string date;
string eventType;
uint ticketPrice;
uint ticketSupply;
bool eventEnded;
address organizer;
}
struct eventToken{
string eventName;
string eventDate;
uint ticketPrice;
uint ticketId;
}
uint ID;
mapping(uint => Event) public events;
address public ownerby;
uint ticketAmount = 1;
function createEvent(
string memory _name,
string memory _date,
string memory _eventType,
uint _price,
uint _ticketAmount
) public onlyOwner returns(uint _ID) {
_ID = ID++;
events[_ID] = Event ({
eventId: _ID,
name: _name,
date: _date,
eventType: _eventType,
ticketPrice: _price * 1 wei,
ticketSupply: _ticketAmount,
eventEnded: false,
organizer: msg.sender
});
return events[_ID].eventId;
}
function getEventDetails(uint _id) public view returns(string memory, string memory, string memory, uint, uint) {
//get event details
require(events[_id].eventId == _id);
return (events[_id].name,
events[_id].date,
events[_id].eventType,
events[_id].ticketPrice,
events[_id].ticketSupply);
}
function endEvent(uint _id) public onlyOwner returns(bool) {
//sets eventEnded to true
return events[_id].eventEnded = true;
}
function kill(address payable _owner) public onlyOwner {
selfdestruct(_owner);
}
function() external payable {
revert();
}
eventToken[] public tickets;
constructor() public{
ownerby = msg.sender;
}
function mintTickets(uint _ticketAmount, string memory _name, string memory _date, uint _tPrice, address buyer) public{
require(ownerby == msg.sender);
while(tickets.length < _ticketAmount){
uint _id = tickets.length;
tickets.push(eventToken(_name, _date, _tPrice, _id));
_mint(buyer, _id);
}
}
function sellToken(address payable buyer, uint amountofTicket) public payable{
require(events[ID].ticketSupply > amountofTicket);
uint256 payed = msg.value;
uint calculatedPrice = events[0].ticketPrice * amountofTicket;
if(calculatedPrice* 1 wei == payed){
mintTickets(amountofTicket, events[0].name,
events[0].date, events[0].ticketPrice, buyer);
events[0].ticketSupply = events[0].ticketSupply - amountofTicket;
}
}
}
pragma solidity ^0.5.7;
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol";
contract TicketingDapp is Ownable, ERC721 {
struct Event {
uint eventId;
string name;
string date;
string eventType;
uint ticketPrice;
uint ticketSupply;
bool eventEnded;
address organizer;
}
struct eventToken{
string eventName;
string eventDate;
uint ticketPrice;
uint ticketId;
}
uint ID;
mapping(uint => Event) public events;
address public ownerby;
uint ticketAmount = 1;
function createEvent(
string memory _name,
string memory _date,
string memory _eventType,
uint _price,
uint _ticketAmount
) public onlyOwner returns(uint _ID) {
_ID = ID++;
events[_ID] = Event ({
eventId: _ID,
name: _name,
date: _date,
eventType: _eventType,
ticketPrice: _price * 1 wei,
ticketSupply: _ticketAmount,
eventEnded: false,
organizer: msg.sender
});
return events[_ID].eventId;
}
function getEventDetails(uint _id) public view returns(string memory, string memory, string memory, uint, uint, uint) {
//get event details
require(events[_id].eventId == _id);
return (events[_id].name,
events[_id].date,
events[_id].eventType,
events[_id].ticketPrice,
events[_id].ticketSupply,
events[_id].eventId);
}
function endEvent(uint _id) public onlyOwner returns(bool) {
//sets eventEnded to true
return events[_id].eventEnded = true;
}
function kill(address payable _owner) public onlyOwner {
selfdestruct(_owner);
}
function() external payable {
revert();
}
// Token SHit
eventToken[] public tickets;
constructor() public{
ownerby = msg.sender;
}
string public name;
string public symbol;
function setTokenInfo(string memory _name, string memory _symbol) public{
name = _name;
symbol = _symbol;
}
function mintTickets(uint _ticketAmount, string memory _name, string memory _date, uint _tPrice, address buyer) public{
require(ownerby == msg.sender);
while(tickets.length < _ticketAmount){
uint _id = tickets.length;
tickets.push(eventToken(_name, _date, _tPrice, _id));
_mint(buyer, _id);
}
}
function sellToken(address payable buyer, uint amountofTicket, uint _id) public payable{
require(events[_id].ticketSupply > amountofTicket);
uint256 payed = msg.value;
uint calculatedPrice = events[_id].ticketPrice * amountofTicket;
if(calculatedPrice* 1 wei == payed){
mintTickets(amountofTicket, events[_id].name,
events[_id].date, events[_id].ticketPrice, buyer);
events[_id].ticketSupply = events[_id].ticketSupply - amountofTicket;
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment