aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-17 17:24:18 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-07-19 07:05:05 +0800
commitcffe52d6d9e23e537c710107292a2058caa3784f (patch)
tree3f5d5927f22295c0366edfcdc4f197be1d1ce033
parent01fbc636239f78134b37f9dedeacf40455ee2e0c (diff)
downloaddexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar.gz
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar.bz2
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar.lz
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar.xz
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.tar.zst
dexon-solidity-cffe52d6d9e23e537c710107292a2058caa3784f.zip
Enable more examples in the documentation for testing
-rw-r--r--docs/abi-spec.rst2
-rw-r--r--docs/assembly.rst8
-rw-r--r--docs/contracts.rst2
-rw-r--r--docs/control-structures.rst2
-rw-r--r--docs/frequently-asked-questions.rst33
-rw-r--r--docs/layout-of-source-files.rst27
6 files changed, 46 insertions, 28 deletions
diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst
index 82c52159..2cf57427 100644
--- a/docs/abi-spec.rst
+++ b/docs/abi-spec.rst
@@ -316,6 +316,8 @@ For example,
::
+ pragma solidity ^0.4.0;
+
contract Test {
function Test(){ b = 0x12345678901234567890123456789012; }
event Event(uint indexed a, bytes32 b)
diff --git a/docs/assembly.rst b/docs/assembly.rst
index 37222faf..855f5d72 100644
--- a/docs/assembly.rst
+++ b/docs/assembly.rst
@@ -490,7 +490,7 @@ is performed by replacing the variable's value on the stack by the new value.
.. code::
- assembly {
+ {
let v := 0 // functional-style assignment as part of variable declaration
let g := add(v, 2)
sload(10)
@@ -509,7 +509,7 @@ case called ``default``.
.. code::
- assembly {
+ {
let x := 0
switch calldataload(4)
case 0 {
@@ -538,7 +538,7 @@ The following example computes the sum of an area in memory.
.. code::
- assembly {
+ {
let x := 0
for { let i := 0 } lt(i, 0x100) { i := add(i, 0x20) } {
x := add(x, mload(i))
@@ -565,7 +565,7 @@ The following example implements the power function by square-and-multiply.
.. code::
- assembly {
+ {
function power(base, exponent) -> result {
switch exponent
case 0 { result := 1 }
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 3c9769ff..11e674d1 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -968,6 +968,8 @@ Interfaces are denoted by their own keyword:
::
+ pragma solidity ^0.4.11;
+
interface Token {
function transfer(address recipient, uint amount);
}
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index 8d7c78a2..128e6fae 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -128,7 +128,6 @@ the gas can be specified with special options ``.value()`` and ``.gas()``, respe
function info() payable returns (uint ret) { return 42; }
}
-
contract Consumer {
InfoFeed feed;
function setFeed(address addr) { feed = InfoFeed(addr); }
@@ -231,7 +230,6 @@ creation-dependencies are not possible.
}
}
-
contract C {
D d = new D(4); // will be executed as part of C's constructor
diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst
index 03ee8388..73210991 100644
--- a/docs/frequently-asked-questions.rst
+++ b/docs/frequently-asked-questions.rst
@@ -116,6 +116,8 @@ array in the return statement. Pretty cool, huh?
Example::
+ pragma solidity ^0.4.0;
+
contract C {
function f() returns (uint8[5]) {
string[4] memory adaArr = ["This", "is", "an", "array"];
@@ -192,6 +194,8 @@ should be noted that you must declare them as static memory arrays.
Examples::
+ pragma solidity ^0.4.0;
+
contract C {
struct S {
uint a;
@@ -200,10 +204,9 @@ Examples::
S public x = S(1, 2);
string name = "Ada";
- string[4] memory adaArr = ["This", "is", "an", "array"];
+ string[4] adaArr = ["This", "is", "an", "array"];
}
-
contract D {
C c = new C();
}
@@ -243,6 +246,8 @@ which will be extended in the future. In addition, Arachnid has written `solidit
For now, if you want to modify a string (even when you only want to know its length),
you should always convert it to a ``bytes`` first::
+ pragma solidity ^0.4.0;
+
contract C {
string s;
@@ -288,6 +293,8 @@ situation.
If you do not want to throw, you can return a pair::
+ pragma solidity ^0.4.0;
+
contract C {
uint[] counters;
@@ -302,9 +309,9 @@ If you do not want to throw, you can return a pair::
function checkCounter(uint index) {
var (counter, error) = getCounter(index);
if (error) {
- ...
+ // ...
} else {
- ...
+ // ...
}
}
}
@@ -363,6 +370,8 @@ of variable it concerns:
Example::
+ pragma solidity ^0.4.0;
+
contract C {
uint[] data1;
uint[] data2;
@@ -375,7 +384,7 @@ Example::
append(data2);
}
- function append(uint[] storage d) {
+ function append(uint[] storage d) internal {
d.push(1);
}
}
@@ -393,6 +402,9 @@ A common mistake is to declare a local variable and assume that it will
be created in memory, although it will be created in storage::
/// THIS CONTRACT CONTAINS AN ERROR
+
+ pragma solidity ^0.4.0;
+
contract C {
uint someVariable;
uint[] data;
@@ -417,6 +429,8 @@ slot ``0``) is modified by ``x.push(2)``.
The correct way to do this is the following::
+ pragma solidity ^0.4.0;
+
contract C {
uint someVariable;
uint[] data;
@@ -533,11 +547,12 @@ In the case of a ``contract A`` calling a new instance of ``contract B``, parent
You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor.
In this example::
+ pragma solidity ^0.4.0;
+
contract B {
function B() payable {}
}
-
contract A {
address child;
@@ -580,6 +595,8 @@ Can a contract pass an array (static size) or string or ``bytes`` (dynamic size)
Sure. Take care that if you cross the memory / storage boundary,
independent copies will be created::
+ pragma solidity ^0.4.0;
+
contract C {
uint[20] x;
@@ -588,11 +605,11 @@ independent copies will be created::
h(x);
}
- function g(uint[20] y) {
+ function g(uint[20] y) internal {
y[2] = 3;
}
- function h(uint[20] storage y) {
+ function h(uint[20] storage y) internal {
y[3] = 4;
}
}
diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst
index e4b403f6..f9d197b7 100644
--- a/docs/layout-of-source-files.rst
+++ b/docs/layout-of-source-files.rst
@@ -197,17 +197,16 @@ for the two input parameters and two returned values.
pragma solidity ^0.4.0;
- /** @title Shape calculator.*/
- contract shapeCalculator{
- /**@dev Calculates a rectangle's surface and perimeter.
- * @param w Width of the rectangle.
- * @param h Height of the rectangle.
- * @return s The calculated surface.
- * @return p The calculated perimeter.
- */
- function rectangle(uint w, uint h) returns (uint s, uint p) {
- s = w * h;
- p = 2 * (w + h);
- }
- }
-
+ /** @title Shape calculator. */
+ contract shapeCalculator {
+ /** @dev Calculates a rectangle's surface and perimeter.
+ * @param w Width of the rectangle.
+ * @param h Height of the rectangle.
+ * @return s The calculated surface.
+ * @return p The calculated perimeter.
+ */
+ function rectangle(uint w, uint h) returns (uint s, uint p) {
+ s = w * h;
+ p = 2 * (w + h);
+ }
+ }