Skip to content

Instantly share code, notes, and snippets.

@micahriggan
Last active July 30, 2018 17:59
Show Gist options
  • Save micahriggan/576b73566679e86cbb4e12ca249f4f96 to your computer and use it in GitHub Desktop.
Save micahriggan/576b73566679e86cbb4e12ca249f4f96 to your computer and use it in GitHub Desktop.
Multi-Sig Smart Contract
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