Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Payable Contracts, Interfaces, and Inheritance #24

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Abeeujah
Copy link

@Abeeujah Abeeujah commented Aug 9, 2024

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 extending StudentRegistry through an interface.
  • IStudentRegistry.sol: Interface defining the required functions for student registry management.

Breakdown

1. StudentRegistry.sol

  • Ownership Management:

    • Inherits from the Ownable contract to control function access.
    • Implements multiple modifiers (isNotAddressZero, isOfAge, isValidName, isRegistered) to enforce business logic.
  • Error Handling:

    • Custom errors (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

  • Struct Definition:
    • Defines the Student struct with properties like studentAddr, name, studentId, age, and hasPaid.

3. Ownable.sol

  • Ownership Management:
    • Implements basic ownership functionality, including getOwner() to return the current owner and changeOwner() to transfer ownership.

4. MyStudentRegistry.sol

  • Interfacing with StudentRegistry:

    • Implements functions that interact with an external StudentRegistry contract via the IStudentRegistry interface.
  • Key Functions:

    • registerStudent(): Registers a student through the external StudentRegistry.
    • 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 external StudentRegistry.
    • retrieveStudent(): Fetches student details by address.
    • studentExpulsion(): Removes a student from the registry.

5. IStudentRegistry.sol

  • Interface Definition:
    • Defines the contract interface for StudentRegistry, ensuring that any contract implementing this interface provides the necessary functions for student management.

Code Explanation

The implementation leverages several advanced Solidity concepts:

  • Modifiers: Used to abstract common checks into reusable code blocks, ensuring that functions are only executed under certain conditions.
  • Payable Functions: Functions like registerStudent and withdraw handle Ether transfers.
  • Inheritance: StudentRegistry inherits from Ownable, enabling ownership management. MyStudentRegistry interacts with StudentRegistry through an interface.
  • Error Handling: Custom errors and require statements are used extensively to prevent invalid operations, such as registering an underage student or using an invalid address.

PR Checklist

  • Tests

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant