diff options
author | Daniel Kirchner <daniel@ekpyron.org> | 2018-09-13 23:30:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-13 23:30:54 +0800 |
commit | e7daed68c1977683546ac3e72d4f84ff538f6711 (patch) | |
tree | bb2595e6cc12d420c22bc0373bcb5a7f81c3b0bb /docs/contracts.rst | |
parent | 5aa5fa78f32c89fcf8f635db026d18a6ba8ef132 (diff) | |
parent | ae35a58124852eda9a5e6bf67f9976198d2f9c0f (diff) | |
download | dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar.gz dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar.bz2 dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar.lz dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar.xz dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.tar.zst dexon-solidity-e7daed68c1977683546ac3e72d4f84ff538f6711.zip |
Merge pull request #4911 from ethereum/addressPayable
Payable and non-payable address type.
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 { |