Skip to content

Commit

Permalink
function endEvents
Browse files Browse the repository at this point in the history
after the end of the events the endevents function will delete the event in the array
  • Loading branch information
SIDHARTH20K4 committed Jan 27, 2024
1 parent 24be9c4 commit c118042
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions web3/contracts/Nft.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@ contract Nft {
uint256 currentTime = block.timestamp;
struct Event{
string eventName;
string evntVenue;
string eventVenue;
uint256 Time;
uint256 Duration;
string createrName;
address creatorAddress;
string imgUrl;
}

Event[] public events; // creation of dynamic array
struct Person{
string Name;
bytes1 Gender;
uint256 Age;
}

Event public myEvent;
Event public myEvent; // creating an instance for this event struct

function createEvent(
string calldata _eventName,
string calldata _evntVenue,
Expand All @@ -29,19 +30,35 @@ contract Nft {
address _creatorAddress,
string memory _imgUrl
)
public returns (uint)
public
{
require(_Time > block.timestamp,"event time must be in future");

myEvent.eventName = _eventName;
myEvent.evntVenue = _evntVenue;
myEvent.eventVenue = _evntVenue;
myEvent.Duration = _Duration;
myEvent.creatorAddress = _creatorAddress;
myEvent.imgUrl = _imgUrl;
myEvent.Time = _Time + currentTime;

if (_Time < currentTime){
return 0;
}
else {
myEvent.Time = _Time + currentTime;
//pushing the event details to the array
Event memory newEvent;
newEvent = myEvent;
events.push(newEvent);
}


function endEvents() private {
uint256 i = 0;
while (i < events.length) {
if (events[i].Time + events[i].Duration < block.timestamp) {
if (i < events.length - 1) {
events[i] = events[events.length - 1];
}
events.pop();
} else {
i++;
}
}
}
}

0 comments on commit c118042

Please sign in to comment.