Change naming to "destructible".

This commit is contained in:
chriseth 2020-01-08 09:17:59 +01:00
parent 70a2902714
commit 7772ee145c
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
// `owned` and applies it to the `close` function, which
// causes that calls to `close` only have an effect if
// they are made by the stored owner.
function close() public onlyOwner {
function destroy() public onlyOwner {
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;
uint price;

View File

@ -51,10 +51,10 @@ Details are given in the following example.
// contracts can access all non-private members including
// internal functions and state variables. These cannot be
// accessed externally via `this`, though.
contract Temporary is Owned {
contract Destructible is Owned {
// The keyword `virtual` means that the function can change
// its behaviour in derived classes ("overriding").
function shutdown() virtual public {
function destroy() virtual public {
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
// 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++).
contract Named is Owned, Temporary {
contract Named is Owned, Destructible {
constructor(bytes32 name) public {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
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
// `override` keyword. You need to specify the `virtual` keyword again
// if you want this function to be overridden again.
function shutdown() public virtual override {
function destroy() public virtual override {
if (msg.sender == owner) {
Config config = Config(0xD5f9D8D94886E70b06E474c3fB14Fd43E2f23970);
NameReg(config.lookup(1)).unregister();
// It is still possible to call a specific
// 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
// provided in the header (or modifier-invocation-style at
// 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 {
if (msg.sender == owner) info = newInfo;
}
// Here, we only specify `override` and not `virtual`.
// This means that contracts deriving from `PriceFeed`
// cannot change the behaviour of `shutdown` anymore.
function shutdown() public override(Temporary, Named) { Named.shutdown(); }
// cannot change the behaviour of `destroy` anymore.
function destroy() public override(Destructible, Named) { Named.destroy(); }
function get() public view returns(uint r) { return 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
seen in the following example::
@ -132,27 +132,27 @@ seen in the following example::
address payable owner;
}
contract Temporary is owned {
function shutdown() public virtual {
contract Destructible is owned {
function destroy() public virtual {
if (msg.sender == owner) selfdestruct(owner);
}
}
contract Base1 is Temporary {
function shutdown() public virtual override { /* do cleanup 1 */ Temporary.shutdown(); }
contract Base1 is Destructible {
function destroy() public virtual override { /* do cleanup 1 */ Destructible.destroy(); }
}
contract Base2 is Temporary {
function shutdown() public virtual override { /* do cleanup 2 */ Temporary.shutdown(); }
contract Base2 is Destructible {
function destroy() public virtual override { /* do cleanup 2 */ Destructible.destroy(); }
}
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
``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;
@ -161,31 +161,31 @@ explicitly in the final override, but this function will bypass
address payable owner;
}
contract Temporary is owned {
function shutdown() virtual public {
contract Destructible is owned {
function destroy() virtual public {
if (msg.sender == owner) selfdestruct(owner);
}
}
contract Base1 is Temporary {
function shutdown() public virtual override { /* do cleanup 1 */ super.shutdown(); }
contract Base1 is Destructible {
function destroy() public virtual override { /* do cleanup 1 */ super.destroy(); }
}
contract Base2 is Temporary {
function shutdown() public virtual override { /* do cleanup 2 */ super.shutdown(); }
contract Base2 is Destructible {
function destroy() public virtual override { /* do cleanup 2 */ super.destroy(); }
}
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
call this function on one of its base contracts. Rather, it
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
derived contract: Final, Base2, Base1, Temporary, owned).
derived contract: Final, Base2, Base1, Destructible, owned).
The actual function that is called when using super is
not known in the context of the class where it is used,
although its type is known. This is similar for ordinary

View File

@ -56,11 +56,11 @@ explanatory purposes.
// Swarm URL is recommended
"urls": [ "bzzr://56ab..." ]
},
"retrievable": {
"destructible": {
// Required: keccak256 hash of the source file
"keccak256": "0x234...",
// 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

View File

@ -180,12 +180,12 @@ Input Description
// `--allow-paths <path>`.
]
},
"retrievable":
"destructible":
{
// Optional: keccak256 hash of the source file
"keccak256": "0x234...",
// 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