From e16e37f5074ce359b852f3b2e4b80095d22952dc Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 2 Jul 2018 16:25:54 +0200 Subject: Updates docs to new constructor syntax. --- docs/abi-spec.rst | 6 +++--- docs/common-patterns.rst | 8 ++++---- docs/contracts.rst | 28 ++++++---------------------- docs/control-structures.rst | 4 ++-- docs/frequently-asked-questions.rst | 4 ++-- docs/introduction-to-smart-contracts.rst | 4 ++-- docs/security-considerations.rst | 8 ++++---- 7 files changed, 23 insertions(+), 39 deletions(-) diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst index e4f8ed4f..146d50e5 100644 --- a/docs/abi-spec.rst +++ b/docs/abi-spec.rst @@ -437,10 +437,10 @@ For example, :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.24; contract Test { - function Test() public { b = 0x12345678901234567890123456789012; } + constructor() public { b = 0x12345678901234567890123456789012; } event Event(uint indexed a, bytes32 b); event Event2(uint indexed a, bytes32 b); function foo(uint a) public { emit Event(a, b); } @@ -582,4 +582,4 @@ Note that constants will be packed using the minimum number of bytes required to This means that, for example, ``abi.encodePacked(0) == abi.encodePacked(uint8(0)) == hex"00"`` and ``abi.encodePacked(0x12345678) == abi.encodePacked(uint32(0x12345678)) == hex"12345678"``. -If padding is needed, explicit type conversions can be used: ``abi.encodePacked(uint16(0x12)) == hex"0012"``. \ No newline at end of file +If padding is needed, explicit type conversions can be used: ``abi.encodePacked(uint16(0x12)) == hex"0012"``. diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index 739e136f..e61e8667 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -28,7 +28,7 @@ become the new richest. :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.24; contract WithdrawalContract { address public richest; @@ -36,7 +36,7 @@ become the new richest. mapping (address => uint) pendingWithdrawals; - function WithdrawalContract() public payable { + constructor() public payable { richest = msg.sender; mostSent = msg.value; } @@ -65,13 +65,13 @@ This is as opposed to the more intuitive sending pattern: :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.24; contract SendContract { address public richest; uint public mostSent; - function SendContract() public payable { + constructor() public payable { richest = msg.sender; mostSent = msg.value; } diff --git a/docs/contracts.rst b/docs/contracts.rst index 845fd973..97684000 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -301,10 +301,10 @@ inheritable properties of contracts and may be overridden by derived contracts. :: - pragma solidity ^0.4.22; + pragma solidity ^0.4.24; contract owned { - function owned() public { owner = msg.sender; } + constructor() public { owner = msg.sender; } address owner; // This contract only defines a modifier but does not use @@ -346,7 +346,7 @@ inheritable properties of contracts and may be overridden by derived contracts. mapping (address => bool) registeredAddresses; uint price; - function Register(uint initialPrice) public { price = initialPrice; } + constructor(uint initialPrice) public { price = initialPrice; } // It is important to also provide the // `payable` keyword here, otherwise the function will @@ -1006,24 +1006,8 @@ default constructor: ``contructor() public {}``. A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract `. -.. note :: - Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax is now deprecated. - -:: - - pragma solidity ^0.4.11; - - contract A { - uint public a; - - function A(uint _a) internal { - a = _a; - } - } - - contract B is A(1) { - function B() public {} - } +.. warning :: + Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax was deprecated is not allowed anymore in version 0.5.0. .. index:: ! base;constructor @@ -1402,7 +1386,7 @@ Using For ********* The directive ``using A for B;`` can be used to attach library -functions (from the library ``A``) to any type (``B``). +functions (from the library ``A``) to any type (``B``). These functions will receive the object they are called on as their first parameter (like the ``self`` variable in Python). diff --git a/docs/control-structures.rst b/docs/control-structures.rst index cc1f7ca5..8e5d2af1 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -225,11 +225,11 @@ creation-dependencies are not possible. :: - pragma solidity ^0.4.0; + pragma solidity ^0.4.24; contract D { uint x; - function D(uint a) public payable { + constructor(uint a) public payable { x = a; } } diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index ca5a1aee..152af607 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -426,10 +426,10 @@ In the case of a ``contract A`` calling a new instance of ``contract B``, parent You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor. In this example:: - pragma solidity ^0.4.0; + pragma solidity ^0.4.24; contract B { - function B() public payable {} + constructor() public payable {} } contract A { diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 71f9bd8e..236b117f 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -80,7 +80,7 @@ registering with username and password — all you need is an Ethereum keypair. :: - pragma solidity ^0.4.21; + pragma solidity ^0.4.24; contract Coin { // The keyword "public" makes those variables @@ -94,7 +94,7 @@ registering with username and password — all you need is an Ethereum keypair. // This is the constructor whose code is // run only when the contract is created. - function Coin() public { + constructor() public { minter = msg.sender; } diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst index ec67773d..d7726f43 100644 --- a/docs/security-considerations.rst +++ b/docs/security-considerations.rst @@ -180,13 +180,13 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.24; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract TxUserWallet { address owner; - function TxUserWallet() public { + constructor() public { owner = msg.sender; } @@ -200,7 +200,7 @@ Now someone tricks you into sending ether to the address of this attack wallet: :: - pragma solidity ^0.4.11; + pragma solidity ^0.4.24; interface TxUserWallet { function transferTo(address dest, uint amount) public; @@ -209,7 +209,7 @@ Now someone tricks you into sending ether to the address of this attack wallet: contract TxAttackWallet { address owner; - function TxAttackWallet() public { + constructor() public { owner = msg.sender; } -- cgit v1.2.3 From 2031e8e0c15a6032c5c446edc2bfca5bd8cd8365 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 2 Jul 2018 16:46:54 +0200 Subject: Adds review suggestions. --- docs/abi-spec.rst | 2 +- docs/common-patterns.rst | 4 ++-- docs/contracts.rst | 4 ++-- docs/control-structures.rst | 2 +- docs/frequently-asked-questions.rst | 2 +- docs/introduction-to-smart-contracts.rst | 2 +- docs/security-considerations.rst | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/abi-spec.rst b/docs/abi-spec.rst index 146d50e5..366ca951 100644 --- a/docs/abi-spec.rst +++ b/docs/abi-spec.rst @@ -437,7 +437,7 @@ For example, :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract Test { constructor() public { b = 0x12345678901234567890123456789012; } diff --git a/docs/common-patterns.rst b/docs/common-patterns.rst index e61e8667..7c38b0e7 100644 --- a/docs/common-patterns.rst +++ b/docs/common-patterns.rst @@ -28,7 +28,7 @@ become the new richest. :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract WithdrawalContract { address public richest; @@ -65,7 +65,7 @@ This is as opposed to the more intuitive sending pattern: :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract SendContract { address public richest; diff --git a/docs/contracts.rst b/docs/contracts.rst index 97684000..00e38bc4 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -990,7 +990,7 @@ default constructor: ``contructor() public {}``. :: - pragma solidity ^0.4.22; + pragma solidity >0.4.24; contract A { uint public a; @@ -1007,7 +1007,7 @@ default constructor: ``contructor() public {}``. A constructor set as ``internal`` causes the contract to be marked as :ref:`abstract `. .. warning :: - Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax was deprecated is not allowed anymore in version 0.5.0. + Prior to version 0.4.22, constructors were defined as functions with the same name as the contract. This syntax was deprecated and is not allowed anymore in version 0.5.0. .. index:: ! base;constructor diff --git a/docs/control-structures.rst b/docs/control-structures.rst index 8e5d2af1..8ced0fbc 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -225,7 +225,7 @@ creation-dependencies are not possible. :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract D { uint x; diff --git a/docs/frequently-asked-questions.rst b/docs/frequently-asked-questions.rst index 152af607..bb00441c 100644 --- a/docs/frequently-asked-questions.rst +++ b/docs/frequently-asked-questions.rst @@ -426,7 +426,7 @@ In the case of a ``contract A`` calling a new instance of ``contract B``, parent You will need to make sure that you have both contracts aware of each other's presence and that ``contract B`` has a ``payable`` constructor. In this example:: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract B { constructor() public payable {} diff --git a/docs/introduction-to-smart-contracts.rst b/docs/introduction-to-smart-contracts.rst index 236b117f..e1b61d8b 100644 --- a/docs/introduction-to-smart-contracts.rst +++ b/docs/introduction-to-smart-contracts.rst @@ -80,7 +80,7 @@ registering with username and password — all you need is an Ethereum keypair. :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract Coin { // The keyword "public" makes those variables diff --git a/docs/security-considerations.rst b/docs/security-considerations.rst index d7726f43..c8d8c30b 100644 --- a/docs/security-considerations.rst +++ b/docs/security-considerations.rst @@ -180,7 +180,7 @@ Never use tx.origin for authorization. Let's say you have a wallet contract like :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; // THIS CONTRACT CONTAINS A BUG - DO NOT USE contract TxUserWallet { @@ -200,7 +200,7 @@ Now someone tricks you into sending ether to the address of this attack wallet: :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; interface TxUserWallet { function transferTo(address dest, uint amount) public; -- cgit v1.2.3 From f74a9a346b1e187567f93a6053a0eb7a7a964f99 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 2 Jul 2018 17:02:17 +0200 Subject: Fixes semantic versioning. --- docs/contracts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/contracts.rst b/docs/contracts.rst index 00e38bc4..86cdb3c4 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -301,7 +301,7 @@ inheritable properties of contracts and may be overridden by derived contracts. :: - pragma solidity ^0.4.24; + pragma solidity >0.4.24; contract owned { constructor() public { owner = msg.sender; } -- cgit v1.2.3