diff --git a/nep-X1.mediawiki b/nep-X1.mediawiki new file mode 100644 index 00000000..6f3b5a20 --- /dev/null +++ b/nep-X1.mediawiki @@ -0,0 +1,67 @@ +
+  NEP: 31
+  Title: Contract Destroy Guideline
+  Author: Owen Zhang 
+  Type: Standard
+  Status: Draft
+  Created: 2024-09-11
+
+ +==Abstract== + +This proposal standardizes the destroy function which is necessary for contract storage deletion and contract disposal from the system. + +==Motivation== + +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. + +==Specification== + +Neo N3 has the native ContractManagement contract that is responsible for contract destruction via its destroy method. When destroy is executed, it will delete all storage entries of calling contract. It will block the calling contract address using the native Policy contract to prevent redeployment or calling any methods on the contract from that point forward. Contracts that want to be destroyable SHOULD implement the destroy method as described below. + +===Methods=== + +====destroy==== + +
+{
+  "name": "destroy",
+  "safe": false,
+  "parameters": [],
+  "returntype": "Void"
+}
+
+This method MUST invoke the destroy method of ContractManagement contract when the contract is destroyed. + +destroy method MUST be parameterless for conformity. It SHOULD purely execute relevant code for contract destruction (but MAY perform other actions relevant for contract destruction). + +destroy method SHOULD use the SYSCALL System.Runtime.CheckWitness to verify the owner. Otherwise anyone will be able to destroy your contract. + +Contract MUST execute all codes before calling destroy method of ContractManagement to ensure they can be executed correctly. Especially contracts holding assets, they SHOULD transfer tokens before calling destroy or else the assets will be lost. + +===Events=== + +====Destroy==== + +
+{
+  "name": "Destroy",
+  "parameters": [
+    {
+      "name": "contract",
+      "type": "Hash160"
+    }
+  ]
+}
+
+ +Destroy notification is emitted automatically by native ContractManagement contract after all contract storage items and the contract itself are removed. This event contains destroyed contract hash. + +==References== + + +==Implementation== + +* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/003a50095efe88f63f518a0c989921be086409f3/examples/Example.SmartContract.NFT/Loot.Admin.cs#L79 +* Go: https://github.com/nspcc-dev/neo-go/blob/e1d5ac8557d7e087158e6a766d059913a56df79f/examples/nft-nd/nft.go#L261 +