-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimpleMultiWallet.sol
49 lines (35 loc) · 1.43 KB
/
simpleMultiWallet.sol
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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.11;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeMath.sol";
contract SimpleWallet is Ownable {
using SafeMath for uint;
mapping(address => uint256) funds;
receive() external payable {
depositFunds();
}
function destroy() public payable onlyOwner {
selfdestruct(payable(owner()));
}
function withdrawFunds(uint256 _amount) public payable {
require(_amount <= address(this).balance, "Not enough in wallet");
require(_amount <= funds[msg.sender], "Not enough allocated for you");
funds[msg.sender] = funds[msg.sender].sub(_amount);
payable(msg.sender).transfer(_amount);
}
function changeAllocationForAddress(address _address, uint256 _amount) public onlyOwner {
require(_amount >= 0);
require(_amount <= getTotalBalance());
funds[_address] = _amount;
}
function depositFunds() public payable {
funds[msg.sender] = funds[msg.sender].add(msg.value);
funds[owner()] = address(this).balance;
}
function getTotalBalance() public view returns (uint256) {
return address(this).balance;
}
function getUserBalance() public view returns (uint256) {
return funds[msg.sender];
}
}