commit
81e59cb12f
@ -0,0 +1,3 @@ |
||||
[submodule "test/sources/openzeppelin-solidity"] |
||||
path = test/sources/zeppelin |
||||
url = https://github.com/OpenZeppelin/openzeppelin-solidity |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,24 @@ |
||||
/* eslint-env node, mocha */ |
||||
|
||||
const solc = require('solc'); |
||||
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js'); |
||||
const util = require('./util/util.js'); |
||||
const path = require('path'); |
||||
|
||||
/** |
||||
* NB: passing '1' to solc as an option activates the optimiser |
||||
* NB: solc will throw if there is a compilation error, causing the test to fail |
||||
* and passing the error to mocha. |
||||
*/ |
||||
describe('generic expressions', () => { |
||||
const filePath = path.resolve('./test.sol'); |
||||
|
||||
it('should compile after instrumenting an assembly function with spaces in parameters', () => { |
||||
const contract = util.getCode('assembly/spaces-in-function.sol'); |
||||
const info = getInstrumentedVersion(contract, filePath); |
||||
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract))); |
||||
console.log(info) |
||||
util.report(output.errors); |
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,18 @@ |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() public { |
||||
assembly { |
||||
function power(base, exponent) -> result { |
||||
switch exponent |
||||
case 0 { result := 1 } |
||||
case 1 { result := base } |
||||
default { |
||||
result := power(mul(base, base), div(exponent, 2)) |
||||
switch mod(exponent, 2) |
||||
case 1 { result := mul(base, result) } |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.13; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(bool test){ |
||||
function a(bool test) public { |
||||
assert(test); |
||||
} |
||||
} |
||||
|
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.17; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
library CLibrary { |
||||
uint constant x = 1; |
||||
function a() public constant returns (uint) { |
||||
function a() public view returns (uint) { |
||||
return x; |
||||
} |
||||
} |
@ -1,4 +1,4 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Empty { |
||||
} |
@ -1,20 +1,25 @@ |
||||
pragma solidity ^0.4.4; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
|
||||
contract Migrations { |
||||
address public owner; |
||||
|
||||
uint public last_completed_migration; |
||||
|
||||
modifier restricted() {if (msg.sender == owner) _;} |
||||
modifier restricted() { |
||||
if (msg.sender == owner) { _; } |
||||
} |
||||
|
||||
function Migrations() { |
||||
constructor() public { |
||||
owner = msg.sender; |
||||
} |
||||
|
||||
function setCompleted(uint completed) restricted { |
||||
function setCompleted(uint completed) public restricted { |
||||
last_completed_migration = completed; |
||||
} |
||||
|
||||
function upgrade(address new_address) restricted { |
||||
function upgrade(address new_address) public restricted { |
||||
Migrations upgraded = Migrations(new_address); |
||||
upgraded.setCompleted(last_completed_migration); |
||||
} |
||||
} |
||||
} |
||||
|
@ -1,6 +1,6 @@ |
||||
pragma solidity ^0.4.4; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Owned { |
||||
function Owned() { owner = msg.sender; } |
||||
constructor() public { owner = msg.sender; } |
||||
address owner; |
||||
} |
@ -1,13 +1,13 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.3; |
||||
|
||||
contract Simple { |
||||
uint x = 0; |
||||
|
||||
function test(uint val) { |
||||
function test(uint val) public { |
||||
x = x + val; |
||||
} |
||||
|
||||
function getX() returns (uint){ |
||||
function getX() public view returns (uint){ |
||||
return x; |
||||
} |
||||
} |
@ -1,14 +1,14 @@ |
||||
// This contract should throw a parse error in instrumentSolidity.js |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract SimpleError { |
||||
uint x = 0; |
||||
|
||||
function test(uint val) { |
||||
function test(uint val) public { |
||||
x = x + val // <-- no semi-colon |
||||
} |
||||
|
||||
function getX() returns (uint){ |
||||
function getX() public returns (uint){ |
||||
return x; |
||||
} |
||||
} |
@ -1,25 +1,25 @@ |
||||
pragma solidity ^0.4.4; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Wallet { |
||||
|
||||
event Deposit(address indexed _sender, uint _value); |
||||
|
||||
function transferPayment(uint payment, address recipient){ |
||||
function transferPayment(uint payment, address payable recipient) public { |
||||
recipient.transfer(payment); |
||||
} |
||||
|
||||
function sendPayment(uint payment, address recipient){ |
||||
function sendPayment(uint payment, address payable recipient) public { |
||||
if (!recipient.send(payment)) |
||||
revert(); |
||||
} |
||||
|
||||
function getBalance() constant returns(uint){ |
||||
function getBalance() public view returns(uint){ |
||||
return address(this).balance; |
||||
} |
||||
|
||||
function() payable |
||||
function() external payable |
||||
{ |
||||
if (msg.value > 0) |
||||
Deposit(msg.sender, msg.value); |
||||
emit Deposit(msg.sender, msg.value); |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.13; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test {//Comment immediately after contract declaration |
||||
function a(bool test){ |
||||
var x = 1; |
||||
var y = 2; |
||||
function a(bool test) public { |
||||
uint8 x = 1; |
||||
uint8 y = 2; |
||||
} |
||||
} |
||||
|
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.13; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(bool test){//Comment immediately after function declaration |
||||
function a(bool test) public {//Comment immediately after function declaration |
||||
} |
||||
function b(bool test){var x=1;}//Comment immediately after function closes |
||||
function b(bool test) public {uint8 x=1;}//Comment immediately after function closes |
||||
} |
||||
|
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.13; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(bool test){ |
||||
var x = 1;//Comment immediately after line |
||||
var y = 2; |
||||
function a(bool test) public { |
||||
uint x = 1;//Comment immediately after line |
||||
uint y = 2; |
||||
} |
||||
} |
||||
|
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var x = false; |
||||
var y = false; |
||||
function a() public { |
||||
bool x = false; |
||||
bool y = false; |
||||
bool z = (x) ? false : true; |
||||
} |
||||
} |
@ -1,10 +1,10 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var x = false; |
||||
var y = false; |
||||
var z = false; |
||||
function a() public { |
||||
bool x = false; |
||||
bool y = false; |
||||
bool z = false; |
||||
z = (x) ? false : true; |
||||
} |
||||
} |
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var x = false; |
||||
var y = false; |
||||
function a() public { |
||||
bool x = false; |
||||
bool y = false; |
||||
(x) ? y = false : y = false; |
||||
} |
||||
} |
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var x = true; |
||||
var y = false; |
||||
function a() public { |
||||
bool x = true; |
||||
bool y = false; |
||||
(x) ? y = false : y = false; |
||||
} |
||||
} |
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var x = false; |
||||
var y = false; |
||||
var z = (x) ? false : true; |
||||
function a() public { |
||||
bool x = false; |
||||
bool y = false; |
||||
bool z = (x) ? false : true; |
||||
} |
||||
} |
@ -1,12 +1,12 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
new Test2(x); |
||||
} |
||||
} |
||||
contract Test2 { |
||||
function Test2(uint x) { |
||||
constructor(uint x) public { |
||||
x+1; |
||||
} |
||||
} |
||||
|
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
x+1; |
||||
} |
||||
} |
||||
|
@ -1,5 +1,5 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function abstractFn(uint x); |
||||
function abstractFn(uint x) public; |
||||
} |
@ -0,0 +1,7 @@ |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(string calldata x) external { |
||||
x; |
||||
} |
||||
} |
@ -1,12 +1,12 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
// This is for a test that verifies solcover can instrument a |
||||
// chained constructor/method call invoked by the new operator. |
||||
contract Chainable { |
||||
function chainWith(uint y, uint z) {} |
||||
function chainWith(uint y, uint z) public {} |
||||
} |
||||
contract Test { |
||||
function a(){ |
||||
function a() public { |
||||
new Chainable().chainWith(3, 4); |
||||
} |
||||
} |
@ -1,12 +1,12 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
// This is for a test that verifies solcover can instrument a |
||||
// another kind of long CallExpression chain |
||||
contract Test { |
||||
function paySomeone(address x, address y) payable { |
||||
function paySomeone(address x, address y) public payable { |
||||
} |
||||
|
||||
function a() payable { |
||||
Test(0x00).paySomeone.value(msg.value)(0x00, 0x00); |
||||
function a() public payable { |
||||
Test(0x00).paySomeone.value(msg.value)(0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000); |
||||
} |
||||
} |
@ -1,11 +1,11 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
// This is for a test that verifies solcover can instrument a |
||||
// chained constructor/method call. |
||||
contract Test { |
||||
function chainWith(uint y, uint z) {} |
||||
function chainWith(uint y, uint z) public {} |
||||
|
||||
function a(){ |
||||
function a() public { |
||||
Test(0x00).chainWith(3, 4); |
||||
} |
||||
} |
||||
|
@ -1,13 +1,13 @@ |
||||
pragma solidity ^0.4.23; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract UsesConstructor { |
||||
uint z; |
||||
constructor(){ |
||||
constructor() public { |
||||
z = 5; |
||||
} |
||||
} |
||||
contract Test { |
||||
function a(){ |
||||
function a() public { |
||||
new UsesConstructor(); |
||||
} |
||||
} |
||||
|
@ -1,5 +1,5 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function emptyBody(uint x){} |
||||
function emptyBody(uint x) public {} |
||||
} |
||||
|
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
// This test verifies that an invoked function gets logged as a statement |
||||
contract Test { |
||||
function loggedAsStatement(uint x) {} |
||||
function a(){ |
||||
function loggedAsStatement(uint x) public {} |
||||
function a() public { |
||||
loggedAsStatement(5); |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(bytes32 x) { |
||||
function a(bytes32 x) public { |
||||
x; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,11 @@ |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
modifier b(){ |
||||
uint y; |
||||
_; |
||||
} |
||||
function a(uint x) b public { |
||||
x; |
||||
} |
||||
} |
@ -1,15 +1,15 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function f1(bytes32 x) { |
||||
function f1(uint x) public { |
||||
x = 1; |
||||
} |
||||
|
||||
function f2(uint x){ x = 2; } |
||||
function f2(uint x) public { x = 2; } |
||||
|
||||
address a; |
||||
|
||||
function f3(uint y){ |
||||
function f3(uint y) public { |
||||
y = 1; |
||||
} |
||||
} |
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
if (x == 1) { |
||||
throw; |
||||
revert(); |
||||
} else |
||||
x = 5; |
||||
} |
||||
|
@ -0,0 +1,21 @@ |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x,uint y, uint z) public { |
||||
if (x == y) { |
||||
z = 0; |
||||
} else if (x == 2) { |
||||
z = 1; |
||||
} else { |
||||
z = 2; |
||||
} |
||||
|
||||
if (x == y) { |
||||
z = 0; |
||||
} else if (x == 2) { |
||||
z = 1; |
||||
} else { |
||||
z = 2; |
||||
} |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
if (x == 1) |
||||
x = 2; |
||||
} |
||||
|
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
if (x == 1) x = 2; |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
if (x == 1) {x = 3;} |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
for(var x = 0; x < 10; x++) |
||||
sha3(x); |
||||
function a() public { |
||||
for(uint x = 0; x < 10; x++) |
||||
keccak256(abi.encodePacked(x)); |
||||
} |
||||
} |
@ -1,9 +1,9 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
for(var x = 0; x < 10; x++){ |
||||
sha3(x); |
||||
function a() public { |
||||
for(uint x = 0; x < 10; x++){ |
||||
keccak256(abi.encodePacked(x)); |
||||
} |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a() { |
||||
var t = true; |
||||
function a() public { |
||||
bool t = true; |
||||
while(t) |
||||
t = false; |
||||
} |
||||
|
@ -1,7 +0,0 @@ |
||||
pragma solidity ^0.4.3; |
||||
|
||||
contract Test { |
||||
function a(uint x) returns (bool) { |
||||
return; |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) returns (bool) { |
||||
function a(uint x) public returns (bool) { |
||||
return true; |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.23; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
event TestEvent(); |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
emit TestEvent(); |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.23; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
event TestEvent(); |
||||
function a(uint x) { |
||||
function a(uint x) public { |
||||
if(true) |
||||
emit TestEvent(); |
||||
} |
||||
|
@ -1,3 +1,3 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test {} |
@ -1,11 +1,11 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(bytes32 x) { |
||||
function a(bytes32 x) public { |
||||
x; |
||||
} |
||||
|
||||
function b (){ |
||||
a(sha3(0)); |
||||
function b () public { |
||||
a(keccak256(abi.encodePacked(uint256(0)))); |
||||
} |
||||
} |
@ -1,8 +1,6 @@ |
||||
pragma experimental "v0.5.0"; |
||||
|
||||
contract Test { |
||||
struct Fn { |
||||
function(bytes32) internal constant returns(bool) startConditions; |
||||
function(bytes32) internal constant endConditions; |
||||
function(bytes32) internal view returns(bool) startConditions; |
||||
function(bytes32) internal view endConditions; |
||||
} |
||||
} |
@ -1,8 +1,8 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
sha3(x); |
||||
sha3(0); |
||||
function a(uint x) public { |
||||
keccak256(abi.encodePacked(x)); |
||||
keccak256(abi.encodePacked(uint256(0))); |
||||
} |
||||
} |
@ -1,7 +1,7 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
function a(uint x) { |
||||
sha3(x); |
||||
function a(uint x) public { |
||||
keccak256(abi.encodePacked(x)); |
||||
} |
||||
} |
@ -1,13 +1,13 @@ |
||||
pragma solidity ^0.4.3; |
||||
pragma solidity ^0.5.0; |
||||
|
||||
contract Test { |
||||
|
||||
function returnTuple() returns (uint x, uint y) { |
||||
function returnTuple() public returns (uint x, uint y) { |
||||
return (10, 20); |
||||
} |
||||
|
||||
function a() { |
||||
var (a, b) = (10, 20); |
||||
var (x, y) = returnTuple(); |
||||
function a() public { |
||||
(uint a, uint b) = (10, 20); |
||||
(a, b) = returnTuple(); |
||||
} |
||||
} |
@ -0,0 +1 @@ |
||||
Subproject commit 0dded493a03623c93845c2d58634c229862ab54a |
@ -1,58 +0,0 @@ |
||||
pragma solidity ^0.4.4; |
||||
|
||||
|
||||
import './PullPayment.sol'; |
||||
import './Killable.sol'; |
||||
|
||||
|
||||
/* |
||||
* Bounty |
||||
* |
||||
* This bounty will pay out to a researcher if they break invariant logic of the contract. |
||||
*/ |
||||
contract Bounty is PullPayment, Killable { |
||||
Target target; |
||||
bool public claimed; |
||||
mapping(address => address) public researchers; |
||||
|
||||
event TargetCreated(address createdAddress); |
||||
|
||||
function() payable { |
||||
if (claimed) throw; |
||||
} |
||||
|
||||
function createTarget() returns(Target) { |
||||
target = Target(deployContract()); |
||||
researchers[target] = msg.sender; |
||||
TargetCreated(target); |
||||
return target; |
||||
} |
||||
|
||||
function deployContract() internal returns(address); |
||||
|
||||
function checkInvariant() returns(bool){ |
||||
return target.checkInvariant(); |
||||
} |
||||
|
||||
function claim(Target target) { |
||||
address researcher = researchers[target]; |
||||
if (researcher == 0) throw; |
||||
// Check Target contract invariants |
||||
if (target.checkInvariant()) { |
||||
throw; |
||||
} |
||||
asyncSend(researcher, this.balance); |
||||
claimed = true; |
||||
} |
||||
|
||||
} |
||||
|
||||
/* |
||||
* Target |
||||
* |
||||
* Your main contract should inherit from this class and implement the checkInvariant method. This is a function that should check everything your contract assumes to be true all the time. If this function returns false, it means your contract was broken in some way and is in an inconsistent state. This is what security researchers will try to acomplish when trying to get the bounty. |
||||
*/ |
||||
contract Target { |
||||
function checkInvariant() returns(bool); |
||||
} |
||||
|
@ -1,30 +0,0 @@ |
||||
pragma solidity ^0.4.0; |
||||
|
||||
|
||||
|
||||
import './Ownable.sol'; |
||||
|
||||
|
||||
/* |
||||
* Claimable |
||||
* |
||||
* Extension for the Ownable contract, where the ownership needs to be claimed. This allows the new owner to accept the transfer. |
||||
*/ |
||||
contract Claimable is Ownable { |
||||
address public pendingOwner; |
||||
|
||||
modifier onlyPendingOwner() { |
||||
if (msg.sender == pendingOwner) |
||||
_; |
||||
} |
||||
|
||||
function transfer(address newOwner) onlyOwner { |
||||
pendingOwner = newOwner; |
||||
} |
||||
|
||||
function claimOwnership() onlyPendingOwner { |
||||
owner = pendingOwner; |
||||
pendingOwner = 0x0; |
||||
} |
||||
|
||||
} |
@ -1,73 +0,0 @@ |
||||
pragma solidity ^0.4.4; |
||||
|
||||
|
||||
import './Shareable.sol'; |
||||
/* |
||||
* DayLimit |
||||
* |
||||
* inheritable "property" contract that enables methods to be protected by placing a linear limit (specifiable) |
||||
* 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. |
||||
*/ |
||||
contract DayLimit is Shareable { |
||||
// FIELDS |
||||
|
||||
uint public dailyLimit; |
||||
uint public spentToday; |
||||
uint public lastDay; |
||||
|
||||
|
||||
// MODIFIERS |
||||
|
||||
// simple modifier for daily limit. |
||||
modifier limitedDaily(uint _value) { |
||||
if (underLimit(_value)) |
||||
_; |
||||
} |
||||
|
||||
|
||||
// CONSTRUCTOR |
||||
// stores initial daily limit and records the present day's index. |
||||
function DayLimit(uint _limit) { |
||||
dailyLimit = _limit; |
||||
lastDay = today(); |
||||
} |
||||
|
||||
|
||||
// METHODS |
||||
|
||||
// (re)sets the daily limit. needs many of the owners to confirm. doesn't alter the amount already spent today. |
||||
function setDailyLimit(uint _newLimit) onlymanyowners(sha3(msg.data)) external { |
||||
dailyLimit = _newLimit; |
||||
} |
||||
|
||||
// resets the amount already spent today. needs many of the owners to confirm |
||||
function resetSpentToday() onlymanyowners(sha3(msg.data)) external { |
||||
spentToday = 0; |
||||
} |
||||
|
||||
|
||||
// INTERNAL METHODS |
||||
|
||||
// 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. |
||||
function underLimit(uint _value) internal onlyOwner returns (bool) { |
||||
// reset the spend limit if we're on a different day to last time. |
||||
if (today() > lastDay) { |
||||
spentToday = 0; |
||||
lastDay = today(); |
||||
} |
||||
// check to see if there's enough left - if so, subtract and return true. |
||||
// overflow protection // dailyLimit check |
||||
if (spentToday + _value >= spentToday && spentToday + _value <= dailyLimit) { |
||||
spentToday += _value; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
// determines today's index. |
||||
function today() private constant returns (uint) { |
||||
return now / 1 days; |
||||
} |
||||
} |
@ -1,15 +0,0 @@ |
||||
pragma solidity ^0.4.4; |
||||
|
||||
|
||||
import "./Ownable.sol"; |
||||
|
||||
|
||||
/* |
||||
* Killable |
||||
* Base contract that can be killed by owner. All funds in contract will be sent to the owner. |
||||
*/ |
||||
contract Killable is Ownable { |
||||
function kill() onlyOwner { |
||||
selfdestruct(owner); |
||||
} |
||||
} |
@ -1,18 +0,0 @@ |
||||
pragma solidity ^0.4.4; |
||||
contract LimitBalance { |
||||
|
||||
uint public limit; |
||||
|
||||
function LimitBalance(uint _limit) { |
||||
limit = _limit; |
||||
} |
||||
|
||||
modifier limitedPayable() { |
||||
if (this.balance > limit) { |
||||
throw; |
||||
} |
||||
_; |
||||
|
||||
} |
||||
|
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue