Updated docs

This commit is contained in:
Harikrishnan Mulackal 2020-07-08 21:11:45 +05:30
parent 6b435b2192
commit bb2faf5e49

View File

@ -635,116 +635,88 @@ If you found a bug or if you have a feature request, please
Example Example
~~~~~~~ ~~~~~~~
Assume you have the following contracts you want to update declared in ``Source.sol``: Assume that you have the following contract in ``Source.sol``:
.. code-block:: none .. code-block:: solidity
// This will not compile after 0.5.0 pragma solidity >=0.6.0 <0.6.4;
// This will not compile after 0.7.0
// SPDX-License-Identifier: GPL-3.0 // SPDX-License-Identifier: GPL-3.0
pragma solidity >0.4.23 <0.5.0; contract C {
// FIXME: remove constructor visibility and make the contract abstract
contract Updateable { constructor() internal {}
function run() public view returns (bool);
function update() public;
} }
contract Upgradable { contract D {
function run() public view returns (bool); uint time;
function upgrade();
function f() public payable {
// FIXME: change now to block.timestamp
time = now;
}
} }
contract Source is Updateable, Upgradable { contract E {
function Source() public {} D d;
function run() // FIXME: remove constructor visibility
public constructor() public {}
view
returns (bool) {}
function update() {} function g() public {
function upgrade() {} // FIXME: change .value(5) => {value: 5}
d.f.value(5)();
} }
}
Required changes Required changes
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
To bring the contracts up to date with the current Solidity version, the The above contract will not compile starting from 0.7.0. To bring the contract up to date with the
following upgrade modules have to be executed: ``constructor``, current Solidity version, the following upgrade modules have to be executed:
``visibility``, ``abstract``, ``override`` and ``virtual``. Please read the ``constructor-visibility``, ``now`` and ``dotsyntax``. Please read the documentation on
documentation on :ref:`available modules <upgrade-modules>` for further details. :ref:`available modules <upgrade-modules>` for further details.
Running the upgrade Running the upgrade
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^
In this example, all modules needed to upgrade the contracts above, It is recommended to explicitly specify the upgrade modules by using ``--modules`` argument.
are available and all of them are activated by default. Therefore you
do not need to specify the ``--modules`` option.
.. code-block:: none .. code-block:: none
$ solidity-upgrade Source.sol --dry-run $ solidity-upgrade --modules constructor-visibility,now,dotsyntax Source.sol
.. code-block:: none The command above applies all changes as shown below. Please review them carefully (the pragmas will
have to be updated manually.)
Running analysis (and upgrade) on given source files.
..............
After upgrade:
Found 0 errors.
Found 0 upgrades.
The above performs a dry-run upgrade on the given file and logs statistics at
the end. In this case, the upgrade was successful and no further adjustments are
needed.
Finally, you can run the upgrade and also write to the source file.
.. code-block:: none
$ solidity-upgrade Source.sol
.. code-block:: none
Running analysis (and upgrade) on given source files.
..............
After upgrade:
Found 0 errors.
Found 0 upgrades.
Review changes
^^^^^^^^^^^^^^
The command above applies all changes as shown below. Please review them carefully.
.. code-block:: solidity .. code-block:: solidity
// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.6.99 <0.8.0; pragma solidity >0.6.99 <0.8.0;
// SPDX-License-Identifier: GPL-3.0
abstract contract Updateable { abstract contract C {
function run() public view virtual returns (bool); // FIXME: remove constructor visibility and make the contract abstract
function update() public virtual; constructor() {}
} }
abstract contract Upgradable { contract D {
function run() public view virtual returns (bool); uint time;
function upgrade() public virtual;
function f() public payable {
// FIXME: change now to block.timestamp
time = block.timestamp;
}
} }
contract Source is Updateable, Upgradable { contract E {
D d;
// FIXME: remove constructor visibility
constructor() {} constructor() {}
function run() function g() public {
public // FIXME: change .value(5) => {value: 5}
view d.f{value: 5}();
override(Updateable,Upgradable) }
returns (bool) {}
function update() public override {}
function upgrade() public override {}
} }