예제 #1
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.
        }
예제 #2
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.
        }