forked from neo-project/neo-devpack-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntime.cs
More file actions
215 lines (192 loc) · 7.42 KB
/
Runtime.cs
File metadata and controls
215 lines (192 loc) · 7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
// Copyright (C) 2015-2026 The Neo Project.
//
// Runtime.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using System;
using System.Numerics;
namespace Neo.SmartContract.Framework.Services
{
public static class Runtime
{
/// <summary>
/// Gets the trigger of the execution. see <see cref="TriggerType"/> for more details.
/// </summary>
public static extern TriggerType Trigger
{
[Syscall("System.Runtime.GetTrigger")]
get;
}
/// <summary>
/// Gets the platform of the execution. Always returns "NEO" for now.
/// </summary>
public static extern string Platform
{
[Syscall("System.Runtime.Platform")]
get;
}
[Obsolete("Use System.Runtime.Transaction instead")]
public static extern object ScriptContainer
{
[Syscall("System.Runtime.GetScriptContainer")]
get;
}
/// <summary>
/// Gets the transaction of the execution.
/// </summary>
public static extern Transaction Transaction
{
[Syscall("System.Runtime.GetScriptContainer")]
get;
}
/// <summary>
/// Gets the script hash of the executing context.
/// </summary>
public static extern UInt160 ExecutingScriptHash
{
[Syscall("System.Runtime.GetExecutingScriptHash")]
get;
}
/// <summary>
/// The script hash of the calling contract.
/// It returns null if the current context is the entry context.
/// </summary>
public static extern UInt160 CallingScriptHash
{
[Syscall("System.Runtime.GetCallingScriptHash")]
get;
}
/// <summary>
/// The script hash of the entry context.
/// </summary>
public static extern UInt160 EntryScriptHash
{
[Syscall("System.Runtime.GetEntryScriptHash")]
get;
}
/// <summary>
/// Gets the unixtimestamp in milliseconds of the current block.
/// </summary>
public static extern ulong Time
{
[Syscall("System.Runtime.GetTime")]
get;
}
/// <summary>
/// Gets the number of times the current contract has been called during the execution.
/// </summary>
public static extern uint InvocationCounter
{
[Syscall("System.Runtime.GetInvocationCounter")]
get;
}
/// <summary>
/// The remaining GAS that can be spent in order to complete the execution.
/// In the unit of datoshi, 1 datoshi = 1e-8 GAS, 1 GAS = 1e8 datoshi
/// </summary>
public static extern long GasLeft
{
[Syscall("System.Runtime.GasLeft")]
get;
}
/// <summary>
/// Gets the address version of the current network.
/// </summary>
public static extern byte AddressVersion
{
[Syscall("System.Runtime.GetAddressVersion")]
get;
}
/// <summary>
/// This method gets current invocation notifications from specific 'scriptHash'
/// 'scriptHash' must have 20 bytes, but if it's all zero 0000...0000 it refers to all existing notifications (like a * wildcard)
/// It will return an array of all matched notifications
/// Each notification has two elements: a ScriptHash and the stackitem content of notification itself (called a 'State')
/// The stackitem 'State' can be of any kind (a number, a string, an array, ...), so it's up to the developer perform the expected cast here
/// </summary>
[Syscall("System.Runtime.GetNotifications")]
public static extern Notification[] GetNotifications(UInt160? hash = null);
/// <summary>
/// Determines whether the specified account has witnessed the current transaction.
/// <para>
/// The execution will fail if the hash is null.
/// </para>
/// </summary>
[Syscall("System.Runtime.CheckWitness")]
public static extern bool CheckWitness(UInt160 hash);
/// <summary>
/// Determines whether the specified public key has witnessed the current transaction.
/// <para>
/// The execution will fail if the pubkey is null or the format of the pubkey is invalid.
/// </para>
/// </summary>
[Syscall("System.Runtime.CheckWitness")]
public static extern bool CheckWitness(ECPoint pubkey);
/// <summary>
/// Writes a log.
/// <para>
/// The execution will fail if:
/// 1. The message is null;
/// 2. The length of the message is greater than MaxNotificationSize(the default value is 1024).
/// 3. The message is not a valid UTF-8 string.
/// </para>
/// </summary>
[Syscall("System.Runtime.Log")]
public static extern void Log(string message);
// Events not present in the ABI were disabled in HF_Basilisk
// [Syscall("System.Runtime.Notify")]
// public static extern void Notify(string eventName, object[] state);
/// <summary>
/// Sends a message as a notification with the name "Debug".
/// <para>
/// The execution will fail if message exceeds limits.
/// </para>
/// </summary>
[OpCode(OpCode.PUSH1)]
[OpCode(OpCode.PACK)]
[OpCode(OpCode.PUSHDATA1, "054465627567")] // 0x5 - Debug
//[OpCode(OpCode.SYSCALL, "95016f61")] // SHA256(System.Runtime.Notify)[0..4]
[Syscall("System.Runtime.Notify")]
public static extern void Debug(string message);
/// <summary>
/// Burns the specified amount of GAS.
/// <para>
/// The execution will fail if the amount is less than or equal to 0.
/// </para>
/// </summary>
[Syscall("System.Runtime.BurnGas")]
public static extern void BurnGas(long gas);
/// <summary>
/// Gets the next random number. The random number is determinstic.
/// </summary>
[Syscall("System.Runtime.GetRandom")]
public static extern BigInteger GetRandom();
/// <summary>
/// Gets the magic number of the current network.
/// </summary>
[Syscall("System.Runtime.GetNetwork")]
public static extern uint GetNetwork();
/// <summary>
/// Loads a script at rumtime.
/// </summary>
/// <para>
/// The execution will fail if:
/// 1. The flags is not a valid <see cref="CallFlags"/>.
/// 2. The arguments is null.
/// </para>
[Syscall("System.Runtime.LoadScript")]
public static extern object LoadScript(ByteString script, CallFlags flags, params object[] args);
/// <summary>
/// Gets the signers of the current transaction.
/// </summary>
[Syscall("System.Runtime.CurrentSigners")]
public static extern Signer[] CurrentSigners();
}
}