mirror of
https://github.com/0xShay/ticketchain.git
synced 2026-01-11 21:23:24 +00:00
update .gitignore to remove cache
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -36,3 +36,4 @@ yarn-error.log*
|
|||||||
next-env.d.ts
|
next-env.d.ts
|
||||||
artifacts
|
artifacts
|
||||||
typechain-types
|
typechain-types
|
||||||
|
cache
|
||||||
2044
cache/solidity-files-cache.json
vendored
2044
cache/solidity-files-cache.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -2,11 +2,22 @@
|
|||||||
|
|
||||||
pragma solidity >=0.8.2 <0.9.0;
|
pragma solidity >=0.8.2 <0.9.0;
|
||||||
|
|
||||||
import {ContractRegistry} from "@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol";
|
import {ContractRegistry} from '@flarenetwork/flare-periphery-contracts/coston2/ContractRegistry.sol';
|
||||||
/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */
|
/* THIS IS A TEST IMPORT, in production use: import {FtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/FtsoV2Interface.sol"; */
|
||||||
import {TestFtsoV2Interface} from "@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol";
|
import {TestFtsoV2Interface} from '@flarenetwork/flare-periphery-contracts/coston2/TestFtsoV2Interface.sol';
|
||||||
|
|
||||||
contract EventManager {
|
contract EventManager {
|
||||||
|
TestFtsoV2Interface internal ftsoV2;
|
||||||
|
bytes21[] public feedIds = [
|
||||||
|
bytes21(0x01464c522f55534400000000000000000000000000) // FLR/USD
|
||||||
|
// bytes21(0x014254432f55534400000000000000000000000000), // BTC/USD
|
||||||
|
// bytes21(0x014554482f55534400000000000000000000000000) // ETH/USD
|
||||||
|
];
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
/* THIS IS A TEST METHOD, in production use: ftsoV2 = ContractRegistry.getFtsoV2(); */
|
||||||
|
ftsoV2 = ContractRegistry.getTestFtsoV2();
|
||||||
|
}
|
||||||
|
|
||||||
struct Event {
|
struct Event {
|
||||||
string name;
|
string name;
|
||||||
@@ -27,9 +38,18 @@ contract EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
event EventCreated(uint256 eventId, string name, uint256 eventDate);
|
event EventCreated(uint256 eventId, string name, uint256 eventDate);
|
||||||
event TicketPurchased(uint256 ticketId, uint256 eventId, address buyer, uint256 price);
|
event TicketPurchased(
|
||||||
|
uint256 ticketId,
|
||||||
|
uint256 eventId,
|
||||||
|
address buyer,
|
||||||
|
uint256 price
|
||||||
|
);
|
||||||
event TicketTransferred(uint256 ticketId, address from, address to);
|
event TicketTransferred(uint256 ticketId, address from, address to);
|
||||||
event TicketTransferApproved(uint256 ticketId, address owner, address trustee);
|
event TicketTransferApproved(
|
||||||
|
uint256 ticketId,
|
||||||
|
address owner,
|
||||||
|
address trustee
|
||||||
|
);
|
||||||
|
|
||||||
mapping(uint256 => Event) public events;
|
mapping(uint256 => Event) public events;
|
||||||
mapping(uint256 => Ticket) public tickets;
|
mapping(uint256 => Ticket) public tickets;
|
||||||
@@ -41,15 +61,23 @@ contract EventManager {
|
|||||||
uint256 public eventCounter;
|
uint256 public eventCounter;
|
||||||
uint256 public ticketCounter;
|
uint256 public ticketCounter;
|
||||||
|
|
||||||
function getFtsoV2CurrentFeedValues() public view returns (
|
function getFtsoV2CurrentFeedValues()
|
||||||
|
public
|
||||||
|
view
|
||||||
|
returns (
|
||||||
uint256[] memory _feedValues,
|
uint256[] memory _feedValues,
|
||||||
int8[] memory _decimals,
|
int8[] memory _decimals,
|
||||||
uint64 _timestamp
|
uint64 _timestamp
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
return ftsoV2.getFeedsById(feedIds);
|
return ftsoV2.getFeedsById(feedIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFlareFeed() public view returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp) {
|
function getFlareFeed()
|
||||||
|
public
|
||||||
|
view
|
||||||
|
returns (uint256 _feedValue, int8 _decimals, uint64 _timestamp)
|
||||||
|
{
|
||||||
uint256[] memory feedValues;
|
uint256[] memory feedValues;
|
||||||
int8[] memory decimals;
|
int8[] memory decimals;
|
||||||
uint64 timestamp;
|
uint64 timestamp;
|
||||||
@@ -61,11 +89,11 @@ contract EventManager {
|
|||||||
uint256 feedValue;
|
uint256 feedValue;
|
||||||
int8 decimals;
|
int8 decimals;
|
||||||
(feedValue, decimals, ) = getFlareFeed();
|
(feedValue, decimals, ) = getFlareFeed();
|
||||||
return _cents * power(10, decimals) * 1 ether / 100 / feedValue;
|
return (_cents * power(10, decimals) * 1 ether) / 100 / feedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
function power(uint base, int8 exponent) private pure returns (uint) {
|
function power(uint base, int8 exponent) private pure returns (uint) {
|
||||||
require(exponent >= 0, "Exponent must be non-negative");
|
require(exponent >= 0, 'Exponent must be non-negative');
|
||||||
uint result = 1;
|
uint result = 1;
|
||||||
for (int8 i = 0; i < exponent; i++) {
|
for (int8 i = 0; i < exponent; i++) {
|
||||||
result *= base;
|
result *= base;
|
||||||
@@ -73,39 +101,70 @@ contract EventManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEventPriceFlare(uint256 _eventId) public view returns (uint256 _flr) {
|
function getEventPriceFlare(
|
||||||
require(_eventId < eventCounter, "Invalid event ID");
|
uint256 _eventId
|
||||||
|
) public view returns (uint256 _flr) {
|
||||||
|
require(_eventId < eventCounter, 'Invalid event ID');
|
||||||
return centsToFlare(events[_eventId].ticketPrice);
|
return centsToFlare(events[_eventId].ticketPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createEvent(string memory _name, string memory _description, uint256 _capacity, uint256 _ticketPrice, uint256 _eventDate, string[] memory _images) public returns (uint256 _eventId) {
|
function createEvent(
|
||||||
events[eventCounter] = Event(_name, _description, _capacity, 0, _ticketPrice, _eventDate, _images, new uint256[](0), payable(msg.sender));
|
string memory _name,
|
||||||
|
string memory _description,
|
||||||
|
uint256 _capacity,
|
||||||
|
uint256 _ticketPrice,
|
||||||
|
uint256 _eventDate,
|
||||||
|
string[] memory _images
|
||||||
|
) public returns (uint256 _eventId) {
|
||||||
|
events[eventCounter] = Event(
|
||||||
|
_name,
|
||||||
|
_description,
|
||||||
|
_capacity,
|
||||||
|
0,
|
||||||
|
_ticketPrice,
|
||||||
|
_eventDate,
|
||||||
|
_images,
|
||||||
|
new uint256[](0),
|
||||||
|
payable(msg.sender)
|
||||||
|
);
|
||||||
eventCounter++;
|
eventCounter++;
|
||||||
emit EventCreated(eventCounter - 1, _name, _eventDate);
|
emit EventCreated(eventCounter - 1, _name, _eventDate);
|
||||||
return eventCounter - 1;
|
return eventCounter - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEventImages(uint256 _eventId) public view returns (string[] memory) {
|
function getEventImages(
|
||||||
require(_eventId < eventCounter, "Invalid event ID");
|
uint256 _eventId
|
||||||
|
) public view returns (string[] memory) {
|
||||||
|
require(_eventId < eventCounter, 'Invalid event ID');
|
||||||
return events[_eventId].images;
|
return events[_eventId].images;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEventTickets(uint256 _eventId) public view returns (uint256[] memory) {
|
function getEventTickets(
|
||||||
require(_eventId < eventCounter, "Invalid event ID");
|
uint256 _eventId
|
||||||
|
) public view returns (uint256[] memory) {
|
||||||
|
require(_eventId < eventCounter, 'Invalid event ID');
|
||||||
return events[_eventId].tickets;
|
return events[_eventId].tickets;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buyTicket(uint256 _eventId) public payable returns (uint256 _ticketId) {
|
function buyTicket(
|
||||||
require(_eventId < eventCounter, "Invalid event ID");
|
uint256 _eventId
|
||||||
require(events[_eventId].eventDate > block.timestamp, "Event has already passed");
|
) public payable returns (uint256 _ticketId) {
|
||||||
require(events[_eventId].tickets.length < events[_eventId].capacity, "Event is full");
|
require(_eventId < eventCounter, 'Invalid event ID');
|
||||||
|
require(
|
||||||
|
events[_eventId].eventDate > block.timestamp,
|
||||||
|
'Event has already passed'
|
||||||
|
);
|
||||||
|
require(
|
||||||
|
events[_eventId].tickets.length < events[_eventId].capacity,
|
||||||
|
'Event is full'
|
||||||
|
);
|
||||||
|
|
||||||
uint256 ticketCost = getEventPriceFlare(_eventId); // Get ticket price in FLR
|
uint256 ticketCost = getEventPriceFlare(_eventId); // Get ticket price in FLR
|
||||||
require(msg.value >= ticketCost, "Insufficient value provided"); // Ensure user has paid >= ticket price
|
require(msg.value >= ticketCost, 'Insufficient value provided'); // Ensure user has paid >= ticket price
|
||||||
if (msg.value > ticketCost) {
|
if (msg.value > ticketCost) {
|
||||||
// Pay any excess the user paid
|
// Pay any excess the user paid
|
||||||
(bool sentExcess, ) = msg.sender.call{value: msg.value - ticketCost}("");
|
(bool sentExcess, ) = msg.sender.call{value: msg.value - ticketCost}('');
|
||||||
require(sentExcess, "Failed to send FLR excess back to buyer");
|
require(sentExcess, 'Failed to send FLR excess back to buyer');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new ticket
|
// Create new ticket
|
||||||
@@ -121,16 +180,21 @@ contract EventManager {
|
|||||||
events[_eventId].ticketsSold++;
|
events[_eventId].ticketsSold++;
|
||||||
|
|
||||||
// Transfer FLR to event host
|
// Transfer FLR to event host
|
||||||
(bool sentToHost, ) = events[_eventId].eventHost.call{value: ticketCost}("");
|
(bool sentToHost, ) = events[_eventId].eventHost.call{value: ticketCost}(
|
||||||
require(sentToHost, "Failed to send FLR to event host");
|
''
|
||||||
|
);
|
||||||
|
require(sentToHost, 'Failed to send FLR to event host');
|
||||||
|
|
||||||
emit TicketPurchased(ticketCounter - 1, _eventId, msg.sender, ticketCost);
|
emit TicketPurchased(ticketCounter - 1, _eventId, msg.sender, ticketCost);
|
||||||
return ticketCounter - 1;
|
return ticketCounter - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferTicketForce(uint256 _ticketId, address _to) private {
|
function transferTicketForce(uint256 _ticketId, address _to) private {
|
||||||
require(_ticketId < ticketCounter, "Invalid ticket ID");
|
require(_ticketId < ticketCounter, 'Invalid ticket ID');
|
||||||
require(events[tickets[_ticketId].eventId].eventDate > block.timestamp, "Event has already passed");
|
require(
|
||||||
|
events[tickets[_ticketId].eventId].eventDate > block.timestamp,
|
||||||
|
'Event has already passed'
|
||||||
|
);
|
||||||
|
|
||||||
address prevHolder = tickets[_ticketId].holder;
|
address prevHolder = tickets[_ticketId].holder;
|
||||||
|
|
||||||
@@ -161,23 +225,31 @@ contract EventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function approveTicket(uint256 _ticketId, address _to, bool _allowed) public {
|
function approveTicket(uint256 _ticketId, address _to, bool _allowed) public {
|
||||||
require(_ticketId < ticketCounter, "Invalid ticket ID");
|
require(_ticketId < ticketCounter, 'Invalid ticket ID');
|
||||||
require(tickets[_ticketId].holder == msg.sender, "You do not own this ticket");
|
require(
|
||||||
|
tickets[_ticketId].holder == msg.sender,
|
||||||
|
'You do not own this ticket'
|
||||||
|
);
|
||||||
ticketAllowance[_ticketId][_to] = _allowed;
|
ticketAllowance[_ticketId][_to] = _allowed;
|
||||||
|
|
||||||
emit TicketTransferApproved(_ticketId, msg.sender, _to);
|
emit TicketTransferApproved(_ticketId, msg.sender, _to);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferTicketFrom(uint256 _ticketId, address _to) public {
|
function transferTicketFrom(uint256 _ticketId, address _to) public {
|
||||||
require(ticketAllowance[_ticketId][msg.sender], "You are not allowed to transfer this ticket");
|
require(
|
||||||
|
ticketAllowance[_ticketId][msg.sender],
|
||||||
|
'You are not allowed to transfer this ticket'
|
||||||
|
);
|
||||||
ticketAllowance[_ticketId][msg.sender] = false;
|
ticketAllowance[_ticketId][msg.sender] = false;
|
||||||
transferTicketForce(_ticketId, _to);
|
transferTicketForce(_ticketId, _to);
|
||||||
}
|
}
|
||||||
|
|
||||||
function transferTicket(uint256 _ticketId, address _to) public {
|
function transferTicket(uint256 _ticketId, address _to) public {
|
||||||
require(_ticketId < ticketCounter, "Invalid ticket ID");
|
require(_ticketId < ticketCounter, 'Invalid ticket ID');
|
||||||
require(tickets[_ticketId].holder == msg.sender, "You do not own this ticket");
|
require(
|
||||||
|
tickets[_ticketId].holder == msg.sender,
|
||||||
|
'You do not own this ticket'
|
||||||
|
);
|
||||||
transferTicketForce(_ticketId, _to);
|
transferTicketForce(_ticketId, _to);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user