示例#1
0
        public void InitializeUtxoExecutionServices(ulong accountId, byte[] secretSpendKey, byte[] secretViewKey, byte[] pwdSecretKey)
        {
            if (_utxoPersistencyItems.ContainsKey(accountId))
            {
                return;
            }

            IPacketsProvider         packetsProvider     = ServiceLocator.Current.GetInstance <IPacketsProvider>();
            IUtxoTransactionsService transactionsService = ServiceLocator.Current.GetInstance <UtxoTransactionsService>();
            IUtxoClientCryptoService clientCryptoService = ServiceLocator.Current.GetInstance <UtxoClientCryptoService>();
            UtxoWalletSynchronizer   walletSynchronizer  = ServiceLocator.Current.GetInstance <UtxoWalletSynchronizer>();

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            packetsProvider.Initialize(accountId, cancellationTokenSource.Token);
            clientCryptoService.Initialize(secretSpendKey, secretViewKey, pwdSecretKey);
            transactionsService.Initialize(clientCryptoService);
            transactionsService.PipeOutTransactions.LinkTo(_gatewayService.PipeInTransactions);
            transactionsService.PipeOutKeyImages.LinkTo(walletSynchronizer.PipeInKeyImages);

            UserIdentitiesUpdater userIdentitiesUpdater = new UserIdentitiesUpdater(accountId, clientCryptoService, _assetsService, _dataAccessService, _identitiesHubContext, _relationsProofsValidationService, _trackingService);

            walletSynchronizer.Initialize(accountId, clientCryptoService, _gatewayService, cancellationTokenSource.Token);

            packetsProvider.PipeOut.LinkTo(walletSynchronizer.PipeIn);
            walletSynchronizer.PipeOut.LinkTo(userIdentitiesUpdater.PipeIn);

            walletSynchronizer.Start();
            packetsProvider.Start();

            AddSubscriberToDictionary(accountId, walletSynchronizer.Subscribe(userIdentitiesUpdater));

            var state = new UtxoPersistency
            {
                AccountId               = accountId,
                PacketsProvider         = packetsProvider,
                TransactionsService     = transactionsService,
                ClientCryptoService     = clientCryptoService,
                WalletSynchronizer      = walletSynchronizer,
                CancellationTokenSource = cancellationTokenSource
            };

            _utxoPersistencyItems.Add(accountId, state);
        }
示例#2
0
        public void InitializeUtxoExecutionServices(long accountId, byte[] secretSpendKey, byte[] secretViewKey, byte[] pwdSecretKey, Func <long, IUtxoClientCryptoService, CancellationToken, IUpdater> updaterFactory = null)
        {
            lock (_utxoPersistencyItems)
            {
                if (_utxoPersistencyItems.ContainsKey(accountId))
                {
                    _logger.Info($"[{accountId}]: account already registered at UtxoPersistency");
                    return;
                }

                _logger.Info($"[{accountId}]: {nameof(InitializeUtxoExecutionServices)}");

                try
                {
                    IWitnessPackagesProvider   packetsProvider            = _witnessPackagesProviderRepository.GetInstance(_restApiConfiguration.WitnessProviderName);
                    IUtxoTransactionsService   transactionsService        = ActivatorUtilities.CreateInstance <UtxoTransactionsService>(_serviceProvider);
                    IUtxoClientCryptoService   clientCryptoService        = ActivatorUtilities.CreateInstance <UtxoClientCryptoService>(_serviceProvider);
                    IRelationsBindingService   relationsBindingService    = ActivatorUtilities.CreateInstance <RelationsBindingService>(_serviceProvider);
                    UtxoWalletSynchronizer     walletSynchronizer         = ActivatorUtilities.CreateInstance <UtxoWalletSynchronizer>(_serviceProvider);
                    UtxoWalletPacketsExtractor utxoWalletPacketsExtractor = ActivatorUtilities.CreateInstance <UtxoWalletPacketsExtractor>(_serviceProvider);

                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

                    packetsProvider.Initialize(accountId, cancellationTokenSource.Token);
                    clientCryptoService.Initialize(secretSpendKey, secretViewKey);

                    TaskCompletionSource <byte[]> pwdSource = new TaskCompletionSource <byte[]>();
                    if (pwdSecretKey != null)
                    {
                        pwdSource.SetResult(pwdSecretKey);
                    }
                    relationsBindingService.Initialize(pwdSource);

                    transactionsService.AccountId = accountId;
                    transactionsService.Initialize(clientCryptoService, relationsBindingService);
                    utxoWalletPacketsExtractor.AccountId = accountId;
                    utxoWalletPacketsExtractor.Initialize(clientCryptoService);
                    transactionsService.PipeOutTransactions.LinkTo(_gatewayService.PipeInTransactions);
                    transactionsService.PipeOutKeyImages.LinkTo(utxoWalletPacketsExtractor.PipeInKeyImages);

                    IUpdater userIdentitiesUpdater = updaterFactory != null?updaterFactory(accountId, clientCryptoService, cancellationTokenSource.Token) : CreateUtxoUpdater(accountId, clientCryptoService, cancellationTokenSource.Token);

                    walletSynchronizer.Initialize(accountId, clientCryptoService);

                    packetsProvider.PipeOut.LinkTo(utxoWalletPacketsExtractor.PipeIn);
                    utxoWalletPacketsExtractor.PipeOutPackets.LinkTo(walletSynchronizer.PipeInPackets);
                    utxoWalletPacketsExtractor.PipeOutProcessed.LinkTo(walletSynchronizer.PipeInPackage);
                    utxoWalletPacketsExtractor.PipeOutNotifications.LinkTo(userIdentitiesUpdater.PipInNotifications);

                    walletSynchronizer.PipeOutPackets.LinkTo(userIdentitiesUpdater.PipeIn);
                    walletSynchronizer.PipeOutNotifications.LinkTo(userIdentitiesUpdater.PipInNotifications);

                    packetsProvider.Start();

                    var state = new UtxoPersistency
                    {
                        AccountId               = accountId,
                        PacketsProvider         = packetsProvider,
                        TransactionsService     = transactionsService,
                        ClientCryptoService     = clientCryptoService,
                        RelationsBindingService = relationsBindingService,
                        PacketsExtractor        = utxoWalletPacketsExtractor,
                        WalletSynchronizer      = walletSynchronizer,
                        CancellationTokenSource = cancellationTokenSource,
                        BindingKeySource        = pwdSource
                    };
                    _utxoPersistencyItems.Add(accountId, state);
                }
                catch (Exception ex)
                {
                    _logger.Error($"[{accountId}]: Failure during {nameof(InitializeUtxoExecutionServices)}", ex);

                    throw;
                }
            }
        }