diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-05 23:59:55 +0800 |
---|---|---|
committer | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-13 21:15:49 +0800 |
commit | 12aaca16458861e9b622818d49a82c1a7026594e (patch) | |
tree | 7b51c4893c6646134618b6c20574317ec014f225 /docs/contracts.rst | |
parent | 9214c7c34f5e4501a50cb29de964bbf04131f9a3 (diff) | |
download | dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.gz dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.bz2 dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.lz dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.xz dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.tar.zst dexon-solidity-12aaca16458861e9b622818d49a82c1a7026594e.zip |
Add payable and non-payable state mutability to AddressType.
Diffstat (limited to 'docs/contracts.rst')
-rw-r--r-- | docs/contracts.rst | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/docs/contracts.rst b/docs/contracts.rst index 8fd1c89e..b9179b27 100644 --- a/docs/contracts.rst +++ b/docs/contracts.rst @@ -334,7 +334,7 @@ inheritable properties of contracts and may be overridden by derived contracts. contract owned { constructor() public { owner = msg.sender; } - address owner; + address payable owner; // This contract only defines a modifier but does not use // it: it will be used in derived contracts. @@ -650,9 +650,14 @@ Like any function, the fallback function can execute complex operations as long require(success); // results in test.x becoming == 1. + // address(test) will not allow to call ``send`` directly, since ``test`` has no payable + // fallback function. It has to be converted to the ``address payable`` type via an + // intermediate conversion to ``uint160`` to even allow calling ``send`` on it. + address payable testPayable = address(uint160(address(test))); + // If someone sends ether to that contract, // the transfer will fail, i.e. this returns false here. - return address(test).send(2 ether); + return testPayable.send(2 ether); } } @@ -891,7 +896,7 @@ Details are given in the following example. contract owned { constructor() public { owner = msg.sender; } - address owner; + address payable owner; } // Use `is` to derive from another contract. Derived @@ -963,7 +968,7 @@ seen in the following example:: contract owned { constructor() public { owner = msg.sender; } - address owner; + address payable owner; } contract mortal is owned { @@ -992,7 +997,7 @@ derived override, but this function will bypass contract owned { constructor() public { owner = msg.sender; } - address owner; + address payable owner; } contract mortal is owned { |