-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathSharedWallet.sol
More file actions
61 lines (49 loc) · 1.89 KB
/
SharedWallet.sol
File metadata and controls
61 lines (49 loc) · 1.89 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
// SPDX-License-Identifier: MIT
//
// https://cryptomarketpool.com/shared-wallet-solidity-smart-contract/
pragma solidity ^0.8.0;
contract SharedWallet {
address private _owner;
// list of shared owners. bool is used to determine is the address enabled of disabled
mapping(address => bool) private _owners;
// required owner of the contract
modifier isOwner() {
require(msg.sender == _owner, "Not contract owner");
_;
}
// required to be valid either contract owner or enabled owner of shared wallet
modifier validOwner() {
require(msg.sender == _owner || _owners[msg.sender], "Not contract owner or owners of shared wallet");
_;
}
event DepositFunds(address from, uint256 amount);
event WithdrawFunds(address from, uint256 amount);
event TransferFunds(address from, address to, uint256 amount);
constructor() {
_owner = msg.sender;
}
// add an owner of shared wallet
function addOwner(address owner) public isOwner {
_owners[owner] = true;
}
// remove an owner of shared wallet
function removeOwner(address owner) public isOwner {
_owners[owner] = false;
}
// receive the deposit into shared wallet (contract's balance)
receive() external payable {
emit DepositFunds(msg.sender, msg.value);
}
// withdraw fund from the shared wallet into the signer of transaction
function withdraw(uint256 amount) public validOwner {
require(address(this).balance >= amount);
payable(msg.sender).transfer(amount);
emit WithdrawFunds(msg.sender, amount);
}
// transfer fund from the shared wallet into another address
function transferTo(address payable to, uint256 amount) public validOwner {
require(address(this).balance >= amount);
payable(to).transfer(amount);
emit TransferFunds(msg.sender, to, amount);
}
}