Exemplo n.º 1
0
        public static async Task InitializeWalletServiceAsync(KeyManager keyManager)
        {
            while (!Initialized)
            {
                await Task.Delay(100);
            }

            if (Config.UseTor.Value)
            {
                ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, () => Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
            }
            else
            {
                ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, Config.GetFallbackBackendUri(), null);
            }
            WalletService = new WalletService(BitcoinStore, keyManager, Synchronizer, ChaumianClient, MemPoolService, Nodes, DataDir, Config.ServiceConfiguration);

            ChaumianClient.Start();
            Logger.LogInfo("Start Chaumian CoinJoin service...");

            using (CancelWalletServiceInitialization = new CancellationTokenSource())
            {
                Logger.LogInfo("Starting WalletService...");
                await WalletService.InitializeAsync(CancelWalletServiceInitialization.Token);

                Logger.LogInfo("WalletService started.");
            }
            CancelWalletServiceInitialization      = null;        // Must make it null explicitly, because dispose won't make it null.
            WalletService.Coins.CollectionChanged += Coins_CollectionChanged;
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public async Task StartAsync(CancellationToken cancel)
        {
            try
            {
                InitializingChanged?.Invoke(null, true);

                if (!Synchronizer.IsRunning)
                {
                    throw new NotSupportedException($"{nameof(Synchronizer)} is not running.");
                }

                while (!BitcoinStore.IsInitialized)
                {
                    await Task.Delay(100).ConfigureAwait(false);

                    cancel.ThrowIfCancellationRequested();
                }

                await RuntimeParams.LoadAsync();

                ChaumianClient.Start();

                using (await HandleFiltersLock.LockAsync())
                {
                    await LoadWalletStateAsync(cancel);
                    await LoadDummyMempoolAsync();
                }
            }
            finally
            {
                InitializingChanged?.Invoke(null, false);
            }
        }
Exemplo n.º 3
0
        public async Task InitializeWalletServiceAsync(KeyManager keyManager)
        {
            using (_cancelWalletServiceInitialization = new CancellationTokenSource())
            {
                var token = _cancelWalletServiceInitialization.Token;
                while (!Initialized)
                {
                    await Task.Delay(100, token);
                }

                if (Config.UseTor)
                {
                    ChaumianClient = new CoinJoinClient(Synchronizer, Network, keyManager, () => Config.GetCurrentBackendUri(), Config.TorSocks5EndPoint);
                }
                else
                {
                    ChaumianClient = new CoinJoinClient(Synchronizer, Network, keyManager, Config.GetFallbackBackendUri(), null);
                }

                try
                {
                    keyManager.CorrectBlockHeights(BitcoinStore.HashChain); // Block heights are wrong sometimes. It's a hack. We have to retroactively fix existing wallets, but also we have to figure out where we ruin the block heights.
                }
                catch (Exception ex)                                        // Whatever this is not critical, but let's log it.
                {
                    Logger.LogWarning(ex);
                }

                WalletService = new WalletService(BitcoinStore, keyManager, Synchronizer, ChaumianClient, Nodes, DataDir, Config.ServiceConfiguration, FeeProviders, BitcoinCoreNode?.RpcClient);

                ChaumianClient.Start();
                Logger.LogInfo("Start Chaumian CoinJoin service...");

                Logger.LogInfo($"Starting {nameof(WalletService)}...");
                await WalletService.InitializeAsync(token);

                Logger.LogInfo($"{nameof(WalletService)} started.");

                token.ThrowIfCancellationRequested();
                WalletService.TransactionProcessor.CoinReceived += CoinReceived;

                TransactionBroadcaster.AddWalletService(WalletService);
            }
            _cancelWalletServiceInitialization = null;             // Must make it null explicitly, because dispose won't make it null.
        }
Exemplo n.º 4
0
        public async Task InitializeWalletServiceAsync(KeyManager keyManager)
        {
            using (_cancelWalletServiceInitialization = new CancellationTokenSource())
            {
                var token = _cancelWalletServiceInitialization.Token;
                while (!Initialized)
                {
                    await Task.Delay(100, token);
                }

                if (Config.UseTor.Value)
                {
                    ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, () => Config.GetCurrentBackendUri(), Config.GetTorSocks5EndPoint());
                }
                else
                {
                    ChaumianClient = new CcjClient(Synchronizer, Network, keyManager, Config.GetFallbackBackendUri(), null);
                }

                keyManager.CorrectBlockHeights(BitcoinStore.HashChain);                 // Block heights are wrong sometimes. It's a hack. We have to retroactively fix existing wallets, but also we have to figure out where we ruin the block heights.

                WalletService = new WalletService(BitcoinStore, keyManager, Synchronizer, ChaumianClient, MemPoolService, Nodes, DataDir, Config.ServiceConfiguration);

                ChaumianClient.Start();
                Logger.LogInfo("Start Chaumian CoinJoin service...");

                Logger.LogInfo("Starting WalletService...");
                await WalletService.InitializeAsync(token);

                Logger.LogInfo("WalletService started.");

                token.ThrowIfCancellationRequested();
                WalletService.Coins.CollectionChanged += Coins_CollectionChanged;
            }
            _cancelWalletServiceInitialization = null;             // Must make it null explicitly, because dispose won't make it null.
        }