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

Feedback #1

Open
wants to merge 3 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/qGwB8rZX)
[![Open in Visual Studio Code](https://classroom.github.com/assets/open-in-vscode-2e0aaae1b6195c2367325f4f02e2d04e9abb55f0b24a779b69b11b9e10269abc.svg)](https://classroom.github.com/online_ide?assignment_repo_id=18752380&assignment_repo_type=AssignmentRepo)

# Description

Expand Down
21 changes: 14 additions & 7 deletions src/Assignment6.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,30 @@ pragma solidity ^0.8.13;

contract Assignment6 {
// 1. Declare an event called `FundsDeposited` with parameters: `sender` and `amount`
event FundsDeposited(address indexed sender, uint256 amount);

// 2. Declare an event called `FundsWithdrawn` with parameters: `receiver` and `amount`
event FundsWithdrawn(address indexed receiver, uint256 amount);

// 3. Create a public mapping called `balances` to tracker users balances
mapping(address => uint256) public balances;

// Modifier to check if sender has enough balance
modifier hasEnoughBalance(uint amount) {
// Fill in the logic using require
require(balances[msg.sender] >= amount, "Insufficient balance");
_;
}

// Function to deposit Ether
// This function should:
// - Be external and payable
// - Emit the `FundsDeposited` event
function deposit() {
function deposit() external payable{
// increment user balance in balances mapping

balances[msg.sender] += msg.value;
// emit suitable event
emit FundsDeposited(msg.sender, msg.value);
}

// Function to withdraw Ether
Expand All @@ -30,21 +35,23 @@ contract Assignment6 {
// - Take one parameter: `amount`
// - Use the `hasEnoughBalance` modifier
// - Emit the `FundsWithdrawn` event
function withdraw() {
// decrement user balance from balances mapping
function withdraw(uint256 amount) external hasEnoughBalance(amount) {
// decrement user balance from balances mapping
balances[msg.sender] -= amount;

// send tokens to the caller
payable(msg.sender).transfer(amount);

// emit suitable event

emit FundsWithdrawn(msg.sender, amount);
}

// Function to check the contract balance
// This function should:
// - Be public and view
// - Return the contract's balance
function getContractBalance() {
function getContractBalance() public view returns(uint256){
// return the balance of the contract

return address(this).balance;
}
}
Loading