Skip to content

Commit 005a759

Browse files
superboyiiiixjeshargonAnnaShalevaJimmy
authored
Destroy standard (#182)
New NEP for "destroy" contract method. --------- Co-authored-by: ixje <[email protected]> Co-authored-by: Shargon <[email protected]> Co-authored-by: Anna Shaleva <[email protected]> Co-authored-by: Jimmy <[email protected]> Co-authored-by: Christopher Schuchardt <[email protected]> Co-authored-by: Roman Khimov <[email protected]>
1 parent b8966af commit 005a759

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

nep-X1.mediawiki

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<pre>
2+
NEP: 31
3+
Title: Contract Destroy Guideline
4+
Author: Owen Zhang <[email protected]>
5+
Type: Standard
6+
Status: Draft
7+
Created: 2024-09-11
8+
</pre>
9+
10+
==Abstract==
11+
12+
This proposal standardizes the <code>destroy</code> function which is necessary for contract storage deletion and contract disposal from the system.
13+
14+
==Motivation==
15+
16+
Contracts that are not relevant anymore may need to be destroyed. Neo N3 has provided contract destroy mechanism but it hasn't been summarized in a standard. This standard will show details.
17+
18+
==Specification==
19+
20+
Neo N3 has the native <code>ContractManagement</code> contract that is responsible for contract destruction via its <code>destroy</code> method. When <code>destroy</code> is executed, it will delete all storage entries of calling contract. It will block the calling contract address using the native <code>Policy</code> contract to prevent redeployment or calling any methods on the contract from that point forward. Contracts that want to be destroyable SHOULD implement the <code>destroy</code> method as described below.
21+
22+
===Methods===
23+
24+
====destroy====
25+
26+
<pre>
27+
{
28+
"name": "destroy",
29+
"safe": false,
30+
"parameters": [],
31+
"returntype": "Void"
32+
}
33+
</pre>
34+
This method MUST invoke the <code>destroy</code> method of <code>ContractManagement</code> contract when the contract is destroyed.
35+
36+
<code>destroy</code> method MUST be parameterless for conformity. It SHOULD purely execute relevant code for contract destruction (but MAY perform other actions relevant for contract destruction).
37+
38+
<code>destroy</code> method SHOULD use the <code>SYSCALL</code> <code>System.Runtime.CheckWitness</code> to verify the <code>owner</code>. Otherwise anyone will be able to destroy your contract.
39+
40+
Contract MUST execute all codes before calling <code>destroy</code> method of <code>ContractManagement</code> to ensure they can be executed correctly. Especially contracts holding assets, they SHOULD transfer tokens before calling <code>destroy</code> or else the assets will be lost.
41+
42+
===Events===
43+
44+
====Destroy====
45+
46+
<pre>
47+
{
48+
"name": "Destroy",
49+
"parameters": [
50+
{
51+
"name": "contract",
52+
"type": "Hash160"
53+
}
54+
]
55+
}
56+
</pre>
57+
58+
<code>Destroy</code> notification is emitted automatically by native <code>ContractManagement</code> contract after all contract storage items and the contract itself are removed. This event contains destroyed contract hash.
59+
60+
==References==
61+
62+
63+
==Implementation==
64+
65+
* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/003a50095efe88f63f518a0c989921be086409f3/examples/Example.SmartContract.NFT/Loot.Admin.cs#L79
66+
* Go: https://github.com/nspcc-dev/neo-go/blob/e1d5ac8557d7e087158e6a766d059913a56df79f/examples/nft-nd/nft.go#L261
67+

0 commit comments

Comments
 (0)