Skip to content

Commit 71d82c7

Browse files
authored
Add: comment doc for Framework.Services (#1460)
1 parent 2f665c7 commit 71d82c7

15 files changed

Lines changed: 558 additions & 6 deletions

src/Neo.SmartContract.Framework/Services/CallFlags.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,43 @@ namespace Neo.SmartContract.Framework.Services
1616
[Flags]
1717
public enum CallFlags : byte
1818
{
19+
/// <summary>
20+
/// No flag is set.
21+
/// </summary>
1922
None = 0,
2023

24+
/// <summary>
25+
/// Indicates that the contract can read the states.
26+
/// </summary>
2127
ReadStates = 0b00000001,
28+
29+
/// <summary>
30+
/// Indicates that the contract can write the states.
31+
/// </summary>
2232
WriteStates = 0b00000010,
33+
34+
/// <summary>
35+
/// Indicates that the contract can call other contracts.
36+
/// </summary>
2337
AllowCall = 0b00000100,
38+
/// <summary>
39+
/// Indicates that the contract can notify other contracts.
40+
/// </summary>
2441
AllowNotify = 0b00001000,
2542

43+
/// <summary>
44+
/// Indicates that the contract can read and write the states.
45+
/// </summary>
2646
States = ReadStates | WriteStates,
47+
48+
/// <summary>
49+
/// Indicates that the contract can read the states and call other contracts.
50+
/// </summary>
2751
ReadOnly = ReadStates | AllowCall,
52+
53+
/// <summary>
54+
/// Indicates that the contract can read and write the states and call other contracts and notify other contracts.
55+
/// </summary>
2856
All = States | AllowCall | AllowNotify
2957
}
3058
}

src/Neo.SmartContract.Framework/Services/Contract.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,68 @@ namespace Neo.SmartContract.Framework.Services
1717
public class Contract
1818
{
1919
/// <summary>
20-
/// Id
20+
/// Id. It generated by the system when the contract is deployed.
2121
/// </summary>
2222
public readonly int Id;
2323

2424
/// <summary>
25-
/// UpdateCounter
25+
/// UpdateCounter. It is used to track the number of updates to the contract.
2626
/// </summary>
2727
public readonly ushort UpdateCounter;
2828

2929
/// <summary>
30-
/// Hash
30+
/// Hash. It is the hash of the contract and generated when the first deployment.
3131
/// </summary>
3232
public readonly UInt160 Hash;
3333

3434
/// <summary>
35-
/// Nef
35+
/// Nef. It is the NEF file(i.e. the compiled contract) of the contract.
3636
/// </summary>
3737
public readonly ByteString Nef;
3838

3939
/// <summary>
40-
/// Manifest
40+
/// Manifest. It is the manifest of the contract.
4141
/// </summary>
4242
public readonly ContractManifest Manifest;
4343

44+
/// <summary>
45+
/// Calls the contract with the specified method, callflags and arguments.
46+
/// <para>
47+
/// The execution will fail if:
48+
/// 1. The 'scriptHash', or 'method' is null.
49+
/// 2. The 'flags' is not a valid <see cref="CallFlags"/>.
50+
/// 3. The contract or method does not exist.
51+
/// 4. The contract is blocked.
52+
/// 5. The arguments.Length is not equal to the parameter count of the method.
53+
/// 6. The method is not safe and the contract method is not allowed to be called by the current context.
54+
/// </para>
55+
/// </summary>
4456
[Syscall("System.Contract.Call")]
4557
public static extern object Call(UInt160 scriptHash, string method, CallFlags flags, params object?[]? args);
4658

59+
/// <summary>
60+
/// Gets the <see cref="CallFlags"/> of the current context.
61+
/// </summary>
4762
[Syscall("System.Contract.GetCallFlags")]
4863
public static extern CallFlags GetCallFlags();
4964

65+
/// <summary>
66+
/// Gets the corresponding account scripthash for the given public key.
67+
/// <para>
68+
/// The execution will fail if the pubkey is null.
69+
/// </para>
70+
/// </summary>
5071
[Syscall("System.Contract.CreateStandardAccount")]
5172
public static extern UInt160 CreateStandardAccount(ECPoint pubKey);
5273

74+
/// <summary>
75+
/// Gets the corresponding multisig account scripthash for the given public keys.
76+
/// <para>
77+
/// The execution will fail if:
78+
/// 1. The pubkeys is null.
79+
/// 2. The 'm' is less than 1 or greater than 1024 or m greater than pubkeys.Length.
80+
/// </para>
81+
/// </summary>
5382
[Syscall("System.Contract.CreateMultisigAccount")]
5483
public static extern UInt160 CreateMultisigAccount(int m, params ECPoint[] pubKey);
5584
}

