Esempio n. 1
0
        public override async Task SendRequestAsync(RpcRequest request, string route = null)
        {
            var response =
                await SendAsync <RpcRequestMessage, RpcResponseMessage>(
                    new RpcRequestMessage(request.Id, request.Method, request.RawParameters))
                .ConfigureAwait(false);

            HandleRpcError(response);
        }
Esempio n. 2
0
        public override async Task SendRequestAsync(RpcRequest request, string route = null)
        {
            var response =
                await SendAsync <EdjCase.JsonRpc.Core.RpcRequest, RpcResponse>(
                    new EdjCase.JsonRpc.Core.RpcRequest(request.Id, request.Method, request.RawParameters))
                .ConfigureAwait(false);

            HandleRpcError(response);
        }
Esempio n. 3
0
        public IEnumerator SendRequest(RpcRequest request)
        {
            var requestFormatted = new Unity.RpcModel.RpcRequest(request.Id, request.Method, request.RawParameters);

            var rpcRequestJson = JsonConvert.SerializeObject(requestFormatted, JsonSerializerSettings);
            var requestBytes   = Encoding.UTF8.GetBytes(rpcRequestJson);

            using (var unityRequest = new UnityWebRequest(_url, "POST"))
            {
                var uploadHandler = new UploadHandlerRaw(requestBytes);
                unityRequest.SetRequestHeader("Content-Type", "application/json");
                uploadHandler.contentType  = "application/json";
                unityRequest.uploadHandler = uploadHandler;

                unityRequest.downloadHandler = new DownloadHandlerBuffer();

                if (RequestHeaders != null)
                {
                    foreach (var requestHeader in RequestHeaders)
                    {
                        unityRequest.SetRequestHeader(requestHeader.Key, requestHeader.Value);
                    }
                }

                yield return(unityRequest.SendWebRequest());

                if (unityRequest.error != null)
                {
                    this.Exception = new Exception(unityRequest.error);
    #if DEBUG
                    Debug.Log(unityRequest.error);
    #endif
                }
                else
                {
                    try
                    {
                        byte[] results      = unityRequest.downloadHandler.data;
                        var    responseJson = Encoding.UTF8.GetString(results);
    #if DEBUG
                        Debug.Log(responseJson);
    #endif
                        var responseObject = JsonConvert.DeserializeObject <RpcResponse>(responseJson, JsonSerializerSettings);
                        this.Result    = responseObject.GetResult <TResult>(true, JsonSerializerSettings);
                        this.Exception = HandleRpcError(responseObject);
                    }
                    catch (Exception ex)
                    {
                        this.Exception = new Exception(ex.Message);
    #if DEBUG
                        Debug.Log(ex.Message);
    #endif
                    }
                }
            }
        }
Esempio n. 4
0
        protected override async Task <T> SendInnerRequestAync <T>(RpcRequest request, string route = null)
        {
            var response =
                await SendAsync <RpcRequestMessage, RpcResponseMessage>(
                    new RpcRequestMessage(request.Id, request.Method, request.RawParameters))
                .ConfigureAwait(false);

            HandleRpcError(response);
            return(response.GetResult <T>());
        }
Esempio n. 5
0
        public IEnumerator SendRequest(RpcRequest request)
        {
            var requestFormatted = new RpcModel.RpcRequest(request.Id, request.Method, request.RawParameters);
            var rpcRequestJson   = JsonConvert.SerializeObject(requestFormatted, JsonSerializerSettings);

            Debug.Log(rpcRequestJson);
            var requestBytes = Encoding.UTF8.GetBytes(rpcRequestJson);
            var url          = URLForNetwork(network);

            Debug.Log(url);
            var unityRequest  = new UnityWebRequest(url, "POST");
            var uploadHandler = new UploadHandlerRaw(requestBytes);

            unityRequest.SetRequestHeader("X-Client-Id", authProvider.ClientId);
            unityRequest.SetRequestHeader("X-API-Key", authProvider.ClientId);
            unityRequest.SetRequestHeader("Content-Type", "application/json");
            if (authProvider.CurrentUser != null && authProvider.CurrentUser.AccessToken != null)
            {
                Debug.Log("Auth token: authProvider.CurrentUser.AccessToken");
                unityRequest.SetRequestHeader("Authorization", "Bearer " + authProvider.CurrentUser.AccessToken);
            }
            else
            {
                Debug.Log("Not signed in, anonymous request");
            }
            uploadHandler.contentType  = "application/json";
            unityRequest.uploadHandler = uploadHandler;

            unityRequest.downloadHandler = new DownloadHandlerBuffer();

            yield return(unityRequest.SendWebRequest());

            if (unityRequest.error != null)
            {
                this.Exception = new Exception(unityRequest.error);
            }
            else
            {
                try
                {
                    byte[] results      = unityRequest.downloadHandler.data;
                    var    responseJson = Encoding.UTF8.GetString(results);
                    Debug.Log(responseJson);
                    var responseObject = JsonConvert.DeserializeObject <RpcResponse>(responseJson, JsonSerializerSettings);
                    this.Result    = responseObject.GetResult <TResult>(true, JsonSerializerSettings);
                    this.Exception = HandleRpcError(responseObject);
                }
                catch (Exception ex)
                {
                    this.Exception = new Exception(ex.Message);
                }
            }
        }
        public override async Task InterceptSendRequestAsync(
            Func <Nethereum.JsonRpc.Client.RpcRequest, string, Task> interceptedSendRequestAsync, Nethereum.JsonRpc.Client.RpcRequest request,
            string route = null)
        {
            if (request.Method == "eth_sendTransaction")
            {
                TransactionInput transaction = (TransactionInput)request.RawParameters[0];
                var response = await SignAndSendTransaction(transaction, route);

                return;
            }

            await interceptedSendRequestAsync(request, route).ConfigureAwait(false);
        }
Esempio n. 7
0
 public Task <RpcResponse> SendRequestAsync(RpcRequest request, string route = null)
 {
     return(innerRpcClient.SendRequestAsync(request, route));
 }
Esempio n. 8
0
 protected abstract Task <T> SendInnerRequestAync <T>(RpcRequest request, string route = null);
Esempio n. 9
0
 public abstract Task SendRequestAsync(RpcRequest request, string route = null);
Esempio n. 10
0
        public override async Task <object> InterceptSendRequestAsync <T>(
            Func <Nethereum.JsonRpc.Client.RpcRequest, string, Task <T> > interceptedSendRequestAsync, Nethereum.JsonRpc.Client.RpcRequest request,
            string route = null)
        {
            if (request.Method == "eth_sendTransaction")
            {
                TransactionInput transaction = (TransactionInput)request.RawParameters[0];
                var response = await SignAndSendTransaction(transaction, route);

                return(response);
            }

            return(await CheckForUnknownTransaction(async() =>
            {
                return await interceptedSendRequestAsync(request, route).ConfigureAwait(false);
            }));
        }
Esempio n. 11
0
 public virtual async Task <object> InterceptSendRequestAsync <T>(
     Func <RpcRequest, string, Task <T> > interceptedSendRequestAsync, RpcRequest request,
     string route = null)
 {
     return(await interceptedSendRequestAsync(request, route).ConfigureAwait(false));
 }
Esempio n. 12
0
 public virtual async Task InterceptSendRequestAsync(
     Func <RpcRequest, string, Task> interceptedSendRequestAsync, RpcRequest request,
     string route = null)
 {
     await interceptedSendRequestAsync(request, route).ConfigureAwait(false);
 }