aboutsummaryrefslogtreecommitdiffstats
path: root/docs/structure-of-a-contract.rst
diff options
context:
space:
mode:
authorholgerd77 <Holger.Drewes@googlemail.com>2016-02-18 18:45:15 +0800
committerholgerd77 <Holger.Drewes@googlemail.com>2016-02-18 18:45:15 +0800
commit2e52170d7a31e846c30770ec0c1383c68d9b71c6 (patch)
tree54926f381fe616009a52b151703f7f4c1a0861f6 /docs/structure-of-a-contract.rst
parent688313cc5131a8aa156c2837a3629842e17ec93c (diff)
downloaddexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar.gz
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar.bz2
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar.lz
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar.xz
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.tar.zst
dexon-solidity-2e52170d7a31e846c30770ec0c1383c68d9b71c6.zip
Added examples, references to structure section
Diffstat (limited to 'docs/structure-of-a-contract.rst')
-rw-r--r--docs/structure-of-a-contract.rst111
1 files changed, 103 insertions, 8 deletions
diff --git a/docs/structure-of-a-contract.rst b/docs/structure-of-a-contract.rst
index c3683b5e..1b80b1c2 100644
--- a/docs/structure-of-a-contract.rst
+++ b/docs/structure-of-a-contract.rst
@@ -1,17 +1,112 @@
.. index:: contract, state variable, function, event, struct, enum, function;modifier
+.. _contract_structure:
+
***********************
Structure of a Contract
***********************
Contracts in Solidity are similar to classes in object-oriented languages.
-Each contract can contain declarations of **state variables**, **functions**,
-**function modifiers**, **events**, **structs types** and **enum types**.
+Each contract can contain declarations of :ref:`state_variables`, :ref:`functions`,
+:ref:`function_modifiers`, :ref:`events`, :ref:`structs_types` and :ref:`enum_types`.
Furthermore, contracts can inherit from other contracts.
-* State variables are values which are permanently stored in contract storage.
-* Functions are the executable units of code within a contract.
-* Function modifiers can be used to amend the semantics of functions in a declarative way.
-* Events are convenience interfaces with the EVM logging facilities.
-* Structs are custom defined types that can group several variables.
-* Enums can be used to create custom types with a finite set of values.
+.. _state_variables:
+
+State Variables
+===============
+
+State variables are values which are permanently stored in contract storage.
+
+::
+
+ contract SimpleStorage {
+ uint storedData; // State variable
+ // ...
+ }
+
+.. _functions:
+
+Functions
+=========
+
+Functions are the executable units of code within a contract.
+
+::
+
+ contract SimpleAuction {
+ function bid() { // Function
+ // ...
+ }
+ }
+
+.. _function_modifiers:
+
+Function Modifiers
+==================
+
+Function modifiers can be used to amend the semantics of functions in a declarative way.
+
+::
+
+ contract Purchase {
+ address public seller;
+
+ modifier onlySeller() { // Modifier
+ if (msg.sender != seller) throw;
+ _
+ }
+
+ function abort() onlySeller { // Modifier usage
+ // ...
+ }
+ }
+
+.. _events:
+
+Events
+======
+
+Events are convenience interfaces with the EVM logging facilities.
+
+::
+
+ contract SimpleAuction {
+ event HighestBidIncreased(address bidder, uint amount); // Event
+
+ function bid() {
+ // ...
+ HighestBidIncreased(msg.sender, msg.value); // Triggering event
+ }
+ }
+
+.. _structs_types:
+
+Structs Types
+=============
+
+Structs are custom defined types that can group several variables.
+
+::
+
+ contract Ballot {
+ struct Voter { // Struct
+ uint weight;
+ bool voted;
+ address delegate;
+ uint vote;
+ }
+ }
+
+.. _enum_types:
+
+Enum Types
+==========
+
+Enums can be used to create custom types with a finite set of values.
+
+::
+
+ contract Purchase {
+ enum State { Created, Locked, Inactive } // Enum
+ }