Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change underLimit func #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions Wallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,39 @@ contract daylimit is multiowned {
m_spentToday = 0;
m_lastDay = today();
}
// check to see if there's enough left - if so, subtract and return true.
// check to see if there's enough left - if so, subtract and return true.
// overflow protection // dailyLimit check
if (m_spentToday + _value >= m_spentToday && m_spentToday + _value <= m_dailyLimit) {
bool err;
uint res;
(err, res) = m_spentToday.plus(_value);
if (!err && res <= m_dailyLimit) {
m_spentToday += _value;
return true;
} else if(!err) {
ErrMsg(msg.sender, "Over daily limit");
return false;
} else {
return false;
}
return false;
}

/// @dev Adds two numbers and checks for overflow before returning.
/// Does not throw but rather logs an Err event if there is overflow.
/// @param a First number
/// @param b Second number
/// @return err False normally, or true if there is overflow
/// @return res The sum of a and b, or 0 if there is overflow
function plus(uint256 a, uint256 b) constant returns (bool err, uint256 res) {
assembly{
res := add(a,b)
jumpi(allGood, and(eq(sub(res,b), a), gt(res,b)))
err := 1
res := 0
allGood:
}
if (err)
Err("plus func overflow");
}
// determines today's index.
function today() private constant returns (uint) { return now / 1 days; }

Expand Down Expand Up @@ -363,8 +388,6 @@ contract Wallet is multisig, multiowned, daylimit {
}
}

// INTERNAL METHODS

function create(uint _value, bytes _code) internal returns (address o_addr) {
assembly {
o_addr := create(_value, add(_code, 0x20), mload(_code))
Expand All @@ -374,7 +397,7 @@ contract Wallet is multisig, multiowned, daylimit {

// confirm a transaction through just the hash. we use the previous transactions map, m_txs, in order
// to determine the body of the transaction from the hash provided.
function confirm(bytes32 _h) onlymanyowners(_h) internal returns (bool o_success) {
function confirm(bytes32 _h) onlymanyowners(_h) returns (bool o_success) {
if (m_txs[_h].to != 0 || m_txs[_h].value != 0 || m_txs[_h].data.length != 0) {
address created;
if (m_txs[_h].to == 0) {
Expand All @@ -390,6 +413,8 @@ contract Wallet is multisig, multiowned, daylimit {
}
}

// INTERNAL METHODS

function clearPending() internal {
uint length = m_pendingIndex.length;
for (uint i = 0; i < length; ++i)
Expand Down