mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #580 from Denton-L/docs-whitespace
Corrections to Documentation Spacing
This commit is contained in:
commit
ec061b09a3
@ -179,6 +179,7 @@ function finishes.
|
|||||||
AreWeDoneYet,
|
AreWeDoneYet,
|
||||||
Finished
|
Finished
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the current stage.
|
// This is the current stage.
|
||||||
Stages public stage = Stages.AcceptingBlindedBids;
|
Stages public stage = Stages.AcceptingBlindedBids;
|
||||||
|
|
||||||
@ -188,9 +189,11 @@ function finishes.
|
|||||||
if (stage != _stage) throw;
|
if (stage != _stage) throw;
|
||||||
_
|
_
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextStage() internal {
|
function nextStage() internal {
|
||||||
stage = Stages(uint(stage) + 1);
|
stage = Stages(uint(stage) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform timed transitions. Be sure to mention
|
// Perform timed transitions. Be sure to mention
|
||||||
// this modifier first, otherwise the guards
|
// this modifier first, otherwise the guards
|
||||||
// will not take the new stage into account.
|
// will not take the new stage into account.
|
||||||
@ -211,6 +214,7 @@ function finishes.
|
|||||||
{
|
{
|
||||||
// We will not implement that here
|
// We will not implement that here
|
||||||
}
|
}
|
||||||
|
|
||||||
function reveal()
|
function reveal()
|
||||||
timedTransitions
|
timedTransitions
|
||||||
atStage(Stages.RevealBids)
|
atStage(Stages.RevealBids)
|
||||||
@ -227,6 +231,7 @@ function finishes.
|
|||||||
_
|
_
|
||||||
nextStage();
|
nextStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
function g()
|
function g()
|
||||||
timedTransitions
|
timedTransitions
|
||||||
atStage(Stages.AnotherStage)
|
atStage(Stages.AnotherStage)
|
||||||
@ -235,12 +240,14 @@ function finishes.
|
|||||||
// If you want to use `return` here,
|
// If you want to use `return` here,
|
||||||
// you have to call `nextStage()` manually.
|
// you have to call `nextStage()` manually.
|
||||||
}
|
}
|
||||||
|
|
||||||
function h()
|
function h()
|
||||||
timedTransitions
|
timedTransitions
|
||||||
atStage(Stages.AreWeDoneYet)
|
atStage(Stages.AreWeDoneYet)
|
||||||
transitionNext
|
transitionNext
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
function i()
|
function i()
|
||||||
timedTransitions
|
timedTransitions
|
||||||
atStage(Stages.Finished)
|
atStage(Stages.Finished)
|
||||||
|
@ -44,7 +44,8 @@ API, this is done as follows::
|
|||||||
var MyContract = web3.eth.contract(abiArray);
|
var MyContract = web3.eth.contract(abiArray);
|
||||||
// deploy new contract
|
// deploy new contract
|
||||||
var contractInstance = MyContract.new(
|
var contractInstance = MyContract.new(
|
||||||
10, 11,
|
10,
|
||||||
|
11,
|
||||||
{from: myAccount, gas: 1000000}
|
{from: myAccount, gas: 1000000}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -84,7 +85,8 @@ This means that cyclic creation dependencies are impossible.
|
|||||||
// Only the creator can alter the name --
|
// Only the creator can alter the name --
|
||||||
// the comparison is possible since contracts
|
// the comparison is possible since contracts
|
||||||
// are implicitly convertible to addresses.
|
// are implicitly convertible to addresses.
|
||||||
if (msg.sender == creator) name = newName;
|
if (msg.sender == creator)
|
||||||
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function transfer(address newOwner) {
|
function transfer(address newOwner) {
|
||||||
@ -221,7 +223,11 @@ The next example is a bit more complex:
|
|||||||
::
|
::
|
||||||
|
|
||||||
contract complex {
|
contract complex {
|
||||||
struct Data { uint a; bytes3 b; mapping(uint => uint) map; }
|
struct Data {
|
||||||
|
uint a;
|
||||||
|
bytes3 b;
|
||||||
|
mapping (uint => uint) map;
|
||||||
|
}
|
||||||
mapping (uint => mapping(bool => Data[])) public data;
|
mapping (uint => mapping(bool => Data[])) public data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +266,11 @@ inheritable properties of contracts and may be overridden by derived contracts.
|
|||||||
// This means that if the owner calls this function, the
|
// This means that if the owner calls this function, the
|
||||||
// function is executed and otherwise, an exception is
|
// function is executed and otherwise, an exception is
|
||||||
// thrown.
|
// thrown.
|
||||||
modifier onlyowner { if (msg.sender != owner) throw; _ }
|
modifier onlyowner {
|
||||||
|
if (msg.sender != owner)
|
||||||
|
throw;
|
||||||
|
_
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,17 +287,24 @@ inheritable properties of contracts and may be overridden by derived contracts.
|
|||||||
|
|
||||||
contract priced {
|
contract priced {
|
||||||
// Modifiers can receive arguments:
|
// Modifiers can receive arguments:
|
||||||
modifier costs(uint price) { if (msg.value >= price) _ }
|
modifier costs(uint price) {
|
||||||
|
if (msg.value >= price) {
|
||||||
|
_
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Register is priced, owned {
|
contract Register is priced, owned {
|
||||||
mapping (address => bool) registeredAddresses;
|
mapping (address => bool) registeredAddresses;
|
||||||
uint price;
|
uint price;
|
||||||
|
|
||||||
function Register(uint initialPrice) { price = initialPrice; }
|
function Register(uint initialPrice) { price = initialPrice; }
|
||||||
|
|
||||||
function register() costs(price) {
|
function register() costs(price) {
|
||||||
registeredAddresses[msg.sender] = true;
|
registeredAddresses[msg.sender] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function changePrice(uint _price) onlyowner {
|
function changePrice(uint _price) onlyowner {
|
||||||
price = _price;
|
price = _price;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ of other contracts, the amount of Wei sent with the call and the gas can be spec
|
|||||||
contract InfoFeed {
|
contract InfoFeed {
|
||||||
function info() returns (uint ret) { return 42; }
|
function info() returns (uint ret) { return 42; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Consumer {
|
contract Consumer {
|
||||||
InfoFeed feed;
|
InfoFeed feed;
|
||||||
function setFeed(address addr) { feed = InfoFeed(addr); }
|
function setFeed(address addr) { feed = InfoFeed(addr); }
|
||||||
@ -77,10 +79,12 @@ of unused parameters (especially return parameters) can be omitted.
|
|||||||
|
|
||||||
contract c {
|
contract c {
|
||||||
function f(uint key, uint value) { ... }
|
function f(uint key, uint value) { ... }
|
||||||
|
|
||||||
function g() {
|
function g() {
|
||||||
// named arguments
|
// named arguments
|
||||||
f({value: 2, key: 3});
|
f({value: 2, key: 3});
|
||||||
}
|
}
|
||||||
|
|
||||||
// omitted parameters
|
// omitted parameters
|
||||||
function func(uint k, uint) returns(uint) {
|
function func(uint k, uint) returns(uint) {
|
||||||
return k;
|
return k;
|
||||||
@ -110,9 +114,11 @@ Solidity internally allows tuple types, i.e. a list of objects of potentially di
|
|||||||
|
|
||||||
contract C {
|
contract C {
|
||||||
uint[] data;
|
uint[] data;
|
||||||
|
|
||||||
function f() returns (uint, bool, uint) {
|
function f() returns (uint, bool, uint) {
|
||||||
return (7, true, 2);
|
return (7, true, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
function g() {
|
function g() {
|
||||||
// Declares and assigns the variables. Specifying the type explicitly is not possible.
|
// Declares and assigns the variables. Specifying the type explicitly is not possible.
|
||||||
var (x, b, y) = f();
|
var (x, b, y) = f();
|
||||||
@ -288,12 +294,16 @@ you really know what you are doing.
|
|||||||
for (uint i = 0; i < _data.length; ++i)
|
for (uint i = 0; i < _data.length; ++i)
|
||||||
o_sum += _data[i];
|
o_sum += _data[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// We know that we only access the array in bounds, so we can avoid the check.
|
// We know that we only access the array in bounds, so we can avoid the check.
|
||||||
// 0x20 needs to be added to an array because the first slot contains the
|
// 0x20 needs to be added to an array because the first slot contains the
|
||||||
// array length.
|
// array length.
|
||||||
function sumAsm(uint[] _data) returns (uint o_sum) {
|
function sumAsm(uint[] _data) returns (uint o_sum) {
|
||||||
for (uint i = 0; i < _data.length; ++i)
|
for (uint i = 0; i < _data.length; ++i) {
|
||||||
assembly { o_sum := mload(add(add(_data, 0x20), i)) }
|
assembly {
|
||||||
|
o_sum := mload(add(add(_data, 0x20), i))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,147 +340,147 @@ In the following, `mem[a...b)` signifies the bytes of memory starting at positio
|
|||||||
|
|
||||||
The opcodes `pushi` and `jumpdest` cannot be used directly.
|
The opcodes `pushi` and `jumpdest` cannot be used directly.
|
||||||
|
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| stop + `-` | stop execution, identical to return(0,0) |
|
| stop + `-` | stop execution, identical to return(0,0) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| add(x, y) | | x + y |
|
| add(x, y) | | x + y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sub(x, y) | | x - y |
|
| sub(x, y) | | x - y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mul(x, y) | | x * y |
|
| mul(x, y) | | x * y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| div(x, y) | | x / y |
|
| div(x, y) | | x / y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sdiv(x, y) | | x / y, for signed numbers in two's complement |
|
| sdiv(x, y) | | x / y, for signed numbers in two's complement |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mod(x, y) | | x % y |
|
| mod(x, y) | | x % y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| smod(x, y) | | x % y, for signed numbers in two's complement |
|
| smod(x, y) | | x % y, for signed numbers in two's complement |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| exp(x, y) | | x to the power of y |
|
| exp(x, y) | | x to the power of y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| not(x) | | ~x, every bit of x is negated |
|
| not(x) | | ~x, every bit of x is negated |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| lt(x, y) | | 1 if x < y, 0 otherwise |
|
| lt(x, y) | | 1 if x < y, 0 otherwise |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| gt(x, y) | | 1 if x > y, 0 otherwise |
|
| gt(x, y) | | 1 if x > y, 0 otherwise |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| slt(x, y) | | 1 if x < y, 0 otherwise, for signed numbers in two's complement |
|
| slt(x, y) | | 1 if x < y, 0 otherwise, for signed numbers in two's complement |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sgt(x, y) | | 1 if x > y, 0 otherwise, for signed numbers in two's complement |
|
| sgt(x, y) | | 1 if x > y, 0 otherwise, for signed numbers in two's complement |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| eq(x, y) | | 1 if x == y, 0 otherwise |
|
| eq(x, y) | | 1 if x == y, 0 otherwise |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| iszero(x) | | 1 if x == 0, 0 otherwise |
|
| iszero(x) | | 1 if x == 0, 0 otherwise |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| and(x, y) | | bitwise and of x and y |
|
| and(x, y) | | bitwise and of x and y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| or(x, y) | | bitwise or of x and y |
|
| or(x, y) | | bitwise or of x and y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| xor(x, y) | | bitwise xor of x and y |
|
| xor(x, y) | | bitwise xor of x and y |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| byte(n, x) | | nth byte of x, where the most significant byte is the 0th byte |
|
| byte(n, x) | | nth byte of x, where the most significant byte is the 0th byte |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| addmod(x, y, m) | | (x + y) % m with arbitrary precision arithmetics |
|
| addmod(x, y, m) | | (x + y) % m with arbitrary precision arithmetics |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mulmod(x, y, m) | | (x * y) % m with arbitrary precision arithmetics |
|
| mulmod(x, y, m) | | (x * y) % m with arbitrary precision arithmetics |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| signextend(i, x) | | sign extend from (i*8+7)th bit counting from least significant |
|
| signextend(i, x) | | sign extend from (i*8+7)th bit counting from least significant |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sha3(p, n) | | keccak(mem[p...(p+n))) |
|
| sha3(p, n) | | keccak(mem[p...(p+n))) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| jump(label) | `-` | jump to label / code position |
|
| jump(label) | `-` | jump to label / code position |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| jumpi(label, cond) | `-` | jump to label if cond is nonzero |
|
| jumpi(label, cond) | `-` | jump to label if cond is nonzero |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| pc | | current position in code |
|
| pc | | current position in code |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| pop | `*` | remove topmost stack slot |
|
| pop | `*` | remove topmost stack slot |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| dup1 ... dup16 | | copy ith stack slot to the top (counting from top) |
|
| dup1 ... dup16 | | copy ith stack slot to the top (counting from top) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| swap1 ... swap1 | `*` | swap topmost and ith stack slot below it |
|
| swap1 ... swap1 | `*` | swap topmost and ith stack slot below it |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mload(p) | | mem[p..(p+32)) |
|
| mload(p) | | mem[p..(p+32)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mstore(p, v) | `-` | mem[p..(p+32)) := v |
|
| mstore(p, v) | `-` | mem[p..(p+32)) := v |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| mstore8(p, v) | `-` | mem[p] := v & 0xff - only modifies a single byte |
|
| mstore8(p, v) | `-` | mem[p] := v & 0xff - only modifies a single byte |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sload(p) | | storage[p] |
|
| sload(p) | | storage[p] |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| sstore(p, v) | `-` | storage[p] := v |
|
| sstore(p, v) | `-` | storage[p] := v |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| msize | | size of memory, i.e. largest accessed memory index |
|
| msize | | size of memory, i.e. largest accessed memory index |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| gas | | gas still available to execution |
|
| gas | | gas still available to execution |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| address | | address of the current contract / execution context |
|
| address | | address of the current contract / execution context |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| balance(a) | | wei balance at address a |
|
| balance(a) | | wei balance at address a |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| caller | | call sender (excluding delegatecall) |
|
| caller | | call sender (excluding delegatecall) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| callvalue | | wei sent together with the current call |
|
| callvalue | | wei sent together with the current call |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| calldataload(p) | | call data starting from position p (32 bytes) |
|
| calldataload(p) | | call data starting from position p (32 bytes) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| calldatasize | | size of call data in bytes |
|
| calldatasize | | size of call data in bytes |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| calldatacopy(t, f, s) | `-` | copy s bytes from calldata at position f to mem at position t |
|
| calldatacopy(t, f, s) | `-` | copy s bytes from calldata at position f to mem at position t |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| codesize | | size of the code of the current contract / execution context |
|
| codesize | | size of the code of the current contract / execution context |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| codecopy(t, f, s) | `-` | copy s bytes from code at position f to mem at position t |
|
| codecopy(t, f, s) | `-` | copy s bytes from code at position f to mem at position t |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| extcodesize(a) | | size of the code at address a |
|
| extcodesize(a) | | size of the code at address a |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| extcodecopy(a, t, f, s) | `-` | like codecopy(t, f, s) but take code at address a |
|
| extcodecopy(a, t, f, s) | `-` | like codecopy(t, f, s) but take code at address a |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei |
|
| create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei |
|
||||||
| | | and return the new address |
|
| | | and return the new address |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)] |
|
| call(g, a, v, in, | | call contract at address a with input mem[in..(in+insize)] |
|
||||||
| insize, out, outsize) | | providing g gas and v wei and output area |
|
| insize, out, outsize) | | providing g gas and v wei and output area |
|
||||||
| | | mem[out..(out+outsize)] returting 1 on error (out of gas) |
|
| | | mem[out..(out+outsize)] returting 1 on error (out of gas) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| callcode(g, a, v, in, | | identical to call but only use the code from a and stay |
|
| callcode(g, a, v, in, | | identical to call but only use the code from a and stay |
|
||||||
| insize, out, outsize) | | in the context of the current contract otherwise |
|
| insize, out, outsize) | | in the context of the current contract otherwise |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| delegatecall(g, a, in, | | identical to callcode but also keep `caller` and `callvalue` |
|
| delegatecall(g, a, in, | | identical to callcode but also keep `caller` and `callvalue` |
|
||||||
| insize, out, outsize) | | |
|
| insize, out, outsize) | | |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| return(p, s) | `*` | end execution, return data mem[p..(p+s)) |
|
| return(p, s) | `*` | end execution, return data mem[p..(p+s)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| selfdestruct(a) | `*` | end execution, destroy current contract and send funds to a |
|
| selfdestruct(a) | `*` | end execution, destroy current contract and send funds to a |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| log0(p, s) | `-` | log without topics and data mem[p..(p+s)) |
|
| log0(p, s) | `-` | log without topics and data mem[p..(p+s)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| log1(p, s, t1) | `-` | log with topic t1 and data mem[p..(p+s)) |
|
| log1(p, s, t1) | `-` | log with topic t1 and data mem[p..(p+s)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| log2(p, s, t1, t2) | `-` | log with topics t1, t2 and data mem[p..(p+s)) |
|
| log2(p, s, t1, t2) | `-` | log with topics t1, t2 and data mem[p..(p+s)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| log3(p, s, t1, t2, t3) | `-` | log with topics t1, t2, t3 and data mem[p..(p+s)) |
|
| log3(p, s, t1, t2, t3) | `-` | log with topics t1, t2, t3 and data mem[p..(p+s)) |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| log4(p, s, t1, t2, t3, | `-` | log with topics t1, t2, t3, t4 and data mem[p..(p+s)) |
|
| log4(p, s, t1, t2, t3, | `-` | log with topics t1, t2, t3, t4 and data mem[p..(p+s)) |
|
||||||
| t4) | | |
|
| t4) | | |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| origin | | transaction sender |
|
| origin | | transaction sender |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| gasprice | | gas price of the transaction |
|
| gasprice | | gas price of the transaction |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| blockhash(b) | | hash of block nr b - only for last 256 blocks excluding current |
|
| blockhash(b) | | hash of block nr b - only for last 256 blocks excluding current |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| coinbase | | current mining beneficiary |
|
| coinbase | | current mining beneficiary |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| timestamp | | timestamp of the current block in seconds since the epoch |
|
| timestamp | | timestamp of the current block in seconds since the epoch |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| number | | current block number |
|
| number | | current block number |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| difficulty | | difficulty of the current block |
|
| difficulty | | difficulty of the current block |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
| gaslimit | | block gas limit of the current block |
|
| gaslimit | | block gas limit of the current block |
|
||||||
+-----------------------+------+---------------------------------------------------------------+
|
+-------------------------+------+-----------------------------------------------------------------+
|
||||||
|
|
||||||
Literals
|
Literals
|
||||||
--------
|
--------
|
||||||
|
@ -713,7 +713,10 @@ In the case of a `contract A` calling a new instance of `contract B`, parenthese
|
|||||||
`new B` because `B.value` would refer to a member of `B` called `value`.
|
`new B` because `B.value` would refer to a member of `B` called `value`.
|
||||||
You will need to make sure that you have both contracts aware of each other's presence.
|
You will need to make sure that you have both contracts aware of each other's presence.
|
||||||
In this example::
|
In this example::
|
||||||
|
|
||||||
contract B {}
|
contract B {}
|
||||||
|
|
||||||
|
|
||||||
contract A {
|
contract A {
|
||||||
address child;
|
address child;
|
||||||
|
|
||||||
|
@ -20,9 +20,11 @@ Storage
|
|||||||
|
|
||||||
contract SimpleStorage {
|
contract SimpleStorage {
|
||||||
uint storedData;
|
uint storedData;
|
||||||
|
|
||||||
function set(uint x) {
|
function set(uint x) {
|
||||||
storedData = x;
|
storedData = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get() constant returns (uint retVal) {
|
function get() constant returns (uint retVal) {
|
||||||
return storedData;
|
return storedData;
|
||||||
}
|
}
|
||||||
@ -88,10 +90,12 @@ registering with username and password - all you need is an Ethereum keypair.
|
|||||||
function Coin() {
|
function Coin() {
|
||||||
minter = msg.sender;
|
minter = msg.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
function mint(address receiver, uint amount) {
|
function mint(address receiver, uint amount) {
|
||||||
if (msg.sender != minter) return;
|
if (msg.sender != minter) return;
|
||||||
balances[receiver] += amount;
|
balances[receiver] += amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send(address receiver, uint amount) {
|
function send(address receiver, uint amount) {
|
||||||
if (balances[msg.sender] < amount) return;
|
if (balances[msg.sender] < amount) return;
|
||||||
balances[msg.sender] -= amount;
|
balances[msg.sender] -= amount;
|
||||||
|
@ -51,9 +51,11 @@ There are some types in Solidity's type system that have no counterpart in the s
|
|||||||
if (useB) f = b;
|
if (useB) f = b;
|
||||||
return f(x);
|
return f(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
function a(uint x) returns (uint z) {
|
function a(uint x) returns (uint z) {
|
||||||
return x * x;
|
return x * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
function b(uint x) returns (uint z) {
|
function b(uint x) returns (uint z) {
|
||||||
return 2 * x;
|
return 2 * x;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +292,7 @@ activate themselves.
|
|||||||
}
|
}
|
||||||
|
|
||||||
Blind Auction
|
Blind Auction
|
||||||
================
|
=============
|
||||||
|
|
||||||
The previous open auction is extended to a blind auction
|
The previous open auction is extended to a blind auction
|
||||||
in the following. The advantage of a blind auction is
|
in the following. The advantage of a blind auction is
|
||||||
|
@ -171,21 +171,21 @@ to and from all integer types but implicit conversion is not allowed.
|
|||||||
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
|
enum ActionChoices { GoLeft, GoRight, GoStraight, SitStill }
|
||||||
ActionChoices choice;
|
ActionChoices choice;
|
||||||
ActionChoices constant defaultChoice = ActionChoices.GoStraight;
|
ActionChoices constant defaultChoice = ActionChoices.GoStraight;
|
||||||
function setGoStraight()
|
|
||||||
{
|
function setGoStraight() {
|
||||||
choice = ActionChoices.GoStraight;
|
choice = ActionChoices.GoStraight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since enum types are not part of the ABI, the signature of "getChoice"
|
// Since enum types are not part of the ABI, the signature of "getChoice"
|
||||||
// will automatically be changed to "getChoice() returns (uint8)"
|
// will automatically be changed to "getChoice() returns (uint8)"
|
||||||
// for all matters external to Solidity. The integer type used is just
|
// for all matters external to Solidity. The integer type used is just
|
||||||
// large enough to hold all enum values, i.e. if you have more values,
|
// large enough to hold all enum values, i.e. if you have more values,
|
||||||
// `uint16` will be used and so on.
|
// `uint16` will be used and so on.
|
||||||
function getChoice() returns (ActionChoices)
|
function getChoice() returns (ActionChoices) {
|
||||||
{
|
|
||||||
return choice;
|
return choice;
|
||||||
}
|
}
|
||||||
function getDefaultChoice() returns (uint)
|
|
||||||
{
|
function getDefaultChoice() returns (uint) {
|
||||||
return uint(defaultChoice);
|
return uint(defaultChoice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -226,8 +226,9 @@ memory-stored reference type does not create a copy.
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
contract c {
|
contract C {
|
||||||
uint[] x; // the data location of x is storage
|
uint[] x; // the data location of x is storage
|
||||||
|
|
||||||
// the data location of memoryArray is memory
|
// the data location of memoryArray is memory
|
||||||
function f(uint[] memoryArray) {
|
function f(uint[] memoryArray) {
|
||||||
x = memoryArray; // works, copies the whole array to storage
|
x = memoryArray; // works, copies the whole array to storage
|
||||||
@ -244,6 +245,7 @@ memory-stored reference type does not create a copy.
|
|||||||
g(x); // calls g, handing over a reference to x
|
g(x); // calls g, handing over a reference to x
|
||||||
h(x); // calls h and creates an independent, temporary copy in memory
|
h(x); // calls h and creates an independent, temporary copy in memory
|
||||||
}
|
}
|
||||||
|
|
||||||
function g(uint[] storage storageArray) internal {}
|
function g(uint[] storage storageArray) internal {}
|
||||||
function h(uint[] memoryArray) {}
|
function h(uint[] memoryArray) {}
|
||||||
}
|
}
|
||||||
@ -343,19 +345,23 @@ Members
|
|||||||
// Note that the following is not a pair of arrays but an array of pairs.
|
// Note that the following is not a pair of arrays but an array of pairs.
|
||||||
bool[2][] m_pairsOfFlags;
|
bool[2][] m_pairsOfFlags;
|
||||||
// newPairs is stored in memory - the default for function arguments
|
// newPairs is stored in memory - the default for function arguments
|
||||||
|
|
||||||
function setAllFlagPairs(bool[2][] newPairs) {
|
function setAllFlagPairs(bool[2][] newPairs) {
|
||||||
// assignment to a storage array replaces the complete array
|
// assignment to a storage array replaces the complete array
|
||||||
m_pairsOfFlags = newPairs;
|
m_pairsOfFlags = newPairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFlagPair(uint index, bool flagA, bool flagB) {
|
function setFlagPair(uint index, bool flagA, bool flagB) {
|
||||||
// access to a non-existing index will throw an exception
|
// access to a non-existing index will throw an exception
|
||||||
m_pairsOfFlags[index][0] = flagA;
|
m_pairsOfFlags[index][0] = flagA;
|
||||||
m_pairsOfFlags[index][1] = flagB;
|
m_pairsOfFlags[index][1] = flagB;
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeFlagArraySize(uint newSize) {
|
function changeFlagArraySize(uint newSize) {
|
||||||
// if the new size is smaller, removed array elements will be cleared
|
// if the new size is smaller, removed array elements will be cleared
|
||||||
m_pairsOfFlags.length = newSize;
|
m_pairsOfFlags.length = newSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
// these clear the arrays completely
|
// these clear the arrays completely
|
||||||
delete m_pairsOfFlags;
|
delete m_pairsOfFlags;
|
||||||
@ -363,7 +369,9 @@ Members
|
|||||||
// identical effect here
|
// identical effect here
|
||||||
m_pairsOfFlags.length = 0;
|
m_pairsOfFlags.length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bytes m_byteData;
|
bytes m_byteData;
|
||||||
|
|
||||||
function byteArrays(bytes data) {
|
function byteArrays(bytes data) {
|
||||||
// byte arrays ("bytes") are different as they are stored without padding,
|
// byte arrays ("bytes") are different as they are stored without padding,
|
||||||
// but can be treated identical to "uint8[]"
|
// but can be treated identical to "uint8[]"
|
||||||
@ -372,9 +380,11 @@ Members
|
|||||||
m_byteData[3] = 8;
|
m_byteData[3] = 8;
|
||||||
delete m_byteData[2];
|
delete m_byteData[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
function addFlag(bool[2] flag) returns (uint) {
|
function addFlag(bool[2] flag) returns (uint) {
|
||||||
return m_pairsOfFlags.push(flag);
|
return m_pairsOfFlags.push(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMemoryArray(uint size) returns (bytes) {
|
function createMemoryArray(uint size) returns (bytes) {
|
||||||
// Dynamic memory arrays are created using `new`:
|
// Dynamic memory arrays are created using `new`:
|
||||||
uint[2][] memory arrayOfPairs = new uint[2][](size);
|
uint[2][] memory arrayOfPairs = new uint[2][](size);
|
||||||
@ -405,6 +415,7 @@ shown in the following example:
|
|||||||
address addr;
|
address addr;
|
||||||
uint amount;
|
uint amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Campaign {
|
struct Campaign {
|
||||||
address beneficiary;
|
address beneficiary;
|
||||||
uint fundingGoal;
|
uint fundingGoal;
|
||||||
@ -412,13 +423,16 @@ shown in the following example:
|
|||||||
uint amount;
|
uint amount;
|
||||||
mapping (uint => Funder) funders;
|
mapping (uint => Funder) funders;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint numCampaigns;
|
uint numCampaigns;
|
||||||
mapping (uint => Campaign) campaigns;
|
mapping (uint => Campaign) campaigns;
|
||||||
|
|
||||||
function newCampaign(address beneficiary, uint goal) returns (uint campaignID) {
|
function newCampaign(address beneficiary, uint goal) returns (uint campaignID) {
|
||||||
campaignID = numCampaigns++; // campaignID is return variable
|
campaignID = numCampaigns++; // campaignID is return variable
|
||||||
// Creates new struct and saves in storage. We leave out the mapping type.
|
// Creates new struct and saves in storage. We leave out the mapping type.
|
||||||
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
|
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
function contribute(uint campaignID) {
|
function contribute(uint campaignID) {
|
||||||
Campaign c = campaigns[campaignID];
|
Campaign 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
|
||||||
@ -427,6 +441,7 @@ shown in the following example:
|
|||||||
c.funders[c.numFunders++] = Funder({addr: msg.sender, amount: msg.value});
|
c.funders[c.numFunders++] = Funder({addr: msg.sender, amount: msg.value});
|
||||||
c.amount += msg.value;
|
c.amount += msg.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkGoalReached(uint campaignID) returns (bool reached) {
|
function checkGoalReached(uint campaignID) returns (bool reached) {
|
||||||
Campaign c = campaigns[campaignID];
|
Campaign c = campaigns[campaignID];
|
||||||
if (c.amount < c.fundingGoal)
|
if (c.amount < c.fundingGoal)
|
||||||
@ -497,6 +512,7 @@ It is important to note that `delete a` really behaves like an assignment to `a`
|
|||||||
contract DeleteExample {
|
contract DeleteExample {
|
||||||
uint data;
|
uint data;
|
||||||
uint[] dataArray;
|
uint[] dataArray;
|
||||||
|
|
||||||
function f() {
|
function f() {
|
||||||
uint x = data;
|
uint x = data;
|
||||||
delete x; // sets x to 0, does not affect data
|
delete x; // sets x to 0, does not affect data
|
||||||
|
Loading…
Reference in New Issue
Block a user