Implement Payable Contracts, Interfaces, and Inheritance #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Smart contract for registering and managing students
Files Modified:
StudentRegistry.sol
: Main contract implementing the student registry logic.Student.sol
: Struct definition for student data.Ownable.sol
: Contract providing ownership management functionality.MyStudentRegistry.sol
: Custom implementation extendingStudentRegistry
through an interface.IStudentRegistry.sol
: Interface defining the required functions for student registry management.Breakdown
1. StudentRegistry.sol
Ownership Management:
Ownable
contract to control function access.isNotAddressZero
,isOfAge
,isValidName
,isRegistered
) to enforce business logic.Error Handling:
NameIsEmpty
,NotRegistered
,UnderAge
) to improve UX by providing clear feedback on issues encountered.Events:
Registration
: Emitted during various stages of student management (registration, enlistment, updates, deletions).Student Management:
registerStudent()
: Registers a student and requires a fee of 1 Ether.authorizeStudentRegistration()
: Allows the contract owner to confirm a student's registration.updateStudent()
: Updates student details.deleteStudent()
: Deletes a student record.Contract Management:
withdraw()
: Allows the owner to withdraw the contract’s balance.getBalance()
: Returns the current contract balance.2. Student.sol
Student
struct with properties likestudentAddr
,name
,studentId
,age
, andhasPaid
.3. Ownable.sol
getOwner()
to return the current owner andchangeOwner()
to transfer ownership.4. MyStudentRegistry.sol
Interfacing with
StudentRegistry
:StudentRegistry
contract via theIStudentRegistry
interface.Key Functions:
registerStudent()
: Registers a student through the externalStudentRegistry
.studentRegistration()
: Handles student registration and fee validation.studentEnlistment()
: Authorizes student enlistment.studentUpdate()
: Updates student details.withdrawEarnings()
: Withdraws contract balance.registryEarnings()
: Retrieves the balance of the externalStudentRegistry
.retrieveStudent()
: Fetches student details by address.studentExpulsion()
: Removes a student from the registry.5. IStudentRegistry.sol
StudentRegistry
, ensuring that any contract implementing this interface provides the necessary functions for student management.Code Explanation
The implementation leverages several advanced Solidity concepts:
registerStudent
andwithdraw
handle Ether transfers.StudentRegistry
inherits fromOwnable
, enabling ownership management.MyStudentRegistry
interacts withStudentRegistry
through an interface.require
statements are used extensively to prevent invalid operations, such as registering an underage student or using an invalid address.PR Checklist
Testing
The implementation has been tested using Remix IDE to ensure that all functions perform as expected.
Documentation
Documentation
The contract is documented using NatSpec format.