From 8bbe99ad1139b82df39207425d020aa8d8d51712 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 11 May 2016 15:30:31 -0400 Subject: More code-style corrections --- docs/contracts.rst | 26 +++++++++++++++++++++----- 1 file 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; } -- cgit