Beispiel #1
0
        /// <summary>
        /// Make the actual HTTP request to the Bitcoin RPC interface.
        /// </summary>
        /// <param name="walletRequest">The request to make.</param>
        /// <returns>The HTTP request object.</returns>
        private HttpWebRequest MakeHttpRequest(OverpoolRequest walletRequest)
        {
            RequestsMeter.Mark();

            var webRequest = (HttpWebRequest)WebRequest.Create(RpcUrl);

            webRequest.Credentials = new NetworkCredential(RpcUser, RpcPassword);

            // Important, otherwise the service can't deserialse your request properly
            webRequest.UserAgent   = string.Format("CoiniumServ {0:} {1:}", VersionInfo.CodeName, Assembly.GetAssembly(typeof(Program)).GetName().Version);
            webRequest.ContentType = "application/json-rpc";
            webRequest.Method      = "POST";
            webRequest.Timeout     = _timeout;

            _logger.Verbose("tx: {0}", Encoding.UTF8.GetString(walletRequest.GetBytes()).PrettifyJson());

            byte[] byteArray = walletRequest.GetBytes();
            webRequest.ContentLength = byteArray.Length;

            try
            {
                using (Stream dataStream = webRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }

                return(webRequest);
            }
            catch (WebException webException)
            {
                webRequest = null;
                throw _rpcExceptionFactory.GetRpcException(webException);
            }
            catch (Exception exception)
            {
                webRequest = null;
                throw _rpcExceptionFactory.GetRpcException("An unknown exception occured while making json request.", exception);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Make a raw JSON RPC request with the given request object. Returns raw JSON.
        /// </summary>
        /// <param name="walletRequest">The request object.</param>
        /// <returns>The raw JSON string.</returns>
        private string MakeRawRpcRequest(OverpoolRequest walletRequest)
        {
            var httpWebRequest = MakeHttpRequest(walletRequest);

            return(GetJsonResponse(httpWebRequest));
        }
Beispiel #3
0
        /// <summary>
        /// Make an JSON RPC request, and return a JSON RPC response object with the result
        /// deserialized as the given type.
        /// </summary>
        /// <typeparam name="T">The type to deserialize the result as.</typeparam>
        /// <param name="walletRequest">The request object.</param>
        /// <returns>A JSON RPC response with the result deserialized as the given type.</returns>
        private OverpoolResponse <T> MakeRpcRequest <T>(OverpoolRequest walletRequest)
        {
            var httpWebRequest = MakeHttpRequest(walletRequest);

            return(GetRpcResponse <T>(httpWebRequest));
        }