diff options
author | chriseth <chris@ethereum.org> | 2017-07-05 18:28:15 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2017-07-05 18:39:55 +0800 |
commit | ac84b36144f746662e5ddb984d283e053c7d06ba (patch) | |
tree | f50ee438a384e60574a4c28ea32d2b6ae2315795 /test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol | |
parent | 05a26fc98c1201057c618c536ca0537e456c9b15 (diff) | |
download | dexon-solidity-ac84b36144f746662e5ddb984d283e053c7d06ba.tar.gz dexon-solidity-ac84b36144f746662e5ddb984d283e053c7d06ba.tar.zst dexon-solidity-ac84b36144f746662e5ddb984d283e053c7d06ba.zip |
Added various contracts for testing.
Diffstat (limited to 'test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol')
-rw-r--r-- | test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol new file mode 100644 index 00000000..024d3ef4 --- /dev/null +++ b/test/compilationTests/MultiSigWallet/MultiSigWalletWithDailyLimit.sol @@ -0,0 +1,97 @@ +pragma solidity ^0.4.4; +import "MultiSigWallet.sol"; + + +/// @title Multisignature wallet with daily limit - Allows an owner to withdraw a daily limit without multisig. +/// @author Stefan George - <stefan.george@consensys.net> +contract MultiSigWalletWithDailyLimit is MultiSigWallet { + + event DailyLimitChange(uint dailyLimit); + + uint public dailyLimit; + uint public lastDay; + uint public spentToday; + + /* + * Public functions + */ + /// @dev Contract constructor sets initial owners, required number of confirmations and daily withdraw limit. + /// @param _owners List of initial owners. + /// @param _required Number of required confirmations. + /// @param _dailyLimit Amount in wei, which can be withdrawn without confirmations on a daily basis. + function MultiSigWalletWithDailyLimit(address[] _owners, uint _required, uint _dailyLimit) + public + MultiSigWallet(_owners, _required) + { + dailyLimit = _dailyLimit; + } + + /// @dev Allows to change the daily limit. Transaction has to be sent by wallet. + /// @param _dailyLimit Amount in wei. + function changeDailyLimit(uint _dailyLimit) + public + onlyWallet + { + dailyLimit = _dailyLimit; + DailyLimitChange(_dailyLimit); + } + + /// @dev Allows anyone to execute a confirmed transaction or ether withdraws until daily limit is reached. + /// @param transactionId Transaction ID. + function executeTransaction(uint transactionId) + public + notExecuted(transactionId) + { + Transaction tx = transactions[transactionId]; + bool confirmed = isConfirmed(transactionId); + if (confirmed || tx.data.length == 0 && isUnderLimit(tx.value)) { + tx.executed = true; + if (!confirmed) + spentToday += tx.value; + if (tx.destination.call.value(tx.value)(tx.data)) + Execution(transactionId); + else { + ExecutionFailure(transactionId); + tx.executed = false; + if (!confirmed) + spentToday -= tx.value; + } + } + } + + /* + * Internal functions + */ + /// @dev Returns if amount is within daily limit and resets spentToday after one day. + /// @param amount Amount to withdraw. + /// @return Returns if amount is under daily limit. + function isUnderLimit(uint amount) + internal + returns (bool) + { + if (now > lastDay + 24 hours) { + lastDay = now; + spentToday = 0; + } + if (spentToday + amount > dailyLimit || spentToday + amount < spentToday) + return false; + return true; + } + + /* + * Web3 call functions + */ + /// @dev Returns maximum withdraw amount. + /// @return Returns amount. + function calcMaxWithdraw() + public + constant + returns (uint) + { + if (now > lastDay + 24 hours) + return dailyLimit; + if (dailyLimit < spentToday) + return 0; + return dailyLimit - spentToday; + } +} |