src/Neo.SmartContract.Framework/Services/ContractAbi.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents the ABI of a contract. Includes methods and events definitions.
16+
/// </summary>
1417
public struct ContractAbi
1518
{
1619
public ContractMethodDescriptor[] Methods;

src/Neo.SmartContract.Framework/Services/ContractEventDescriptor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents an event in the ABI of a contract.
16+
/// </summary>
1417
public struct ContractEventDescriptor
1518
{
1619
public string Name;

src/Neo.SmartContract.Framework/Services/ContractGroup.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents a set of mutually trusted contracts.
16+
/// A contract will trust and allow any contract in the same group to invoke it,
17+
/// and the user interface will not give any warnings.
18+
/// A group is identified by a public key and must be accompanied by a signature
19+
/// for the contract hash to prove that the contract is indeed included in the group.
20+
/// </summary>
1421
public struct ContractGroup
1522
{
23+
/// <summary>
24+
/// The public key of the group.
25+
/// </summary>
1626
public ECPoint PubKey;
27+
28+
/// <summary>
29+
/// The signature of the contract hash which can be verified by the `PubKey`.
30+
/// </summary>
1731
public ByteString Signature;
1832
}
1933
}

src/Neo.SmartContract.Framework/Services/ContractManifest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents the manifest of a smart contract.
16+
/// When a smart contract is deployed, it must explicitly declare the features and permissions it will use.
17+
/// When it is running, it will be limited by its declared list of features and permissions, and cannot make any behavior beyond the scope of the list.
18+
/// </summary>
19+
/// <remarks>For more details, see NEP-15.</remarks>
1420
public struct ContractManifest
1521
{
1622
public string Name;

src/Neo.SmartContract.Framework/Services/ContractMethodDescriptor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents a method in the ABI of a contract.
16+
/// Including name, parameters, return type, the offset in the contract NEF file and it's safe or not.
17+
/// </summary>
1418
public struct ContractMethodDescriptor
1519
{
1620
public string Name;

src/Neo.SmartContract.Framework/Services/ContractParameterDefinition.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents a parameter of an event or method in ABI, including name and type.
16+
/// </summary>
1417
public struct ContractParameterDefinition
1518
{
1619
public string Name;

src/Neo.SmartContract.Framework/Services/ContractPermission.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,28 @@
1111

1212
namespace Neo.SmartContract.Framework.Services
1313
{
14+
/// <summary>
15+
/// Represents a permission of a contract. It describes which contracts may be
16+
/// invoked and which methods are called.
17+
/// If a contract invokes a contract or method that is not declared in the manifest
18+
/// at runtime, the invocation will fail.
19+
/// </summary>
1420
public struct ContractPermission
1521
{
22+
/// <summary>
23+
/// Indicates which contract to be invoked.
24+
/// It can be a hash of a contract, a public key of a group, or a wildcard *.
25+
/// If it specifies a hash of a contract, then the contract will be invoked;
26+
/// If it specifies a public key of a group, then any contract in this group
27+
/// may be invoked; If it specifies a wildcard *, then any contract may be invoked.
28+
/// </summary>
1629
public ByteString Contract;
30+
31+
/// <summary>
32+
/// Indicates which methods to be called.
33+
/// It can also be assigned with a wildcard *. If it is a wildcard *,
34+
/// then it means that any method can be called.
35+
/// </summary>
1736
public string[] Methods;
1837
}
1938
}

src/Neo.SmartContract.Framework/Services/Crypto.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,27 @@ namespace Neo.SmartContract.Framework.Services
1515
{
1616
public static class Crypto
1717
{
18+
/// <summary>
19+
/// Checks the signature for the current script container(for example: a transaction).
20+
/// True if the signature is valid, otherwise false.
21+
/// <para>
22+
/// The execution will fail if the format of pubkey is invalid.
23+
/// </para>
24+
/// </summary>
1825
[Syscall("System.Crypto.CheckSig")]
1926
public extern static bool CheckSig(ECPoint pubkey, ByteString signature);
2027

28+
/// <summary>
29+
/// Checks the signatures for the current script container(for example: a transaction).
30+
/// True if the signatures are valid, otherwise false.
31+
/// <para>
32+
/// The execution will fail if:
33+
/// 1. the pubkeys or signatures is null orempty;
34+
/// 2. If signatures.Length > pubkeys.Length.
35+
/// 3. The format of any pubkey is invalid.
36+
/// </para>
37+
/// </summary>
2138
[Syscall("System.Crypto.CheckMultisig")]
22-
public extern static bool CheckMultisig(ECPoint[] pubkey, ByteString[] signature);
39+
public extern static bool CheckMultisig(ECPoint[] pubkeys, ByteString[] signatures);
2340
}
2441
}

0 commit comments

Comments
 (0)