-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW5day6.sol
More file actions
46 lines (35 loc) · 955 Bytes
/
W5day6.sol
File metadata and controls
46 lines (35 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract BaseAccess{
address owner;
constructor(){
owner = msg.sender;
}
error notOwner();
modifier onlyOwner(){
require(owner == msg.sender, notOwner());
_;
}
}
library SavingsLib{
struct Account{
uint256 increase;
uint256 decrease;
}
function deposit(Account storage self, uint256 amount) internal {
self.increase += amount;
}
function withdraw(Account storage self, uint256 amount) internal {
self.increase -= amount;
}
}
contract Savings is BaseAccess{
using SavingsLib for SavingsLib.Account;
SavingsLib.Account private account;
function deposit(uint256 amount) public payable {
account.deposit(amount);
}
function withdaw(uint256 amount) public payable onlyOwner {
account.withdraw(amount);
}
}