aboutsummaryrefslogtreecommitdiffstats
path: root/docs/contracts.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r--docs/contracts.rst54
1 files changed, 40 insertions, 14 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 9145f016..8d7af2c1 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -27,7 +27,7 @@ From ``web3.js``, i.e. the JavaScript
API, this is done as follows::
// Need to specify some source including contract name for the data param below
- var source = "contract CONTRACT_NAME { function CONTRACT_NAME(unit a, uint b) {} }";
+ var source = "contract CONTRACT_NAME { function CONTRACT_NAME(uint a, uint b) {} }";
// The json abi array generated by the compiler
var abiArray = [
@@ -327,7 +327,7 @@ inheritable properties of contracts and may be overridden by derived contracts.
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
contract owned {
function owned() { owner = msg.sender; }
@@ -341,8 +341,7 @@ inheritable properties of contracts and may be overridden by derived contracts.
// function is executed and otherwise, an exception is
// thrown.
modifier onlyOwner {
- if (msg.sender != owner)
- throw;
+ require(msg.sender == owner);
_;
}
}
@@ -390,7 +389,7 @@ inheritable properties of contracts and may be overridden by derived contracts.
contract Mutex {
bool locked;
modifier noReentrancy() {
- if (locked) throw;
+ require(!locked);
locked = true;
_;
locked = false;
@@ -401,7 +400,7 @@ inheritable properties of contracts and may be overridden by derived contracts.
/// The `return 7` statement assigns 7 to the return value but still
/// executes the statement `locked = false` in the modifier.
function f() noReentrancy returns (uint) {
- if (!msg.sender.call()) throw;
+ require(msg.sender.call());
return 7;
}
}
@@ -436,7 +435,7 @@ execution data (``msg.gas``) or make calls to external contracts are disallowed.
that might have a side-effect on memory allocation are allowed, but those that
might have a side-effect on other memory objects are not. The built-in functions
``keccak256``, ``sha256``, ``ripemd160``, ``ecrecover``, ``addmod`` and ``mulmod``
-are allowed (ever though they do call external contracts).
+are allowed (even though they do call external contracts).
The reason behind allowing side-effects on the memory allocator is that it
should be possible to construct complex objects like e.g. lookup-tables.
@@ -922,6 +921,35 @@ Such contracts cannot be compiled (even if they contain implemented functions al
If a contract inherits from an abstract contract and does not implement all non-implemented functions by overriding, it will itself be abstract.
+.. index:: ! contract;interface, ! interface contract
+
+**********
+Interfaces
+**********
+
+Interfaces are similar to abstract contracts, but they cannot have any functions implemented. There are further restrictions:
+
+#. Cannot inherit other contracts or interfaces.
+#. Cannot define constructor.
+#. Cannot define variables.
+#. Cannot define structs.
+#. Cannot define enums.
+
+Some of these restrictions might be lifted in the future.
+
+Interfaces are basically limited to what the Contract ABI can represent and the conversion between the ABI and
+an Interface should be possible without any information loss.
+
+Interfaces are denoted by their own keyword:
+
+::
+
+ interface Token {
+ function transfer(address recipient, uint amount);
+ }
+
+Contracts can inherit interfaces as they would inherit other contracts.
+
.. index:: ! library, callcode, delegatecall
.. _libraries:
@@ -960,7 +988,7 @@ more advanced example to implement a set).
::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
library Set {
// We define a new struct datatype that will be used to
@@ -1006,8 +1034,7 @@ more advanced example to implement a set).
// The library functions can be called without a
// specific instance of the library, since the
// "instance" will be the current contract.
- if (!Set.insert(knownValues, value))
- throw;
+ require(Set.insert(knownValues, value));
}
// In this contract, we can also directly access knownValues.flags, if we want.
}
@@ -1101,7 +1128,7 @@ Restrictions for libraries in comparison to contracts:
- No state variables
- Cannot inherit nor be inherited
-- Cannot recieve Ether
+- Cannot receive Ether
(These might be lifted at a later point.)
@@ -1137,7 +1164,7 @@ available without having to add further code.
Let us rewrite the set example from the
:ref:`libraries` in this way::
- pragma solidity ^0.4.0;
+ pragma solidity ^0.4.11;
// This is the same code as before, just without comments
library Set {
@@ -1178,8 +1205,7 @@ Let us rewrite the set example from the
// corresponding member functions.
// The following function call is identical to
// Set.insert(knownValues, value)
- if (!knownValues.insert(value))
- throw;
+ require(knownValues.insert(value));
}
}