MultisigWallet.sol 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. pragma solidity ^0.4.8;
  2. import "./ownership/Multisig.sol";
  3. import "./ownership/Shareable.sol";
  4. import "./DayLimit.sol";
  5. /*
  6. * MultisigWallet
  7. * usage:
  8. * bytes32 h = Wallet(w).from(oneOwner).execute(to, value, data);
  9. * Wallet(w).from(anotherOwner).confirm(h);
  10. */
  11. contract MultisigWallet is Multisig, Shareable, DayLimit {
  12. struct Transaction {
  13. address to;
  14. uint value;
  15. bytes data;
  16. }
  17. function MultisigWallet(address[] _owners, uint _required, uint _daylimit)
  18. Shareable(_owners, _required)
  19. DayLimit(_daylimit) { }
  20. // destroys the contract sending everything to `_to`.
  21. function destroy(address _to) onlymanyowners(keccak256(msg.data)) external {
  22. selfdestruct(_to);
  23. }
  24. // gets called when no other function matches
  25. function() payable {
  26. // just being sent some cash?
  27. if (msg.value > 0)
  28. Deposit(msg.sender, msg.value);
  29. }
  30. // Outside-visible transact entry point. Executes transaction immediately if below daily spend limit.
  31. // If not, goes into multisig process. We provide a hash on return to allow the sender to provide
  32. // shortcuts for the other confirmations (allowing them to avoid replicating the _to, _value
  33. // and _data arguments). They still get the option of using them if they want, anyways.
  34. function execute(address _to, uint _value, bytes _data) external onlyOwner returns (bytes32 _r) {
  35. // first, take the opportunity to check that we're under the daily limit.
  36. if (underLimit(_value)) {
  37. SingleTransact(msg.sender, _value, _to, _data);
  38. // yes - just execute the call.
  39. if (!_to.call.value(_value)(_data)) {
  40. throw;
  41. }
  42. return 0;
  43. }
  44. // determine our operation hash.
  45. _r = keccak256(msg.data, block.number);
  46. if (!confirm(_r) && txs[_r].to == 0) {
  47. txs[_r].to = _to;
  48. txs[_r].value = _value;
  49. txs[_r].data = _data;
  50. ConfirmationNeeded(_r, msg.sender, _value, _to, _data);
  51. }
  52. }
  53. // confirm a transaction through just the hash. we use the previous transactions map, txs, in order
  54. // to determine the body of the transaction from the hash provided.
  55. function confirm(bytes32 _h) onlymanyowners(_h) returns (bool) {
  56. if (txs[_h].to != 0) {
  57. if (!txs[_h].to.call.value(txs[_h].value)(txs[_h].data)) {
  58. throw;
  59. }
  60. MultiTransact(msg.sender, _h, txs[_h].value, txs[_h].to, txs[_h].data);
  61. delete txs[_h];
  62. return true;
  63. }
  64. }
  65. function setDailyLimit(uint _newLimit) onlymanyowners(keccak256(msg.data)) external {
  66. _setDailyLimit(_newLimit);
  67. }
  68. function resetSpentToday() onlymanyowners(keccak256(msg.data)) external {
  69. _resetSpentToday();
  70. }
  71. // INTERNAL METHODS
  72. function clearPending() internal {
  73. uint length = pendingsIndex.length;
  74. for (uint i = 0; i < length; ++i) {
  75. delete txs[pendingsIndex[i]];
  76. }
  77. super.clearPending();
  78. }
  79. // FIELDS
  80. // pending transactions we have at present.
  81. mapping (bytes32 => Transaction) txs;
  82. }