Repository navigation
Expand file tree
/
Copy pathSmartWallet.sol
More file actions
62 lines (47 loc) · 1.99 KB
/
Copy pathSmartWallet.sol
File metadata and controls
62 lines (47 loc) · 1.99 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
54
55
56
57
58
59
60
61
62
//SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
contract SampleWallet {
address payable owner;
mapping(address => uint) public allowance;
mapping(address => bool) public isAllowedToSend;
mapping(address => bool) public guardian;
address payable nextOwner;
uint guardiansResetCount;
uint public constant confirmationsFromGuardiansForReset = 3;
constructor() {
owner = payable(msg.sender);
}
function proposeNewOwner(address payable newOwner) public {
require(guardian[msg.sender], "You are no guardian, aborting");
if(nextOwner != newOwner) {
nextOwner = newOwner;
guardiansResetCount = 0;
}
guardiansResetCount++;
if(guardiansResetCount >= confirmationsFromGuardiansForReset) {
owner = nextOwner;
nextOwner = payable(address(0));
}
}
function setAllowance(address _from, uint _amount) public {
require(msg.sender == owner, "You are not the owner, aborting!");
allowance[_from] = _amount;
isAllowedToSend[_from] = true;
}
function denySending(address _from) public {
require(msg.sender == owner, "You are not the owner, aborting!");
isAllowedToSend[_from] = false;
}
function transfer(address payable _to, uint _amount, bytes memory payload) public returns (bytes memory) {
require(_amount <= address(this).balance, "Can't send more than the contract owns, aborting.");
if(msg.sender != owner) {
require(isAllowedToSend[msg.sender], "You are not allowed to send any transactions, aborting");
require(allowance[msg.sender] >= _amount, "You are trying to send more than you are allowed to, aborting");
allowance[msg.sender] -= _amount;
}
(bool success, bytes memory returnData) = _to.call{value: _amount}(payload);
require(success, "Transaction failed, aborting");
return returnData;
}
receive() external payable {}
}