mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Docs, changelog and tests
This commit is contained in:
parent
b5612f96c9
commit
a207613f17
@ -3,6 +3,7 @@
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
* Type Checker: Disallow virtual for library functions.
|
* Type Checker: Disallow virtual for library functions.
|
||||||
* Deprecated dot syntax for `value` and `gas`.
|
* Deprecated dot syntax for `value` and `gas`.
|
||||||
|
* Deprecated the identifier `now`.
|
||||||
|
|
||||||
Language Features:
|
Language Features:
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ The following is the order of precedence for operators, listed in order of evalu
|
|||||||
| *15* | Comma operator | ``,`` |
|
| *15* | Comma operator | ``,`` |
|
||||||
+------------+-------------------------------------+--------------------------------------------+
|
+------------+-------------------------------------+--------------------------------------------+
|
||||||
|
|
||||||
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
|
.. index:: assert, block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin, revert, require, keccak256, ripemd160, sha256, ecrecover, addmod, mulmod, cryptography, this, super, selfdestruct, balance, send
|
||||||
|
|
||||||
Global Variables
|
Global Variables
|
||||||
================
|
================
|
||||||
@ -91,7 +91,6 @@ Global Variables
|
|||||||
- ``msg.data`` (``bytes``): complete calldata
|
- ``msg.data`` (``bytes``): complete calldata
|
||||||
- ``msg.sender`` (``address payable``): sender of the message (current call)
|
- ``msg.sender`` (``address payable``): sender of the message (current call)
|
||||||
- ``msg.value`` (``uint``): number of wei sent with the message
|
- ``msg.value`` (``uint``): number of wei sent with the message
|
||||||
- ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``)
|
|
||||||
- ``tx.gasprice`` (``uint``): gas price of the transaction
|
- ``tx.gasprice`` (``uint``): gas price of the transaction
|
||||||
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
|
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
|
||||||
- ``assert(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for internal error)
|
- ``assert(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for internal error)
|
||||||
@ -124,7 +123,7 @@ Global Variables
|
|||||||
- ``type(I).interfaceId`` (``bytes4``): value containing the EIP-165 interface identifier of the given interface, see :ref:`Type Information<meta-type>`.
|
- ``type(I).interfaceId`` (``bytes4``): value containing the EIP-165 interface identifier of the given interface, see :ref:`Type Information<meta-type>`.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness,
|
Do not rely on ``block.timestamp`` or ``blockhash`` as a source of randomness,
|
||||||
unless you know what you are doing.
|
unless you know what you are doing.
|
||||||
|
|
||||||
Both the timestamp and the block hash can be influenced by miners to some degree.
|
Both the timestamp and the block hash can be influenced by miners to some degree.
|
||||||
@ -144,6 +143,8 @@ Global Variables
|
|||||||
In version 0.5.0, the following aliases were removed: ``suicide`` as alias for ``selfdestruct``,
|
In version 0.5.0, the following aliases were removed: ``suicide`` as alias for ``selfdestruct``,
|
||||||
``msg.gas`` as alias for ``gasleft``, ``block.blockhash`` as alias for ``blockhash`` and
|
``msg.gas`` as alias for ``gasleft``, ``block.blockhash`` as alias for ``blockhash`` and
|
||||||
``sha3`` as alias for ``keccak256``.
|
``sha3`` as alias for ``keccak256``.
|
||||||
|
.. note::
|
||||||
|
In version 0.7.0, the alias ``now`` (for ``block.timestamp``) was removed.
|
||||||
|
|
||||||
.. index:: visibility, public, private, external, internal
|
.. index:: visibility, public, private, external, internal
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ Constant
|
|||||||
|
|
||||||
For ``constant`` variables, the value has to be a constant at compile time and it has to be
|
For ``constant`` variables, the value has to be a constant at compile time and it has to be
|
||||||
assigned where the variable is declared. Any expression
|
assigned where the variable is declared. Any expression
|
||||||
that accesses storage, blockchain data (e.g. ``now``, ``address(this).balance`` or
|
that accesses storage, blockchain data (e.g. ``block.timestamp``, ``address(this).balance`` or
|
||||||
``block.number``) or
|
``block.number``) or
|
||||||
execution data (``msg.value`` or ``gasleft()``) or makes calls to external contracts is disallowed. Expressions
|
execution data (``msg.value`` or ``gasleft()``) or makes calls to external contracts is disallowed. Expressions
|
||||||
that might have a side-effect on memory allocation are allowed, but those that
|
that might have a side-effect on memory allocation are allowed, but those that
|
||||||
|
@ -146,7 +146,7 @@ The following statements are considered modifying the state:
|
|||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint b) public view returns (uint) {
|
function f(uint a, uint b) public view returns (uint) {
|
||||||
return a * (b + 42) + now;
|
return a * (b + 42) + block.timestamp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ to receive their money - contracts cannot activate themselves.
|
|||||||
address payable _beneficiary
|
address payable _beneficiary
|
||||||
) public {
|
) public {
|
||||||
beneficiary = _beneficiary;
|
beneficiary = _beneficiary;
|
||||||
auctionEndTime = now + _biddingTime;
|
auctionEndTime = block.timestamp + _biddingTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bid on the auction with the value sent
|
/// Bid on the auction with the value sent
|
||||||
@ -78,7 +78,7 @@ to receive their money - contracts cannot activate themselves.
|
|||||||
// Revert the call if the bidding
|
// Revert the call if the bidding
|
||||||
// period is over.
|
// period is over.
|
||||||
require(
|
require(
|
||||||
now <= auctionEndTime,
|
block.timestamp <= auctionEndTime,
|
||||||
"Auction already ended."
|
"Auction already ended."
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ to receive their money - contracts cannot activate themselves.
|
|||||||
// external contracts.
|
// external contracts.
|
||||||
|
|
||||||
// 1. Conditions
|
// 1. Conditions
|
||||||
require(now >= auctionEndTime, "Auction not yet ended.");
|
require(block.timestamp >= auctionEndTime, "Auction not yet ended.");
|
||||||
require(!ended, "auctionEnd has already been called.");
|
require(!ended, "auctionEnd has already been called.");
|
||||||
|
|
||||||
// 2. Effects
|
// 2. Effects
|
||||||
@ -211,8 +211,8 @@ invalid bids.
|
|||||||
/// functions. `onlyBefore` is applied to `bid` below:
|
/// functions. `onlyBefore` is applied to `bid` below:
|
||||||
/// The new function body is the modifier's body where
|
/// The new function body is the modifier's body where
|
||||||
/// `_` is replaced by the old function body.
|
/// `_` is replaced by the old function body.
|
||||||
modifier onlyBefore(uint _time) { require(now < _time); _; }
|
modifier onlyBefore(uint _time) { require(block.timestamp < _time); _; }
|
||||||
modifier onlyAfter(uint _time) { require(now > _time); _; }
|
modifier onlyAfter(uint _time) { require(block.timestamp > _time); _; }
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
uint _biddingTime,
|
uint _biddingTime,
|
||||||
@ -220,7 +220,7 @@ invalid bids.
|
|||||||
address payable _beneficiary
|
address payable _beneficiary
|
||||||
) public {
|
) public {
|
||||||
beneficiary = _beneficiary;
|
beneficiary = _beneficiary;
|
||||||
biddingEnd = now + _biddingTime;
|
biddingEnd = block.timestamp + _biddingTime;
|
||||||
revealEnd = biddingEnd + _revealTime;
|
revealEnd = biddingEnd + _revealTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,4 +326,4 @@ invalid bids.
|
|||||||
highestBidder = bidder;
|
highestBidder = bidder;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ The full contract
|
|||||||
{
|
{
|
||||||
sender = msg.sender;
|
sender = msg.sender;
|
||||||
recipient = _recipient;
|
recipient = _recipient;
|
||||||
expiration = now + duration;
|
expiration = block.timestamp + duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// the recipient can close the channel at any time by presenting a
|
/// the recipient can close the channel at any time by presenting a
|
||||||
@ -376,7 +376,7 @@ The full contract
|
|||||||
/// if the timeout is reached without the recipient closing the channel,
|
/// if the timeout is reached without the recipient closing the channel,
|
||||||
/// then the Ether is released back to the sender.
|
/// then the Ether is released back to the sender.
|
||||||
function claimTimeout() public {
|
function claimTimeout() public {
|
||||||
require(now >= expiration);
|
require(block.timestamp >= expiration);
|
||||||
selfdestruct(sender);
|
selfdestruct(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ These suffixes cannot be applied to variables. For example, if you want to
|
|||||||
interpret a function parameter in days, you can in the following way::
|
interpret a function parameter in days, you can in the following way::
|
||||||
|
|
||||||
function f(uint start, uint daysAfter) public {
|
function f(uint start, uint daysAfter) public {
|
||||||
if (now >= start + daysAfter * 1 days) {
|
if (block.timestamp >= start + daysAfter * 1 days) {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ There are special variables and functions which always exist in the global
|
|||||||
namespace and are mainly used to provide information about the blockchain
|
namespace and are mainly used to provide information about the blockchain
|
||||||
or are general-use utility functions.
|
or are general-use utility functions.
|
||||||
|
|
||||||
.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin
|
.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, gas price, origin
|
||||||
|
|
||||||
|
|
||||||
Block and Transaction Properties
|
Block and Transaction Properties
|
||||||
@ -78,7 +78,6 @@ Block and Transaction Properties
|
|||||||
- ``msg.sender`` (``address payable``): sender of the message (current call)
|
- ``msg.sender`` (``address payable``): sender of the message (current call)
|
||||||
- ``msg.sig`` (``bytes4``): first four bytes of the calldata (i.e. function identifier)
|
- ``msg.sig`` (``bytes4``): first four bytes of the calldata (i.e. function identifier)
|
||||||
- ``msg.value`` (``uint``): number of wei sent with the message
|
- ``msg.value`` (``uint``): number of wei sent with the message
|
||||||
- ``now`` (``uint``): current block timestamp (alias for ``block.timestamp``)
|
|
||||||
- ``tx.gasprice`` (``uint``): gas price of the transaction
|
- ``tx.gasprice`` (``uint``): gas price of the transaction
|
||||||
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
|
- ``tx.origin`` (``address payable``): sender of the transaction (full call chain)
|
||||||
|
|
||||||
@ -88,7 +87,7 @@ Block and Transaction Properties
|
|||||||
This includes calls to library functions.
|
This includes calls to library functions.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness,
|
Do not rely on ``block.timestamp`` or ``blockhash`` as a source of randomness,
|
||||||
unless you know what you are doing.
|
unless you know what you are doing.
|
||||||
|
|
||||||
Both the timestamp and the block hash can be influenced by miners to some degree.
|
Both the timestamp and the block hash can be influenced by miners to some degree.
|
||||||
@ -327,4 +326,3 @@ for an interface type ``I``:
|
|||||||
A ``bytes4`` value containing the `EIP-165 <https://eips.ethereum.org/EIPS/eip-165>`_
|
A ``bytes4`` value containing the `EIP-165 <https://eips.ethereum.org/EIPS/eip-165>`_
|
||||||
interface identifier of the given interface ``I``. This identifier is defined as the ``XOR`` of all
|
interface identifier of the given interface ``I``. This identifier is defined as the ``XOR`` of all
|
||||||
function selectors defined within the interface itself - excluding all inherited functions.
|
function selectors defined within the interface itself - excluding all inherited functions.
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
|
|||||||
internal
|
internal
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
if (now > lastDay + 24 hours) {
|
if (block.timestamp > lastDay + 24 hours) {
|
||||||
lastDay = now;
|
lastDay = block.timestamp;
|
||||||
spentToday = 0;
|
spentToday = 0;
|
||||||
}
|
}
|
||||||
if (spentToday + amount > dailyLimit || spentToday + amount < spentToday)
|
if (spentToday + amount > dailyLimit || spentToday + amount < spentToday)
|
||||||
@ -88,7 +88,7 @@ contract MultiSigWalletWithDailyLimit is MultiSigWallet {
|
|||||||
view
|
view
|
||||||
returns (uint)
|
returns (uint)
|
||||||
{
|
{
|
||||||
if (now > lastDay + 24 hours)
|
if (block.timestamp > lastDay + 24 hours)
|
||||||
return dailyLimit;
|
return dailyLimit;
|
||||||
if (dailyLimit < spentToday)
|
if (dailyLimit < spentToday)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public {
|
||||||
|
now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (38-41): "now" has been deprecated. Use "block.timestamp" instead.
|
@ -0,0 +1,8 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public view {
|
||||||
|
uint now = block.timestamp;
|
||||||
|
now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (43-51): This declaration shadows a builtin symbol.
|
@ -1,7 +1,7 @@
|
|||||||
contract C {
|
contract C {
|
||||||
uint x;
|
uint x;
|
||||||
function g() pure public {}
|
function g() pure public {}
|
||||||
function f() view public returns (uint) { return now; }
|
function f() view public returns (uint) { return block.timestamp; }
|
||||||
function h() public { x = 2; }
|
function h() public { x = 2; }
|
||||||
function i() payable public { x = 2; }
|
function i() payable public { x = 2; }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user