diff options
Diffstat (limited to 'docs/common-patterns.rst')
-rw-r--r-- | docs/common-patterns.rst | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 7e09f534..739e136f 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -130,7 +130,7 @@ restrictions highly readable. :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.22; contract AccessRestriction { // These will be assigned at the construction @@ -147,7 +147,10 @@ restrictions highly readable. // a certain address. modifier onlyBy(address _account) { - require(msg.sender == _account); + require( + msg.sender == _account, + "Sender not authorized." + ); // Do not forget the "_;"! It will // be replaced by the actual function // body when the modifier is used. @@ -164,7 +167,10 @@ restrictions highly readable. } modifier onlyAfter(uint _time) { - require(now >= _time); + require( + now >= _time, + "Function called too early." + ); _; } @@ -186,7 +192,10 @@ restrictions highly readable. // This was dangerous before Solidity version 0.4.0, // where it was possible to skip the part after `_;`. modifier costs(uint _amount) { - require(msg.value >= _amount); + require( + msg.value >= _amount, + "Not enough Ether provided." + ); _; if (msg.value > _amount) msg.sender.send(msg.value - _amount); @@ -194,6 +203,7 @@ restrictions highly readable. function forceOwnerChange(address _newOwner) public + payable costs(200 ether) { owner = _newOwner; @@ -272,7 +282,7 @@ function finishes. :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.22; contract StateMachine { enum Stages { @@ -289,7 +299,10 @@ function finishes. uint public creationTime = now; modifier atStage(Stages _stage) { - require(stage == _stage); + require( + stage == _stage, + "Function cannot be called at this time." + ); _; } |