Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy standard #182

Merged
merged 23 commits into from
Jan 11, 2025
Merged
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions nep-X1.mediawiki
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<pre>
NEP: 31
Title: Contract Destroy Guideline
Author: Owen Zhang <[email protected]>
Type: Standard
Status: Draft
Created: 2024-09-11
</pre>

==Abstract==

This proposal standardizes the destroy function which is necessary for contract storage deletion and contract disposal from the system.
shargon marked this conversation as resolved.
Show resolved Hide resolved

==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.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

==Specification==

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.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

===Methods===

====destroy====

<pre>
{
"name": "destroy",
"safe": false,
"parameters": [],
"returntype": "Void"
}
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
</pre>
This method MUST invoke the <code>destroy</code> method of <code>ContractManagement</code> contract when the contract is destroyed.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

<code>destroy</code> method can have multi parameters for any specific purpose since it's an operation only for contract owner.
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved

<code>destroy</code> method SHOULD do checkwitness for contract <code>owner</code> to avoid security risks. This function SHOULD use the SYSCALL <code>Neo.Runtime.CheckWitness</code> to verify the <code>signer</code>.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

Contract SHOULD execute all codes before calling ContractManagement.Destroy() to ensure they can be executed correctly.
superboyiii marked this conversation as resolved.
Show resolved Hide resolved

superboyiii marked this conversation as resolved.
Show resolved Hide resolved
===Events===

====Destroy====

<pre>
{
"name": "Destroy",
"parameters": [
{
"name": "contract",
"type": "Hash160"
}
]
}
</pre>

<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.

==References==


==Implementation==

* C#: https://github.com/neo-project/neo-devpack-dotnet/blob/003a50095efe88f63f518a0c989921be086409f3/examples/Example.SmartContract.NFT/Loot.Admin.cs#L79
superboyiii marked this conversation as resolved.
Show resolved Hide resolved
* Go: https://github.com/nspcc-dev/neo-go/blob/e1d5ac8557d7e087158e6a766d059913a56df79f/examples/nft-nd/nft.go#L261