-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathW5day4.sol
More file actions
53 lines (38 loc) · 1.04 KB
/
W5day4.sol
File metadata and controls
53 lines (38 loc) · 1.04 KB
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
47
48
49
50
51
52
53
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
/*library MathLib {
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
}
contract Calculator {
function compute(uint256 a, uint256 b) public pure returns (uint256) {
return MathLib.add(a, b);
}
}*/
struct Wallet{
uint256 balance;
}
library WalletLib{
function deposit(Wallet storage self, uint256 amount) internal {
self.balance += amount;
}
function withdraw(Wallet storage self, uint256 amt) internal {
self.balance -= amt;
}
}
contract Wallit {
using WalletLib for Wallet;
Wallet public whaleWalet;
function deposit(uint256 amount) public {
whaleWalet.deposit(amount);
}
function withdraw(uint256 amount) public {
whaleWalet.withdraw(amount);
}
}
/*Create a struct Wallet with balance.
Create WalletLib with:
Use
Test deposit and withdraw.
Observe storage behavior carefully.*/