Documentation.

This commit is contained in:
chriseth 2019-01-16 10:55:18 +01:00
parent fed56f33d5
commit 01ad4bffe7
3 changed files with 36 additions and 1 deletions

View File

@ -385,6 +385,8 @@ Global Variables
- ``<address>.balance`` (``uint256``): balance of the :ref:`address` in Wei - ``<address>.balance`` (``uint256``): balance of the :ref:`address` in Wei
- ``<address payable>.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure - ``<address payable>.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure
- ``<address payable>.transfer(uint256 amount)``: send given amount of Wei to :ref:`address`, throws on failure - ``<address payable>.transfer(uint256 amount)``: send given amount of Wei to :ref:`address`, throws on failure
- ``type(C).creationCode`` (``bytes memory``): creation bytecode of the given contract, see :ref:`Type Information<meta-type>`.
- ``type(C).runtimeCode`` (``bytes memory``): runtime bytecode of the given contract, see :ref:`Type Information<meta-type>`.
.. note:: .. note::
Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness, Do not rely on ``block.timestamp``, ``now`` and ``blockhash`` as a source of randomness,
@ -445,7 +447,7 @@ These keywords are reserved in Solidity. They might become part of the syntax in
``abstract``, ``after``, ``alias``, ``apply``, ``auto``, ``case``, ``catch``, ``copyof``, ``default``, ``abstract``, ``after``, ``alias``, ``apply``, ``auto``, ``case``, ``catch``, ``copyof``, ``default``,
``define``, ``final``, ``immutable``, ``implements``, ``in``, ``inline``, ``let``, ``macro``, ``match``, ``define``, ``final``, ``immutable``, ``implements``, ``in``, ``inline``, ``let``, ``macro``, ``match``,
``mutable``, ``null``, ``of``, ``override``, ``partial``, ``promise``, ``reference``, ``relocatable``, ``mutable``, ``null``, ``of``, ``override``, ``partial``, ``promise``, ``reference``, ``relocatable``,
``sealed``, ``sizeof``, ``static``, ``supports``, ``switch``, ``try``, ``type``, ``typedef``, ``typeof``, ``sealed``, ``sizeof``, ``static``, ``supports``, ``switch``, ``try``, ``typedef``, ``typeof``,
``unchecked``. ``unchecked``.
Language Grammar Language Grammar

View File

@ -329,6 +329,9 @@ Contracts do not support any operators.
The members of contract types are the external functions of the contract The members of contract types are the external functions of the contract
including public state variables. including public state variables.
For a contract ``C`` you can use ``type(C)`` to access
:ref:`type information<meta-type>` about the contract.
.. index:: byte array, bytes32 .. index:: byte array, bytes32
Fixed-size byte arrays Fixed-size byte arrays

View File

@ -244,3 +244,33 @@ Furthermore, all functions of the current contract are callable directly includi
.. note:: .. note::
Prior to version 0.5.0, there was a function called ``suicide`` with the same Prior to version 0.5.0, there was a function called ``suicide`` with the same
semantics as ``selfdestruct``. semantics as ``selfdestruct``.
.. index:: type, creationCode, runtimeCode
.. _meta-type:
Type Information
----------------
The expression ``type(X)`` can be used to retrieve information about the
type ``X``. Currently, there is limited support for this feature, but
it might be expanded in the future. The following properties are
available for a conract type ``C``:
``type(C).creationCode``:
Memory byte array that contains the creation bytecode of the contract.
This can be used in inline assembly to build custom creation routines,
especially by using the ``create2`` opcode.
This property can **not** be accessed in the contract itself or any
derived contract. It causes the bytecode to be included in the bytecode
of the call site and thus circular references like that are not possible.
``type(C).runtimeCode``:
Memory byte array that contains the runtime bytecode of the contract.
This is the code that is usually deployed by the constructor of ``C``.
If ``C`` has a constructor that uses inline assembly, this might be
different from the actually deployed bytecode. Also note that libraries
modify their runtime bytecode at time of deployment to guard against
regular calls.
The same restrictions as with ``.creationCode`` also apply for this
property.