Skip to content

Commit

Permalink
add "pragma solidity ^0.4.0;" to code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
winsvega committed Sep 5, 2016
1 parent 341c943 commit 183cd70
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/common-patterns.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ become the new richest.

::

pragma solidity ^0.4.0;

contract WithdrawalContract {
address public richest;
uint public mostSent;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -270,6 +276,8 @@ function finishes.

::

pragma solidity ^0.4.0;

contract StateMachine {
enum Stages {
AcceptingBlindedBids,
Expand Down
26 changes: 26 additions & 0 deletions docs/contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand All @@ -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;

Expand Down Expand Up @@ -243,6 +249,8 @@ be done at declaration.

::

pragma solidity ^0.4.0;

contract C {
uint public data = 42;
}
Expand All @@ -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() {
Expand All @@ -274,6 +284,8 @@ The next example is a bit more complex:

::

pragma solidity ^0.4.0;

contract Complex {
struct Data {
uint a;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -931,6 +955,8 @@ custom types without the overhead of external function calls:

::

pragma solidity ^0.4.0;

library BigInt {
struct bigint {
uint[] limbs;
Expand Down
14 changes: 14 additions & 0 deletions docs/control-structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) { ... }

Expand All @@ -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) {
Expand All @@ -136,6 +140,8 @@ creation-dependencies are now possible.

::

pragma solidity ^0.4.0;

contract D {
uint x;
function D(uint a) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand Down Expand Up @@ -622,6 +632,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) {
Expand Down Expand Up @@ -696,6 +708,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 {
Expand Down
4 changes: 4 additions & 0 deletions docs/introduction-to-smart-contracts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Storage

::

pragma solidity ^0.4.0;

contract SimpleStorage {
uint storedData;

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/layout-of-source-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions docs/security-considerations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions docs/solidity-by-example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -377,6 +381,8 @@ high or low invalid bids.

::

pragma solidity ^0.4.0;

contract BlindAuction {
struct Bid {
bytes32 blindedBid;
Expand Down Expand Up @@ -543,6 +549,8 @@ Safe Remote Purchase

::

pragma solidity ^0.4.0;

contract Purchase {
uint public value;
address public seller;
Expand Down
12 changes: 12 additions & 0 deletions docs/structure-of-a-contract.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ...
Expand All @@ -38,6 +40,8 @@ Functions are the executable units of code within a contract.

::

pragma solidity ^0.4.0;

contract SimpleAuction {
function bid() { // Function
// ...
Expand All @@ -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;

Expand All @@ -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

Expand All @@ -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;
Expand All @@ -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
}
Loading

0 comments on commit 183cd70

Please sign in to comment.