aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-04-14 00:36:33 +0800
committerchriseth <chris@ethereum.org>2018-04-14 00:36:33 +0800
commit559fa58ddf3d6b32242286e392b2695d56594423 (patch)
tree2336e003d25a9709e214010fdb8d80670d4b2a63
parent2001cc6bdca87d715380b15f11c797666528e040 (diff)
downloaddexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar.gz
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar.bz2
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar.lz
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar.xz
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.tar.zst
dexon-solidity-559fa58ddf3d6b32242286e392b2695d56594423.zip
Document ABI encoding functions.
-rw-r--r--Changelog.md1
-rw-r--r--docs/miscellaneous.rst5
-rw-r--r--docs/units-and-global-variables.rst25
3 files changed, 29 insertions, 2 deletions
diff --git a/Changelog.md b/Changelog.md
index 80f02a2d..81c8b974 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@ Features:
* General: Allow providing reason string for ``revert()`` and ``require()``.
* General: Limit the number of errors output in a single run to 256.
* General: Support accessing dynamic return data in post-byzantium EVMs.
+ * General: Add encoding routines ``abi.encodePacked``, ``abi.encode``, ``abi.encodeWithSelector`` and ``abi.encodeWithSignature``.
* Interfaces: Allow overriding external functions in interfaces with public in an implementing contract.
* Optimizer: Optimize ``SHL`` and ``SHR`` only involving constants (Constantinople only).
* Optimizer: Remove useless ``SWAP1`` instruction preceding a commutative instruction (such as ``ADD``, ``MUL``, etc).
diff --git a/docs/miscellaneous.rst b/docs/miscellaneous.rst
index 8270727f..c7c32528 100644
--- a/docs/miscellaneous.rst
+++ b/docs/miscellaneous.rst
@@ -317,6 +317,11 @@ The following is the order of precedence for operators, listed in order of evalu
Global Variables
================
+- ``abi.encode(...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
+- ``abi.encodePacked(...) returns (bytes)``: Performes :ref:`packed encoding <abi_packed_mode>` of the given arguments
+- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: :ref:`ABI <ABI>`-encodes the given arguments
+ starting from the second and prepends the given four-byte selector
+- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)```
- ``block.blockhash(uint blockNumber) returns (bytes32)``: hash of the given block - only works for 256 most recent, excluding current, blocks - deprecated in version 0.4.22 and replaced by ``blockhash(uint blockNumber)``.
- ``block.coinbase`` (``address``): current block miner's address
- ``block.difficulty`` (``uint``): current block difficulty
diff --git a/docs/units-and-global-variables.rst b/docs/units-and-global-variables.rst
index 9d5821d5..51f7b9f3 100644
--- a/docs/units-and-global-variables.rst
+++ b/docs/units-and-global-variables.rst
@@ -44,9 +44,10 @@ Special Variables and Functions
===============================
There are special variables and functions which always exist in the global
-namespace and are mainly used to provide information about the blockchain.
+namespace and are mainly used to provide information about the blockchain
+or are general-use utility functions.
-.. index:: block, coinbase, difficulty, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin
+.. index:: abi, block, coinbase, difficulty, encode, number, block;number, timestamp, block;timestamp, msg, data, gas, sender, value, now, gas price, origin
Block and Transaction Properties
@@ -90,6 +91,26 @@ Block and Transaction Properties
You can only access the hashes of the most recent 256 blocks, all other
values will be zero.
+.. index:: abi, encoding, packed
+
+ABI Encoding Functions
+----------------------
+
+- ``abi.encode(...) returns (bytes)``: ABI-encodes the given arguments
+- ``abi.encodePacked(...) returns (bytes)``: Performes packed encoding of the given arguments
+- ``abi.encodeWithSelector(bytes4 selector, ...) returns (bytes)``: ABI-encodes the given arguments
+ starting from the second and prepends the given four-byte selector
+- ``abi.encodeWithSignature(string signature, ...) returns (bytes)``: Equivalent to ``abi.encodeWithSelector(bytes4(keccak256(signature), ...)```
+
+.. note::
+ These encoding functions can be used to craft data for function calls without actually
+ calling a function. Furthermore, ``keccak256(abi.encodePacked(a, b))`` is a more
+ explicit way to compute ``keccak256(a, b)``, which will be deprecated in future
+ versions.
+
+See the documentation about the :ref:`ABI <ABI>` and the
+:ref:`tightly packed encoding <abi_packed_mode>` for details about the encoding.
+
.. index:: assert, revert, require
Error Handling