1

I'm trying to modify the CoiniumServ codebase ( https://github.com/int6/CoiniumServ ), so it supports bitcoind in regtest mode.

I know using bitcoin-cli you need to add -regtest to the bitcoin-cli calls, or else it doesn't work. But looking through the C# code I'm not sure where/how to add it.

This is the part where a WebRequest object is created: https://github.com/int6/CoiniumServ/blob/fbfcc55b6182902c42fb0cd76411cd646a898fca/src/CoiniumServ/Daemon/DaemonBase.cs#L134

private HttpWebRequest MakeHttpRequest(DaemonRequest 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);                
            }
        }

I tried adding "regtest:1" to the json object of walletRequest, and adding "-regtest=1" as an extra parameter. walletRequest is a "DaemonRequest", seen here: https://github.com/int6/CoiniumServ/blob/fbfcc55b6182902c42fb0cd76411cd646a898fca/src/CoiniumServ/Daemon/DaemonRequest.cs

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace CoiniumServ.Daemon
{
    /// <summary>
    /// Class containing data sent to the coin wallet as a JSON RPC call.
    /// </summary>
    public class DaemonRequest
    {
        /// <summary>
        /// The method to call on the coin wallet.
        /// </summary>
        [JsonProperty(PropertyName = "method", Order = 0)]
        public string Method { get; set; }

        /// <summary>
        /// A list of parameters to pass to the method.
        /// </summary>
        [JsonProperty(PropertyName = "params", Order = 1)]
        public IList<object> Parameters { get; set; }

        /// <summary>
        /// Id of the RPC call. This id will be returned in the response.
        /// </summary>
        [JsonProperty(PropertyName = "id", Order = 2)]
        public int Id { get; set; }

        /// <summary>
        /// Create a new JSON RPC request with the given id, method and optionally parameters.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="method"></param>
        /// <param name="parameters"></param>
        public DaemonRequest(int id, string method, params object[] parameters)
        {
            Id = id;
            Method = method;

            Parameters = parameters != null ? parameters.ToList() : new List<object>();
        }

        /// <summary>
        /// Get the bytes of the JSON representation of this object.
        /// </summary>
        /// <returns></returns>
        public byte[] GetBytes()
        {
            string json = JsonConvert.SerializeObject(this);
            return Encoding.UTF8.GetBytes(json);
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.