Example #1
0
            public static bool TryFromJson(JToken token, out OracleResponseInvocation invocation)
            {
                if (token.Type == JTokenType.Object)
                {
                    var response = token["oracle-response"];
                    if (response != null)
                    {
                        var url      = response.Value <string>("url");
                        var callback = response.Value <string>("callback");
                        var result   = response["result"] != null
                            ? response.Value <string>()
                            : (TryLoadResultFile(response, out var resultFileContents) ? resultFileContents : null);

                        if (!string.IsNullOrEmpty(url) && result != null)
                        {
                            var filter = response.Value <string>("filter") ?? string.Empty;
                            var code   = response["code"] == null
                                ? OracleResponseCode.Success
                                : Enum.Parse <OracleResponseCode>(token.Value <string>("code") ?? "", true);
                            var gas = response["gas"] == null ? (long)0 : token.Value <long>("gas");

                            invocation = new OracleResponseInvocation(code, url, callback, result, filter, token["user-data"], gas);
                            return(true);
                        }
                    }
                }

                invocation = default;
                return(false);
            static bool TryGetInvocation(JToken json, out Invocation result)
            {
                if (json["invokeFile"] != null)
                {
                    result = new InvokeFileInvocation(json.Value <string>("invokeFile"));
                    return(true);
                }

                if (OracleResponseInvocation.TryFromJson(json["oracleResponse"], out var oracleInvocation))
                {
                    result = oracleInvocation;
                    return(true);
                }

                if (LaunchInvocation.TryFromJson(json, out var launchInvocation))
                {
                    result = launchInvocation;
                    return(true);
                }

                result = default;
                return(false);
            }