Merge pull request #2636 from ethereum/docs-random

Random documentation fixes
This commit is contained in:
Yoichi Hirai 2017-07-27 11:30:12 +02:00 committed by GitHub
commit a20e5fc048
5 changed files with 29 additions and 21 deletions

View File

@ -469,7 +469,7 @@ Global Variables
- ``require(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for malformed input or error in external component) - ``require(bool condition)``: abort execution and revert state changes if condition is ``false`` (use for malformed input or error in external component)
- ``revert()``: abort execution and revert state changes - ``revert()``: abort execution and revert state changes
- ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments - ``keccak256(...) returns (bytes32)``: compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments
- ``sha3(...) returns (bytes32)``: an alias to `keccak256()` - ``sha3(...) returns (bytes32)``: an alias to `keccak256`
- ``sha256(...) returns (bytes32)``: compute the SHA-256 hash of the (tightly packed) arguments - ``sha256(...) returns (bytes32)``: compute the SHA-256 hash of the (tightly packed) arguments
- ``ripemd160(...) returns (bytes20)``: compute the RIPEMD-160 hash of the (tightly packed) arguments - ``ripemd160(...) returns (bytes20)``: compute the RIPEMD-160 hash of the (tightly packed) arguments
- ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover address associated with the public key from elliptic curve signature, return zero on error - ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: recover address associated with the public key from elliptic curve signature, return zero on error
@ -478,6 +478,7 @@ Global Variables
- ``this`` (current contract's type): the current contract, explicitly convertible to ``address`` - ``this`` (current contract's type): the current contract, explicitly convertible to ``address``
- ``super``: the contract one level higher in the inheritance hierarchy - ``super``: the contract one level higher in the inheritance hierarchy
- ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address - ``selfdestruct(address recipient)``: destroy the current contract, sending its funds to the given address
- ``suicide(address recipieint)``: an alias to `selfdestruct``
- ``<address>.balance`` (``uint256``): balance of the :ref:`address` in Wei - ``<address>.balance`` (``uint256``): balance of the :ref:`address` in Wei
- ``<address>.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure - ``<address>.send(uint256 amount) returns (bool)``: send given amount of Wei to :ref:`address`, returns ``false`` on failure
- ``<address>.transfer(uint256 amount)``: send given amount of Wei to :ref:`address`, throws on failure - ``<address>.transfer(uint256 amount)``: send given amount of Wei to :ref:`address`, throws on failure
@ -515,7 +516,7 @@ Reserved Keywords
These keywords are reserved in Solidity. They might become part of the syntax in the future: These keywords are reserved in Solidity. They might become part of the syntax in the future:
``abstract``, ``after``, ``case``, ``catch``, ``default``, ``final``, ``in``, ``inline``, ``interface``, ``let``, ``match``, ``null``, ``abstract``, ``after``, ``case``, ``catch``, ``default``, ``final``, ``in``, ``inline``, ``let``, ``match``, ``null``,
``of``, ``pure``, ``relocatable``, ``static``, ``switch``, ``try``, ``type``, ``typeof``, ``view``. ``of``, ``pure``, ``relocatable``, ``static``, ``switch``, ``try``, ``type``, ``typeof``, ``view``.
Language Grammar Language Grammar

View File

@ -280,8 +280,7 @@ Formal Verification
Using formal verification, it is possible to perform an automated mathematical Using formal verification, it is possible to perform an automated mathematical
proof that your source code fulfills a certain formal specification. proof that your source code fulfills a certain formal specification.
The specification is still formal (just as the source code), but usually much The specification is still formal (just as the source code), but usually much
simpler. There is a prototype in Solidity that performs formal verification and simpler.
it will be better documented soon.
Note that formal verification itself can only help you understand the Note that formal verification itself can only help you understand the
difference between what you did (the specification) and how you did it difference between what you did (the specification) and how you did it

View File

@ -101,7 +101,7 @@ of votes.
/// Delegate your vote to the voter `to`. /// Delegate your vote to the voter `to`.
function delegate(address to) { function delegate(address to) {
// assigns reference // assigns reference
Voter sender = voters[msg.sender]; Voter storage sender = voters[msg.sender];
require(!sender.voted); require(!sender.voted);
// Self-delegation is not allowed. // Self-delegation is not allowed.
@ -141,7 +141,7 @@ of votes.
/// Give your vote (including votes delegated to you) /// Give your vote (including votes delegated to you)
/// to proposal `proposals[proposal].name`. /// to proposal `proposals[proposal].name`.
function vote(uint proposal) { function vote(uint proposal) {
Voter sender = voters[msg.sender]; Voter storage sender = voters[msg.sender];
require(!sender.voted); require(!sender.voted);
sender.voted = true; sender.voted = true;
sender.vote = proposal; sender.vote = proposal;
@ -289,7 +289,7 @@ activate themselves.
/// Withdraw a bid that was overbid. /// Withdraw a bid that was overbid.
function withdraw() returns (bool) { function withdraw() returns (bool) {
var amount = pendingReturns[msg.sender]; uint amount = pendingReturns[msg.sender];
if (amount > 0) { if (amount > 0) {
// It is important to set this to zero because the recipient // It is important to set this to zero because the recipient
// can call this function again as part of the receiving call // can call this function again as part of the receiving call
@ -491,8 +491,8 @@ high or low invalid bids.
} }
/// Withdraw a bid that was overbid. /// Withdraw a bid that was overbid.
function withdraw() returns (bool) { function withdraw() {
var amount = pendingReturns[msg.sender]; uint amount = pendingReturns[msg.sender];
if (amount > 0) { if (amount > 0) {
// It is important to set this to zero because the recipient // It is important to set this to zero because the recipient
// can call this function again as part of the receiving call // can call this function again as part of the receiving call
@ -500,13 +500,8 @@ high or low invalid bids.
// conditions -> effects -> interaction). // conditions -> effects -> interaction).
pendingReturns[msg.sender] = 0; pendingReturns[msg.sender] = 0;
if (!msg.sender.send(amount)){ msg.sender.transfer(amount);
// No need to call throw here, just reset the amount owing
pendingReturns[msg.sender] = amount;
return false;
}
} }
return true;
} }
/// End the auction and send the highest bid /// End the auction and send the highest bid

View File

@ -135,6 +135,9 @@ The ``.gas()`` option is available on all three methods, while the ``.value()``
All contracts inherit the members of address, so it is possible to query the balance of the All contracts inherit the members of address, so it is possible to query the balance of the
current contract using ``this.balance``. current contract using ``this.balance``.
.. note::
The use of ``callcode`` is discouraged and will be removed in the future.
.. warning:: .. warning::
All these functions are low-level functions and should be used with care. All these functions are low-level functions and should be used with care.
Specifically, any unknown contract might be malicious and if you call it, you Specifically, any unknown contract might be malicious and if you call it, you
@ -436,7 +439,8 @@ Another example that uses external function types::
} }
} }
Note that lambda or inline functions are planned but not yet supported. .. note::
Lambda or inline functions are planned but not yet supported.
.. index:: ! type;reference, ! reference type, storage, memory, location, array, struct .. index:: ! type;reference, ! reference type, storage, memory, location, array, struct
@ -739,7 +743,7 @@ shown in the following example:
} }
function contribute(uint campaignID) payable { function contribute(uint campaignID) payable {
Campaign c = campaigns[campaignID]; Campaign storage c = campaigns[campaignID];
// Creates a new temporary memory struct, initialised with the given values // Creates a new temporary memory struct, initialised with the given values
// and copies it over to storage. // and copies it over to storage.
// Note that you can also use Funder(msg.sender, msg.value) to initialise. // Note that you can also use Funder(msg.sender, msg.value) to initialise.
@ -748,7 +752,7 @@ shown in the following example:
} }
function checkGoalReached(uint campaignID) returns (bool reached) { function checkGoalReached(uint campaignID) returns (bool reached) {
Campaign c = campaigns[campaignID]; Campaign storage c = campaigns[campaignID];
if (c.amount < c.fundingGoal) if (c.amount < c.fundingGoal)
return false; return false;
uint amount = c.amount; uint amount = c.amount;

View File

@ -35,7 +35,9 @@ These suffixes cannot be applied to variables. If you want to
interpret some input variable in e.g. days, you can do it in the following way:: interpret some input variable in e.g. days, you can do it in the following way::
function f(uint start, uint daysAfter) { function f(uint start, uint daysAfter) {
if (now >= start + daysAfter * 1 days) { ... } if (now >= start + daysAfter * 1 days) {
// ...
}
} }
Special Variables and Functions Special Variables and Functions
@ -70,6 +72,7 @@ Block and Transaction Properties
``msg.value`` can change for every **external** function call. ``msg.value`` can change for every **external** function call.
This includes calls to library functions. This includes calls to library functions.
.. note::
If you want to implement access restrictions in library functions using If you want to implement access restrictions in library functions using
``msg.sender``, you have to manually supply the value of ``msg.sender``, you have to manually supply the value of
``msg.sender`` as an argument. ``msg.sender`` as an argument.
@ -102,10 +105,10 @@ Mathematical and Cryptographic Functions
compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``. compute ``(x * y) % k`` where the multiplication is performed with arbitrary precision and does not wrap around at ``2**256``.
``keccak256(...) returns (bytes32)``: ``keccak256(...) returns (bytes32)``:
compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments compute the Ethereum-SHA-3 (Keccak-256) hash of the (tightly packed) arguments
``sha3(...) returns (bytes32)``:
alias to ``keccak256()``
``sha256(...) returns (bytes32)``: ``sha256(...) returns (bytes32)``:
compute the SHA-256 hash of the (tightly packed) arguments compute the SHA-256 hash of the (tightly packed) arguments
``sha3(...) returns (bytes32)``:
alias to ``keccak256``
``ripemd160(...) returns (bytes20)``: ``ripemd160(...) returns (bytes20)``:
compute RIPEMD-160 hash of the (tightly packed) arguments compute RIPEMD-160 hash of the (tightly packed) arguments
``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``: ``ecrecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) returns (address)``:
@ -157,6 +160,9 @@ For more information, see the section on :ref:`address`.
to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better: to make safe Ether transfers, always check the return value of ``send``, use ``transfer`` or even better:
Use a pattern where the recipient withdraws the money. Use a pattern where the recipient withdraws the money.
.. note::
The use of ``callcode`` is discouraged and will be removed in the future.
.. index:: this, selfdestruct .. index:: this, selfdestruct
Contract Related Contract Related
@ -168,5 +174,8 @@ Contract Related
``selfdestruct(address recipient)``: ``selfdestruct(address recipient)``:
destroy the current contract, sending its funds to the given :ref:`address` destroy the current contract, sending its funds to the given :ref:`address`
``suicide(address recipient)``:
alias to ``selfdestruct``
Furthermore, all functions of the current contract are callable directly including the current function. Furthermore, all functions of the current contract are callable directly including the current function.