Changed whitespace formatting

This commit is contained in:
Denton Liu 2016-05-18 11:05:28 -04:00
parent ff26ea6c08
commit 7c22a387f3
9 changed files with 219 additions and 186 deletions

View File

@ -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)

View File

@ -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}
);

View File

@ -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;
@ -212,7 +216,7 @@ In the following example, we show how `throw` can be used to easily revert an Et
contract Sharer {
function sendHalf(address addr) returns (uint balance) {
if (!addr.send(msg.value/2))
if (!addr.send(msg.value / 2))
throw; // also reverts the transfer to Sharer
return this.balance;
}
@ -290,6 +294,7 @@ 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.

View File

@ -692,11 +692,11 @@ What happens to a struct's mapping when copying over a struct?
This is a very interesting question. Suppose that we have a contract field set up like such::
struct user{
struct user {
mapping(string => address) usedContracts;
}
function somefunction{
function somefunction {
user user1;
user1.usedContracts["Hello"] = "World";
user user2 = user1;
@ -715,6 +715,8 @@ You will need to make sure that you have both contracts aware of each other's pr
In this example::
contract B {}
contract A {
address child;

View File

@ -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;
}

View File

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

View File

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