Created
April 24, 2020 16:44
-
-
Save ogwurujohnson/128caea6c3705a25b4510957cfab5030 to your computer and use it in GitHub Desktop.
A multi signatory smart contract for sending funds on the block chain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.0; | |
pragma experimental ABIEncoderV2; | |
contract MultiSigWallet { | |
uint minApprovers; | |
address beneficiary; | |
address owner; | |
mapping(address => bool) approvedBy; | |
mapping(address => bool) isApprover; | |
uint approvalsNum; | |
constructor(address _beneficiary, uint _minApprovers, address[] _approvers) public payable { | |
require(_minApprovers <= _approvers.length, "Required number of approvers should be less than number of approvers"); | |
minApprovers = _minApprovers; | |
beneficiary = _beneficiary; | |
owner = msg.sender; | |
for (uint i = 0; i < _approvers.length; i++) { | |
address approver = _approvers[i]; | |
isApprover[approver] = true; | |
} | |
} | |
function approve() public { | |
require(isApprover[msg.sender], 'Not an approver'); | |
if (!approvedBy[msg.sender]) { | |
approvalsNum++; | |
approvedBy[msg.sender] = true; | |
} | |
if (approvalsNum == minApprovers) { | |
beneficiary.send(address(this).balance); | |
selfdestruct(owner); | |
} | |
} | |
function reject() public { | |
require(isApprover[msg.sender], 'Not an approver'); | |
selfdestruct(owner); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment