public OracleResponseInvocation(OracleResponseCode code, string url, string callback, string filter, JToken?userData, JToken result, long gasForResponse)
 {
     Code           = code;
     Url            = url;
     Callback       = callback;
     Filter         = filter;
     UserData       = userData;
     Result         = result;
     GasForResponse = gasForResponse;
 }
Beispiel #2
0
 protected override void DeserializeWithoutType(ref MemoryReader reader)
 {
     Id   = reader.ReadUInt64();
     Code = (OracleResponseCode)reader.ReadByte();
     if (!Enum.IsDefined(typeof(OracleResponseCode), Code))
     {
         throw new FormatException();
     }
     Result = reader.ReadVarMemory(MaxResultSize);
     if (Code != OracleResponseCode.Success && Result.Length > 0)
     {
         throw new FormatException();
     }
 }
Beispiel #3
0
        public static void Callback(string url, string userdata, OracleResponseCode code, string result)
        {
            if (code != OracleResponseCode.Success)
            {
                throw new Exception("Oracle response failure with code " + (byte)code);
            }

            object ret = StdLib.JsonDeserialize(result); // [ "hello world" ]

            object[] arr   = (object[])ret;
            string   value = (string)arr[0];

            Runtime.Log("userdata: " + userdata);
            Runtime.Log("response value: " + value);
        }
Beispiel #4
0
        public static void GetPriceCallback(string url, string userdata, OracleResponseCode code, string result)
        {
            if (Runtime.CallingScriptHash != Oracle.Hash)
            {
                throw new Exception("No authorization");
            }
            if (code != OracleResponseCode.Success)
            {
                throw new Exception("Oracle response failure with code " + (byte)code);
            }

            object[] arr   = (object[])StdLib.JsonDeserialize(result); // ["11988.2"]
            string   value = (string)arr[0];

            string[] data = StdLib.StringSplit(userdata, "#");
            Contract.Call(ProviderRegistry, "updatePriceByProvider", CallFlags.All, new object[] { data[0], data[1], value });
        }