aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2019-01-18 07:16:06 +0800
committerGitHub <noreply@github.com>2019-01-18 07:16:06 +0800
commit2ec997e697e306dd54165aad365406ee88c534cb (patch)
tree5e943e23d38e332de3eedd33be11f2cf9df5fd69 /docs
parent0711873a2f13d7b0f27e268fcd0a7683665f339d (diff)
parent2a92403690a4998ab097503231ac39f854b9c76c (diff)
downloaddexon-solidity-2ec997e697e306dd54165aad365406ee88c534cb.tar.gz
dexon-solidity-2ec997e697e306dd54165aad365406ee88c534cb.tar.zst
dexon-solidity-2ec997e697e306dd54165aad365406ee88c534cb.zip
Merge pull request #5775 from ethereum/codeAccess
Provide access to code of contract types.
Diffstat (limited to 'docs')
-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.