-
Notifications
You must be signed in to change notification settings - Fork 0
/
SharedWallet.sol
63 lines (45 loc) · 1.79 KB
/
SharedWallet.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
pragma solidity ^0.5.13;
contract SharedWallet {
address payable public owner;
mapping(address => uint) public wallet;
event walletToppedUp(address indexed to, address indexed from, uint amount);
event walletWithdrawn(address indexed account, uint amount);
constructor() public {
owner = msg.sender;
}
modifier isOwner {
require (msg.sender == owner, "This operation is reserved to the wallet owner!");
_;
}
function topUp() public payable {
assert(wallet[msg.sender] + msg.value > wallet[msg.sender]);
wallet[msg.sender] += msg.value;
emit walletToppedUp(msg.sender, msg.sender, msg.value);
}
function topUpWallet(address payable toAddress) public payable isOwner {
assert(wallet[toAddress] + msg.value > wallet[toAddress]);
wallet[toAddress] += msg.value;
emit walletToppedUp(toAddress, msg.sender, msg.value);
}
function withdraw(uint amount) public {
assert(wallet[msg.sender] - amount < wallet[msg.sender]);
assert(wallet[msg.sender] - amount >= 0);
wallet[msg.sender] -= amount;
address(msg.sender).transfer(amount);
emit walletWithdrawn(msg.sender, amount);
}
function withdrawFromWallet(address fromAddress, uint amount) public isOwner {
assert(wallet[fromAddress] - amount < wallet[fromAddress]);
assert(wallet[fromAddress] - amount >= 0);
wallet[fromAddress] -= amount;
owner.transfer(amount);
emit walletWithdrawn(fromAddress, amount);
}
//fallback function
function () external payable {
topUp();
}
function terminateWallet() public isOwner {
selfdestruct(owner);
}
}