Merge pull request #8111 from ethereum/docNameDestructible

Change naming to "destructible".
This commit is contained in:
chriseth 2020-01-08 10:01:41 +01:00 committed by GitHub
commit 8de05a4a9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 35 deletions

View File

@ -39,12 +39,12 @@ if they are marked ``virtual``. For details, please see
} }
} }
contract retrievable is owned { contract destructible is owned {
// This contract inherits the `onlyOwner` modifier from // This contract inherits the `onlyOwner` modifier from
// `owned` and applies it to the `close` function, which // `owned` and applies it to the `close` function, which
// causes that calls to `close` only have an effect if // causes that calls to `close` only have an effect if
// they are made by the stored owner. // they are made by the stored owner.
function close() public onlyOwner { function destroy() public onlyOwner {
selfdestruct(owner); selfdestruct(owner);
} }
} }
@ -58,7 +58,7 @@ if they are marked ``virtual``. For details, please see
} }
} }
contract Register is priced, owned { contract Register is priced, destructible {
mapping (address => bool) registeredAddresses; mapping (address => bool) registeredAddresses;
uint price; uint price;

View File

@ -51,10 +51,10 @@ Details are given in the following example.
// contracts can access all non-private members including // contracts can access all non-private members including
// internal functions and state variables. These cannot be // internal functions and state variables. These cannot be
// accessed externally via `this`, though. // accessed externally via `this`, though.
contract Temporary is Owned { contract Destructible is Owned {
// The keyword `virtual` means that the function can change // The keyword `virtual` means that the function can change
// its behaviour in derived classes ("overriding"). // its behaviour in derived classes ("overriding").
function shutdown() virtual public { function destroy() virtual public {
if (msg.sender == owner) selfdestruct(owner); if (msg.sender == owner) selfdestruct(owner);
} }
} }
@ -76,9 +76,9 @@ Details are given in the following example.
// Multiple inheritance is possible. Note that `owned` is // Multiple inheritance is possible. Note that `owned` is
// also a base class of `Temporary`, yet there is only a single // also a base class of `Destructible`, yet there is only a single
// instance of `owned` (as for virtual inheritance in C++). // instance of `owned` (as for virtual inheritance in C++).
contract Named is Owned, Temporary { contract Named is Owned, Destructible {
constructor(bytes32 name) public { constructor(bytes32 name) public {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
NameReg(config.lookup(1)).register(name); NameReg(config.lookup(1)).register(name);
@ -92,13 +92,13 @@ Details are given in the following example.
// If you want the function to override, you need to use the // If you want the function to override, you need to use the
// `override` keyword. You need to specify the `virtual` keyword again // `override` keyword. You need to specify the `virtual` keyword again
// if you want this function to be overridden again. // if you want this function to be overridden again.
function shutdown() public virtual override { function destroy() public virtual override {
if (msg.sender == owner) { if (msg.sender == owner) {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970); Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
NameReg(config.lookup(1)).unregister(); NameReg(config.lookup(1)).unregister();
// It is still possible to call a specific // It is still possible to call a specific
// overridden function. // overridden function.
Temporary.shutdown(); Destructible.destroy();
} }
} }
} }
@ -107,21 +107,21 @@ Details are given in the following example.
// If a constructor takes an argument, it needs to be // If a constructor takes an argument, it needs to be
// provided in the header (or modifier-invocation-style at // provided in the header (or modifier-invocation-style at
// the constructor of the derived contract (see below)). // the constructor of the derived contract (see below)).
contract PriceFeed is Owned, Temporary, Named("GoldFeed") { contract PriceFeed is Owned, Destructible, Named("GoldFeed") {
function updateInfo(uint newInfo) public { function updateInfo(uint newInfo) public {
if (msg.sender == owner) info = newInfo; if (msg.sender == owner) info = newInfo;
} }
// Here, we only specify `override` and not `virtual`. // Here, we only specify `override` and not `virtual`.
// This means that contracts deriving from `PriceFeed` // This means that contracts deriving from `PriceFeed`
// cannot change the behaviour of `shutdown` anymore. // cannot change the behaviour of `destroy` anymore.
function shutdown() public override(Temporary, Named) { Named.shutdown(); } function destroy() public override(Destructible, Named) { Named.destroy(); }
function get() public view returns(uint r) { return info; } function get() public view returns(uint r) { return info; }
uint info; uint info;
} }
Note that above, we call ``Temporary.shutdown()`` to "forward" the Note that above, we call ``Destructible.destroy()`` to "forward" the
destruction request. The way this is done is problematic, as destruction request. The way this is done is problematic, as
seen in the following example:: seen in the following example::
@ -132,27 +132,27 @@ seen in the following example::
address payable owner; address payable owner;
} }
contract Temporary is owned { contract Destructible is owned {
function shutdown() public virtual { function destroy() public virtual {
if (msg.sender == owner) selfdestruct(owner); if (msg.sender == owner) selfdestruct(owner);
} }
} }
contract Base1 is Temporary { contract Base1 is Destructible {
function shutdown() public virtual override { /* do cleanup 1 */ Temporary.shutdown(); } function destroy() public virtual override { /* do cleanup 1 */ Destructible.destroy(); }
} }
contract Base2 is Temporary { contract Base2 is Destructible {
function shutdown() public virtual override { /* do cleanup 2 */ Temporary.shutdown(); } function destroy() public virtual override { /* do cleanup 2 */ Destructible.destroy(); }
} }
contract Final is Base1, Base2 { contract Final is Base1, Base2 {
function shutdown() public override(Base1, Base2) { Base2.shutdown(); } function destroy() public override(Base1, Base2) { Base2.destroy(); }
} }
A call to ``Final.shutdown()`` will call ``Base2.shutdown`` because we specify it A call to ``Final.destroy()`` will call ``Base2.destroy`` because we specify it
explicitly in the final override, but this function will bypass explicitly in the final override, but this function will bypass
``Base1.shutdown``. The way around this is to use ``super``:: ``Base1.destroy``. The way around this is to use ``super``::
pragma solidity >=0.4.22 <0.7.0; pragma solidity >=0.4.22 <0.7.0;
@ -161,31 +161,31 @@ explicitly in the final override, but this function will bypass
address payable owner; address payable owner;
} }
contract Temporary is owned { contract Destructible is owned {
function shutdown() virtual public { function destroy() virtual public {
if (msg.sender == owner) selfdestruct(owner); if (msg.sender == owner) selfdestruct(owner);
} }
} }
contract Base1 is Temporary { contract Base1 is Destructible {
function shutdown() public virtual override { /* do cleanup 1 */ super.shutdown(); } function destroy() public virtual override { /* do cleanup 1 */ super.destroy(); }
} }
contract Base2 is Temporary { contract Base2 is Destructible {
function shutdown() public virtual override { /* do cleanup 2 */ super.shutdown(); } function destroy() public virtual override { /* do cleanup 2 */ super.destroy(); }
} }
contract Final is Base1, Base2 { contract Final is Base1, Base2 {
function shutdown() public override(Base1, Base2) { super.shutdown(); } function destroy() public override(Base1, Base2) { super.destroy(); }
} }
If ``Base2`` calls a function of ``super``, it does not simply If ``Base2`` calls a function of ``super``, it does not simply
call this function on one of its base contracts. Rather, it call this function on one of its base contracts. Rather, it
calls this function on the next base contract in the final calls this function on the next base contract in the final
inheritance graph, so it will call ``Base1.shutdown()`` (note that inheritance graph, so it will call ``Base1.destroy()`` (note that
the final inheritance sequence is -- starting with the most the final inheritance sequence is -- starting with the most
derived contract: Final, Base2, Base1, Temporary, owned). derived contract: Final, Base2, Base1, Destructible, owned).
The actual function that is called when using super is The actual function that is called when using super is
not known in the context of the class where it is used, not known in the context of the class where it is used,
although its type is known. This is similar for ordinary although its type is known. This is similar for ordinary

View File

@ -56,11 +56,11 @@ explanatory purposes.
// Swarm URL is recommended // Swarm URL is recommended
"urls": [ "bzzr://56ab..." ] "urls": [ "bzzr://56ab..." ]
}, },
"retrievable": { "destructible": {
// Required: keccak256 hash of the source file // Required: keccak256 hash of the source file
"keccak256": "0x234...", "keccak256": "0x234...",
// Required (unless "url" is used): literal contents of the source file // Required (unless "url" is used): literal contents of the source file
"content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }" "content": "contract destructible is owned { function destroy() { if (msg.sender == owner) selfdestruct(owner); } }"
} }
}, },
// Required: Compiler settings // Required: Compiler settings

View File

@ -180,12 +180,12 @@ Input Description
// `--allow-paths <path>`. // `--allow-paths <path>`.
] ]
}, },
"retrievable": "destructible":
{ {
// Optional: keccak256 hash of the source file // Optional: keccak256 hash of the source file
"keccak256": "0x234...", "keccak256": "0x234...",
// Required (unless "urls" is used): literal contents of the source file // Required (unless "urls" is used): literal contents of the source file
"content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }" "content": "contract destructible is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }"
} }
}, },
// Optional // Optional