aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-16 17:55:18 +0800
committerchriseth <chris@ethereum.org>2019-01-18 03:36:48 +0800
commit01ad4bffe7e16251efdf17121479369cabe5f993 (patch)
treec9270311d6916f06d11e3c95a5d46da959408630
parentfed56f33d562266726fa73df0d613c541eeb652c (diff)
downloaddexon-solidity-01ad4bffe7e16251efdf17121479369cabe5f993.tar.gz
dexon-solidity-01ad4bffe7e16251efdf17121479369cabe5f993.tar.zst
dexon-solidity-01ad4bffe7e16251efdf17121479369cabe5f993.zip
Documentation.
-rw-r--r--docs/miscellaneous.rst4
-rw-r--r--docs/types/value-types.rst3
-rw-r--r--docs/units-and-global-variables.rst30
3 files changed, 36 insertions, 1 deletions
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst
index 5a6f3875..69124c77 100644
--- a/docs/miscellaneous.rst
+++ b/docs/miscellaneous.rst
@@ -385,6 +385,8 @@ Global Variables
- ``<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>.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::
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``,
``define``, ``final``, ``immutable``, ``implements``, ``in``, ``inline``, ``let``, ``macro``, ``match``,
``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``.
Language Grammar
diff --git a/docs/types/value-types.rst b/docs/types/value-types.rst
index 077587dd..09db1423 100644
--- a/docs/types/value-types.rst
+++ b/docs/types/value-types.rst
@@ -329,6 +329,9 @@ Contracts do not support any operators.
The members of contract types are the external functions of the contract
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
Fixed-size byte arrays
diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst
index c47f257b..ce7706c1 100644
--- a/docs/units-and-global-variables.rst
+++ b/docs/units-and-global-variables.rst
@@ -244,3 +244,33 @@ Furthermore, all functions of the current contract are callable directly includi
.. note::
Prior to version 0.5.0, there was a function called ``suicide`` with the same
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.