public TumblerServerTester(string directory, bool shouldBeStandard) { try { var network = AltNetworkSets.Bitcoin.Regtest; var rootTestData = "TestData"; directory = rootTestData + "/" + directory; _Directory = directory; if (!Directory.Exists(rootTestData)) { Directory.CreateDirectory(rootTestData); } if (!TryDelete(directory, false)) { foreach (var process in Process.GetProcessesByName("bitcoind")) { if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal)) { process.Kill(); process.WaitForExit(); } } TryDelete(directory, true); } _NodeBuilder = NodeBuilder.Create(NodeDownloadData.Bitcoin.v0_16_3, network, directory); _NodeBuilder.ConfigParameters.Add("prematurewitness", "1"); _NodeBuilder.ConfigParameters.Add("walletprematurewitness", "1"); _TumblerNode = _NodeBuilder.CreateNode(false); _AliceNode = _NodeBuilder.CreateNode(false); _BobNode = _NodeBuilder.CreateNode(false); _TumblerNode.CookieAuth = false; _AliceNode.CookieAuth = false; _BobNode.CookieAuth = false; Directory.CreateDirectory(directory); _NodeBuilder.StartAll(); //Activate segwit SyncNodes(); _TumblerNode.Generate(440); _TumblerNode.CreateRPCClient().SendToAddress(_AliceNode.CreateRPCClient().GetNewAddress(), Money.Coins(100m)); _TumblerNode.Generate(1); SyncNodes(); var conf = new TumblerConfiguration(); conf.DataDir = Path.Combine(directory, "server"); Directory.CreateDirectory(conf.DataDir); File.WriteAllBytes(Path.Combine(conf.DataDir, "Tumbler.pem"), TestKeys.Default.ToBytes()); File.WriteAllBytes(Path.Combine(conf.DataDir, "Voucher.pem"), TestKeys.Default2.ToBytes()); conf.RPC.Url = TumblerNode.CreateRPCClient().Address; var creds = ExtractCredentials(File.ReadAllText(_TumblerNode.Config)); conf.RPC.User = creds.Item1; conf.RPC.Password = creds.Item2; conf.TorMandatory = false; conf.Network = network; conf.Listen = new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000); conf.AllowInsecure = !shouldBeStandard; conf.NoRSAProof = !shouldBeStandard; if (!shouldBeStandard) { conf.ClassicTumblerParameters.FakePuzzleCount = 10; conf.ClassicTumblerParameters.FakeTransactionCount = 10; conf.ClassicTumblerParameters.RealTransactionCount = 10; conf.ClassicTumblerParameters.RealPuzzleCount = 2; conf.ClassicTumblerParameters.CycleGenerator.FirstCycle.Start = 105; } else { var standard = new StandardCycles(conf.Network).Shorty2x; conf.ClassicTumblerParameters.CycleGenerator = standard.Generator; conf.ClassicTumblerParameters.Denomination = standard.Denomination; } var runtime = TumblerRuntime.FromConfiguration(conf, new AcceptAllClientInteraction()); _Host = new WebHostBuilder() .UseAppConfiguration(runtime) .UseContentRoot(Path.GetFullPath(directory)) .UseStartup <Startup>() .Build(); _Host.Start(); ServerRuntime = runtime; //Overrides server fee ((RPCFeeService)runtime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(100), 1); ((RPCWalletService)runtime.Services.WalletService).BatchInterval = TimeSpan.FromMilliseconds(10); ((RPCWalletService)runtime.Services.WalletService).AddressGenerationBatchInterval = TimeSpan.FromMilliseconds(10); ((RPCBroadcastService)runtime.Services.BroadcastService).BatchInterval = TimeSpan.FromMilliseconds(10); ((RPCBlockExplorerService)runtime.Services.BlockExplorerService).BatchInterval = TimeSpan.FromMilliseconds(10); var clientConfig = new TumblerClientConfiguration(); clientConfig.DataDir = Path.Combine(directory, "client"); clientConfig.AllowInsecure = !shouldBeStandard; Directory.CreateDirectory(clientConfig.DataDir); clientConfig.Network = conf.Network; clientConfig.CheckIp = false; clientConfig.TorMandatory = false; clientConfig.OutputWallet.KeyPath = new KeyPath("0"); clientConfig.OutputWallet.RootKey = new ExtKey().Neuter().GetWif(conf.Network); clientConfig.RPCArgs.Url = AliceNode.CreateRPCClient().Address; creds = ExtractCredentials(File.ReadAllText(AliceNode.Config)); clientConfig.RPCArgs.User = creds.Item1; clientConfig.RPCArgs.Password = creds.Item2; clientConfig.TumblerServer = runtime.TumblerUris.First(); ClientRuntime = TumblerClientRuntime.FromConfiguration(clientConfig, new AcceptAllClientInteraction()); //Overrides client fee ((RPCFeeService)ClientRuntime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(50), 1); } catch { Dispose(); throw; } }
public TumblerServerTester(string directory) { try { var rootTestData = "TestData"; directory = rootTestData + "/" + directory; _Directory = directory; if (!Directory.Exists(rootTestData)) { Directory.CreateDirectory(rootTestData); } if (!TryDelete(directory, false)) { foreach (var process in Process.GetProcessesByName("bitcoind")) { if (process.MainModule.FileName.Replace("\\", "/").StartsWith(Path.GetFullPath(rootTestData).Replace("\\", "/"), StringComparison.Ordinal)) { process.Kill(); process.WaitForExit(); } } TryDelete(directory, true); } _NodeBuilder = NodeBuilder.Create(directory); _TumblerNode = _NodeBuilder.CreateNode(false); _AliceNode = _NodeBuilder.CreateNode(false); _BobNode = _NodeBuilder.CreateNode(false); Directory.CreateDirectory(directory); _NodeBuilder.StartAll(); SyncNodes(); var conf = new TumblerConfiguration(); conf.DataDir = Path.Combine(directory, "server"); Directory.CreateDirectory(conf.DataDir); File.WriteAllBytes(Path.Combine(conf.DataDir, "Tumbler.pem"), TestKeys.Default.ToBytes()); File.WriteAllBytes(Path.Combine(conf.DataDir, "Voucher.pem"), TestKeys.Default2.ToBytes()); conf.RPC.Url = TumblerNode.CreateRPCClient().Address; var creds = ExtractCredentials(File.ReadAllText(_TumblerNode.Config)); conf.RPC.User = creds.Item1; conf.RPC.Password = creds.Item2; conf.Network = Network.RegTest; conf.Listen.Add(new System.Net.IPEndPoint(IPAddress.Parse("127.0.0.1"), 5000)); conf.ClassicTumblerParameters.FakePuzzleCount /= 4; conf.ClassicTumblerParameters.FakeTransactionCount /= 4; conf.ClassicTumblerParameters.RealTransactionCount /= 4; conf.ClassicTumblerParameters.RealPuzzleCount /= 4; conf.ClassicTumblerParameters.CycleGenerator.FirstCycle.Start = 105; var runtime = TumblerRuntime.FromConfiguration(conf, new AcceptAllClientInteraction()); _Host = new WebHostBuilder() .UseKestrel() .UseAppConfiguration(runtime) .UseContentRoot(Path.GetFullPath(directory)) .UseStartup <Startup>() .UseUrls(conf.GetUrls()) .Build(); _Host.Start(); ServerRuntime = runtime; //Overrides server fee ((RPCFeeService)runtime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(100), 1); var clientConfig = new TumblerClientConfiguration(); clientConfig.DataDir = Path.Combine(directory, "client"); clientConfig.AllowInsecure = true; Directory.CreateDirectory(clientConfig.DataDir); clientConfig.Network = conf.Network; clientConfig.CheckIp = false; clientConfig.OutputWallet.KeyPath = new KeyPath("0"); clientConfig.OutputWallet.RootKey = new ExtKey().Neuter().GetWif(conf.Network); clientConfig.RPCArgs.Url = AliceNode.CreateRPCClient().Address; creds = ExtractCredentials(File.ReadAllText(AliceNode.Config)); clientConfig.RPCArgs.User = creds.Item1; clientConfig.RPCArgs.Password = creds.Item2; clientConfig.TumblerServer = Address; ClientRuntime = TumblerClientRuntime.FromConfiguration(clientConfig, new AcceptAllClientInteraction()); //Overrides client fee ((RPCFeeService)ClientRuntime.Services.FeeService).FallBackFeeRate = new FeeRate(Money.Satoshis(50), 1); } catch { Dispose(); throw; } }