mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #7869 from fulldecent/fix-kill
Reduce usage of word kill
This commit is contained in:
commit
a2141d3be2
@ -39,7 +39,7 @@ if they are marked ``virtual``. For details, please see
|
||||
}
|
||||
}
|
||||
|
||||
contract mortal is owned {
|
||||
contract retrievable 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
|
||||
|
@ -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 Mortal is Owned {
|
||||
contract Temporary is Owned {
|
||||
// The keyword `virtual` means that the function can change
|
||||
// its behaviour in derived classes ("overriding").
|
||||
function kill() virtual public {
|
||||
function shutdown() 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 `mortal`, yet there is only a single
|
||||
// also a base class of `Temporary`, yet there is only a single
|
||||
// instance of `owned` (as for virtual inheritance in C++).
|
||||
contract Named is Owned, Mortal {
|
||||
contract Named is Owned, Temporary {
|
||||
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 kill() public virtual override {
|
||||
function shutdown() 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.
|
||||
Mortal.kill();
|
||||
Temporary.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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, Mortal, Named("GoldFeed") {
|
||||
contract PriceFeed is Owned, Temporary, 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 `kill` anymore.
|
||||
function kill() public override(Mortal, Named) { Named.kill(); }
|
||||
// cannot change the behaviour of `shutdown` anymore.
|
||||
function shutdown() public override(Temporary, Named) { Named.shutdown(); }
|
||||
function get() public view returns(uint r) { return info; }
|
||||
|
||||
uint info;
|
||||
}
|
||||
|
||||
Note that above, we call ``mortal.kill()`` to "forward" the
|
||||
Note that above, we call ``Temporary.shutdown()`` 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 mortal is owned {
|
||||
function kill() public virtual {
|
||||
contract Temporary is owned {
|
||||
function shutdown() public virtual {
|
||||
if (msg.sender == owner) selfdestruct(owner);
|
||||
}
|
||||
}
|
||||
|
||||
contract Base1 is mortal {
|
||||
function kill() public virtual override { /* do cleanup 1 */ mortal.kill(); }
|
||||
contract Base1 is Temporary {
|
||||
function shutdown() public virtual override { /* do cleanup 1 */ Temporary.shutdown(); }
|
||||
}
|
||||
|
||||
contract Base2 is mortal {
|
||||
function kill() public virtual override { /* do cleanup 2 */ mortal.kill(); }
|
||||
contract Base2 is Temporary {
|
||||
function shutdown() public virtual override { /* do cleanup 2 */ Temporary.shutdown(); }
|
||||
}
|
||||
|
||||
contract Final is Base1, Base2 {
|
||||
function kill() public override(Base1, Base2) { Base2.kill(); }
|
||||
function shutdown() public override(Base1, Base2) { Base2.shutdown(); }
|
||||
}
|
||||
|
||||
A call to ``Final.kill()`` will call ``Base2.kill`` because we specify it
|
||||
A call to ``Final.shutdown()`` will call ``Base2.shutdown`` because we specify it
|
||||
explicitly in the final override, but this function will bypass
|
||||
``Base1.kill``. The way around this is to use ``super``::
|
||||
``Base1.shutdown``. 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 mortal is owned {
|
||||
function kill() virtual public {
|
||||
contract Temporary is owned {
|
||||
function shutdown() virtual public {
|
||||
if (msg.sender == owner) selfdestruct(owner);
|
||||
}
|
||||
}
|
||||
|
||||
contract Base1 is mortal {
|
||||
function kill() public virtual override { /* do cleanup 1 */ super.kill(); }
|
||||
contract Base1 is Temporary {
|
||||
function shutdown() public virtual override { /* do cleanup 1 */ super.shutdown(); }
|
||||
}
|
||||
|
||||
|
||||
contract Base2 is mortal {
|
||||
function kill() public virtual override { /* do cleanup 2 */ super.kill(); }
|
||||
contract Base2 is Temporary {
|
||||
function shutdown() public virtual override { /* do cleanup 2 */ super.shutdown(); }
|
||||
}
|
||||
|
||||
contract Final is Base1, Base2 {
|
||||
function kill() public override(Base1, Base2) { super.kill(); }
|
||||
function shutdown() public override(Base1, Base2) { super.shutdown(); }
|
||||
}
|
||||
|
||||
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.kill()`` (note that
|
||||
inheritance graph, so it will call ``Base1.shutdown()`` (note that
|
||||
the final inheritance sequence is -- starting with the most
|
||||
derived contract: Final, Base2, Base1, mortal, owned).
|
||||
derived contract: Final, Base2, Base1, Temporary, 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
|
||||
|
@ -164,7 +164,7 @@ The full contract
|
||||
}
|
||||
|
||||
/// destroy the contract and reclaim the leftover funds.
|
||||
function kill() public {
|
||||
function shutdown() public {
|
||||
require(msg.sender == owner);
|
||||
selfdestruct(msg.sender);
|
||||
}
|
||||
|
@ -56,11 +56,11 @@ explanatory purposes.
|
||||
// Swarm URL is recommended
|
||||
"urls": [ "bzzr://56ab..." ]
|
||||
},
|
||||
"mortal": {
|
||||
"retrievable": {
|
||||
// Required: keccak256 hash of the source file
|
||||
"keccak256": "0x234...",
|
||||
// Required (unless "url" is used): literal contents of the source file
|
||||
"content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }"
|
||||
"content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }"
|
||||
}
|
||||
},
|
||||
// Required: Compiler settings
|
||||
|
@ -584,7 +584,7 @@ Yes::
|
||||
return balanceOf[from];
|
||||
}
|
||||
|
||||
function kill() public onlyowner {
|
||||
function shutdown() public onlyowner {
|
||||
selfdestruct(owner);
|
||||
}
|
||||
|
||||
@ -594,7 +594,7 @@ No::
|
||||
return balanceOf[from];
|
||||
}
|
||||
|
||||
function kill() onlyowner public {
|
||||
function shutdown() onlyowner public {
|
||||
selfdestruct(owner);
|
||||
}
|
||||
|
||||
|
@ -180,12 +180,12 @@ Input Description
|
||||
// `--allow-paths <path>`.
|
||||
]
|
||||
},
|
||||
"mortal":
|
||||
"retrievable":
|
||||
{
|
||||
// Optional: keccak256 hash of the source file
|
||||
"keccak256": "0x234...",
|
||||
// Required (unless "urls" is used): literal contents of the source file
|
||||
"content": "contract mortal is owned { function kill() { if (msg.sender == owner) selfdestruct(owner); } }"
|
||||
"content": "contract retrievable is owned { function shutdown() { if (msg.sender == owner) selfdestruct(owner); } }"
|
||||
}
|
||||
},
|
||||
// Optional
|
||||
|
@ -378,7 +378,7 @@ contract Wallet is multisig, multiowned, daylimit {
|
||||
multiowned.changeOwner(_from, _to);
|
||||
}
|
||||
// destroys the contract sending everything to `_to`.
|
||||
function kill(address payable _to) onlymanyowners(keccak256(msg.data)) external {
|
||||
function shutdown(address payable _to) onlymanyowners(keccak256(msg.data)) external {
|
||||
selfdestruct(_to);
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
".delegatecall("
|
||||
".gas("
|
||||
".kill("
|
||||
".shutdown("
|
||||
".length"
|
||||
".pop();"
|
||||
".push("
|
||||
|
Loading…
Reference in New Issue
Block a user