mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Updates documentation to 0.7.0.
This commit is contained in:
@@ -13,7 +13,7 @@ This can be done by using the ``abstract`` keyword as shown in the following exa
|
||||
defined as abstract, because the function ``utterance()`` was defined, but no implementation was
|
||||
provided (no implementation body ``{ }`` was given).::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
abstract contract Feline {
|
||||
function utterance() public virtual returns (bytes32);
|
||||
@@ -22,7 +22,7 @@ provided (no implementation body ``{ }`` was given).::
|
||||
Such abstract contracts can not be instantiated directly. This is also true, if an abstract contract itself does implement
|
||||
all defined functions. The usage of an abstract contract as a base class is shown in the following example::
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity >=0.6.0 <0.8.0;
|
||||
|
||||
abstract contract Feline {
|
||||
function utterance() public virtual returns (bytes32);
|
||||
|
||||
@@ -26,7 +26,7 @@ value types and strings.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
uint constant x = 32**22 + 8;
|
||||
|
||||
@@ -34,7 +34,7 @@ This means that cyclic creation dependencies are impossible.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
pragma solidity >=0.4.22 <0.8.0;
|
||||
|
||||
|
||||
contract OwnedToken {
|
||||
|
||||
@@ -65,7 +65,7 @@ is that they are cheaper to deploy and call.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.21 <0.7.0;
|
||||
pragma solidity >=0.4.21 <0.8.0;
|
||||
|
||||
contract ClientReceipt {
|
||||
event Deposit(
|
||||
@@ -138,7 +138,7 @@ as topics. The event call above can be performed in the same way as
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.10 <0.7.0;
|
||||
pragma solidity >=0.4.10 <0.8.0;
|
||||
|
||||
contract C {
|
||||
function f() public payable {
|
||||
|
||||
@@ -17,7 +17,7 @@ if they are marked ``virtual``. For details, please see
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract owned {
|
||||
constructor() public { owner = msg.sender; }
|
||||
|
||||
@@ -23,7 +23,7 @@ unused parameters can be omitted.
|
||||
For example, if you want your contract to accept one kind of external call
|
||||
with two integers, you would use something like the following::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract Simple {
|
||||
uint sum;
|
||||
@@ -55,7 +55,7 @@ Function return variables are declared with the same syntax after the
|
||||
For example, suppose you want to return two results: the sum and the product of
|
||||
two integers passed as function parameters, then you use something like::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract Simple {
|
||||
function arithmetic(uint _a, uint _b)
|
||||
@@ -79,7 +79,7 @@ or you can provide return values
|
||||
(either a single or :ref:`multiple ones<multi-return>`) directly with the ``return``
|
||||
statement::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract Simple {
|
||||
function arithmetic(uint _a, uint _b)
|
||||
@@ -142,7 +142,7 @@ The following statements are considered modifying the state:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
function f(uint a, uint b) public view returns (uint) {
|
||||
@@ -187,7 +187,7 @@ In addition to the list of state modifying statements explained above, the follo
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
function f(uint a, uint b) public pure returns (uint) {
|
||||
@@ -280,7 +280,7 @@ Below you can see an example of a Sink contract that uses function ``receive``.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity >=0.6.0 <0.8.0;
|
||||
|
||||
// This contract keeps all Ether sent to it with no way
|
||||
// to get it back.
|
||||
@@ -335,7 +335,7 @@ operations as long as there is enough gas passed on to it.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity >=0.6.0 <0.8.0;
|
||||
|
||||
contract Test {
|
||||
// This function is called for all messages sent to
|
||||
@@ -407,7 +407,7 @@ The following example shows overloading of the function
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract A {
|
||||
function f(uint _in) public pure returns (uint out) {
|
||||
@@ -425,7 +425,7 @@ externally visible functions differ by their Solidity types but not by their ext
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
// This will not compile
|
||||
contract A {
|
||||
@@ -458,7 +458,7 @@ candidate, resolution fails.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract A {
|
||||
function f(uint8 _in) public pure returns (uint8 out) {
|
||||
|
||||
@@ -38,7 +38,7 @@ Details are given in the following example.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity >=0.6.0 <0.8.0;
|
||||
|
||||
|
||||
contract Owned {
|
||||
@@ -125,7 +125,7 @@ Note that above, we call ``mortal.kill()`` to "forward" the
|
||||
destruction request. The way this is done is problematic, as
|
||||
seen in the following example::
|
||||
|
||||
pragma solidity ^0.6.0;
|
||||
pragma solidity >=0.6.0 <0.8.0;
|
||||
|
||||
contract owned {
|
||||
constructor() public { owner = msg.sender; }
|
||||
@@ -154,7 +154,7 @@ A call to ``Final.kill()`` will call ``Base2.kill`` because we specify it
|
||||
explicitly in the final override, but this function will bypass
|
||||
``Base1.kill``. The way around this is to use ``super``::
|
||||
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
pragma solidity >=0.4.22 <0.8.0;
|
||||
|
||||
contract owned {
|
||||
constructor() public { owner = msg.sender; }
|
||||
@@ -204,7 +204,7 @@ use the ``override`` keyword in the function header as shown in this example:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract Base
|
||||
{
|
||||
@@ -227,7 +227,7 @@ bases, it has to explicitly override it:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract Base1
|
||||
{
|
||||
@@ -253,7 +253,7 @@ that already overrides all other functions.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract A { function f() public pure{} }
|
||||
contract B is A {}
|
||||
@@ -293,7 +293,7 @@ of the variable:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract A
|
||||
{
|
||||
@@ -324,7 +324,7 @@ and the ``override`` keyword must be used in the overriding modifier:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract Base
|
||||
{
|
||||
@@ -342,7 +342,7 @@ explicitly:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract Base1
|
||||
{
|
||||
@@ -389,7 +389,7 @@ equivalent to ``constructor() public {}``. For example:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
contract A {
|
||||
uint public a;
|
||||
@@ -419,7 +419,7 @@ The constructors of all the base contracts will be called following the
|
||||
linearization rules explained below. If the base constructors have arguments,
|
||||
derived contracts need to specify all of them. This can be done in two ways::
|
||||
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
pragma solidity >=0.4.22 <0.8.0;
|
||||
|
||||
contract Base {
|
||||
uint x;
|
||||
@@ -478,7 +478,7 @@ error "Linearization of inheritance graph impossible".
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract X {}
|
||||
contract A is X {}
|
||||
@@ -498,7 +498,7 @@ One area where inheritance linearization is especially important and perhaps not
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract Base1 {
|
||||
constructor() public {}
|
||||
|
||||
@@ -22,7 +22,7 @@ Interfaces are denoted by their own keyword:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
pragma solidity >=0.5.0 <0.8.0;
|
||||
|
||||
interface Token {
|
||||
enum TokenType { Fungible, NonFungible }
|
||||
|
||||
@@ -47,7 +47,7 @@ more advanced example to implement a set).
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
pragma solidity >=0.4.22 <0.8.0;
|
||||
|
||||
|
||||
// We define a new struct datatype that will be used to
|
||||
@@ -123,7 +123,7 @@ custom types without the overhead of external function calls:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
struct bigint {
|
||||
uint[] limbs;
|
||||
@@ -237,7 +237,7 @@ Its value can be obtained from Solidity using the ``.selector`` member as follow
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >0.5.13 <0.7.0;
|
||||
pragma solidity >0.5.13 <0.8.0;
|
||||
|
||||
library L {
|
||||
function f(uint256) external {}
|
||||
|
||||
@@ -29,7 +29,7 @@ may only be used inside a contract, not inside any of its functions.
|
||||
Let us rewrite the set example from the
|
||||
:ref:`libraries` in this way::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
|
||||
// This is the same code as before, just without comments
|
||||
@@ -81,7 +81,7 @@ Let us rewrite the set example from the
|
||||
|
||||
It is also possible to extend elementary types in that way::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
library Search {
|
||||
function indexOf(uint[] storage self, uint value)
|
||||
|
||||
@@ -54,7 +54,7 @@ return parameter list for functions.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
pragma solidity >=0.4.16 <0.8.0;
|
||||
|
||||
contract C {
|
||||
function f(uint a) private pure returns (uint b) { return a + 1; }
|
||||
@@ -68,7 +68,7 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
uint private data;
|
||||
@@ -112,7 +112,7 @@ when they are declared.
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
uint public data = 42;
|
||||
@@ -132,7 +132,7 @@ it evaluates to a state variable. If it is accessed externally
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract C {
|
||||
uint public data;
|
||||
@@ -151,7 +151,7 @@ to write a function, for example:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract arrayExample {
|
||||
// public state variable
|
||||
@@ -177,7 +177,7 @@ The next example is more complex:
|
||||
|
||||
::
|
||||
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
pragma solidity >=0.4.0 <0.8.0;
|
||||
|
||||
contract Complex {
|
||||
struct Data {
|
||||
|
||||
Reference in New Issue
Block a user