-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
16,238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Sample Hardhat Project | ||
|
||
This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, and a script that deploys that contract. | ||
|
||
Try running some of the following tasks: | ||
|
||
```shell | ||
npx hardhat help | ||
npx hardhat test | ||
REPORT_GAS=true npx hardhat test | ||
npx hardhat node | ||
npx hardhat run scripts/deploy.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.9; | ||
|
||
interface IScore { | ||
event SetScore(address indexed student, uint256 score); | ||
|
||
function setScore(address student, uint256 score) external; | ||
function getScore(address student) external view returns(uint256 score); | ||
|
||
} | ||
|
||
contract Score is IScore { | ||
address public teacher; | ||
address public owner; | ||
mapping(address => uint256) private scores; | ||
|
||
error NotOwner(); | ||
error NotTeacher(); | ||
error InvalidScore(); | ||
error ZeroAddress(); | ||
|
||
constructor(address teacher_) { | ||
owner = msg.sender; | ||
teacher = teacher_; | ||
} | ||
|
||
modifier onlyTeacher() { | ||
if(msg.sender != teacher) revert NotTeacher(); | ||
_; | ||
} | ||
|
||
modifier onlyOwner() { | ||
if(msg.sender != owner) revert NotOwner(); | ||
_; | ||
} | ||
|
||
function setScore(address student, uint256 score) onlyTeacher external override { | ||
if(msg.sender == address(0)) revert ZeroAddress(); | ||
if(score > 100) revert InvalidScore(); | ||
scores[student] = score; | ||
emit SetScore(student,score); | ||
} | ||
|
||
function getScore(address student) external view override returns (uint256){ | ||
return scores[student]; | ||
} | ||
|
||
function setTeacher(address teacher_) onlyOwner external { | ||
teacher = teacher_; | ||
} | ||
|
||
function getTeacher() external view returns(address) { | ||
return teacher; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.9; | ||
import "./Score.sol"; | ||
|
||
contract Teacher{ | ||
|
||
function callSetScore(IScore scoreContract, address student, uint256 score) external { | ||
scoreContract.setScore(student, score); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require("@nomicfoundation/hardhat-toolbox"); | ||
require("@nomiclabs/hardhat-etherscan"); | ||
const dotenv = require("dotenv"); | ||
|
||
dotenv.config(); | ||
|
||
/** @type import('hardhat/config').HardhatUserConfig */ | ||
module.exports = { | ||
solidity: "0.8.18", | ||
networks: { | ||
hardhat: {}, | ||
goerli: { | ||
url: process.env.GOERLI_RPC_URL, | ||
accounts: [process.env.PRIVATE_KEY] | ||
} | ||
}, | ||
etherscan: { | ||
apiKey: process.env.ETHERSCAN_KEY | ||
}, | ||
|
||
}; |
Oops, something went wrong.