-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dice.cs
51 lines (44 loc) · 1.99 KB
/
Dice.cs
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
using System;
using System.ComponentModel;
using System.Numerics;
using Neo;
using Neo.SmartContract;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
namespace example
{
[DisplayName("example")]
[ManifestExtra("Author", "NEO")]
[ManifestExtra("Email", "developer@neo.org")]
[ContractPermission("*", "*")]
[ManifestExtra("Description", "This is a example")]
public class example : SmartContract
{
[DisplayName("Win")] // account
public static event Action<UInt160> Win;
public struct OraclePayload
{
public UInt256 hashkey;
public object data;
public ulong timestamp;
}
public static UInt256 HashKey() => (UInt256)CryptoLib.Sha256("RANDOM");
public static readonly BigInteger MOD = 1048576;
// TODO: change to the real R3E address in your dAPP, this address is from the test
[InitialValue("NhSXp1NpMQE4g3x5pGm3VkzM1uverSJ9nU", ContractParameterType.Hash160)]
private static readonly UInt160 R3E = default;
// must be two parameters, the first is the account verified by R3E, the second is an array accept all other needed args
public static void Play(UInt160 account, object args)
{
ExecutionEngine.Assert(Runtime.CallingScriptHash == R3E, "not called by R3E");
UInt256 HASHKEY = HashKey();
OraclePayload data = (OraclePayload)Contract.Call(R3E, "data", CallFlags.ReadOnly, HASHKEY);
ExecutionEngine.Assert(data.hashkey == HASHKEY, "oracle record not exist");
ExecutionEngine.Assert(data.timestamp > (BigInteger)Runtime.Time + 30_000, "oracle record exipred");
if ((BigInteger)CryptoLib.Sha256((ByteString)data.data) % MOD == 0 || (ByteString)data.data == "awsl!")
Win(account);
}
}
}