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,
|
||||
Finished
|
||||
}
|
||||
|
||||
// This is the current stage.
|
||||
Stages public stage = Stages.AcceptingBlindedBids;
|
||||
|
||||
@ -188,9 +189,11 @@ function finishes.
|
||||
if (stage != _stage) throw;
|
||||
_
|
||||
}
|
||||
|
||||
function nextStage() internal {
|
||||
stage = Stages(uint(stage) + 1);
|
||||
}
|
||||
|
||||
// Perform timed transitions. Be sure to mention
|
||||
// this modifier first, otherwise the guards
|
||||
// will not take the new stage into account.
|
||||
@ -211,6 +214,7 @@ function finishes.
|
||||
{
|
||||
// We will not implement that here
|
||||
}
|
||||
|
||||
function reveal()
|
||||
timedTransitions
|
||||
atStage(Stages.RevealBids)
|
||||
@ -227,6 +231,7 @@ function finishes.
|
||||
_
|
||||
nextStage();
|
||||
}
|
||||
|
||||
function g()
|
||||
timedTransitions
|
||||
atStage(Stages.AnotherStage)
|
||||
@ -235,12 +240,14 @@ function finishes.
|
||||
// If you want to use `return` here,
|
||||
// you have to call `nextStage()` manually.
|
||||
}
|
||||
|
||||
function h()
|
||||
timedTransitions
|
||||
atStage(Stages.AreWeDoneYet)
|
||||
transitionNext
|
||||
{
|
||||
}
|
||||
|
||||
function i()
|
||||
timedTransitions
|
||||
atStage(Stages.Finished)
|
||||
|
@ -44,7 +44,8 @@ API, this is done as follows::
|
||||
var MyContract = web3.eth.contract(abiArray);
|
||||
// deploy new contract
|
||||
var contractInstance = MyContract.new(
|
||||
10, 11,
|
||||
10,
|
||||
11,
|
||||
{from: myAccount, gas: 1000000}
|
||||
);
|
||||
|
||||
@ -84,7 +85,8 @@ This means that cyclic creation dependencies are impossible.
|
||||
// Only the creator can alter the name --
|
||||
// the comparison is possible since contracts
|
||||
// are implicitly convertible to addresses.
|
||||
if (msg.sender == creator) name = newName;
|
||||
if (msg.sender == creator)
|
||||
name = newName;
|
||||
}
|
||||
|
||||
function transfer(address newOwner) {
|
||||
@ -221,7 +223,11 @@ The next example is a bit more 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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
// function is executed and otherwise, an exception is
|
||||
// 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 {
|
||||
// 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 {
|
||||
mapping (address => bool) registeredAddresses;
|
||||
uint price;
|
||||
|
||||
function Register(uint initialPrice) { price = initialPrice; }
|
||||
|
||||
function register() costs(price) {
|
||||
registeredAddresses[msg.sender] = true;
|
||||
}
|
||||
|
||||
function changePrice(uint _price) onlyowner {
|
||||
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 {
|
||||
function info() returns (uint ret) { return 42; }
|
||||
}
|
||||
|
||||
|
||||
contract Consumer {
|
||||
InfoFeed feed;
|
||||
function setFeed(address addr) { feed = InfoFeed(addr); }
|
||||
@ -77,10 +79,12 @@ of unused parameters (especially return parameters) can be omitted.
|
||||
|
||||
contract c {
|
||||
function f(uint key, uint value) { ... }
|
||||
|
||||
function g() {
|
||||
// named arguments
|
||||
f({value: 2, key: 3});
|
||||
}
|
||||
|
||||
// omitted parameters
|
||||
function func(uint k, uint) returns(uint) {
|
||||
return k;
|
||||
@ -110,9 +114,11 @@ Solidity internally allows tuple types, i.e. a list of objects of potentially di
|
||||
|
||||
contract C {
|
||||
uint[] data;
|
||||
|
||||
function f() returns (uint, bool, uint) {
|
||||
return (7, true, 2);
|
||||
}
|
||||
|
||||
function g() {
|
||||
// Declares and assigns the variables. Specifying the type explicitly is not possible.
|
||||
var (x, b, y) = f();
|
||||
@ -288,12 +294,16 @@ you really know what you are doing.
|
||||
for (uint i = 0; i < _data.length; ++i)
|
||||
o_sum += _data[i];
|
||||
}
|
||||
|
||||
// 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
|
||||
// array length.
|
||||
function sumAsm(uint[] _data) returns (uint o_sum) {
|
||||
for (uint i = 0; i < _data.length; ++i)
|
||||
assembly { o_sum := mload(add(add(_data, 0x20), i)) }
|
||||
for (uint i = 0; i < _data.length; ++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.
|
||||
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| stop + `-` | stop execution, identical to return(0,0) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| add(x, y) | | x + y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| sub(x, y) | | x - y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| mul(x, y) | | x * y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| div(x, y) | | x / y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| sdiv(x, y) | | x / y, for signed numbers in two's complement |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| mod(x, y) | | x % y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| smod(x, y) | | x % y, for signed numbers in two's complement |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| exp(x, y) | | x to the power of y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| not(x) | | ~x, every bit of x is negated |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| lt(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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| iszero(x) | | 1 if x == 0, 0 otherwise |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| and(x, y) | | bitwise and of x and y |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| or(x, y) | | bitwise or 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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| addmod(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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| sha3(p, n) | | keccak(mem[p...(p+n))) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| jump(label) | `-` | jump to label / code position |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| jumpi(label, cond) | `-` | jump to label if cond is nonzero |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| pc | | current position in code |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| pop | `*` | remove topmost stack slot |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| dup1 ... dup16 | | copy ith stack slot to the top (counting from top) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| swap1 ... swap1 | `*` | swap topmost and ith stack slot below it |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| mload(p) | | mem[p..(p+32)) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| mstore(p, v) | `-` | mem[p..(p+32)) := v |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| mstore8(p, v) | `-` | mem[p] := v & 0xff - only modifies a single byte |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| sload(p) | | storage[p] |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| sstore(p, v) | `-` | storage[p] := v |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| msize | | size of memory, i.e. largest accessed memory index |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| gas | | gas still available to execution |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| address | | address of the current contract / execution context |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| balance(a) | | wei balance at address a |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| caller | | call sender (excluding delegatecall) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| callvalue | | wei sent together with the current call |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| calldataload(p) | | call data starting from position p (32 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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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 |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| create(v, p, s) | | create new contract with code mem[p..(p+s)) and send v wei |
|
||||
| | | and return the new address |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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 |
|
||||
| | | 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 |
|
||||
| insize, out, outsize) | | in the context of the current contract otherwise |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| delegatecall(g, a, in, | | identical to callcode but also keep `caller` and `callvalue` |
|
||||
| insize, out, outsize) | | |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| return(p, s) | `*` | end execution, return data mem[p..(p+s)) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| selfdestruct(a) | `*` | end execution, destroy current contract and send funds to a |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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)) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| 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)) |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| log4(p, s, t1, t2, t3, | `-` | log with topics t1, t2, t3, t4 and data mem[p..(p+s)) |
|
||||
| t4) | | |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| origin | | transaction sender |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| gasprice | | gas price of the transaction |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| blockhash(b) | | hash of block nr b - only for last 256 blocks excluding current |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| coinbase | | current mining beneficiary |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| timestamp | | timestamp of the current block in seconds since the epoch |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| number | | current block number |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| difficulty | | difficulty of the current block |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
| gaslimit | | block gas limit of the current block |
|
||||
+-----------------------+------+---------------------------------------------------------------+
|
||||
+-------------------------+------+-----------------------------------------------------------------+
|
||||
|
||||
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`.
|
||||
You will need to make sure that you have both contracts aware of each other's presence.
|
||||
In this example::
|
||||
|
||||
contract B {}
|
||||
|
||||
|
||||
contract A {
|
||||
address child;
|
||||
|
||||
|
@ -20,9 +20,11 @@ Storage
|
||||
|
||||
contract SimpleStorage {
|
||||
uint storedData;
|
||||
|
||||
function set(uint x) {
|
||||
storedData = x;
|
||||
}
|
||||
|
||||
function get() constant returns (uint retVal) {
|
||||
return storedData;
|
||||
}
|
||||
@ -88,10 +90,12 @@ registering with username and password - all you need is an Ethereum keypair.
|
||||
function Coin() {
|
||||
minter = msg.sender;
|
||||
}
|
||||
|
||||
function mint(address receiver, uint amount) {
|
||||
if (msg.sender != minter) return;
|
||||
balances[receiver] += amount;
|
||||
}
|
||||
|
||||
function send(address receiver, uint amount) {
|
||||
if (balances[msg.sender] < amount) return;
|
||||
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;
|
||||
return f(x);
|
||||
}
|
||||
|
||||
function a(uint x) returns (uint z) {
|
||||
return x * x;
|
||||
}
|
||||
|
||||
function b(uint x) returns (uint z) {
|
||||
return 2 * x;
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ activate themselves.
|
||||
}
|
||||
|
||||
Blind Auction
|
||||
================
|
||||
=============
|
||||
|
||||
The previous open auction is extended to a blind auction
|
||||
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 }
|
||||
ActionChoices choice;
|
||||
ActionChoices constant defaultChoice = ActionChoices.GoStraight;
|
||||
function setGoStraight()
|
||||
{
|
||||
|
||||
function setGoStraight() {
|
||||
choice = ActionChoices.GoStraight;
|
||||
}
|
||||
|
||||
// Since enum types are not part of the ABI, the signature of "getChoice"
|
||||
// will automatically be changed to "getChoice() returns (uint8)"
|
||||
// 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,
|
||||
// `uint16` will be used and so on.
|
||||
function getChoice() returns (ActionChoices)
|
||||
{
|
||||
function getChoice() returns (ActionChoices) {
|
||||
return choice;
|
||||
}
|
||||
function getDefaultChoice() returns (uint)
|
||||
{
|
||||
|
||||
function getDefaultChoice() returns (uint) {
|
||||
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
|
||||
|
||||
// the data location of memoryArray is memory
|
||||
function f(uint[] memoryArray) {
|
||||
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
|
||||
h(x); // calls h and creates an independent, temporary copy in memory
|
||||
}
|
||||
|
||||
function g(uint[] storage storageArray) internal {}
|
||||
function h(uint[] memoryArray) {}
|
||||
}
|
||||
@ -343,19 +345,23 @@ Members
|
||||
// Note that the following is not a pair of arrays but an array of pairs.
|
||||
bool[2][] m_pairsOfFlags;
|
||||
// newPairs is stored in memory - the default for function arguments
|
||||
|
||||
function setAllFlagPairs(bool[2][] newPairs) {
|
||||
// assignment to a storage array replaces the complete array
|
||||
m_pairsOfFlags = newPairs;
|
||||
}
|
||||
|
||||
function setFlagPair(uint index, bool flagA, bool flagB) {
|
||||
// access to a non-existing index will throw an exception
|
||||
m_pairsOfFlags[index][0] = flagA;
|
||||
m_pairsOfFlags[index][1] = flagB;
|
||||
}
|
||||
|
||||
function changeFlagArraySize(uint newSize) {
|
||||
// if the new size is smaller, removed array elements will be cleared
|
||||
m_pairsOfFlags.length = newSize;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
// these clear the arrays completely
|
||||
delete m_pairsOfFlags;
|
||||
@ -363,7 +369,9 @@ Members
|
||||
// identical effect here
|
||||
m_pairsOfFlags.length = 0;
|
||||
}
|
||||
|
||||
bytes m_byteData;
|
||||
|
||||
function byteArrays(bytes data) {
|
||||
// byte arrays ("bytes") are different as they are stored without padding,
|
||||
// but can be treated identical to "uint8[]"
|
||||
@ -372,9 +380,11 @@ Members
|
||||
m_byteData[3] = 8;
|
||||
delete m_byteData[2];
|
||||
}
|
||||
|
||||
function addFlag(bool[2] flag) returns (uint) {
|
||||
return m_pairsOfFlags.push(flag);
|
||||
}
|
||||
|
||||
function createMemoryArray(uint size) returns (bytes) {
|
||||
// Dynamic memory arrays are created using `new`:
|
||||
uint[2][] memory arrayOfPairs = new uint[2][](size);
|
||||
@ -405,6 +415,7 @@ shown in the following example:
|
||||
address addr;
|
||||
uint amount;
|
||||
}
|
||||
|
||||
struct Campaign {
|
||||
address beneficiary;
|
||||
uint fundingGoal;
|
||||
@ -412,13 +423,16 @@ shown in the following example:
|
||||
uint amount;
|
||||
mapping (uint => Funder) funders;
|
||||
}
|
||||
|
||||
uint numCampaigns;
|
||||
mapping (uint => Campaign) campaigns;
|
||||
|
||||
function newCampaign(address beneficiary, uint goal) returns (uint campaignID) {
|
||||
campaignID = numCampaigns++; // campaignID is return variable
|
||||
// Creates new struct and saves in storage. We leave out the mapping type.
|
||||
campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
|
||||
}
|
||||
|
||||
function contribute(uint campaignID) {
|
||||
Campaign c = campaigns[campaignID];
|
||||
// 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.amount += msg.value;
|
||||
}
|
||||
|
||||
function checkGoalReached(uint campaignID) returns (bool reached) {
|
||||
Campaign c = campaigns[campaignID];
|
||||
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 {
|
||||
uint data;
|
||||
uint[] dataArray;
|
||||
|
||||
function f() {
|
||||
uint x = data;
|
||||
delete x; // sets x to 0, does not affect data
|
||||
|
Loading…
Reference in New Issue
Block a user