private async Task <T> MakeRPCCall <T>(Node node, string method = "getblockcount")
        {
            try
            {
                HttpResponseMessage response = null;
                var rpcRequest = new RPCRequestBody(method);

                if (!string.IsNullOrEmpty(node.SuccessUrl))
                {
                    response = await RpcCaller.SendRPCCall(HttpMethod.Post, $"{node.SuccessUrl}", rpcRequest);
                }
                else
                {
                    var ports = this.netSettings.GetPorts();
                    foreach (var portWithType in ports)
                    {
                        var triedUrl = default(string);
                        if (!string.IsNullOrEmpty(node.Url))
                        {
                            triedUrl = portWithType.GetFullUrl(node.Url);
                            response = await RpcCaller.SendRPCCall(HttpMethod.Post, triedUrl, rpcRequest);
                        }
                        else
                        {
                            triedUrl = portWithType.GetFullUrl(node.NodeAddresses.FirstOrDefault().Ip);
                            response = await RpcCaller.SendRPCCall(HttpMethod.Post, triedUrl, rpcRequest);
                        }

                        if (response != null && response.IsSuccessStatusCode)
                        {
                            node.SuccessUrl = triedUrl;
                            break;
                        }
                    }
                }

                if (response != null && response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    var serializedResult = JsonConvert.DeserializeObject <T>(result);
                    return(serializedResult);
                }
            }
            catch (Exception e)
            {
            }

            return(default(T));
        }
        private async Task <T> MakeRPCCall <T>(string endpoint, string method = "getblockcount")
        {
            var rpcRequest = new RPCRequestBody
            {
                Method = method
            };
            var response = await SendRPCCall(HttpMethod.Post, endpoint, rpcRequest);

            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                var serializedResult = JsonConvert.DeserializeObject <T>(result);
                return(serializedResult);
            }
            return(default(T));
        }
        private async Task <T> MakeRPCCall <T>(Node node, string method = "getblockcount")
        {
            HttpResponseMessage response = null;
            bool succesfulCall           = false;
            var  successUrl = string.Empty;
            var  url        = string.Empty;

            var rpcRequest = new RPCRequestBody
            {
                Method = method
            };

            if (!string.IsNullOrEmpty(node.SuccessUrl))
            {
                response = await SendRPCCall(HttpMethod.Post, $"{node.SuccessUrl}", rpcRequest);

                if (response.IsSuccessStatusCode)
                {
                    successUrl    = node.SuccessUrl;
                    succesfulCall = true;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(successUrl))
                {
                    if (!string.IsNullOrEmpty(node.Protocol) &&
                        !string.IsNullOrEmpty(node.Url))
                    {
                        foreach (var address in node.NodeAddresses)
                        {
                            if (address.Port.HasValue)
                            {
                                url      = $"{node.Protocol}://{node.Url}:{address.Port}";
                                response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                if (response.IsSuccessStatusCode)
                                {
                                    node.Type    = NodeAddressType.RPC;
                                    address.Type = NodeAddressType.RPC;
                                    successUrl   = url;
                                    break;
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(successUrl))
                        {
                            foreach (var port in _netSettings.GetPorts())
                            {
                                url      = $"{node.Protocol}://{node.Url}:{port}";
                                response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                if (response.IsSuccessStatusCode)
                                {
                                    node.Type  = NodeAddressType.RPC;
                                    successUrl = url;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(successUrl))
                {
                    if (string.IsNullOrEmpty(node.Protocol) &&
                        !string.IsNullOrEmpty(node.Url))
                    {
                        if (node.Url.Contains(RPCCallConstants.PROTOCOL_TYPES_TESTS[0]) ||
                            node.Url.Contains(RPCCallConstants.PROTOCOL_TYPES_TESTS[1]))
                        {
                            foreach (var address in node.NodeAddresses)
                            {
                                if (address.Port.HasValue)
                                {
                                    url      = $"{node.Url}:{address.Port}";
                                    response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                    if (response.IsSuccessStatusCode)
                                    {
                                        node.Type     = NodeAddressType.RPC;
                                        address.Type  = NodeAddressType.RPC;
                                        successUrl    = url;
                                        succesfulCall = true;
                                        break;
                                    }
                                }
                            }
                            if (string.IsNullOrEmpty(successUrl))
                            {
                                foreach (var port in _netSettings.GetPorts())
                                {
                                    url      = $"{node.Url}:{port}";
                                    response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                    if (response.IsSuccessStatusCode)
                                    {
                                        node.Type  = NodeAddressType.RPC;
                                        successUrl = url;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            foreach (var address in node.NodeAddresses)
                            {
                                if (address.Port.HasValue)
                                {
                                    foreach (var protocol in RPCCallConstants.PROTOCOL_TYPES_TESTS)
                                    {
                                        url      = $"{protocol}://{node.Url}:{address.Port}";
                                        response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                        if (response.IsSuccessStatusCode)
                                        {
                                            node.Type     = NodeAddressType.RPC;
                                            address.Type  = NodeAddressType.RPC;
                                            successUrl    = url;
                                            succesfulCall = true;
                                            break;
                                        }
                                    }
                                }
                                if (succesfulCall)
                                {
                                    break;
                                }
                            }
                            if (string.IsNullOrEmpty(successUrl))
                            {
                                foreach (var port in _netSettings.GetPorts())
                                {
                                    foreach (var protocol in RPCCallConstants.PROTOCOL_TYPES_TESTS)
                                    {
                                        url      = $"{protocol}://{node.Url}:{port}";
                                        response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                        if (response.IsSuccessStatusCode)
                                        {
                                            node.Type     = NodeAddressType.RPC;
                                            successUrl    = url;
                                            succesfulCall = true;
                                            break;
                                        }
                                    }
                                    if (succesfulCall)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (string.IsNullOrEmpty(successUrl))
                {
                    foreach (var address in node.NodeAddresses)
                    {
                        if (address.Port.HasValue)
                        {
                            foreach (var protocol in RPCCallConstants.PROTOCOL_TYPES_TESTS)
                            {
                                url      = $"{protocol}://{address.Ip}:{address.Port}";
                                response = await SendRPCCall(HttpMethod.Post, $"{protocol}://{address.Ip}:{address.Port}", rpcRequest);

                                if (response.IsSuccessStatusCode)
                                {
                                    node.Type     = NodeAddressType.RPC;
                                    address.Type  = NodeAddressType.RPC;
                                    successUrl    = url;
                                    succesfulCall = true;
                                    break;
                                }
                            }
                        }
                        if (string.IsNullOrEmpty(successUrl))
                        {
                            foreach (var port in _netSettings.GetPorts())
                            {
                                foreach (var protocol in RPCCallConstants.PROTOCOL_TYPES_TESTS)
                                {
                                    url      = $"{protocol}://{address.Ip}:{port}";
                                    response = await SendRPCCall(HttpMethod.Post, url, rpcRequest);

                                    if (response.IsSuccessStatusCode)
                                    {
                                        node.Type     = NodeAddressType.RPC;
                                        address.Type  = NodeAddressType.RPC;
                                        successUrl    = url;
                                        succesfulCall = true;
                                        break;
                                    }
                                }
                                if (succesfulCall)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(successUrl))
            {
                node.SuccessUrl = successUrl;
                if (response != null && response.IsSuccessStatusCode)
                {
                    var result = await response.Content.ReadAsStringAsync();

                    var serializedResult = JsonConvert.DeserializeObject <T>(result);
                    return(serializedResult);
                }
            }

            return(default(T));
        }