-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTestContract.sol
More file actions
41 lines (32 loc) · 1.19 KB
/
TestContract.sol
File metadata and controls
41 lines (32 loc) · 1.19 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
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.2 <0.9.0;
contract TestContract {
event Deposit(address indexed destination, uint256 amount);
event Withdraw(address indexed destination, uint256 amount);
event ValueChanged(uint256 oldValue, uint256 newValue);
mapping(address => uint256) private balances;
uint256 private value;
function save(address destination) public payable {
uint256 amount = msg.value;
balances[destination] += amount;
emit Deposit(destination, amount);
}
function setValue(uint256 _value) external {
emit ValueChanged(value, _value);
value = _value;
}
function retrieveValue() external view returns (uint256) {
return value;
}
function getBalance(address destination) external view returns (uint256) {
return balances[destination];
}
function withdraw() external {
uint256 balance = balances[msg.sender];
require(balance > 0, "Insufficient balance");
balances[msg.sender] = 0;
(bool success,) = msg.sender.call{value: balance}("");
require(success, "Error sending the tokens");
emit Withdraw(msg.sender, value);
}
}