Skip to content

Commit

Permalink
Merge pull request #123 from chenzhitong/SupportedStandards
Browse files Browse the repository at this point in the history
SupportedStandards
  • Loading branch information
Celia18305 authored Jul 1, 2024
2 parents 8316833 + b26b84a commit c566c2c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
16 changes: 8 additions & 8 deletions docs/n3/develop/write/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ namespace Helloworld
public class Contract1 : SmartContract
{
//TODO: Replace it with your own address.
[InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)]
static readonly UInt160 Owner = default;
static readonly UInt160 Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB";

private static bool IsOwner() => Runtime.CheckWitness(Owner);

Expand Down Expand Up @@ -69,8 +68,7 @@ Inside the contract class, the property defined with `static readonly` or `const

```cs
// Represents onwner of this contract, which is a fixed address. Usually should be the contract creator
[InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)]
static readonly UInt160 Owner = default;
static readonly UInt160 Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB";

// A constant number
private const ulong factor = 100000000;
Expand Down Expand Up @@ -196,8 +194,8 @@ You can declare more features:
[ContractSourceCode("https://github.com/neo-project/neo-devpack-dotnet/tree/master/examples/")]
[ContractVersion("0.0.1")]
[DisplayName("SampleNep17Token")]
[SupportedStandards("NEP-17")]
[ContractPermission("*", "onNEP17Payment")]
[SupportedStandards(NepStandard.Nep17)]
[ContractPermission(Permission.Any, "onNEP17Payment")]
[ContractTrust("0x0a0b00ff00ff00ff00ff00ff00ff00ff00ff00a4")]
[ManifestExtra("WebSite", "https://neo.org")]
public class Contract1 : SmartContract
Expand All @@ -210,7 +208,7 @@ public class Contract1 : SmartContract
```

- `DisplayName`: The name of the nef and manifest.json files generated by the compiler, and the DisplayName is also written to the name field of manifest.json.
- `SupportedStandards`: The NEP standards the contract conform to, such as NEP-17, a token standard on Neo.
- `SupportedStandards`: The NEP standards the contract conform to, such as `NepStandard.Nep17`, a token standard on Neo.
- `ContractPermission` : The permission requested by the contract, and `ContractTrust` indicates which contracts trust the contract to call itself. See [invocation-permission](../deploy/invoke.md#invocation-permission).
- `ContractAuthor`: The author field, which can be filled with the author's name and email address. It will output to the extra json object in manifest.json.
- `ContractEmail`: The email field. It will be output to the extra json object in manifest.json.
Expand All @@ -224,7 +222,9 @@ The generated manifest is as follows:
```json
{
"name": "SampleNep17Token",
"supportedstandards": [],
"supportedstandards": [
"NEP-17"
],
"abi": {
},
"permissions": [
Expand Down
7 changes: 3 additions & 4 deletions docs/n3/develop/write/difference.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ using System;

| | Neo Legacy | Neo N3 |
| ----------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| Contract info | You need to fill in contract information such as the name, author, email, etc. when deploying the contract. | Add the contract features to the contract file, written as [C# Features](https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/attributes/), for example:<br/>[ManifestExtra("Author", "Neo")]<br/>[ManifestExtra("Email", "[email protected]")]<br/>[ContractTrust("\*")]<br/>[ContractPermission("\*", "\*")]<br/>[SupportedStandards("NEP-17")]<br/>[ManifestExtra("Description", "This is a contract example")]<br/>public class Contract1 : SmartContract |
| Contract info | You need to fill in contract information such as the name, author, email, etc. when deploying the contract. | Add the contract features to the contract file, written as [C# Features](https://docs.microsoft.com/zh-cn/dotnet/csharp/programming-guide/concepts/attributes/), for example:<br/>[ContractAuthor("core-dev", "[email protected]")]<br/>[ContractEmail("[email protected]")]<br/>[ContractDescription("A sample NEP-17 token")]<br/>[ContractPermission(Permission.Any, Method.Any)]<br/>[ContractTrust(Permission.Any)]<br/>[SupportedStandards(NepStandard.Nep17)]<br/>public class Contract1 : SmartContract |
| Contract function | When deploying a contract, you need to declare contract features such as whether to use storage, whether it can be called dynamically, and whether to accept NEP-5 assets. | All contracts can use the storage and dynamic calls by default. You can implement the OnNEP17Payment method to accept NEP-17 assets and implement the OnNEP11Payment method to accept NEP-11 (NFT standard) assets. |
| Declare support for NEP | Code example:<br/>public static string[] SupportedStandards()<br/>{<br/> string[] result = { "NEP-5", "NEP-7", "NEP-10" };<br/> return result;<br/>} | Directly add the feature to the contract class name `[SupportedStandards("NEP-17")]` |
| Declare support for NEP | Code example:<br/>public static string[] SupportedStandards()<br/>{<br/> string[] result = { "NEP-11", "NEP-17", "NEP-24" };<br/> return result;<br/>} | Directly add the feature to the contract class name `[SupportedStandards(NepStandard.Nep17)]` |

### Declaration of static variables

Expand All @@ -72,8 +72,7 @@ private static readonly byte[] InitialOwnerScriptHash = "AJhZmdHxW44FWMiMxD5bTiF
Neo N3

```cs
[InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)]
static readonly UInt160 Owner = default;
static readonly UInt160 Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB";
```

### Methods and Events
Expand Down
7 changes: 3 additions & 4 deletions docs/n3/develop/write/nep11.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ using System;

namespace Contract1
{
[SupportedStandards("NEP-11")]
[SupportedStandards(NepStandard.Nep11)]
public class Contract1 : Nep11Token<MyTokenState>
{
//TODO: Replace it with your own address.
[InitialValue("NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB", ContractParameterType.Hash160)]
static readonly UInt160 Owner = default;
static readonly UInt160 Owner = "NiNmXL8FjEUEs1nfX9uHFBNaenxDHJtmuB";

private static bool IsOwner() => Runtime.CheckWitness(Owner);

Expand Down Expand Up @@ -155,7 +154,7 @@ The base class `Nep11Token` also provides the following methods and events:

### Compatibility check

Compatibility checks will be activated for any contract that includes the `[SupportedStandards("NEP-17")]` or `[SupportedStandards("NEP-11")]` attribute.
Compatibility checks will be activated for any contract that includes the `[SupportedStandards(NepStandard.Nep17)]` or `[SupportedStandards(NepStandard.Nep11)]` attribute.
The Compatibility Check reviews method names, parameters, return values, events, and similar elements to ensure they comply with the standard, and alerts about any failures in the check.

### NFT Royalty Standard
Expand Down
4 changes: 2 additions & 2 deletions docs/n3/develop/write/nep17.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ The name method is moved to the manifest file, and you need to add `[DisplayName
[ContractAuthor("core-dev", "[email protected]")]
[ContractEmail("[email protected]")]
[ContractDescription("This is a NEP17 example")]
[SupportedStandards("NEP-17")]
[SupportedStandards(NepStandard.Nep17)]
public class NEP17 : Nep17Token
{
public override string Symbol { [Safe] get => "EXAMPLE"; }
Expand All @@ -309,6 +309,6 @@ The ability of the contract to receive assets has been changed from a fixed cons

### Compatibility check

Compatibility checks will be activated for any contract that includes the `[SupportedStandards("NEP-17")]` or `[SupportedStandards("NEP-11")]` attribute.
Compatibility checks will be activated for any contract that includes the `[SupportedStandards(NepStandard.Nep17)]`, `[SupportedStandards(NepStandard.Nep11)]` or `[SupportedStandards(NepStandard.Nep24)]` attribute.
The Compatibility Check reviews method names, parameters, return values, events, and similar elements to ensure they comply with the standard, and alerts about any failures in the check.

0 comments on commit c566c2c

Please sign in to comment.