aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-07-11 06:07:27 +0800
committerchriseth <chris@ethereum.org>2017-07-14 03:47:29 +0800
commit41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f (patch)
tree8b8e9eb1136a3705c2e6b9bff04ba1243832db31 /docs
parentb2fcd59ee6941de4a392b89295c734385d6019e3 (diff)
downloaddexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar.gz
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar.bz2
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar.lz
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar.xz
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.tar.zst
dexon-solidity-41e5b2c3c2a84f395da03bfd4cf5bf8586f9df3f.zip
Fix bugs in example contracts
Diffstat (limited to 'docs')
-rw-r--r--docs/contracts.rst31
-rw-r--r--docs/control-structures.rst6
-rw-r--r--docs/security-considerations.rst8
-rw-r--r--docs/types.rst8
4 files changed, 42 insertions, 11 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index e9ea1b3b..3c9769ff 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -213,6 +213,8 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
::
+ // This will not compile
+
pragma solidity ^0.4.0;
contract C {
@@ -545,9 +547,11 @@ Please ensure you test your fallback function thoroughly to ensure the execution
test.call(0xabcdef01); // hash does not exist
// results in test.x becoming == 1.
- // The following call will fail, reject the
- // Ether and return false:
- test.send(2 ether);
+ // The following will not compile, but even
+ // if someone sends ether to that contract,
+ // the transaction will fail and reject the
+ // Ether.
+ //test.send(2 ether);
}
}
@@ -773,13 +777,17 @@ seen in the following example::
pragma solidity ^0.4.0;
+ contract owned {
+ function owned() { owner = msg.sender; }
+ address owner;
+ }
+
contract mortal is owned {
function kill() {
if (msg.sender == owner) selfdestruct(owner);
}
}
-
contract Base1 is mortal {
function kill() { /* do cleanup 1 */ mortal.kill(); }
}
@@ -800,6 +808,11 @@ derived override, but this function will bypass
pragma solidity ^0.4.0;
+ contract owned {
+ function owned() { owner = msg.sender; }
+ address owner;
+ }
+
contract mortal is owned {
function kill() {
if (msg.sender == owner) selfdestruct(owner);
@@ -879,6 +892,8 @@ error "Linearization of inheritance graph impossible".
::
+ // This will not compile
+
pragma solidity ^0.4.0;
contract X {}
@@ -914,10 +929,16 @@ Contract functions can lack an implementation as in the following example (note
function utterance() 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;
+ contract Feline {
+ function utterance() returns (bytes32);
+ }
+
contract Cat is Feline {
function utterance() returns (bytes32) { return "miaow"; }
}
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index c7185e22..f4c0b776 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -181,7 +181,9 @@ parameters from the function declaration, but can be in arbitrary order.
pragma solidity ^0.4.0;
contract C {
- function f(uint key, uint value) { ... }
+ function f(uint key, uint value) {
+ // ...
+ }
function g() {
// named arguments
@@ -323,6 +325,8 @@ This happens because Solidity inherits its scoping rules from JavaScript.
This is in contrast to many languages where variables are only scoped where they are declared until the end of the semantic block.
As a result, the following code is illegal and cause the compiler to throw an error, ``Identifier already declared``::
+ // This will not compile
+
pragma solidity ^0.4.0;
contract ScopingErrors {
diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst
index 33c613d8..658c12b2 100644
--- a/docs/security-considerations.rst
+++ b/docs/security-considerations.rst
@@ -179,11 +179,13 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like
}
}
-Now someone tricks you into sending ether to the address of this attack wallet:
+Now someone tricks you into sending ether to the address of this attack wallet::
-::
+ pragma solidity ^0.4.11;
- pragma solidity ^0.4.0;
+ interface TxUserWallet {
+ function transferTo(address dest, uint amount);
+ }
contract TxAttackWallet {
address owner;
diff --git a/docs/types.rst b/docs/types.rst
index 67549499..b9ecd083 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -376,7 +376,7 @@ Example that shows how to use internal function types::
function (uint, uint) returns (uint) f
)
internal
- returns (uint)
+ returns (uint r)
{
r = self[0];
for (uint i = 1; i < self.length; i++) {
@@ -599,6 +599,8 @@ possible:
::
+ // This will not compile.
+
pragma solidity ^0.4.0;
contract C {
@@ -606,6 +608,7 @@ possible:
// The next line creates a type error because uint[3] memory
// cannot be converted to uint[] memory.
uint[] x = [uint(1), 3, 4];
+ }
}
It is planned to remove this restriction in the future but currently creates
@@ -812,8 +815,9 @@ for each ``_KeyType``, recursively.
}
contract MappingUser {
+ address contractAddress = 0x42;
function f() returns (uint) {
- return MappingExample(<address>).balances(this);
+ return MappingExample(contractAddress).balances(this);
}
}