Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation updates for internal constructors and function signature #3365

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/abi-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ The first four bytes of the call data for a function call specifies the function
first (left, high-order in big-endian) four bytes of the Keccak (SHA-3) hash of the signature of the function. The signature is defined as the canonical expression of the basic prototype, i.e.
the function name with the parenthesised list of parameter types. Parameter types are split by a single comma - no spaces are used.

.. note::
The return type of a function is not part of this signature. In :ref:`Solidity's function overloading <overload-function>` return types are not considered. The reason is to keep function call resolution context-independent.
The JSON description of the ABI however contains both inputs and outputs. See (the :ref:`JSON ABI <abi_json>`)

Argument Encoding
=================

Expand Down Expand Up @@ -290,6 +294,8 @@ In effect, a log entry using this ABI is described as:

For all fixed-length Solidity types, the ``EVENT_INDEXED_ARGS`` array contains the 32-byte encoded value directly. However, for *types of dynamic length*, which include ``string``, ``bytes``, and arrays, ``EVENT_INDEXED_ARGS`` will contain the *Keccak hash* of the encoded value, rather than the encoded value directly. This allows applications to efficiently query for values of dynamic-length types (by setting the hash of the encoded value as the topic), but leaves applications unable to decode indexed values they have not queried for. For dynamic-length types, application developers face a trade-off between fast search for predetermined values (if the argument is indexed) and legibility of arbitrary values (which requires that the arguments not be indexed). Developers may overcome this tradeoff and achieve both efficient search and arbitrary legibility by defining events with two arguments — one indexed, one not — intended to hold the same value.

.. _abi_json:

JSON
====

Expand Down
35 changes: 31 additions & 4 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,31 @@ not known in the context of the class where it is used,
although its type is known. This is similar for ordinary
virtual method lookup.

.. index:: ! constructor

Constructors
============
A constructor is an optional function with the same name as the contract which is executed upon contract creation.
Constructor functions can be either ``public`` or ``internal``.

::

pragma solidity ^0.4.11;

contract A {
uint public a;

function A(uint _a) internal {
a = _a;
}
}

contract B is A(1) {
function B() public {}
}

A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract <abstract-contract>`.

.. index:: ! base;constructor

Arguments for Base Constructors
Expand Down Expand Up @@ -1027,21 +1052,21 @@ As an exception, a state variable getter can override a public function.

.. index:: ! contract;abstract, ! abstract contract

.. _abstract-contract:

******************
Abstract Contracts
******************

Contract functions can lack an implementation as in the following example (note that the function declaration header is terminated by ``;``)::
Contracts are marked as abstract when at least one of their functions lacks an implementation as in the following example (note that the function declaration header is terminated by ``;``)::

pragma solidity ^0.4.0;

contract Feline {
function utterance() public returns (bytes32);
}

Such contracts cannot be compiled (even if they contain
implemented functions alongside non-implemented functions),
but they can be used as base contracts::
Such contracts cannot be compiled (even if they contain implemented functions alongside non-implemented functions), but they can be used as base contracts::

pragma solidity ^0.4.0;

Expand All @@ -1065,6 +1090,8 @@ Example of a Function Type (a variable declaration, where the variable is of typ

function(address) external returns (address) foo;

Abstract contracts decouple the definition of a contract from its implementation providing better extensibility and self-documentation and
facilitating patterns like the `Template method <https://en.wikipedia.org/wiki/Template_method_pattern>`_ and removing code duplication.

.. index:: ! contract;interface, ! interface contract

Expand Down