|
| 1 | +// Copyright (C) 2015-2024 The Neo Project. |
| 2 | +// |
| 3 | +// ContractBasicMethod.cs file belongs to the neo project and is free |
| 4 | +// software distributed under the MIT software license, see the |
| 5 | +// accompanying file LICENSE in the main directory of the |
| 6 | +// repository or http://www.opensource.org/licenses/mit-license.php |
| 7 | +// for more details. |
| 8 | +// |
| 9 | +// Redistribution and use in source and binary forms with or without |
| 10 | +// modifications are permitted. |
| 11 | + |
| 12 | +namespace Neo.SmartContract |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// This class provides a guideline for basic methods used in the Neo blockchain, offering |
| 16 | + /// a generalized interaction mechanism for smart contract deployment, verification, updates, and destruction. |
| 17 | + /// </summary> |
| 18 | + public record ContractBasicMethod |
| 19 | + { |
| 20 | + /// <summary> |
| 21 | + /// The verification method. This must be called when withdrawing tokens from the contract. |
| 22 | + /// If the contract address is included in the transaction signature, this method verifies the signature. |
| 23 | + /// Example: |
| 24 | + /// <code> |
| 25 | + /// public static bool Verify() => Runtime.CheckWitness(Owner); |
| 26 | + /// </code> |
| 27 | + /// <code> |
| 28 | + /// { |
| 29 | + /// "name": "verify", |
| 30 | + /// "safe": false, |
| 31 | + /// "parameters": [], |
| 32 | + /// "returntype": "bool" |
| 33 | + /// } |
| 34 | + /// </code> |
| 35 | + /// </summary> |
| 36 | + public static string Verify { get; } = "verify"; |
| 37 | + |
| 38 | + /// <summary> |
| 39 | + /// The initialization method. Compiled into the <see cref="Manifest"/> file if any function uses the initialize statement. |
| 40 | + /// These functions are executed first when loading the contract. |
| 41 | + /// Example: |
| 42 | + /// <code> |
| 43 | + /// private static readonly UInt160 owner = "NdUL5oDPD159KeFpD5A9zw5xNF1xLX6nLT"; |
| 44 | + /// </code> |
| 45 | + /// </summary> |
| 46 | + public static string Initialize { get; } = "_initialize"; |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// The deployment method. Automatically executed by the ContractManagement contract when a contract is first deployed or updated. |
| 50 | + /// <code> |
| 51 | + /// { |
| 52 | + /// "name": "_deploy", |
| 53 | + /// "safe": false, |
| 54 | + /// "parameters": [ |
| 55 | + /// { |
| 56 | + /// "name": "data", |
| 57 | + /// "type": "Any" |
| 58 | + /// }, |
| 59 | + /// { |
| 60 | + /// "name": "update", |
| 61 | + /// "type": "Boolean" |
| 62 | + /// } |
| 63 | + /// ], |
| 64 | + /// "returntype": "Void" |
| 65 | + /// } |
| 66 | + /// </code> |
| 67 | + /// </summary> |
| 68 | + public static string Deploy { get; } = "_deploy"; |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// The update method. Requires <see cref="NefFile"/> or <see cref="Manifest"/>, or both, and is passed to _deploy. |
| 72 | + /// Should verify the signer's address using SYSCALL <code>Neo.Runtime.CheckWitness</code>. |
| 73 | + /// <code> |
| 74 | + /// { |
| 75 | + /// "name": "update", |
| 76 | + /// "safe": false, |
| 77 | + /// "parameters": [ |
| 78 | + /// { |
| 79 | + /// "name": "nefFile", |
| 80 | + /// "type": "ByteArray" |
| 81 | + /// }, |
| 82 | + /// { |
| 83 | + /// "name": "manifest", |
| 84 | + /// "type": "ByteArray" |
| 85 | + /// }, |
| 86 | + /// { |
| 87 | + /// "name": "data", |
| 88 | + /// "type": "Any" |
| 89 | + /// } |
| 90 | + /// ], |
| 91 | + /// "returntype": "Void" |
| 92 | + /// } |
| 93 | + /// </code> |
| 94 | + /// </summary> |
| 95 | + public static string Update { get; } = "update"; |
| 96 | + |
| 97 | + /// <summary> |
| 98 | + /// The destruction method. Deletes all the storage of the contract. |
| 99 | + /// Should verify the signer's address using SYSCALL <code>Neo.Runtime.CheckWitness</code>. |
| 100 | + /// Any tokens in the contract must be transferred before destruction. |
| 101 | + /// <code> |
| 102 | + /// { |
| 103 | + /// "name": "destroy", |
| 104 | + /// "safe": false, |
| 105 | + /// "parameters": [], |
| 106 | + /// "returntype": "Void" |
| 107 | + /// } |
| 108 | + /// </code> |
| 109 | + /// </summary> |
| 110 | + public static string Destroy { get; } = "destroy"; |
| 111 | + |
| 112 | + /// <summary> |
| 113 | + /// Parameter counts for the methods. |
| 114 | + /// -1 represents the method can take arbitrary parameters. |
| 115 | + /// </summary> |
| 116 | + public static int VerifyPCount { get; } = -1; |
| 117 | + public static int InitializePCount { get; } = 0; |
| 118 | + public static int DeployPCount { get; } = 2; |
| 119 | + public static int UpdatePCount { get; } = 3; |
| 120 | + public static int DestroyPCount { get; } = 0; |
| 121 | + } |
| 122 | +} |
0 commit comments