mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add license tags to documentation snippets.
This commit is contained in:
parent
bcc4bbcad7
commit
d33b67b3c2
@ -292,6 +292,7 @@ Consider you have the following pre-0.5.0 contract already deployed:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.4.25;
|
||||
// This will report a warning until version 0.4.25 of the compiler
|
||||
// This will not compile after 0.5.0
|
||||
@ -309,6 +310,7 @@ This will no longer compile with Solidity v0.5.0. However, you can define a comp
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
interface OldContract {
|
||||
function someOldFunction(uint8 a) external;
|
||||
@ -326,6 +328,7 @@ Given the interface defined above, you can now easily use the already deployed p
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
interface OldContract {
|
||||
@ -347,6 +350,7 @@ commandline compiler for linking):
|
||||
::
|
||||
|
||||
// This will not compile after 0.6.0
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.5.99;
|
||||
|
||||
library OldLibrary {
|
||||
@ -370,6 +374,7 @@ Old version:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.4.25;
|
||||
// This will not compile after 0.5.0
|
||||
|
||||
@ -432,6 +437,7 @@ New version:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.5.99;
|
||||
// This will not compile after 0.6.0
|
||||
|
||||
|
@ -232,6 +232,7 @@ Given the contract:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract Foo {
|
||||
@ -535,6 +536,7 @@ For example,
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
|
||||
@ -583,6 +585,7 @@ As an example, the code
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.19 <0.7.0;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
|
@ -41,6 +41,7 @@ without a compiler change.
|
||||
|
||||
.. code::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
library GetCode {
|
||||
@ -66,6 +67,7 @@ efficient code, for example:
|
||||
|
||||
.. code::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
|
||||
@ -136,6 +138,7 @@ Local Solidity variables are available for assignments, for example:
|
||||
|
||||
.. code::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
|
@ -27,6 +27,7 @@ you receive the funds of the person who is now the richest.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract WithdrawalContract {
|
||||
@ -60,6 +61,7 @@ This is as opposed to the more intuitive sending pattern:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract SendContract {
|
||||
@ -121,6 +123,7 @@ restrictions highly readable.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract AccessRestriction {
|
||||
@ -273,6 +276,7 @@ function finishes.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract StateMachine {
|
||||
|
@ -13,6 +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).::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
abstract contract Feline {
|
||||
@ -22,6 +23,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::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
abstract contract Feline {
|
||||
|
@ -17,6 +17,7 @@ Not all types for constants and immutables are implemented at this time. The onl
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >0.6.4 <0.7.0;
|
||||
|
||||
contract C {
|
||||
|
@ -34,6 +34,7 @@ This means that cyclic creation dependencies are impossible.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
|
||||
|
@ -65,6 +65,7 @@ is that they are cheaper to deploy and call.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.21 <0.7.0;
|
||||
|
||||
contract ClientReceipt {
|
||||
@ -138,6 +139,7 @@ as topics. The event call above can be performed in the same way as
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.10 <0.7.0;
|
||||
|
||||
contract C {
|
||||
|
@ -17,6 +17,7 @@ if they are marked ``virtual``. For details, please see
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract owned {
|
||||
|
@ -23,6 +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::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract Simple {
|
||||
@ -55,6 +56,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::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract Simple {
|
||||
@ -79,6 +81,7 @@ or you can provide return values
|
||||
(either a single or :ref:`multiple ones<multi-return>`) directly with the ``return``
|
||||
statement::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract Simple {
|
||||
@ -142,6 +145,7 @@ The following statements are considered modifying the state:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -187,6 +191,7 @@ In addition to the list of state modifying statements explained above, the follo
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -280,6 +285,7 @@ Below you can see an example of a Sink contract that uses function ``receive``.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
// This contract keeps all Ether sent to it with no way
|
||||
@ -335,6 +341,7 @@ operations as long as there is enough gas passed on to it.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
contract Test {
|
||||
@ -407,6 +414,7 @@ The following example shows overloading of the function
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract A {
|
||||
@ -425,6 +433,7 @@ externally visible functions differ by their Solidity types but not by their ext
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
// This will not compile
|
||||
@ -458,6 +467,7 @@ candidate, resolution fails.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract A {
|
||||
|
@ -38,6 +38,7 @@ Details are given in the following example.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
|
||||
@ -125,6 +126,7 @@ Note that above, we call ``Destructible.destroy()`` to "forward" the
|
||||
destruction request. The way this is done is problematic, as
|
||||
seen in the following example::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
contract owned {
|
||||
@ -154,6 +156,7 @@ A call to ``Final.destroy()`` will call ``Base2.destroy`` because we specify it
|
||||
explicitly in the final override, but this function will bypass
|
||||
``Base1.destroy``. The way around this is to use ``super``::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract owned {
|
||||
@ -204,6 +207,7 @@ use the ``override`` keyword in the function header as shown in this example:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Base
|
||||
@ -227,6 +231,7 @@ bases, it has to explicitly override it:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Base1
|
||||
@ -253,6 +258,7 @@ that already overrides all other functions.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract A { function f() public pure{} }
|
||||
@ -293,6 +299,7 @@ of the variable:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract A
|
||||
@ -324,6 +331,7 @@ and the ``override`` keyword must be used in the overriding modifier:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Base
|
||||
@ -342,6 +350,7 @@ explicitly:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Base1
|
||||
@ -389,6 +398,7 @@ equivalent to ``constructor() public {}``. For example:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract A {
|
||||
@ -419,6 +429,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::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract Base {
|
||||
@ -478,6 +489,7 @@ error "Linearization of inheritance graph impossible".
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract X {}
|
||||
@ -498,6 +510,7 @@ One area where inheritance linearization is especially important and perhaps not
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract Base1 {
|
||||
|
@ -22,6 +22,7 @@ Interfaces are denoted by their own keyword:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
interface Token {
|
||||
@ -42,6 +43,7 @@ inheritance.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
interface ParentA {
|
||||
|
@ -47,6 +47,7 @@ more advanced example to implement a set).
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
|
||||
@ -125,6 +126,7 @@ custom types without the overhead of external function calls:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
struct bigint {
|
||||
@ -239,6 +241,7 @@ Its value can be obtained from Solidity using the ``.selector`` member as follow
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.14 <0.7.0;
|
||||
|
||||
library L {
|
||||
|
@ -29,6 +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::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
|
||||
@ -81,6 +82,7 @@ Let us rewrite the set example from the
|
||||
|
||||
It is also possible to extend elementary types in that way::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
library Search {
|
||||
|
@ -54,6 +54,7 @@ return parameter list for functions.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -68,6 +69,7 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -112,6 +114,7 @@ when they are declared.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -132,6 +135,7 @@ it evaluates to a state variable. If it is accessed externally
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -151,6 +155,7 @@ to write a function, for example:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract arrayExample {
|
||||
@ -177,6 +182,7 @@ The next example is more complex:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract Complex {
|
||||
|
@ -41,6 +41,7 @@ Internal Function Calls
|
||||
Functions of the current contract can be called directly ("internally"), also recursively, as seen in
|
||||
this nonsensical example::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -82,6 +83,7 @@ to the total balance of that contract:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
contract InfoFeed {
|
||||
@ -137,6 +139,7 @@ parameters from the function declaration, but can be in arbitrary order.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -160,6 +163,7 @@ Those parameters will still be present on the stack, but they are inaccessible.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -183,6 +187,7 @@ is compiled so recursive creation-dependencies are not possible.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
contract D {
|
||||
@ -238,6 +243,7 @@ which only need to be created if there is a dispute.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
contract D {
|
||||
@ -307,6 +313,7 @@ groupings of expressions.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -352,6 +359,7 @@ because only a reference and not a copy is passed.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -410,6 +418,7 @@ the two variables have the same name but disjoint scopes.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
contract C {
|
||||
function minimalScoping() pure public {
|
||||
@ -431,6 +440,7 @@ In any case, you will get a warning about the outer variable being shadowed.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
// This will report a warning
|
||||
contract C {
|
||||
@ -452,6 +462,7 @@ In any case, you will get a warning about the outer variable being shadowed.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
// This will not compile
|
||||
contract C {
|
||||
@ -540,6 +551,7 @@ and ``assert`` for internal error checking.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract Sharer {
|
||||
@ -584,6 +596,7 @@ The following example shows how to use an error string together with ``revert``
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract VendingMachine {
|
||||
@ -627,6 +640,7 @@ A failure in an external call can be caught using a try/catch statement, as foll
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
interface DataFeed { function getData(address token) external returns (uint value); }
|
||||
|
@ -24,6 +24,7 @@ to receive their money - contracts cannot activate themselves.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract SimpleAuction {
|
||||
@ -184,6 +185,7 @@ invalid bids.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract BlindAuction {
|
||||
|
@ -142,6 +142,7 @@ The full contract
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.24 <0.7.0;
|
||||
|
||||
contract ReceiverPays {
|
||||
@ -338,6 +339,7 @@ The full contract
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract SimplePaymentChannel {
|
||||
|
@ -19,6 +19,7 @@ and the sum of all balances is an invariant across the lifetime of the contract.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
library Balances {
|
||||
|
@ -25,6 +25,7 @@ you can use state machine-like constructs inside a contract.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract Purchase {
|
||||
|
@ -32,6 +32,7 @@ of votes.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
/// @title Voting with delegation.
|
||||
|
@ -71,6 +71,7 @@ So for the following contract snippet
|
||||
the position of ``data[4][9].b`` is at ``keccak256(uint256(9) . keccak256(uint256(4) . uint256(1))) + 1``::
|
||||
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
|
||||
@ -171,6 +172,7 @@ value and reference types, types that are encoded packed, and nested types.
|
||||
|
||||
.. code::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
contract A {
|
||||
struct S {
|
||||
|
@ -17,6 +17,7 @@ Storage Example
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract SimpleStorage {
|
||||
@ -81,6 +82,7 @@ registering with a username and password, all you need is an Ethereum keypair.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract Coin {
|
||||
|
@ -316,6 +316,7 @@ for the two function parameters and two return variables.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.21 <0.7.0;
|
||||
|
||||
/** @title Shape calculator. */
|
||||
|
@ -49,6 +49,7 @@ The following example shows a contract and a function using all available tags.
|
||||
|
||||
.. code:: solidity
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
/// @title A simulator for trees
|
||||
|
@ -58,6 +58,7 @@ complete contract):
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||
@ -81,6 +82,7 @@ as it uses ``call`` which forwards all remaining gas by default:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.2 <0.7.0;
|
||||
|
||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||
@ -100,6 +102,7 @@ outlined further below:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.11 <0.7.0;
|
||||
|
||||
contract Fund {
|
||||
@ -197,6 +200,7 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||
@ -217,6 +221,7 @@ Now someone tricks you into sending Ether to the address of this attack wallet:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
interface TxUserWallet {
|
||||
@ -277,6 +282,7 @@ field of a ``struct`` that is the base type of a dynamic storage array. The
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Map {
|
||||
@ -555,6 +561,7 @@ not mean loss of proving power.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0;
|
||||
pragma experimental SMTChecker;
|
||||
// This may report a warning if no SMT solver available.
|
||||
@ -609,6 +616,7 @@ types.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0;
|
||||
pragma experimental SMTChecker;
|
||||
// This will report a warning
|
||||
|
@ -26,6 +26,7 @@ storage.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract SimpleStorage {
|
||||
@ -46,6 +47,7 @@ Functions are the executable units of code within a contract.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract SimpleAuction {
|
||||
@ -74,6 +76,7 @@ Like functions, modifiers can be :ref:`overridden <modifier-overriding>`.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract Purchase {
|
||||
@ -101,6 +104,7 @@ Events are convenience interfaces with the EVM logging facilities.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.21 <0.7.0;
|
||||
|
||||
contract SimpleAuction {
|
||||
@ -125,6 +129,7 @@ Structs are custom defined types that can group several variables (see
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract Ballot {
|
||||
@ -146,6 +151,7 @@ Enums can be used to create custom types with a finite set of 'constant values'
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract Purchase {
|
||||
|
@ -55,6 +55,7 @@ Surround top level declarations in solidity source with two blank lines.
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract A {
|
||||
@ -73,6 +74,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract A {
|
||||
@ -92,6 +94,7 @@ Blank lines may be omitted between groups of related one-liners (such as stub fu
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
abstract contract A {
|
||||
@ -112,6 +115,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
abstract contract A {
|
||||
@ -246,6 +250,7 @@ Import statements should always be placed at the top of the file.
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
import "./Owned.sol";
|
||||
@ -260,6 +265,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract A {
|
||||
@ -293,6 +299,7 @@ Within a grouping, place the ``view`` and ``pure`` functions last.
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
contract A {
|
||||
@ -329,6 +336,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.6.0;
|
||||
|
||||
contract A {
|
||||
@ -436,6 +444,7 @@ should:
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract Coin {
|
||||
@ -447,6 +456,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract Coin
|
||||
@ -747,6 +757,7 @@ manner as modifiers if the function declaration is long or hard to read.
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
// Base contracts just to make this compile
|
||||
@ -779,6 +790,7 @@ Yes::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
|
||||
@ -1002,6 +1014,7 @@ As shown in the example below, if the contract name is ``Congress`` and the libr
|
||||
|
||||
Yes::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
|
||||
@ -1025,6 +1038,7 @@ Yes::
|
||||
|
||||
and in ``Congress.sol``::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
import "./Owned.sol";
|
||||
@ -1036,6 +1050,7 @@ and in ``Congress.sol``::
|
||||
|
||||
No::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
|
||||
@ -1140,6 +1155,7 @@ multiline comment starting with ``/**`` and ending with ``*/``.
|
||||
For example, the contract from `a simple smart contract <simple-smart-contract>`_ with the comments
|
||||
added looks like the one below::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
|
||||
|
@ -41,6 +41,7 @@ contract that returns the value at the specified address.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract MappingExample {
|
||||
@ -66,6 +67,7 @@ The example below uses ``_allowances`` to record the amount someone else is allo
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
contract MappingExample {
|
||||
@ -120,6 +122,7 @@ the ``sum`` function iterates over to sum all the values.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
struct IndexValue { uint keyIndex; uint value; }
|
||||
|
@ -42,6 +42,7 @@ value it referred to previously.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
contract DeleteExample {
|
||||
|
@ -57,6 +57,7 @@ Data locations are not only relevant for persistency of data, but also for the s
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.5.0 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -167,6 +168,7 @@ or create a new memory array and copy every element.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -198,6 +200,7 @@ the first element to ``uint``.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract C {
|
||||
@ -214,6 +217,7 @@ memory arrays, i.e. the following is not possible:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.0 <0.7.0;
|
||||
|
||||
// This will not compile.
|
||||
@ -274,6 +278,7 @@ Array Members
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract ArrayContract {
|
||||
@ -406,6 +411,7 @@ Array slices are useful to ABI-decode secondary data passed in function paramete
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
contract Proxy {
|
||||
@ -443,6 +449,7 @@ shown in the following example:
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
// Defines a new type with two fields.
|
||||
|
@ -543,6 +543,7 @@ subsequent unsigned integer values starting from ``0``.
|
||||
|
||||
::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
contract test {
|
||||
@ -653,6 +654,7 @@ External (or public) functions have the following members:
|
||||
|
||||
Example that shows how to use the members::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
// This will report a warning
|
||||
|
||||
@ -671,6 +673,7 @@ Example that shows how to use the members::
|
||||
|
||||
Example that shows how to use internal function types::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.16 <0.7.0;
|
||||
|
||||
library ArrayUtils {
|
||||
@ -728,6 +731,7 @@ Example that shows how to use internal function types::
|
||||
|
||||
Another example that uses external function types::
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.4.22 <0.7.0;
|
||||
|
||||
|
||||
|
@ -617,6 +617,7 @@ Assume you have the following contracts you want to update declared in ``Source.
|
||||
.. code-block:: none
|
||||
|
||||
// This will not compile after 0.5.0
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >0.4.23 <0.5.0;
|
||||
|
||||
contract Updateable {
|
||||
@ -698,6 +699,7 @@ The command above applies all changes as shown below. Please review them careful
|
||||
|
||||
.. code-block:: solidity
|
||||
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.6.0 <0.7.0;
|
||||
|
||||
abstract contract Updateable {
|
||||
|
Loading…
Reference in New Issue
Block a user