Created
December 1, 2017 23:30
-
-
Save io4/7923bf4179a2923637081cd0804cb75e to your computer and use it in GitHub Desktop.
Multisig solidity wallet
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.18; | |
contract ERC721 { | |
function totalSupply() public view returns (uint256 total); | |
function balanceOf(address _owner) public view returns (uint256 balance); | |
function ownerOf(uint256 _tokenId) external view returns (address owner); | |
function approve(address _to, uint256 _tokenId) external; | |
function transfer(address _to, uint256 _tokenId) external; | |
function transferFrom(address _from, address _to, uint256 _tokenId) external; | |
event Transfer(address from, address to, uint256 tokenId); | |
event Approval(address owner, address approved, uint256 tokenId); | |
function supportsInterface(bytes4 _interfaceID) external view returns (bool); | |
} | |
contract MultiCat { | |
ERC721 public target; | |
struct Proposal { | |
uint votesNeeded; | |
uint action; | |
address from; | |
address to; | |
uint tokenId; | |
mapping (address => bool) voters; | |
} | |
mapping (address => bool) public owners; | |
uint ownerCount; | |
mapping (uint => Proposal) public proposals; | |
uint proposalCount; | |
function MultiCat () public { | |
owners[msg.sender] = true; | |
ownerCount = 1; | |
} | |
modifier onlyOwner() { | |
if (!owners[msg.sender]) { | |
revert(); | |
} | |
_; | |
} | |
function vote (uint propsalId) onlyOwner public { | |
Proposal storage proposal = proposals[propsalId]; | |
require(!proposal.voters[msg.sender]); | |
proposal.votesNeeded--; | |
proposal.voters[msg.sender] = true; | |
if(proposal.votesNeeded == 0) { | |
if(proposal.action == 0) { // transfer | |
target.transfer(proposal.to, proposal.tokenId); | |
} | |
if(proposal.action == 1) { // transferFrom | |
target.transferFrom(proposal.from, proposal.to, proposal.tokenId); | |
} | |
if(proposal.action == 2) { // addOwner | |
owners[proposal.to] = true; | |
ownerCount++; | |
} | |
if(proposal.action == 3) { // delOwner | |
owners[proposal.to] = false; | |
ownerCount--; | |
} | |
} | |
} | |
function transfer(address _to, uint _tokenId) onlyOwner public { | |
proposals[proposalCount++] = Proposal(ownerCount, 0, 0x0, _to, _tokenId); | |
vote(proposalCount-1); | |
} | |
function transferFrom(address _from, address _to, uint _tokenId) onlyOwner public { | |
proposals[proposalCount++] = Proposal(ownerCount, 1, _from, _to, _tokenId); | |
vote(proposalCount-1); | |
} | |
function addOwner(address _to) onlyOwner public { | |
proposals[proposalCount++] = Proposal(ownerCount, 2, 0x0, _to, 0); | |
vote(proposalCount-1); | |
} | |
function delOwner(address _to) onlyOwner public { | |
proposals[proposalCount++] = Proposal(ownerCount, 3, 0x0, _to, 0); | |
vote(proposalCount-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment