aboutsummaryrefslogtreecommitdiffstats
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/common-patterns.rst8
-rw-r--r--docs/contracts.rst26
-rw-r--r--docs/control-structures.rst14
-rw-r--r--docs/introduction-to-smart-contracts.rst4
-rw-r--r--docs/layout-of-source-files.rst2
-rw-r--r--docs/security-considerations.rst8
-rw-r--r--docs/solidity-by-example.rst8
-rw-r--r--docs/structure-of-a-contract.rst12
-rw-r--r--docs/types.rst14
9 files changed, 96 insertions, 0 deletions
diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst
index 0894aae2..e56e7a6c 100644
--- a/docs/common-patterns.rst
+++ b/docs/common-patterns.rst
@@ -28,6 +28,8 @@ become the new richest.
::
+ pragma solidity ^0.4.0;
+
contract WithdrawalContract {
address public richest;
uint public mostSent;
@@ -68,6 +70,8 @@ This is as opposed to the more intuitive sending pattern.
::
+ pragma solidity ^0.4.0;
+
contract SendContract {
address public richest;
uint public mostSent;
@@ -131,6 +135,8 @@ restrictions highly readable.
::
+ pragma solidity ^0.4.0;
+
contract AccessRestriction {
// These will be assigned at the construction
// phase, where `msg.sender` is the account
@@ -270,6 +276,8 @@ function finishes.
::
+ pragma solidity ^0.4.0;
+
contract StateMachine {
enum Stages {
AcceptingBlindedBids,
diff --git a/docs/contracts.rst b/docs/contracts.rst
index dfa79e79..4fe046ed 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -65,6 +65,8 @@ This means that cyclic creation dependencies are impossible.
::
+ pragma solidity ^0.4.0;
+
contract OwnedToken {
// TokenCreator is a contract type that is defined below.
// It is fine to reference it as long as it is not used
@@ -189,6 +191,8 @@ return parameter list for functions.
::
+ pragma solidity ^0.4.0;
+
contract C {
function f(uint a) private returns (uint b) { return a + 1; }
function setData(uint a) internal { data = a; }
@@ -201,6 +205,8 @@ In the following example, ``D``, can call ``c.getData()`` to retrieve the value
::
+ pragma solidity ^0.4.0;
+
contract C {
uint private data;
@@ -243,6 +249,8 @@ be done at declaration.
::
+ pragma solidity ^0.4.0;
+
contract C {
uint public data = 42;
}
@@ -262,6 +270,8 @@ it is evaluated as a state variable and if it is accessed externally
::
+ pragma solidity ^0.4.0;
+
contract C {
uint public data;
function x() {
@@ -274,6 +284,8 @@ The next example is a bit more complex:
::
+ pragma solidity ^0.4.0;
+
contract Complex {
struct Data {
uint a;
@@ -307,6 +319,8 @@ inheritable properties of contracts and may be overridden by derived contracts.
::
+ pragma solidity ^0.4.0;
+
contract owned {
function owned() { owner = msg.sender; }
address owner;
@@ -408,6 +422,8 @@ for array and struct types and not possible for mapping types).
::
+ pragma solidity ^0.4.0;
+
contract C {
uint constant x = 32**22 + 8;
string constant text = "abc";
@@ -455,6 +471,8 @@ Please ensure you test your fallback function thoroughly to ensure the execution
::
+ pragma solidity ^0.4.0;
+
contract Test {
function() { x = 1; }
uint x;
@@ -523,6 +541,8 @@ All non-indexed arguments will be stored in the data part of the log.
::
+ pragma solidity ^0.4.0;
+
contract ClientReceipt {
event Deposit(
address indexed _from,
@@ -791,6 +811,8 @@ error "Linearization of inheritance graph impossible".
::
+ pragma solidity ^0.4.0;
+
contract X {}
contract A is X {}
contract C is A, X {}
@@ -861,6 +883,8 @@ more advanced example to implement a set).
::
+ pragma solidity ^0.4.0;
+
library Set {
// We define a new struct datatype that will be used to
// hold its data in the calling contract.
@@ -931,6 +955,8 @@ custom types without the overhead of external function calls:
::
+ pragma solidity ^0.4.0;
+
library BigInt {
struct bigint {
uint[] limbs;
diff --git a/docs/control-structures.rst b/docs/control-structures.rst
index e6dfe4f6..61a8611e 100644
--- a/docs/control-structures.rst
+++ b/docs/control-structures.rst
@@ -98,6 +98,8 @@ parameters from the function declaration, but can be in arbitrary order.
::
+ pragma solidity ^0.4.0;
+
contract C {
function f(uint key, uint value) { ... }
@@ -115,6 +117,8 @@ Those names will still be present on the stack, but they are inaccessible.
::
+ pragma solidity ^0.4.0;
+
contract C {
// omitted name for parameter
function func(uint k, uint) returns(uint) {
@@ -136,6 +140,8 @@ creation-dependencies are now possible.
::
+ pragma solidity ^0.4.0;
+
contract D {
uint x;
function D(uint a) {
@@ -343,6 +349,8 @@ idea is that assembly libraries will be used to enhance the language in such way
.. code::
+ pragma solidity ^0.4.0;
+
library GetCode {
function at(address _addr) returns (bytes o_code) {
assembly {
@@ -368,6 +376,8 @@ you really know what you are doing.
.. code::
+ pragma solidity ^0.4.0;
+
library VectorSum {
// This function is less efficient because the optimizer currently fails to
// remove the bounds checks in array access.
@@ -623,6 +633,8 @@ It is planned that the stack height changes can be specified in inline assembly.
.. code::
+ pragma solidity ^0.4.0;
+
contract C {
uint b;
function f(uint x) returns (uint r) {
@@ -697,6 +709,8 @@ be just ``0``, but it can also be a complex functional-style expression.
.. code::
+ pragma solidity ^0.4.0;
+
contract C {
function f(uint x) returns (uint b) {
assembly {
diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst
index 6fcd4854..de126a5a 100644
--- a/docs/introduction-to-smart-contracts.rst
+++ b/docs/introduction-to-smart-contracts.rst
@@ -16,6 +16,8 @@ Storage
::
+ pragma solidity ^0.4.0;
+
contract SimpleStorage {
uint storedData;
@@ -63,6 +65,8 @@ registering with username and password - all you need is an Ethereum keypair.
::
+ pragma solidity ^0.4.0;
+
contract Coin {
// The keyword "public" makes those variables
// readable from outside.
diff --git a/docs/layout-of-source-files.rst b/docs/layout-of-source-files.rst
index fdb7b5e8..17ac8c6f 100644
--- a/docs/layout-of-source-files.rst
+++ b/docs/layout-of-source-files.rst
@@ -192,6 +192,8 @@ 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.
diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst
index 7e846674..8800487c 100644
--- a/docs/security-considerations.rst
+++ b/docs/security-considerations.rst
@@ -51,6 +51,8 @@ complete contract):
::
+ pragma solidity ^0.4.0;
+
// THIS CONTRACT CONTAINS A BUG - DO NOT USE
contract Fund {
/// Mapping of ether shares of the contract.
@@ -73,6 +75,8 @@ outlined further below:
::
+ pragma solidity ^0.4.0;
+
contract Fund {
/// Mapping of ether shares of the contract.
mapping(address => uint) shares;
@@ -149,6 +153,8 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like
::
+ pragma solidity ^0.4.0;
+
contract TxUserWallet {
address owner;
@@ -166,6 +172,8 @@ Now someone tricks you into sending ether to the address of this attack wallet:
::
+ pragma solidity ^0.4.0;
+
contract TxAttackWallet {
address owner;
diff --git a/docs/solidity-by-example.rst b/docs/solidity-by-example.rst
index b8fa4a73..1eefa4d4 100644
--- a/docs/solidity-by-example.rst
+++ b/docs/solidity-by-example.rst
@@ -36,6 +36,8 @@ of votes.
::
+ pragma solidity ^0.4.0;
+
/// @title Voting with delegation.
contract Ballot {
// This declares a new complex type which will
@@ -208,6 +210,8 @@ activate themselves.
::
+ pragma solidity ^0.4.0;
+
contract SimpleAuction {
// Parameters of the auction. Times are either
// absolute unix timestamps (seconds since 1970-01-01)
@@ -377,6 +381,8 @@ high or low invalid bids.
::
+ pragma solidity ^0.4.0;
+
contract BlindAuction {
struct Bid {
bytes32 blindedBid;
@@ -543,6 +549,8 @@ Safe Remote Purchase
::
+ pragma solidity ^0.4.0;
+
contract Purchase {
uint public value;
address public seller;
diff --git a/docs/structure-of-a-contract.rst b/docs/structure-of-a-contract.rst
index 79f78422..1036289a 100644
--- a/docs/structure-of-a-contract.rst
+++ b/docs/structure-of-a-contract.rst
@@ -20,6 +20,8 @@ State variables are values which are permanently stored in contract storage.
::
+ pragma solidity ^0.4.0;
+
contract SimpleStorage {
uint storedData; // State variable
// ...
@@ -38,6 +40,8 @@ Functions are the executable units of code within a contract.
::
+ pragma solidity ^0.4.0;
+
contract SimpleAuction {
function bid() { // Function
// ...
@@ -58,6 +62,8 @@ Function modifiers can be used to amend the semantics of functions in a declarat
::
+ pragma solidity ^0.4.0;
+
contract Purchase {
address public seller;
@@ -80,6 +86,8 @@ Events are convenience interfaces with the EVM logging facilities.
::
+ pragma solidity ^0.4.0;
+
contract SimpleAuction {
event HighestBidIncreased(address bidder, uint amount); // Event
@@ -102,6 +110,8 @@ Structs are custom defined types that can group several variables (see
::
+ pragma solidity ^0.4.0;
+
contract Ballot {
struct Voter { // Struct
uint weight;
@@ -121,6 +131,8 @@ Enums can be used to create custom types with a finite set of values (see
::
+ pragma solidity ^0.4.0;
+
contract Purchase {
enum State { Created, Locked, Inactive } // Enum
}
diff --git a/docs/types.rst b/docs/types.rst
index 737fbe7d..988a0ed0 100644
--- a/docs/types.rst
+++ b/docs/types.rst
@@ -241,6 +241,8 @@ to and from all integer types but implicit conversion is not allowed.
::
+ pragma solidity ^0.4.0;
+
contract test {
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
ActionChoices choice;
@@ -300,6 +302,8 @@ memory-stored reference type does not create a copy.
::
+ pragma solidity ^0.4.0;
+
contract C {
uint[] x; // the data location of x is storage
@@ -378,6 +382,8 @@ the ``.length`` member.
::
+ pragma solidity ^0.4.0;
+
contract C {
function f(uint len) {
uint[] memory a = new uint[](7);
@@ -397,6 +403,8 @@ assigned to a variable right away.
::
+ pragma solidity ^0.4.0;
+
contract C {
function f() {
g([uint(1), 2, 3]);
@@ -416,6 +424,8 @@ possible:
::
+ pragma solidity ^0.4.0;
+
contract C {
function f() {
// The next line creates a type error because uint[3] memory
@@ -452,6 +462,8 @@ Members
::
+ pragma solidity ^0.4.0;
+
contract ArrayContract {
uint[2**20] m_aLotOfIntegers;
// Note that the following is not a pair of arrays but an array of pairs.
@@ -521,6 +533,8 @@ shown in the following example:
::
+ pragma solidity ^0.4.0;
+
contract CrowdFunding {
// Defines a new type with two fields.
struct Funder {