Beispiel #1
0
        /// <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);
                }
            }
        }