aboutsummaryrefslogtreecommitdiffstats
path: root/docs/contracts.rst
diff options
context:
space:
mode:
authorDenton Liu <liu.denton+github@gmail.com>2016-05-12 03:30:31 +0800
committerDenton Liu <liu.denton+github@gmail.com>2016-05-18 23:23:47 +0800
commit8bbe99ad1139b82df39207425d020aa8d8d51712 (patch)
tree374976b6a6457f7c825a431daad4c3c8a5b294f1 /docs/contracts.rst
parent0a37072e4c0b6413aa7aa37863230f3a0d26b2a9 (diff)
downloaddexon-solidity-8bbe99ad1139b82df39207425d020aa8d8d51712.tar.gz
dexon-solidity-8bbe99ad1139b82df39207425d020aa8d8d51712.tar.zst
dexon-solidity-8bbe99ad1139b82df39207425d020aa8d8d51712.zip
More code-style corrections
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r--docs/contracts.rst26
1 files changed, 21 insertions, 5 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst
index 42c716d5..a9d7e167 100644
--- a/docs/contracts.rst
+++ b/docs/contracts.rst
@@ -84,7 +84,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,8 +222,12 @@ The next example is a bit more complex:
::
contract complex {
- struct Data { uint a; bytes3 b; mapping(uint => uint) map; }
- mapping(uint => mapping(bool => Data[])) public data;
+ struct Data {
+ uint a;
+ bytes3 b;
+ mapping (uint => uint) map;
+ }
+ mapping (uint => mapping(bool => Data[])) public data;
}
It will generate a function of the following form::
@@ -260,7 +265,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 +286,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;
}