Skip to content

Commit

Permalink
Merge pull request #60 from pradyumna14/pradyumna14-patch-1
Browse files Browse the repository at this point in the history
Prevent duplicate registrations and add input validation
  • Loading branch information
Ramsey99 authored Oct 21, 2024
2 parents 61e78f1 + 523e4d1 commit bc0ce9c
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions contracts/event_registration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ contract EventRegistration {
mapping(address => Participant) public participants;
address[] public participantAddresses;

event ParticipantRegistered(
address indexed participantAddress,
string fullname,
string eventName
);
event ParticipantUpdated(
address indexed participantAddress,
string fullname,
string eventName
);

function registerParticipant(
string memory _fullname,
string memory _stream,
Expand All @@ -22,16 +33,28 @@ contract EventRegistration {
string memory _phno,
string memory _roll
) public {
Participant memory newParticipant = Participant({
require(bytes(_fullname).length > 0, "Full name is required.");
require(bytes(_stream).length > 0, "Stream is required.");
require(bytes(_eventName).length > 0, "Event name is required.");
require(bytes(_email).length > 0, "Email is required.");
require(bytes(_phno).length > 0, "Phone number is required.");
require(bytes(_roll).length > 0, "Roll number is required.");

if (bytes(participants[msg.sender].fullname).length == 0) {
participantAddresses.push(msg.sender);
emit ParticipantRegistered(msg.sender, _fullname, _eventName);
} else {
emit ParticipantUpdated(msg.sender, _fullname, _eventName);
}

participants[msg.sender] = Participant({
fullname: _fullname,
stream: _stream,
eventName: _eventName,
email: _email,
phno: _phno,
roll: _roll
});
participants[msg.sender] = newParticipant;
participantAddresses.push(msg.sender);
}

function getParticipant(address _addr)
Expand Down

0 comments on commit bc0ce9c

Please sign in to comment.