mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Adjust docs example to work with v0.8.0
This commit is contained in:
parent
559ab3f1ec
commit
b72fb1333b
@ -311,7 +311,7 @@ This will no longer compile with Solidity v0.5.0. However, you can define a comp
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
interface OldContract {
|
interface OldContract {
|
||||||
function someOldFunction(uint8 a) external;
|
function someOldFunction(uint8 a) external;
|
||||||
function anotherOldFunction() external returns (bool);
|
function anotherOldFunction() external returns (bool);
|
||||||
@ -329,7 +329,7 @@ Given the interface defined above, you can now easily use the already deployed p
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
interface OldContract {
|
interface OldContract {
|
||||||
function someOldFunction(uint8 a) external;
|
function someOldFunction(uint8 a) external;
|
||||||
|
@ -233,7 +233,7 @@ Given the contract:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract Foo {
|
contract Foo {
|
||||||
function bar(bytes3[2] memory) public pure {}
|
function bar(bytes3[2] memory) public pure {}
|
||||||
@ -537,7 +537,7 @@ For example,
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
contract Test {
|
contract Test {
|
||||||
@ -586,7 +586,7 @@ As an example, the code
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.19 <0.8.0;
|
pragma solidity >=0.4.19 <0.9.0;
|
||||||
pragma experimental ABIEncoderV2;
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
contract Test {
|
contract Test {
|
||||||
|
@ -42,7 +42,7 @@ without a compiler change.
|
|||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
library GetCode {
|
library GetCode {
|
||||||
function at(address _addr) public view returns (bytes memory o_code) {
|
function at(address _addr) public view returns (bytes memory o_code) {
|
||||||
@ -68,7 +68,7 @@ efficient code, for example:
|
|||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
library VectorSum {
|
library VectorSum {
|
||||||
@ -140,7 +140,7 @@ Local Solidity variables are available for assignments, for example:
|
|||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint b;
|
uint b;
|
||||||
|
@ -28,7 +28,7 @@ you receive the funds of the person who is now the richest.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract WithdrawalContract {
|
contract WithdrawalContract {
|
||||||
address public richest;
|
address public richest;
|
||||||
@ -62,7 +62,7 @@ This is as opposed to the more intuitive sending pattern:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract SendContract {
|
contract SendContract {
|
||||||
address payable public richest;
|
address payable public richest;
|
||||||
@ -124,7 +124,7 @@ restrictions highly readable.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract AccessRestriction {
|
contract AccessRestriction {
|
||||||
// These will be assigned at the construction
|
// These will be assigned at the construction
|
||||||
@ -277,7 +277,7 @@ function finishes.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract StateMachine {
|
contract StateMachine {
|
||||||
enum Stages {
|
enum Stages {
|
||||||
|
@ -14,7 +14,7 @@ defined as abstract, because the function ``utterance()`` was defined, but no im
|
|||||||
provided (no implementation body ``{ }`` was given).::
|
provided (no implementation body ``{ }`` was given).::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract Feline {
|
abstract contract Feline {
|
||||||
function utterance() public virtual returns (bytes32);
|
function utterance() public virtual returns (bytes32);
|
||||||
@ -24,7 +24,7 @@ Such abstract contracts can not be instantiated directly. This is also true, if
|
|||||||
all defined functions. The usage of an abstract contract as a base class is shown in the following example::
|
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
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract Feline {
|
abstract contract Feline {
|
||||||
function utterance() public pure virtual returns (bytes32);
|
function utterance() public pure virtual returns (bytes32);
|
||||||
|
@ -26,7 +26,7 @@ Not all types for constants and immutables are implemented at this time. The onl
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint constant X = 32**22 + 8;
|
uint constant X = 32**22 + 8;
|
||||||
|
@ -35,7 +35,7 @@ This means that cyclic creation dependencies are impossible.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
contract OwnedToken {
|
contract OwnedToken {
|
||||||
|
@ -66,7 +66,7 @@ is that they are cheaper to deploy and call.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.21 <0.8.0;
|
pragma solidity >=0.4.21 <0.9.0;
|
||||||
|
|
||||||
contract ClientReceipt {
|
contract ClientReceipt {
|
||||||
event Deposit(
|
event Deposit(
|
||||||
@ -140,7 +140,7 @@ as topics. The event call above can be performed in the same way as
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.10 <0.8.0;
|
pragma solidity >=0.4.10 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f() public payable {
|
function f() public payable {
|
||||||
|
@ -18,7 +18,7 @@ if they are marked ``virtual``. For details, please see
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.7.0 <0.8.0;
|
pragma solidity >0.7.0 <0.9.0;
|
||||||
|
|
||||||
contract owned {
|
contract owned {
|
||||||
constructor() { owner = msg.sender; }
|
constructor() { owner = msg.sender; }
|
||||||
|
@ -15,7 +15,7 @@ that call them, similar to internal library functions.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.7.0 <0.8.0;
|
pragma solidity >0.7.0 <0.9.0;
|
||||||
|
|
||||||
function sum(uint[] memory _arr) pure returns (uint s) {
|
function sum(uint[] memory _arr) pure returns (uint s) {
|
||||||
for (uint i = 0; i < _arr.length; i++)
|
for (uint i = 0; i < _arr.length; i++)
|
||||||
@ -52,7 +52,7 @@ For example, if you want your contract to accept one kind of external call
|
|||||||
with two integers, you would use something like the following::
|
with two integers, you would use something like the following::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract Simple {
|
contract Simple {
|
||||||
uint sum;
|
uint sum;
|
||||||
@ -85,7 +85,7 @@ 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::
|
two integers passed as function parameters, then you use something like::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract Simple {
|
contract Simple {
|
||||||
function arithmetic(uint _a, uint _b)
|
function arithmetic(uint _a, uint _b)
|
||||||
@ -110,7 +110,7 @@ or you can provide return values
|
|||||||
statement::
|
statement::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract Simple {
|
contract Simple {
|
||||||
function arithmetic(uint _a, uint _b)
|
function arithmetic(uint _a, uint _b)
|
||||||
@ -174,7 +174,7 @@ The following statements are considered modifying the state:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint b) public view returns (uint) {
|
function f(uint a, uint b) public view returns (uint) {
|
||||||
@ -220,7 +220,7 @@ In addition to the list of state modifying statements explained above, the follo
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a, uint b) public pure returns (uint) {
|
function f(uint a, uint b) public pure returns (uint) {
|
||||||
@ -314,7 +314,7 @@ Below you can see an example of a Sink contract that uses function ``receive``.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
// This contract keeps all Ether sent to it with no way
|
// This contract keeps all Ether sent to it with no way
|
||||||
// to get it back.
|
// to get it back.
|
||||||
@ -370,7 +370,7 @@ operations as long as there is enough gas passed on to it.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.2 <0.8.0;
|
pragma solidity >=0.6.2 <0.9.0;
|
||||||
|
|
||||||
contract Test {
|
contract Test {
|
||||||
// This function is called for all messages sent to
|
// This function is called for all messages sent to
|
||||||
@ -443,7 +443,7 @@ The following example shows overloading of the function
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
function f(uint _in) public pure returns (uint out) {
|
function f(uint _in) public pure returns (uint out) {
|
||||||
@ -462,7 +462,7 @@ externally visible functions differ by their Solidity types but not by their ext
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
// This will not compile
|
// This will not compile
|
||||||
contract A {
|
contract A {
|
||||||
@ -496,7 +496,7 @@ candidate, resolution fails.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
function f(uint8 _in) public pure returns (uint8 out) {
|
function f(uint8 _in) public pure returns (uint8 out) {
|
||||||
|
@ -39,7 +39,7 @@ Details are given in the following example.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
contract Owned {
|
contract Owned {
|
||||||
@ -127,7 +127,7 @@ destruction request. The way this is done is problematic, as
|
|||||||
seen in the following example::
|
seen in the following example::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract owned {
|
contract owned {
|
||||||
constructor() { owner = msg.sender; }
|
constructor() { owner = msg.sender; }
|
||||||
@ -157,7 +157,7 @@ explicitly in the final override, but this function will bypass
|
|||||||
``Base1.destroy``. The way around this is to use ``super``::
|
``Base1.destroy``. The way around this is to use ``super``::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract owned {
|
contract owned {
|
||||||
constructor() { owner = msg.sender; }
|
constructor() { owner = msg.sender; }
|
||||||
@ -214,7 +214,7 @@ The following example demonstrates changing mutability and visibility:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract Base
|
contract Base
|
||||||
{
|
{
|
||||||
@ -238,7 +238,7 @@ bases, it has to explicitly override it:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract Base1
|
contract Base1
|
||||||
{
|
{
|
||||||
@ -265,7 +265,7 @@ that already overrides all other functions.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract A { function f() public pure{} }
|
contract A { function f() public pure{} }
|
||||||
contract B is A {}
|
contract B is A {}
|
||||||
@ -306,7 +306,7 @@ of the variable:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract A
|
contract A
|
||||||
{
|
{
|
||||||
@ -338,7 +338,7 @@ and the ``override`` keyword must be used in the overriding modifier:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract Base
|
contract Base
|
||||||
{
|
{
|
||||||
@ -357,7 +357,7 @@ explicitly:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract Base1
|
contract Base1
|
||||||
{
|
{
|
||||||
@ -405,7 +405,7 @@ equivalent to ``constructor() {}``. For example:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
abstract contract A {
|
abstract contract A {
|
||||||
uint public a;
|
uint public a;
|
||||||
@ -442,7 +442,7 @@ 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::
|
derived contracts need to specify all of them. This can be done in two ways::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract Base {
|
contract Base {
|
||||||
uint x;
|
uint x;
|
||||||
@ -502,7 +502,7 @@ error "Linearization of inheritance graph impossible".
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract X {}
|
contract X {}
|
||||||
contract A is X {}
|
contract A is X {}
|
||||||
@ -523,7 +523,7 @@ One area where inheritance linearization is especially important and perhaps not
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract Base1 {
|
contract Base1 {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
@ -23,7 +23,7 @@ Interfaces are denoted by their own keyword:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.2 <0.8.0;
|
pragma solidity >=0.6.2 <0.9.0;
|
||||||
|
|
||||||
interface Token {
|
interface Token {
|
||||||
enum TokenType { Fungible, NonFungible }
|
enum TokenType { Fungible, NonFungible }
|
||||||
@ -44,7 +44,7 @@ inheritance.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.2 <0.8.0;
|
pragma solidity >=0.6.2 <0.9.0;
|
||||||
|
|
||||||
interface ParentA {
|
interface ParentA {
|
||||||
function test() external returns (uint256);
|
function test() external returns (uint256);
|
||||||
|
@ -47,7 +47,7 @@ more advanced example to implement a set).
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
// We define a new struct datatype that will be used to
|
// We define a new struct datatype that will be used to
|
||||||
@ -126,7 +126,7 @@ custom types without the overhead of external function calls:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
struct bigint {
|
struct bigint {
|
||||||
uint[] limbs;
|
uint[] limbs;
|
||||||
@ -243,7 +243,7 @@ Its value can be obtained from Solidity using the ``.selector`` member as follow
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.14 <0.8.0;
|
pragma solidity >=0.5.14 <0.9.0;
|
||||||
|
|
||||||
library L {
|
library L {
|
||||||
function f(uint256) external {}
|
function f(uint256) external {}
|
||||||
|
@ -30,7 +30,7 @@ Let us rewrite the set example from the
|
|||||||
:ref:`libraries` in this way::
|
:ref:`libraries` in this way::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
// This is the same code as before, just without comments
|
// This is the same code as before, just without comments
|
||||||
@ -83,7 +83,7 @@ Let us rewrite the set example from the
|
|||||||
It is also possible to extend elementary types in that way::
|
It is also possible to extend elementary types in that way::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
library Search {
|
library Search {
|
||||||
function indexOf(uint[] storage self, uint value)
|
function indexOf(uint[] storage self, uint value)
|
||||||
|
@ -55,7 +55,7 @@ return parameter list for functions.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint a) private pure returns (uint b) { return a + 1; }
|
function f(uint a) private pure returns (uint b) { return a + 1; }
|
||||||
@ -70,7 +70,7 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint private data;
|
uint private data;
|
||||||
@ -115,7 +115,7 @@ when they are declared.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint public data = 42;
|
uint public data = 42;
|
||||||
@ -136,7 +136,7 @@ it evaluates to a state variable. If it is accessed externally
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint public data;
|
uint public data;
|
||||||
@ -156,7 +156,7 @@ to write a function, for example:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract arrayExample {
|
contract arrayExample {
|
||||||
// public state variable
|
// public state variable
|
||||||
@ -183,7 +183,7 @@ The next example is more complex:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract Complex {
|
contract Complex {
|
||||||
struct Data {
|
struct Data {
|
||||||
|
@ -443,7 +443,7 @@ or ``interface`` using the ``./test/cmdlineTests.sh`` script when you create a P
|
|||||||
ensure they work and pass tests before creating the PR.
|
ensure they work and pass tests before creating the PR.
|
||||||
|
|
||||||
Ensure that all code examples begin with a ``pragma`` version that spans the largest where the contract code is valid.
|
Ensure that all code examples begin with a ``pragma`` version that spans the largest where the contract code is valid.
|
||||||
For example ``pragma solidity >=0.4.0 <0.8.0;``.
|
For example ``pragma solidity >=0.4.0 <0.9.0;``.
|
||||||
|
|
||||||
Running Documentation Tests
|
Running Documentation Tests
|
||||||
---------------------------
|
---------------------------
|
||||||
|
@ -42,7 +42,7 @@ Functions of the current contract can be called directly ("internally"), also re
|
|||||||
this nonsensical example::
|
this nonsensical example::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function g(uint a) public pure returns (uint ret) { return a + f(); }
|
function g(uint a) public pure returns (uint ret) { return a + f(); }
|
||||||
@ -84,7 +84,7 @@ to the total balance of that contract:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.2 <0.8.0;
|
pragma solidity >=0.6.2 <0.9.0;
|
||||||
|
|
||||||
contract InfoFeed {
|
contract InfoFeed {
|
||||||
function info() public payable returns (uint ret) { return 42; }
|
function info() public payable returns (uint ret) { return 42; }
|
||||||
@ -140,7 +140,7 @@ parameters from the function declaration, but can be in arbitrary order.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
mapping(uint => uint) data;
|
mapping(uint => uint) data;
|
||||||
@ -164,7 +164,7 @@ Those parameters will still be present on the stack, but they are inaccessible.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
// omitted name for parameter
|
// omitted name for parameter
|
||||||
@ -188,7 +188,7 @@ is compiled so recursive creation-dependencies are not possible.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract D {
|
contract D {
|
||||||
uint public x;
|
uint public x;
|
||||||
@ -244,7 +244,7 @@ which only need to be created if there is a dispute.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract D {
|
contract D {
|
||||||
uint public x;
|
uint public x;
|
||||||
@ -314,7 +314,7 @@ groupings of expressions.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint index;
|
uint index;
|
||||||
@ -360,7 +360,7 @@ because only a reference and not a copy is passed.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint[20] x;
|
uint[20] x;
|
||||||
@ -419,7 +419,7 @@ the two variables have the same name but disjoint scopes.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
contract C {
|
contract C {
|
||||||
function minimalScoping() pure public {
|
function minimalScoping() pure public {
|
||||||
{
|
{
|
||||||
@ -441,7 +441,7 @@ In any case, you will get a warning about the outer variable being shadowed.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
// This will report a warning
|
// This will report a warning
|
||||||
contract C {
|
contract C {
|
||||||
function f() pure public returns (uint) {
|
function f() pure public returns (uint) {
|
||||||
@ -463,7 +463,7 @@ In any case, you will get a warning about the outer variable being shadowed.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
// This will not compile
|
// This will not compile
|
||||||
contract C {
|
contract C {
|
||||||
function f() pure public returns (uint) {
|
function f() pure public returns (uint) {
|
||||||
@ -552,7 +552,7 @@ and ``assert`` for internal error checking.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract Sharer {
|
contract Sharer {
|
||||||
function sendHalf(address payable addr) public payable returns (uint balance) {
|
function sendHalf(address payable addr) public payable returns (uint balance) {
|
||||||
@ -597,7 +597,7 @@ The following example shows how to use an error string together with ``revert``
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract VendingMachine {
|
contract VendingMachine {
|
||||||
function buy(uint amount) public payable {
|
function buy(uint amount) public payable {
|
||||||
@ -641,7 +641,7 @@ A failure in an external call can be caught using a try/catch statement, as foll
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
interface DataFeed { function getData(address token) external returns (uint value); }
|
interface DataFeed { function getData(address token) external returns (uint value); }
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ to receive their money - contracts cannot activate themselves.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract SimpleAuction {
|
contract SimpleAuction {
|
||||||
// Parameters of the auction. Times are either
|
// Parameters of the auction. Times are either
|
||||||
@ -186,7 +186,7 @@ invalid bids.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract BlindAuction {
|
contract BlindAuction {
|
||||||
struct Bid {
|
struct Bid {
|
||||||
|
@ -143,7 +143,7 @@ The full contract
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract ReceiverPays {
|
contract ReceiverPays {
|
||||||
address owner = msg.sender;
|
address owner = msg.sender;
|
||||||
@ -340,7 +340,7 @@ The full contract
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract SimplePaymentChannel {
|
contract SimplePaymentChannel {
|
||||||
address payable public sender; // The account sending payments.
|
address payable public sender; // The account sending payments.
|
||||||
|
@ -20,7 +20,7 @@ and the sum of all balances is an invariant across the lifetime of the contract.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
library Balances {
|
library Balances {
|
||||||
function move(mapping(address => uint256) storage balances, address from, address to, uint amount) internal {
|
function move(mapping(address => uint256) storage balances, address from, address to, uint amount) internal {
|
||||||
|
@ -26,7 +26,7 @@ you can use state machine-like constructs inside a contract.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract Purchase {
|
contract Purchase {
|
||||||
uint public value;
|
uint public value;
|
||||||
|
@ -33,7 +33,7 @@ of votes.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
/// @title Voting with delegation.
|
/// @title Voting with delegation.
|
||||||
contract Ballot {
|
contract Ballot {
|
||||||
|
@ -72,7 +72,7 @@ the position of ``data[4][9].b`` is at ``keccak256(uint256(9) . keccak256(uint25
|
|||||||
|
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
@ -173,7 +173,7 @@ value and reference types, types that are encoded packed, and nested types.
|
|||||||
.. code::
|
.. code::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
contract A {
|
contract A {
|
||||||
struct S {
|
struct S {
|
||||||
uint128 a;
|
uint128 a;
|
||||||
|
@ -18,7 +18,7 @@ Storage Example
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract SimpleStorage {
|
contract SimpleStorage {
|
||||||
uint storedData;
|
uint storedData;
|
||||||
@ -83,7 +83,7 @@ registering with a username and password, all you need is an Ethereum keypair.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.5.99 <0.8.0;
|
pragma solidity >0.5.99 <0.9.0;
|
||||||
|
|
||||||
contract Coin {
|
contract Coin {
|
||||||
// The keyword "public" makes variables
|
// The keyword "public" makes variables
|
||||||
|
@ -317,7 +317,7 @@ for the two function parameters and two return variables.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.21 <0.8.0;
|
pragma solidity >=0.4.21 <0.9.0;
|
||||||
|
|
||||||
/** @title Shape calculator. */
|
/** @title Shape calculator. */
|
||||||
contract ShapeCalculator {
|
contract ShapeCalculator {
|
||||||
|
@ -49,7 +49,7 @@ The following example shows a contract and a function using all available tags.
|
|||||||
.. code:: Solidity
|
.. code:: Solidity
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.10 <0.8.0;
|
pragma solidity >0.6.10 <0.9.0;
|
||||||
|
|
||||||
/// @title A simulator for trees
|
/// @title A simulator for trees
|
||||||
/// @author Larry A. Gardner
|
/// @author Larry A. Gardner
|
||||||
|
@ -59,7 +59,7 @@ complete contract):
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||||
contract Fund {
|
contract Fund {
|
||||||
@ -83,7 +83,7 @@ as it uses ``call`` which forwards all remaining gas by default:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.2 <0.8.0;
|
pragma solidity >=0.6.2 <0.9.0;
|
||||||
|
|
||||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||||
contract Fund {
|
contract Fund {
|
||||||
@ -103,7 +103,7 @@ outlined further below:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.11 <0.8.0;
|
pragma solidity >=0.4.11 <0.9.0;
|
||||||
|
|
||||||
contract Fund {
|
contract Fund {
|
||||||
/// @dev Mapping of ether shares of the contract.
|
/// @dev Mapping of ether shares of the contract.
|
||||||
@ -201,7 +201,7 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
|
||||||
contract TxUserWallet {
|
contract TxUserWallet {
|
||||||
@ -222,7 +222,7 @@ Now someone tricks you into sending Ether to the address of this attack wallet:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
interface TxUserWallet {
|
interface TxUserWallet {
|
||||||
function transferTo(address payable dest, uint amount) external;
|
function transferTo(address payable dest, uint amount) external;
|
||||||
@ -283,7 +283,7 @@ field of a ``struct`` that is the base type of a dynamic storage array. The
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract Map {
|
contract Map {
|
||||||
mapping (uint => uint)[] array;
|
mapping (uint => uint)[] array;
|
||||||
|
@ -27,7 +27,7 @@ storage.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract SimpleStorage {
|
contract SimpleStorage {
|
||||||
uint storedData; // State variable
|
uint storedData; // State variable
|
||||||
@ -50,7 +50,7 @@ contracts.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.7.0 <0.8.0;
|
pragma solidity >0.7.0 <0.9.0;
|
||||||
|
|
||||||
contract SimpleAuction {
|
contract SimpleAuction {
|
||||||
function bid() public payable { // Function
|
function bid() public payable { // Function
|
||||||
@ -84,7 +84,7 @@ Like functions, modifiers can be :ref:`overridden <modifier-overriding>`.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract Purchase {
|
contract Purchase {
|
||||||
address public seller;
|
address public seller;
|
||||||
@ -112,7 +112,7 @@ Events are convenience interfaces with the EVM logging facilities.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.21 <0.8.0;
|
pragma solidity >=0.4.21 <0.9.0;
|
||||||
|
|
||||||
contract SimpleAuction {
|
contract SimpleAuction {
|
||||||
event HighestBidIncreased(address bidder, uint amount); // Event
|
event HighestBidIncreased(address bidder, uint amount); // Event
|
||||||
@ -137,7 +137,7 @@ Structs are custom defined types that can group several variables (see
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract Ballot {
|
contract Ballot {
|
||||||
struct Voter { // Struct
|
struct Voter { // Struct
|
||||||
@ -159,7 +159,7 @@ Enums can be used to create custom types with a finite set of 'constant values'
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract Purchase {
|
contract Purchase {
|
||||||
enum State { Created, Locked, Inactive } // Enum
|
enum State { Created, Locked, Inactive } // Enum
|
||||||
|
@ -56,7 +56,7 @@ Surround top level declarations in solidity source with two blank lines.
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
// ...
|
// ...
|
||||||
@ -75,7 +75,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
// ...
|
// ...
|
||||||
@ -95,7 +95,7 @@ Blank lines may be omitted between groups of related one-liners (such as stub fu
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract A {
|
abstract contract A {
|
||||||
function spam() public virtual pure;
|
function spam() public virtual pure;
|
||||||
@ -116,7 +116,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract A {
|
abstract contract A {
|
||||||
function spam() virtual pure public;
|
function spam() virtual pure public;
|
||||||
@ -251,7 +251,7 @@ Import statements should always be placed at the top of the file.
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
import "./Owned.sol";
|
import "./Owned.sol";
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
// ...
|
// ...
|
||||||
@ -300,7 +300,7 @@ Within a grouping, place the ``view`` and ``pure`` functions last.
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -337,7 +337,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ should:
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract Coin {
|
contract Coin {
|
||||||
struct Bank {
|
struct Bank {
|
||||||
@ -457,7 +457,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract Coin
|
contract Coin
|
||||||
{
|
{
|
||||||
@ -758,7 +758,7 @@ manner as modifiers if the function declaration is long or hard to read.
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
// Base contracts just to make this compile
|
// Base contracts just to make this compile
|
||||||
contract B {
|
contract B {
|
||||||
@ -790,7 +790,7 @@ Yes::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
// Base contracts just to make this compile
|
// Base contracts just to make this compile
|
||||||
@ -1012,7 +1012,7 @@ As shown in the example below, if the contract name is ``Congress`` and the libr
|
|||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
// Owned.sol
|
// Owned.sol
|
||||||
@ -1036,7 +1036,7 @@ Yes::
|
|||||||
and in ``Congress.sol``::
|
and in ``Congress.sol``::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
import "./Owned.sol";
|
import "./Owned.sol";
|
||||||
|
|
||||||
@ -1048,7 +1048,7 @@ and in ``Congress.sol``::
|
|||||||
No::
|
No::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
// owned.sol
|
// owned.sol
|
||||||
@ -1153,7 +1153,7 @@ For example, the contract from :ref:`a simple smart contract <simple-smart-contr
|
|||||||
added looks like the one below::
|
added looks like the one below::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
/// @author The Solidity Team
|
/// @author The Solidity Team
|
||||||
|
@ -43,7 +43,7 @@ contract that returns the value at the specified address.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract MappingExample {
|
contract MappingExample {
|
||||||
mapping(address => uint) public balances;
|
mapping(address => uint) public balances;
|
||||||
@ -69,7 +69,7 @@ The example below uses ``_allowances`` to record the amount someone else is allo
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
contract MappingExample {
|
contract MappingExample {
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ the ``sum`` function iterates over to sum all the values.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
struct IndexValue { uint keyIndex; uint value; }
|
struct IndexValue { uint keyIndex; uint value; }
|
||||||
struct KeyFlag { uint key; bool deleted; }
|
struct KeyFlag { uint key; bool deleted; }
|
||||||
|
@ -43,7 +43,7 @@ value it referred to previously.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract DeleteExample {
|
contract DeleteExample {
|
||||||
uint data;
|
uint data;
|
||||||
|
@ -63,7 +63,7 @@ Data locations are not only relevant for persistency of data, but also for the s
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.5.0 <0.8.0;
|
pragma solidity >=0.5.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
// The data location of x is storage.
|
// The data location of x is storage.
|
||||||
@ -174,7 +174,7 @@ or create a new memory array and copy every element.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f(uint len) public pure {
|
function f(uint len) public pure {
|
||||||
@ -206,7 +206,7 @@ the first element to ``uint``.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f() public pure {
|
function f() public pure {
|
||||||
@ -223,7 +223,7 @@ memory arrays, i.e. the following is not possible:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
// This will not compile.
|
// This will not compile.
|
||||||
contract C {
|
contract C {
|
||||||
@ -243,7 +243,7 @@ individual elements:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
function f() public pure {
|
function f() public pure {
|
||||||
@ -301,7 +301,7 @@ Array Members
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
contract ArrayContract {
|
contract ArrayContract {
|
||||||
uint[2**20] m_aLotOfIntegers;
|
uint[2**20] m_aLotOfIntegers;
|
||||||
@ -434,7 +434,7 @@ Array slices are useful to ABI-decode secondary data passed in function paramete
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
|
|
||||||
contract Proxy {
|
contract Proxy {
|
||||||
/// @dev Address of the client contract managed by proxy i.e., this contract
|
/// @dev Address of the client contract managed by proxy i.e., this contract
|
||||||
@ -478,7 +478,7 @@ shown in the following example:
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.0 <0.8.0;
|
pragma solidity >=0.6.0 <0.9.0;
|
||||||
|
|
||||||
// Defines a new type with two fields.
|
// Defines a new type with two fields.
|
||||||
// Declaring a struct outside of a contract allows
|
// Declaring a struct outside of a contract allows
|
||||||
|
@ -561,7 +561,7 @@ subsequent unsigned integer values starting from ``0``.
|
|||||||
::
|
::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
contract test {
|
contract test {
|
||||||
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
|
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
|
||||||
@ -674,7 +674,7 @@ External (or public) functions have the following members:
|
|||||||
Example that shows how to use the members::
|
Example that shows how to use the members::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.6.4 <0.8.0;
|
pragma solidity >=0.6.4 <0.9.0;
|
||||||
|
|
||||||
contract Example {
|
contract Example {
|
||||||
function f() public payable returns (bytes4) {
|
function f() public payable returns (bytes4) {
|
||||||
@ -690,7 +690,7 @@ Example that shows how to use the members::
|
|||||||
Example that shows how to use internal function types::
|
Example that shows how to use internal function types::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.16 <0.8.0;
|
pragma solidity >=0.4.16 <0.9.0;
|
||||||
|
|
||||||
library ArrayUtils {
|
library ArrayUtils {
|
||||||
// internal functions can be used in internal library functions because
|
// internal functions can be used in internal library functions because
|
||||||
@ -748,7 +748,7 @@ Example that shows how to use internal function types::
|
|||||||
Another example that uses external function types::
|
Another example that uses external function types::
|
||||||
|
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
pragma solidity >=0.4.22 <0.8.0;
|
pragma solidity >=0.4.22 <0.9.0;
|
||||||
|
|
||||||
|
|
||||||
contract Oracle {
|
contract Oracle {
|
||||||
|
@ -693,7 +693,7 @@ have to be updated manually.)
|
|||||||
|
|
||||||
.. code-block:: Solidity
|
.. code-block:: Solidity
|
||||||
|
|
||||||
pragma solidity >0.6.99 <0.8.0;
|
pragma solidity >0.6.99 <0.9.0;
|
||||||
// SPDX-License-Identifier: GPL-3.0
|
// SPDX-License-Identifier: GPL-3.0
|
||||||
abstract contract C {
|
abstract contract C {
|
||||||
// FIXME: remove constructor visibility and make the contract abstract
|
// FIXME: remove constructor visibility and make the contract abstract
|
||||||
|
@ -43,7 +43,7 @@ namespace solidity::frontend::test
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
static char const* registrarCode = R"DELIMITER(
|
static char const* registrarCode = R"DELIMITER(
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract NameRegister {
|
abstract contract NameRegister {
|
||||||
function addr(string memory _name) public virtual view returns (address o_owner);
|
function addr(string memory _name) public virtual view returns (address o_owner);
|
||||||
|
@ -55,7 +55,7 @@ static char const* registrarCode = R"DELIMITER(
|
|||||||
// @authors:
|
// @authors:
|
||||||
// Gav Wood <g@ethdev.com>
|
// Gav Wood <g@ethdev.com>
|
||||||
|
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
abstract contract Registrar {
|
abstract contract Registrar {
|
||||||
event Changed(string indexed name);
|
event Changed(string indexed name);
|
||||||
|
@ -56,7 +56,7 @@ static char const* walletCode = R"DELIMITER(
|
|||||||
// some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
|
// some number (specified in constructor) of the set of owners (specified in the constructor, modifiable) before the
|
||||||
// interior is executed.
|
// interior is executed.
|
||||||
|
|
||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract multiowned {
|
contract multiowned {
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract InvalidTest {
|
contract InvalidTest {
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
pragma solidity >=0.4.0 <0.8.0;
|
pragma solidity >=0.4.0 <0.9.0;
|
||||||
|
|
||||||
contract ERC20 {
|
contract ERC20 {
|
||||||
event Transfer(address indexed from, address indexed to, uint256 value);
|
event Transfer(address indexed from, address indexed to, uint256 value);
|
||||||
|
Loading…
Reference in New Issue
Block a user