Last active
July 30, 2018 17:59
-
-
Save micahriggan/576b73566679e86cbb4e12ca249f4f96 to your computer and use it in GitHub Desktop.
Multi-Sig Smart Contract
This file contains hidden or 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
vim: set ft=solidity: | |
pragma solidity ^0.4.24; | |
contract MultiSig { | |
struct Proposal { | |
address to; | |
uint amount; | |
mapping(address => bool) signers; | |
bool finalized; | |
} | |
address[] public signers; | |
mapping(address => bool) canSign; | |
Proposal[] public proposals; | |
constructor(address[] initSigners) public { | |
signers = initSigners; | |
for(uint i = 0; i < signers.length; i++) { | |
canSign[signers[i]] = true; | |
} | |
} | |
function () payable public { | |
// allow this contract to receive eth | |
} | |
modifier isSigner(address potentialSigner ) { | |
require(canSign[potentialSigner]); | |
_; | |
} | |
function proposeSend(address to, uint value) public isSigner(msg.sender) { | |
proposals.push(Proposal({ | |
to: to, | |
amount: value, | |
finalized: false | |
})); | |
} | |
function sign(uint proposalIndex) public isSigner(msg.sender) { | |
proposals[proposalIndex].signers[msg.sender] = true; | |
} | |
function checkAllSigned(uint proposalIndex) public view returns(bool) { | |
bool allSigned = true; | |
for(uint i = 0; i < signers.length; i++) { | |
if(proposals[proposalIndex].signers[signers[i]] == false) { | |
allSigned = false; | |
} | |
} | |
return allSigned; | |
} | |
modifier allSigned(uint proposalIndex) { | |
require(checkAllSigned(proposalIndex)); | |
_; | |
} | |
function finalize(uint proposalIndex) allSigned(proposalIndex) public isSigner(msg.sender) { | |
proposals[proposalIndex].finalized = true; | |
proposals[proposalIndex].to.transfer(proposals[proposalIndex].amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment