Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
openzeppelin-contracts-upgradeable
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
俞永鹏
openzeppelin-contracts-upgradeable
Commits
36fa2a72
Commit
36fa2a72
authored
Dec 21, 2016
by
Arseniy Klempner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Decouple Shareable from DayLimit
parent
11cf9f87
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
13 deletions
+21
-13
DayLimit.sol
contracts/DayLimit.sol
+7
-7
MultisigWallet.sol
contracts/MultisigWallet.sol
+8
-0
DayLimitMock.sol
contracts/test-helpers/DayLimitMock.sol
+1
-1
DayLimit.js
test/DayLimit.js
+5
-5
No files found.
contracts/DayLimit.sol
View file @
36fa2a72
...
@@ -11,7 +11,7 @@ import './Shareable.sol';
...
@@ -11,7 +11,7 @@ import './Shareable.sol';
* on a particular resource per calendar day. is multiowned to allow the limit to be altered. resource that method
* on a particular resource per calendar day. is multiowned to allow the limit to be altered. resource that method
* uses is specified in the modifier.
* uses is specified in the modifier.
*/
*/
contract DayLimit
is Shareable
{
contract DayLimit {
// FIELDS
// FIELDS
uint public dailyLimit;
uint public dailyLimit;
...
@@ -38,13 +38,13 @@ contract DayLimit is Shareable {
...
@@ -38,13 +38,13 @@ contract DayLimit is Shareable {
// METHODS
// METHODS
// (re)sets the daily limit.
needs many of the owners to confirm.
doesn't alter the amount already spent today.
// (re)sets the daily limit. doesn't alter the amount already spent today.
function setDailyLimit(uint _newLimit)
onlymanyowners(sha3(msg.data))
external {
function setDailyLimit(uint _newLimit) external {
dailyLimit = _newLimit;
dailyLimit = _newLimit;
}
}
// resets the amount already spent today.
needs many of the owners to confirm
// resets the amount already spent today.
function resetSpentToday()
onlymanyowners(sha3(msg.data))
external {
function resetSpentToday() external {
spentToday = 0;
spentToday = 0;
}
}
...
@@ -53,14 +53,14 @@ contract DayLimit is Shareable {
...
@@ -53,14 +53,14 @@ contract DayLimit is Shareable {
// checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
// checks to see if there is at least `_value` left from the daily limit today. if there is, subtracts it and
// returns true. otherwise just returns false.
// returns true. otherwise just returns false.
function underLimit(uint _value) internal
onlyOwner
returns (bool) {
function underLimit(uint _value) internal returns (bool) {
// reset the spend limit if we're on a different day to last time.
// reset the spend limit if we're on a different day to last time.
if (today() > lastDay) {
if (today() > lastDay) {
spentToday = 0;
spentToday = 0;
lastDay = today();
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
// overflow protection // dailyLimit check
if (spentToday + _value >= spentToday && spentToday + _value <= dailyLimit) {
if (spentToday + _value >= spentToday && spentToday + _value <= dailyLimit) {
spentToday += _value;
spentToday += _value;
return true;
return true;
...
...
contracts/MultisigWallet.sol
View file @
36fa2a72
...
@@ -83,6 +83,14 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
...
@@ -83,6 +83,14 @@ contract MultisigWallet is Multisig, Shareable, DayLimit {
}
}
}
}
function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external {
this.setDailyLimit(_newLimit);
}
function resetSpentToday() onlymanyowners(sha3(msg.data)) external {
this.resetSpentToday();
}
// INTERNAL METHODS
// INTERNAL METHODS
...
...
contracts/test-helpers/DayLimitMock.sol
View file @
36fa2a72
...
@@ -4,7 +4,7 @@ import "../DayLimit.sol";
...
@@ -4,7 +4,7 @@ import "../DayLimit.sol";
contract DayLimitMock is DayLimit {
contract DayLimitMock is DayLimit {
uint public totalSpending;
uint public totalSpending;
function DayLimitMock(uint _value
, address[] _owners, uint _required) DayLimit(_value) Shareable(_owners, _required
) {
function DayLimitMock(uint _value
) DayLimit(_value
) {
totalSpending = 0;
totalSpending = 0;
}
}
...
...
test/DayLimit.js
View file @
36fa2a72
...
@@ -2,14 +2,14 @@ contract('DayLimit', function(accounts) {
...
@@ -2,14 +2,14 @@ contract('DayLimit', function(accounts) {
it
(
'should construct with the passed daily limit'
,
async
function
()
{
it
(
'should construct with the passed daily limit'
,
async
function
()
{
let
initLimit
=
10
;
let
initLimit
=
10
;
let
dayLimit
=
await
DayLimitMock
.
new
(
initLimit
,
accounts
,
2
);
let
dayLimit
=
await
DayLimitMock
.
new
(
initLimit
);
let
dailyLimit
=
await
dayLimit
.
dailyLimit
();
let
dailyLimit
=
await
dayLimit
.
dailyLimit
();
assert
.
equal
(
initLimit
,
dailyLimit
);
assert
.
equal
(
initLimit
,
dailyLimit
);
});
});
it
(
'should be able to spend if daily limit is not reached'
,
async
function
()
{
it
(
'should be able to spend if daily limit is not reached'
,
async
function
()
{
let
limit
=
10
;
let
limit
=
10
;
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
,
accounts
,
1
);
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
);
await
dayLimit
.
attemptSpend
(
8
);
await
dayLimit
.
attemptSpend
(
8
);
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
...
@@ -22,7 +22,7 @@ contract('DayLimit', function(accounts) {
...
@@ -22,7 +22,7 @@ contract('DayLimit', function(accounts) {
it
(
'should prevent spending if daily limit is reached'
,
async
function
()
{
it
(
'should prevent spending if daily limit is reached'
,
async
function
()
{
let
limit
=
10
;
let
limit
=
10
;
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
,
accounts
,
1
);
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
);
await
dayLimit
.
attemptSpend
(
8
);
await
dayLimit
.
attemptSpend
(
8
);
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
...
@@ -35,7 +35,7 @@ contract('DayLimit', function(accounts) {
...
@@ -35,7 +35,7 @@ contract('DayLimit', function(accounts) {
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
it
(
'should allow spending if daily limit is reached and then set higher'
,
async
function
()
{
let
limit
=
10
;
let
limit
=
10
;
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
,
accounts
,
1
);
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
);
await
dayLimit
.
attemptSpend
(
8
);
await
dayLimit
.
attemptSpend
(
8
);
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
...
@@ -53,7 +53,7 @@ contract('DayLimit', function(accounts) {
...
@@ -53,7 +53,7 @@ contract('DayLimit', function(accounts) {
it
(
'should allow spending if daily limit is reached and then amount spent is reset'
,
async
function
()
{
it
(
'should allow spending if daily limit is reached and then amount spent is reset'
,
async
function
()
{
let
limit
=
10
;
let
limit
=
10
;
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
,
accounts
,
1
);
let
dayLimit
=
await
DayLimitMock
.
new
(
limit
);
await
dayLimit
.
attemptSpend
(
8
);
await
dayLimit
.
attemptSpend
(
8
);
let
spentToday
=
await
dayLimit
.
spentToday
();
let
spentToday
=
await
dayLimit
.
spentToday
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment