Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3738107

Browse files
committed
Merge pull request argotorg#399 from holgerd77/develop
Readability improvements and additional code examples for the Solidity docs
2 parents 565d717 + aec2f48 commit 3738107

File tree

6 files changed

+167
-14
lines changed

6 files changed

+167
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# Build directory
3131
build/
3232
docs/_build
33+
docs/utils/__pycache__
3334

3435
# vim stuff
3536
*.swp

docs/contracts.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ possible.
359359

360360
.. index:: ! event
361361

362+
.. _events:
363+
362364
******
363365
Events
364366
******

docs/control-structures.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ there is in C and JavaScript, so `if (1) { ... }` is *not* valid Solidity.
2020

2121
.. index:: ! function;call, function;internal, function;external
2222

23+
.. _function-calls:
24+
2325
Function Calls
2426
==============
2527

docs/layout-of-source-files.rst

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,32 @@ Solidity supports import statements that are very similar to those available in
1717

1818
At a global level, you can use import statements of the following form:
1919

20-
`import "filename";` will import all global symbols from "filename" (and symbols imported there) into the current global scope (different than in ES6 but backwards-compatible for Solidity).
20+
::
2121

22-
`import * as symbolName from "filename";` creates a new global symbol `symbolName` whose members are all the global symbols from `"filename"`.
22+
import "filename";
2323

24-
`import {symbol1 as alias, symbol2} from "filename";` creates new global symbols `alias` and `symbol2` which reference `symbol1` and `symbal2` from `"filename"`, respectively.
24+
...will import all global symbols from "filename" (and symbols imported there) into the
25+
current global scope (different than in ES6 but backwards-compatible for Solidity).
26+
27+
::
28+
29+
import * as symbolName from "filename";
30+
31+
...creates a new global symbol `symbolName` whose members are all the global symbols from `"filename"`.
32+
33+
::
34+
35+
import {symbol1 as alias, symbol2} from "filename";
36+
37+
...creates new global symbols `alias` and `symbol2` which reference `symbol1` and `symbol2` from `"filename"`, respectively.
2538

2639
Another syntax is not part of ES6, but probably convenient:
2740

28-
`import "filename" as symbolName;` is equivalent to `import * as symbolName from "filename";`.
41+
::
42+
43+
import "filename" as symbolName;
44+
45+
...is equivalent to `import * as symbolName from "filename";`.
2946

3047
Paths
3148
-----
@@ -65,11 +82,15 @@ So as an example, if you clone
6582
`github.com/ethereum/dapp-bin/` locally to `/usr/local/dapp-bin`, you can use
6683
the following in your source file:
6784

68-
`import "github.com/ethereum/dapp-bin/library/iterable_mapping.sol" as it_mapping;`
85+
::
86+
87+
import "github.com/ethereum/dapp-bin/library/iterable_mapping.sol" as it_mapping;
6988

7089
and then run the compiler as
7190

72-
`solc github.com/ethereum/dapp-bin/=/usr/local/dapp-bin/ source.sol`
91+
.. code-block:: shell
92+
93+
solc github.com/ethereum/dapp-bin/=/usr/local/dapp-bin/ source.sol
7394
7495
Note that solc only allows you to include files from certain directories:
7596
They have to be in the directory (or subdirectory) of one of the explicitly
@@ -98,6 +119,16 @@ Comments
98119

99120
Single-line comments (`//`) and multi-line comments (`/*...*/`) are possible.
100121

122+
::
123+
124+
// This is a single-line comment.
125+
126+
/*
127+
This is a
128+
multi-line comment.
129+
*/
130+
131+
101132
There are special types of comments called natspec comments
102133
(documentation yet to be written). These are introduced by
103134
triple-slash comments (`///`) or using double asterisks (`/** ... */`).

docs/structure-of-a-contract.rst

Lines changed: 119 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,128 @@
11
.. index:: contract, state variable, function, event, struct, enum, function;modifier
22

3+
.. _contract_structure:
4+
35
***********************
46
Structure of a Contract
57
***********************
68

