Created
July 18, 2016 19:20
-
-
Save anonymous/e4fdac24643c7146a04bd9b3d96fbb4c to your computer and use it in GitHub Desktop.
Created using browser-solidity: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://ethereum.github.io/browser-solidity/#version=soljson-latest.js&optimize=undefined&gist=
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
/** | |
A joint account multisig wallet. Highly simplified only for learning purpose. | |
If you are looking for a strong multisig wallet contract for production, visit | |
https://github.com/ethereum/dapp-bin/blob/master/wallet/wallet.sol | |
*/ | |
contract JointAccount { | |
//Create 2 joint owners of the account. | |
address accountWindows = 0xa1dC3Cf881DbCc9B167D590545F023Ad050907B8; | |
address accountUbuntu = 0x6E22dc2F17962dcE7f8e6c5D12654403A0395821; | |
struct Transaction{ | |
address to; //address to which ethers will be withdrawn | |
uint value; //Amount of ethers to be withdrawn | |
bytes data; //some data that you would like to send | |
bool confirmedByWindows; //Confirmation by 1st owner | |
bool confirmedByUbuntu; //Confirmation by 2nd owner | |
} | |
mapping (bytes32 => Transaction) pendingTransactions; //This is where we will keep the list of our pending Transactions | |
//Create some events to notify you of the activities. You will be able to see them in mist wallet | |
event RequireConfirmtion(bytes32 pendingTransactionHash, address to, uint256 value, bytes data); | |
event ConfirmedTransaction(bytes32 pendingTransactionHash, address to, uint256 value, bytes data); | |
event TransactionConfirmationFailed(bytes32 pendingTransactionHash, address to, uint256 value, bytes data); | |
//Withdraw ethers | |
function withdraw(address _to, uint256 _value, bytes _data) returns (bytes32 _withdrawalHash){ | |
_withdrawalHash = sha3(msg.data, block.number); | |
if(pendingTransactions[_withdrawalHash].to == 0) { | |
pendingTransactions[_withdrawalHash].to = _to; | |
pendingTransactions[_withdrawalHash].value = _value; | |
pendingTransactions[_withdrawalHash].data = _data; | |
//The owner who starts the transaction confirms it for himself | |
if(msg.sender == accountWindows) { | |
pendingTransactions[_withdrawalHash].confirmedByWindows = true; | |
} else if(msg.sender == accountUbuntu) { | |
pendingTransactions[_withdrawalHash].confirmedByUbuntu = true; | |
} | |
RequireConfirmtion(_withdrawalHash, _to, _value, _data); | |
} | |
} | |
function confirmWithdrawal(bytes32 _confirmationHash) returns(bool confirmation) { | |
Transaction tr = pendingTransactions[_confirmationHash]; | |
if(msg.sender == accountUbuntu) { | |
tr.confirmedByUbuntu = true; | |
} else if(msg.sender == accountWindows) { | |
tr.confirmedByWindows = true; | |
} | |
//check if confirmed by both the owners | |
if(tr.confirmedByUbuntu && tr.confirmedByWindows) { | |
bool withdrawal = tr.to.send(tr.value); //Send the ethers | |
if(withdrawal) { | |
ConfirmedTransaction(_confirmationHash, tr.to, tr.value, tr.data); | |
delete pendingTransactions[_confirmationHash]; //Free up the storage on EVM | |
} else { | |
TransactionConfirmationFailed(_confirmationHash, tr.to, tr.value, tr.data); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment