/// <inheritdoc /> public async Task <ClassicTumblerParameters> ConnectToTumblerAsync(Uri serverAddress) { // TODO this method will probably need to change as the connection to a tumbler is currently done during configuration // of the TumblebitRuntime. This method can then be modified to potentially be a convenience method // where a user wants to check a tumbler's paramters before commiting to tumbling (and therefore before configuring the runtime). // TODO: Temporary measure string[] args = { "-testnet" }; var config = new TumblerClientConfiguration(); config.LoadArgs(args); // AcceptAllClientConfiguration should be used if the interaction is null this.runtime = TumblerClientRuntime.FromConfiguration(config, null); //this.tumblerService = new TumblerService(serverAddress); //this.TumblerParameters = await this.tumblerService.GetClassicTumblerParametersAsync(); this.TumblerParameters = runtime.TumblerParameters; if (this.TumblerParameters.Network != this.network) { throw new Exception($"The tumbler is on network {this.TumblerParameters.Network} while the wallet is on network {this.network}."); } // Load the current tumbling state fromt the file system this.tumblingState.LoadStateFromMemory(); // Update and save the state this.tumblingState.TumblerUri = serverAddress; this.tumblingState.TumblerParameters = this.TumblerParameters; this.tumblingState.Save(); return(this.TumblerParameters); }
public void Run(string[] args) { var argsConf = new TextFileConfiguration(args); var debug = argsConf.GetOrDefault <bool>("debug", false); ConsoleLoggerProcessor loggerProcessor = new ConsoleLoggerProcessor(); Logs.Configure(new FuncLoggerFactory(i => new CustomerConsoleLogger(i, Logs.SupportDebug(debug), false, loggerProcessor))); using (var interactive = new Interactive()) { try { var config = new TumblerClientConfiguration(); config.LoadArgs(args); var runtime = TumblerClientRuntime.FromConfiguration(config, new TextWriterClientInteraction(Console.Out, Console.In)); interactive.Runtime = new ClientInteractiveRuntime(runtime); var broadcaster = runtime.CreateBroadcasterJob(); broadcaster.Start(); interactive.Services.Add(broadcaster); //interactive.Services.Add(new CheckIpService(runtime)); //interactive.Services.Last().Start(); if (!config.OnlyMonitor) { var stateMachine = runtime.CreateStateMachineJob(); stateMachine.Start(); interactive.Services.Add(stateMachine); } interactive.StartInteractive(); } catch (ClientInteractionException ex) { if (!string.IsNullOrEmpty(ex.Message)) { Logs.Configuration.LogError(ex.Message); } } catch (ConfigException ex) { if (!string.IsNullOrEmpty(ex.Message)) { Logs.Configuration.LogError(ex.Message); } } catch (InterruptedConsoleException) { } catch (Exception ex) { Logs.Configuration.LogError(ex.Message); Logs.Configuration.LogDebug(ex.StackTrace); } } }
public TumblerServerTester(string directory, bool shouldBeStandard) { 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); _NodeBuilder.ConfigParameters.Add("prematurewitness", "1"); _NodeBuilder.ConfigParameters.Add("walletprematurewitness", "1"); _TumblerNode = _NodeBuilder.CreateNode(false); _AliceNode = _NodeBuilder.CreateNode(false); _BobNode = _NodeBuilder.CreateNode(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.RegTest; 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; } }