79
Contracts in Solidity are similar to classes in object-oriented languages.
8-
Each contract can contain declarations of **state variables**, **functions**,
9-
**function modifiers**, **events**, **structs types** and **enum types**.
10+
Each contract can contain declarations of :ref:`structure-state-variables`, :ref:`structure-functions`,
11+
:ref:`structure-function-modifiers`, :ref:`structure-events`, :ref:`structure-structs-types` and :ref:`structure-enum-types`.
1012
Furthermore, contracts can inherit from other contracts.
1113

12-
* State variables are values which are permanently stored in contract storage.
13-
* Functions are the executable units of code within a contract.
14-
* Function modifiers can be used to amend the semantics of functions in a declarative way.
15-
* Events are convenience interfaces with the EVM logging facilities.
16-
* Structs are custom defined types that can group several variables.
17-
* Enums can be used to create custom types with a finite set of values.
14+
.. _structure-state-variables:
15+
16+
State Variables
17+
===============
18+
19+
State variables are values which are permanently stored in contract storage.
20+
21+
::
22+
23+
contract SimpleStorage {
24+
uint storedData; // State variable
25+
// ...
26+
}
27+
28+
See the :ref:`types` section for valid state variable types and
29+
:ref:`visibility-and-accessors` for possible choices for
30+
visability.
31+
32+
.. _structure-functions:
33+
34+
Functions
35+
=========
36+
37+
Functions are the executable units of code within a contract.
38+
39+
::
40+
41+
contract SimpleAuction {
42+
function bid() { // Function
43+
// ...
44+
}
45+
}
46+
47+
:ref:`function-calls` can happen internally or externally
48+
and have different levels of visibility (:ref:`visibility-and-accessors`)
49+
towards other contracts.
50+
51+
.. _structure-function-modifiers:
52+
53+
Function Modifiers
54+
==================
55+
56+
Function modifiers can be used to amend the semantics of functions in a declarative way
57+
(see :ref:`modifiers` in contracts section).
58+
59+
::
60+
61+
contract Purchase {
62+
address public seller;
63+
64+
modifier onlySeller() { // Modifier
65+
if (msg.sender != seller) throw;
66+
_
67+
}
68+
69+
function abort() onlySeller { // Modifier usage
70+
// ...
71+
}
72+
}
73+
74+
in the section on contracts for a more in-depth explanation.
75+
76+
.. _structure-events:
77+
78+
Events
79+
======
80+
81+
Events are convenience interfaces with the EVM logging facilities.
82+
83+
::
84+
85+
contract SimpleAuction {
86+
event HighestBidIncreased(address bidder, uint amount); // Event
87+
88+
function bid() {
89+
// ...
90+
HighestBidIncreased(msg.sender, msg.value); // Triggering event
91+
}
92+
}
93+
94+
See :ref:`events` in contracts section for information on how events are declared
95+
and can be used from within a dapp.
96+
97+
.. _structure-structs-types:
98+
99+
Structs Types
100+
=============
101+
102+
Structs are custom defined types that can group several variables (see
103+
:ref:`structs` in types section).
104+
105+
::
106+
107+
contract Ballot {
108+
struct Voter { // Struct
109+
uint weight;
110+
bool voted;
111+
address delegate;
112+
uint vote;
113+
}
114+
}
115+
116+
.. _structure-enum-types:
117+
118+
Enum Types
119+
==========
120+
121+
Enums can be used to create custom types with a finite set of values (see
122+
:ref:`enums` in types section).
123+
124+
::
125+
126+
contract Purchase {
127+
enum State { Created, Locked, Inactive } // Enum
128+
}

docs/types.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. index:: type
22

3+
.. _types:
4+
35
*****
46
Types
57
*****
@@ -146,6 +148,8 @@ String Literals are written with double quotes (`"abc"`). As with integer litera
146148

147149
.. index:: enum
148150

151+
.. _enums:
152+
149153
Enums
150154
=====
151155

@@ -355,6 +359,8 @@ Members
355359

356360
.. index:: ! struct, ! type;struct
357361

362+
.. _structs:
363+
358364
Structs
359365
-------
360366

0 commit comments

Comments
 (0)