-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiSign.sol
76 lines (57 loc) · 2.12 KB
/
multiSign.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
64
65
66
67
68
69
70
71
72
73
74
75
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
contract multiSign{
address[] public owners;
mapping(address => bool) public ownerList;
mapping(uint => mapping(address => bool)) public alreadyVoted;
uint public approvalsNeeded;
struct transaction{
address sendTo;
uint amount;
uint approvals;
bool execution;
}
transaction[] public proposedTransactions;
constructor(){
ownerList[msg.sender] = true;
owners.push(msg.sender);
}
receive() external payable{}
modifier onlyOwner{
require(ownerList[msg.sender] == true, "Only owner is allowed");
_;
}
function setApprovalsNeeded(uint need) public {
approvalsNeeded = need;
}
function addOwner(address newOwner) onlyOwner public {
owners.push(newOwner);
ownerList[newOwner] = true;
}
function proposeTransaction(address to, uint value) public {
proposedTransactions.push(transaction({
sendTo: to,
amount: value,
approvals: 0,
execution: false
}));
}
function voteTransaction(uint index) onlyOwner public {
require(alreadyVoted[index][msg.sender]==false, "Already voted");
proposedTransactions[index].approvals += 1;
alreadyVoted[index][msg.sender] = true;
}
function revokeVote(uint index) onlyOwner public {
require(alreadyVoted[index][msg.sender]==true, "No Previous vote found to revoke");
proposedTransactions[index].approvals -= 1;
alreadyVoted[index][msg.sender] = false;
}
function executeTx(uint index) onlyOwner public{
require(proposedTransactions[index].approvals >= approvalsNeeded,"No enough approvals");
require(proposedTransactions[index].execution==false, "Already executed");
address payable sender = payable(proposedTransactions[index].sendTo);
(bool tryToSend,) = sender.call{value: proposedTransactions[index].amount, gas: 5000}("");
require(tryToSend== true,"No enough ETH balance");
proposedTransactions[index].execution = true;
}
}