Skip to content

Commit 609fd2a

Browse files
🔥feat solved adder assignment
1 parent 5460323 commit 609fd2a

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Assignment6.sol

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,30 @@ pragma solidity ^0.8.13;
33

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

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

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

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

1721
// Function to deposit Ether
1822
// This function should:
1923
// - Be external and payable
2024
// - Emit the `FundsDeposited` event
21-
function deposit() {
25+
function deposit() external payable{
2226
// increment user balance in balances mapping
23-
27+
balances[msg.sender] += msg.value;
2428
// emit suitable event
29+
emit FundsDeposited(msg.sender, msg.value);
2530
}
2631

2732
// Function to withdraw Ether
@@ -30,21 +35,23 @@ contract Assignment6 {
3035
// - Take one parameter: `amount`
3136
// - Use the `hasEnoughBalance` modifier
3237
// - Emit the `FundsWithdrawn` event
33-
function withdraw() {
34-
// decrement user balance from balances mapping
38+
function withdraw(uint256 amount) external hasEnoughBalance(amount) {
39+
// decrement user balance from balances mapping
40+
balances[msg.sender] -= amount;
3541

3642
// send tokens to the caller
43+
payable(msg.sender).transfer(amount);
3744

3845
// emit suitable event
39-
46+
emit FundsWithdrawn(msg.sender, amount);
4047
}
4148

4249
// Function to check the contract balance
4350
// This function should:
4451
// - Be public and view
4552
// - Return the contract's balance
46-
function getContractBalance() {
53+
function getContractBalance() public view returns(uint256){
4754
// return the balance of the contract
48-
55+
return address(this).balance;
4956
}
5057
}

0 commit comments

Comments
 (0)