Add Bitcoin Core dependency
MODIFY
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
HiddenWallet.ChaumianTumbler/Configuration/Config.cs
@@ -20,6 +20,12 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
[JsonConverter(typeof(NetworkConverter))]
public Network Network { get; private set; }
+ [JsonProperty(PropertyName = "BitcoinRpcUser")]
+ public string BitcoinRpcUser { get; private set; }
+
+ [JsonProperty(PropertyName = "BitcoinRpcPassword")]
+ public string BitcoinRpcPassword { get; private set; }
+
[JsonProperty(PropertyName = "DenominationAlgorithm")]
[JsonConverter(typeof(StringEnumConverter))]
public DenominationAlgorithm? DenominationAlgorithm { get; private set; }
@@ -73,6 +79,8 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
if (path == null) throw new ArgumentNullException(nameof(path));
Network = Network.Main;
+ BitcoinRpcUser = "user";
+ BitcoinRpcPassword = "password";
DenominationAlgorithm = Configuration.DenominationAlgorithm.FixedUSD;
DenominationUSD = 10000;
DenominationBTC = new Money(1m, MoneyUnit.BTC);
@@ -94,6 +102,8 @@ namespace HiddenWallet.ChaumianTumbler.Configuration
var config = JsonConvert.DeserializeObject<Config>(jsonString);
Network = config.Network ?? Network;
+ BitcoinRpcUser = config.BitcoinRpcUser ?? BitcoinRpcUser;
+ BitcoinRpcPassword = config.BitcoinRpcPassword ?? BitcoinRpcPassword;
DenominationAlgorithm = config.DenominationAlgorithm ?? DenominationAlgorithm;
DenominationUSD = config.DenominationUSD ?? DenominationUSD;
DenominationBTC = config.DenominationBTC ?? DenominationBTC;

MODIFY
HiddenWallet.ChaumianTumbler/Program.cs
HiddenWallet.ChaumianTumbler/Program.cs
@@ -10,6 +10,8 @@ using Microsoft.Extensions.Logging;
using System.Threading;
using NBitcoin;
using HiddenWallet.ChaumianTumbler.Configuration;
+using NBitcoin.RPC;
+using System.Net;
namespace HiddenWallet.ChaumianTumbler
{
@@ -18,11 +20,21 @@ namespace HiddenWallet.ChaumianTumbler
#pragma warning disable IDE1006 // Naming Styles
public static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
+ {
+ try
{
var configFilePath = Path.Combine(Global.DataDir, "Config.json");
Global.Config = new Config();
await Global.Config.LoadOrCreateDefaultFileAsync(configFilePath, CancellationToken.None);
+ Global.RpcClient = new RPCClient(
+ credentials: new RPCCredentialString
+ {
+ UserPassword = new NetworkCredential(Global.Config.BitcoinRpcUser, Global.Config.BitcoinRpcPassword)
+ },
+ network: Global.Config.Network);
+ await AssertRpcNodeFullyInitializedAsync();
+
Global.StateMachine = new TumblerStateMachine();
Global.StateMachineJobCancel = new CancellationTokenSource();
Global.StateMachineJob = Global.StateMachine.StartAsync(Global.StateMachineJobCancel.Token);
@@ -34,5 +46,52 @@ namespace HiddenWallet.ChaumianTumbler
await host.RunAsync();
}
}
+ catch (Exception ex)
+ {
+ Console.WriteLine(ex);
+ Console.WriteLine("Press a key to exit...");
+ Console.ReadKey();
+ }
+ }
+
+ private static async Task AssertRpcNodeFullyInitializedAsync()
+ {
+ RPCResponse blockchainInfo = await Global.RpcClient.SendCommandAsync(RPCOperations.getblockchaininfo);
+ try
+ {
+ if (blockchainInfo.Error != null)
+ {
+ throw new NotSupportedException("blockchainInfo.Error != null");
+ }
+ if (blockchainInfo.Result == null)
+ {
+ throw new NotSupportedException("blockchainInfo.Result == null");
+ }
+ int blocks = blockchainInfo.Result.Value<int>("blocks");
+ if (blocks == 0)
+ {
+ throw new NotSupportedException("blocks == 0");
+ }
+ int headers = blockchainInfo.Result.Value<int>("headers");
+ if (headers == 0)
+ {
+ throw new NotSupportedException("headers == 0");
+ }
+ if (blocks != headers)
+ {
+ throw new NotSupportedException("blocks != headers");
+ }
+
+ if (await Global.RpcClient.EstimateFeeRateAsync(1) == null)
+ {
+ throw new NotSupportedException("estimatefee 1 == null");
+ }
+ }
+ catch
+ {
+ Console.WriteLine("Bitcoin Core is not yet fully initialized.");
+ throw;
+ }
+ }
}
}

MODIFY
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
HiddenWallet.ChaumianTumbler/TumblerStateMachine.cs
@@ -166,7 +166,7 @@ namespace HiddenWallet.ChaumianTumbler
var exchangeRates = await SmartBitClient.GetExchangeRatesAsync(cancel);
decimal price = exchangeRates.Single(x => x.Code == "USD").Rate;
decimal denominationUSD = (decimal)Global.Config.DenominationUSD;
- decimal denominationBTC = denominationUSD / price;
+ decimal denominationBTC = Math.Round(denominationUSD / price, 2);
Denomination = new Money(denominationBTC, MoneyUnit.BTC);
}
catch

Add Bitcoin Core dependency