Exemplo n.º 1
0
        public void Init(INdmApi api)
        {
            AddDecoders();
            ILogManager logManager = api.LogManager;
            ILogger     logger     = logManager.GetClassLogger();

            bool disableSendingDepositTransaction  = HasEnabledVariable("SENDING_DEPOSIT_TRANSACTION_DISABLED");
            bool instantDepositVerificationEnabled = HasEnabledVariable("INSTANT_DEPOSIT_VERIFICATION_ENABLED");
            bool backgroundServicesDisabled        = HasEnabledVariable("BACKGROUND_SERVICES_DISABLED");

            if (disableSendingDepositTransaction)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM sending deposit transaction is disabled ***");
                }
            }

            if (instantDepositVerificationEnabled)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM instant deposit verification is enabled ***");
                }
            }

            if (backgroundServicesDisabled)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM background services are disabled ***");
                }
            }

            INdmConfig ndmConfig       = api.NdmConfig;
            string     configId        = ndmConfig.Id;
            IDbConfig  dbConfig        = api.ConfigProvider.GetConfig <IDbConfig>();
            Address    contractAddress = string.IsNullOrWhiteSpace(ndmConfig.ContractAddress)
                ? Address.Zero
                : new Address(ndmConfig.ContractAddress);
            ConsumerRocksDbProvider rocksDbProvider = new ConsumerRocksDbProvider(api.BaseDbPath, dbConfig,
                                                                                  logManager);
            DepositDetailsDecoder             depositDetailsRlpDecoder  = new DepositDetailsDecoder();
            DepositApprovalDecoder            depositApprovalRlpDecoder = new DepositApprovalDecoder();
            DataDeliveryReceiptDetailsDecoder receiptRlpDecoder         = new DataDeliveryReceiptDetailsDecoder();
            ConsumerSessionDecoder            sessionRlpDecoder         = new ConsumerSessionDecoder();
            ReceiptRequestValidator           receiptRequestValidator   = new ReceiptRequestValidator(logManager);

            IDepositDetailsRepository          depositRepository;
            IConsumerDepositApprovalRepository depositApprovalRepository;
            IProviderRepository        providerRepository;
            IReceiptRepository         receiptRepository;
            IConsumerSessionRepository sessionRepository;

            switch (ndmConfig.Persistence?.ToLowerInvariant())
            {
            case "mongo":
                IMongoDatabase?database = api.MongoProvider.GetDatabase();
                if (database == null)
                {
                    throw new ApplicationException("Failed to initialize Mongo DB.");
                }

                depositRepository         = new DepositDetailsMongoRepository(database);
                depositApprovalRepository = new ConsumerDepositApprovalMongoRepository(database);
                providerRepository        = new ProviderMongoRepository(database);
                receiptRepository         = new ReceiptMongoRepository(database, "consumerReceipts");
                sessionRepository         = new ConsumerSessionMongoRepository(database);
                break;

            case "memory":
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM is using in memory database ***");
                }
                DepositsInMemoryDb depositsDatabase = new DepositsInMemoryDb();
                depositRepository         = new DepositDetailsInMemoryRepository(depositsDatabase);
                depositApprovalRepository = new ConsumerDepositApprovalInMemoryRepository();
                providerRepository        = new ProviderInMemoryRepository(depositsDatabase);
                receiptRepository         = new ReceiptInMemoryRepository();
                sessionRepository         = new ConsumerSessionInMemoryRepository();
                break;

            default:
                depositRepository = new DepositDetailsRocksRepository(rocksDbProvider.DepositsDb,
                                                                      depositDetailsRlpDecoder);
                depositApprovalRepository = new ConsumerDepositApprovalRocksRepository(
                    rocksDbProvider.ConsumerDepositApprovalsDb, depositApprovalRlpDecoder);
                providerRepository = new ProviderRocksRepository(rocksDbProvider.DepositsDb,
                                                                 depositDetailsRlpDecoder);
                receiptRepository = new ReceiptRocksRepository(rocksDbProvider.ConsumerReceiptsDb,
                                                               receiptRlpDecoder);
                sessionRepository = new ConsumerSessionRocksRepository(rocksDbProvider.ConsumerSessionsDb,
                                                                       sessionRlpDecoder);
                break;
            }

            uint                       requiredBlockConfirmations = ndmConfig.BlockConfirmations;
            IAbiEncoder                abiEncoder                = api.AbiEncoder;
            INdmBlockchainBridge       blockchainBridge          = api.BlockchainBridge;
            IBlockProcessor            blockProcessor            = api.MainBlockProcessor;
            IConfigManager             configManager             = api.ConfigManager;
            Address                    consumerAddress           = api.ConsumerAddress;
            ICryptoRandom              cryptoRandom              = api.CryptoRandom;
            IDepositService            depositService            = api.DepositService;
            GasPriceService            gasPriceService           = api.GasPriceService;
            IEthereumEcdsa             ecdsa                     = api.EthereumEcdsa;
            IEthRequestService         ethRequestService         = api.EthRequestService;
            IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel = api.JsonRpcNdmConsumerChannel;
            INdmNotifier               ndmNotifier               = api.NdmNotifier;
            PublicKey                  nodePublicKey             = api.Enode.PublicKey;
            ITimestamper               timestamper               = api.Timestamper;
            IWallet                    wallet                    = api.Wallet;
            IHttpClient                httpClient                = api.HttpClient;
            IJsonRpcClientProxy?       jsonRpcClientProxy        = api.JsonRpcClientProxy;
            IEthJsonRpcClientProxy?    ethJsonRpcClientProxy     = api.EthJsonRpcClientProxy;
            TransactionService         transactionService        = api.TransactionService;
            IMonitoringService         monitoringService         = api.MonitoringService;

            monitoringService?.RegisterMetrics(typeof(Metrics));

            DataRequestFactory     dataRequestFactory     = new DataRequestFactory(wallet, nodePublicKey);
            TransactionVerifier    transactionVerifier    = new TransactionVerifier(blockchainBridge, requiredBlockConfirmations);
            DepositUnitsCalculator depositUnitsCalculator = new DepositUnitsCalculator(sessionRepository, timestamper);
            DepositProvider        depositProvider        = new DepositProvider(depositRepository, depositUnitsCalculator, logManager);
            KycVerifier            kycVerifier            = new KycVerifier(depositApprovalRepository, logManager);
            ConsumerNotifier       consumerNotifier       = new ConsumerNotifier(ndmNotifier);

            DataAssetService   dataAssetService   = new DataAssetService(providerRepository, consumerNotifier, logManager);
            ProviderService    providerService    = new ProviderService(providerRepository, consumerNotifier, logManager);
            DataRequestService dataRequestService = new DataRequestService(dataRequestFactory, depositProvider, kycVerifier, wallet,
                                                                           providerService, timestamper, sessionRepository, consumerNotifier, logManager);

            SessionService sessionService = new SessionService(providerService, depositProvider, dataAssetService,
                                                               sessionRepository, timestamper, consumerNotifier, logManager);
            DataConsumerService dataConsumerService = new DataConsumerService(depositProvider, sessionService,
                                                                              consumerNotifier, timestamper, sessionRepository, logManager);
            DataStreamService dataStreamService = new DataStreamService(dataAssetService, depositProvider,
                                                                        providerService, sessionService, wallet, consumerNotifier, sessionRepository, logManager);
            DepositApprovalService depositApprovalService = new DepositApprovalService(dataAssetService, providerService,
                                                                                       depositApprovalRepository, timestamper, consumerNotifier, logManager);
            DepositConfirmationService depositConfirmationService = new DepositConfirmationService(blockchainBridge, consumerNotifier,
                                                                                                   depositRepository, depositService, logManager, requiredBlockConfirmations);

            IDepositManager depositManager = new DepositManager(depositService, depositUnitsCalculator,
                                                                dataAssetService, kycVerifier, providerService, abiEncoder, cryptoRandom, wallet, gasPriceService,
                                                                depositRepository, timestamper, logManager, requiredBlockConfirmations,
                                                                disableSendingDepositTransaction);

            if (instantDepositVerificationEnabled)
            {
                depositManager = new InstantDepositManager(depositManager, depositRepository, timestamper, logManager,
                                                           requiredBlockConfirmations);
            }

            DepositReportService depositReportService = new DepositReportService(depositRepository, receiptRepository, sessionRepository,
                                                                                 timestamper);
            ReceiptService receiptService = new ReceiptService(depositProvider, providerService, receiptRequestValidator,
                                                               sessionService, timestamper, receiptRepository, sessionRepository, abiEncoder, wallet, ecdsa,
                                                               nodePublicKey, logManager);
            RefundService refundService = new RefundService(blockchainBridge, abiEncoder, depositRepository,
                                                            contractAddress, logManager);
            RefundClaimant refundClaimant = new RefundClaimant(refundService, blockchainBridge, depositRepository,
                                                               transactionVerifier, gasPriceService, timestamper, logManager);

            api.AccountService = new AccountService(configManager, dataStreamService, providerService,
                                                    sessionService, consumerNotifier, wallet, configId, consumerAddress, logManager);
            ProxyService proxyService = new ProxyService(jsonRpcClientProxy, configManager, configId, logManager);

            api.ConsumerService = new ConsumerService(api.AccountService, dataAssetService, dataRequestService,
                                                      dataConsumerService, dataStreamService, depositManager, depositApprovalService, providerService,
                                                      receiptService, refundService, sessionService, proxyService);
            EthPriceService             ethPriceService             = new EthPriceService(httpClient, timestamper, logManager);
            ConsumerTransactionsService consumerTransactionsService = new ConsumerTransactionsService(transactionService, depositRepository,
                                                                                                      timestamper, logManager);
            ConsumerGasLimitsService gasLimitService = new ConsumerGasLimitsService(depositService, refundService);


            api.RpcModuleProvider.Register(
                new SingletonModulePool <INdmRpcConsumerModule>(new NdmRpcConsumerModule(api.ConsumerService,
                                                                                         depositReportService, jsonRpcNdmConsumerChannel, ethRequestService, ethPriceService,
                                                                                         gasPriceService, consumerTransactionsService, gasLimitService, wallet, timestamper), true));

            if (!backgroundServicesDisabled)
            {
                bool useDepositTimer = ndmConfig.ProxyEnabled;
                ConsumerServicesBackgroundProcessor consumerServicesBackgroundProcessor =
                    new ConsumerServicesBackgroundProcessor(
                        api.AccountService,
                        refundClaimant,
                        depositConfirmationService,
                        ethPriceService,
                        api.GasPriceService,
                        api.MainBlockProcessor,
                        depositRepository,
                        consumerNotifier,
                        logManager,
                        useDepositTimer,
                        ethJsonRpcClientProxy);
                consumerServicesBackgroundProcessor.Init();
            }
        }
Exemplo n.º 2
0
        public INdmConsumerServices Init(INdmServices services)
        {
            AddDecoders();
            var logManager = services.RequiredServices.LogManager;
            var logger     = logManager.GetClassLogger();

            var disableSendingDepositTransaction  = HasEnabledVariable("SENDING_DEPOSIT_TRANSACTION_DISABLED");
            var instantDepositVerificationEnabled = HasEnabledVariable("INSTANT_DEPOSIT_VERIFICATION_ENABLED");
            var backgroundServicesDisabled        = HasEnabledVariable("BACKGROUND_SERVICES_DISABLED");

            if (disableSendingDepositTransaction)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM sending deposit transaction is disabled ***");
                }
            }

            if (instantDepositVerificationEnabled)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM instant deposit verification is enabled ***");
                }
            }

            if (backgroundServicesDisabled)
            {
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM background services are disabled ***");
                }
            }

            var ndmConfig       = services.RequiredServices.NdmConfig;
            var configId        = ndmConfig.Id;
            var dbConfig        = services.RequiredServices.ConfigProvider.GetConfig <IDbConfig>();
            var contractAddress = string.IsNullOrWhiteSpace(ndmConfig.ContractAddress)
                ? Address.Zero
                : new Address(ndmConfig.ContractAddress);
            var rocksDbProvider = new ConsumerRocksDbProvider(services.RequiredServices.BaseDbPath, dbConfig,
                                                              logManager);
            var depositDetailsRlpDecoder  = new DepositDetailsDecoder();
            var depositApprovalRlpDecoder = new DepositApprovalDecoder();
            var receiptRlpDecoder         = new DataDeliveryReceiptDetailsDecoder();
            var sessionRlpDecoder         = new ConsumerSessionDecoder();
            var receiptRequestValidator   = new ReceiptRequestValidator(logManager);

            IDepositDetailsRepository          depositRepository;
            IConsumerDepositApprovalRepository depositApprovalRepository;
            IProviderRepository        providerRepository;
            IReceiptRepository         receiptRepository;
            IConsumerSessionRepository sessionRepository;

            switch (ndmConfig.Persistence?.ToLowerInvariant())
            {
            case "mongo":
                var database = services.RequiredServices.MongoProvider.GetDatabase();
                depositRepository         = new DepositDetailsMongoRepository(database);
                depositApprovalRepository = new ConsumerDepositApprovalMongoRepository(database);
                providerRepository        = new ProviderMongoRepository(database);
                receiptRepository         = new ReceiptMongoRepository(database, "consumerReceipts");
                sessionRepository         = new ConsumerSessionMongoRepository(database);
                break;

            case "memory":
                if (logger.IsWarn)
                {
                    logger.Warn("*** NDM is using in memory database ***");
                }
                var depositsDatabase = new DepositsInMemoryDb();
                depositRepository         = new DepositDetailsInMemoryRepository(depositsDatabase);
                depositApprovalRepository = new ConsumerDepositApprovalInMemoryRepository();
                providerRepository        = new ProviderInMemoryRepository(depositsDatabase);
                receiptRepository         = new ReceiptInMemoryRepository();
                sessionRepository         = new ConsumerSessionInMemoryRepository();
                break;

            default:
                depositRepository = new DepositDetailsRocksRepository(rocksDbProvider.DepositsDb,
                                                                      depositDetailsRlpDecoder);
                depositApprovalRepository = new ConsumerDepositApprovalRocksRepository(
                    rocksDbProvider.ConsumerDepositApprovalsDb, depositApprovalRlpDecoder);
                providerRepository = new ProviderRocksRepository(rocksDbProvider.DepositsDb,
                                                                 depositDetailsRlpDecoder);
                receiptRepository = new ReceiptRocksRepository(rocksDbProvider.ConsumerReceiptsDb,
                                                               receiptRlpDecoder);
                sessionRepository = new ConsumerSessionRocksRepository(rocksDbProvider.ConsumerSessionsDb,
                                                                       sessionRlpDecoder);
                break;
            }

            var requiredBlockConfirmations = ndmConfig.BlockConfirmations;
            var abiEncoder                = services.CreatedServices.AbiEncoder;
            var blockchainBridge          = services.CreatedServices.BlockchainBridge;
            var blockProcessor            = services.RequiredServices.BlockProcessor;
            var configManager             = services.RequiredServices.ConfigManager;
            var consumerAddress           = services.CreatedServices.ConsumerAddress;
            var cryptoRandom              = services.RequiredServices.CryptoRandom;
            var depositService            = services.CreatedServices.DepositService;
            var gasPriceService           = services.CreatedServices.GasPriceService;
            var ecdsa                     = services.RequiredServices.Ecdsa;
            var ethRequestService         = services.RequiredServices.EthRequestService;
            var jsonRpcNdmConsumerChannel = services.CreatedServices.JsonRpcNdmConsumerChannel;
            var ndmNotifier               = services.RequiredServices.Notifier;
            var nodePublicKey             = services.RequiredServices.Enode.PublicKey;
            var timestamper               = services.RequiredServices.Timestamper;
            var wallet                    = services.RequiredServices.Wallet;
            var httpClient                = services.RequiredServices.HttpClient;
            var jsonRpcClientProxy        = services.RequiredServices.JsonRpcClientProxy;
            var ethJsonRpcClientProxy     = services.RequiredServices.EthJsonRpcClientProxy;
            var transactionService        = services.CreatedServices.TransactionService;
            var monitoringService         = services.RequiredServices.MonitoringService;

            monitoringService?.RegisterMetrics(typeof(Metrics));

            var dataRequestFactory     = new DataRequestFactory(wallet, nodePublicKey);
            var transactionVerifier    = new TransactionVerifier(blockchainBridge, requiredBlockConfirmations);
            var depositUnitsCalculator = new DepositUnitsCalculator(sessionRepository, timestamper);
            var depositProvider        = new DepositProvider(depositRepository, depositUnitsCalculator, logManager);
            var kycVerifier            = new KycVerifier(depositApprovalRepository, logManager);
            var consumerNotifier       = new ConsumerNotifier(ndmNotifier);

            var dataAssetService   = new DataAssetService(providerRepository, consumerNotifier, logManager);
            var providerService    = new ProviderService(providerRepository, consumerNotifier, logManager);
            var dataRequestService = new DataRequestService(dataRequestFactory, depositProvider, kycVerifier, wallet,
                                                            providerService, timestamper, sessionRepository, consumerNotifier, logManager);

            var sessionService = new SessionService(providerService, depositProvider, dataAssetService,
                                                    sessionRepository, timestamper, consumerNotifier, logManager);
            var dataConsumerService = new DataConsumerService(depositProvider, sessionService,
                                                              consumerNotifier, timestamper, sessionRepository, logManager);
            var dataStreamService = new DataStreamService(dataAssetService, depositProvider,
                                                          providerService, sessionService, wallet, consumerNotifier, sessionRepository, logManager);
            var depositApprovalService = new DepositApprovalService(dataAssetService, providerService,
                                                                    depositApprovalRepository, timestamper, consumerNotifier, logManager);
            var depositConfirmationService = new DepositConfirmationService(blockchainBridge, consumerNotifier,
                                                                            depositRepository, depositService, logManager, requiredBlockConfirmations);

            IDepositManager depositManager = new DepositManager(depositService, depositUnitsCalculator,
                                                                dataAssetService, kycVerifier, providerService, abiEncoder, cryptoRandom, wallet, gasPriceService,
                                                                depositRepository, timestamper, logManager, requiredBlockConfirmations,
                                                                disableSendingDepositTransaction);

            if (instantDepositVerificationEnabled)
            {
                depositManager = new InstantDepositManager(depositManager, depositRepository, timestamper, logManager,
                                                           requiredBlockConfirmations);
            }

            var depositReportService = new DepositReportService(depositRepository, receiptRepository, sessionRepository,
                                                                timestamper);
            var receiptService = new ReceiptService(depositProvider, providerService, receiptRequestValidator,
                                                    sessionService, timestamper, receiptRepository, sessionRepository, abiEncoder, wallet, ecdsa,
                                                    nodePublicKey, logManager);
            var refundService = new RefundService(blockchainBridge, abiEncoder, wallet, depositRepository,
                                                  contractAddress, logManager);
            var refundClaimant = new RefundClaimant(refundService, blockchainBridge, depositRepository,
                                                    transactionVerifier, gasPriceService, timestamper, logManager);
            var accountService = new AccountService(configManager, dataStreamService, providerService,
                                                    sessionService, consumerNotifier, wallet, configId, consumerAddress, logManager);
            var proxyService    = new ProxyService(jsonRpcClientProxy, configManager, configId, logManager);
            var consumerService = new ConsumerService(accountService, dataAssetService, dataRequestService,
                                                      dataConsumerService, dataStreamService, depositManager, depositApprovalService, providerService,
                                                      receiptService, refundService, sessionService, proxyService);
            var ethPriceService             = new EthPriceService(httpClient, timestamper, logManager);
            var consumerTransactionsService = new ConsumerTransactionsService(transactionService, depositRepository,
                                                                              timestamper, logManager);
            var gasLimitService = new ConsumerGasLimitsService(depositService, refundService);

            IPersonalBridge personalBridge = services.RequiredServices.EnableUnsecuredDevWallet
                ? new PersonalBridge(ecdsa, wallet)
                : null;

            services.RequiredServices.RpcModuleProvider.Register(
                new SingletonModulePool <INdmRpcConsumerModule>(new NdmRpcConsumerModule(consumerService,
                                                                                         depositReportService, jsonRpcNdmConsumerChannel, ethRequestService, ethPriceService,
                                                                                         gasPriceService, consumerTransactionsService, gasLimitService, personalBridge, timestamper), true));

            if (!backgroundServicesDisabled)
            {
                var useDepositTimer = ndmConfig.ProxyEnabled;
                var consumerServicesBackgroundProcessor = new ConsumerServicesBackgroundProcessor(accountService,
                                                                                                  refundClaimant, depositConfirmationService, ethPriceService, gasPriceService, blockProcessor,
                                                                                                  depositRepository, consumerNotifier, logManager, useDepositTimer, ethJsonRpcClientProxy);
                consumerServicesBackgroundProcessor.Init();
            }

            return(new NdmConsumerServices(accountService, consumerService));
        }
Exemplo n.º 3
0
        public INdmConsumerServices Init(INdmServices services)
        {
            AddDecoders();
            var ndmConfig       = services.RequiredServices.NdmConfig;
            var configId        = ndmConfig.Id;
            var dbConfig        = services.RequiredServices.ConfigProvider.GetConfig <IDbConfig>();
            var contractAddress = string.IsNullOrWhiteSpace(ndmConfig.ContractAddress)
                ? Address.Zero
                : new Address(ndmConfig.ContractAddress);
            var logManager      = services.RequiredServices.LogManager;
            var rocksDbProvider = new ConsumerRocksDbProvider(services.RequiredServices.BaseDbPath, dbConfig,
                                                              logManager);
            var depositDetailsRlpDecoder  = new DepositDetailsDecoder();
            var depositApprovalRlpDecoder = new DepositApprovalDecoder();
            var receiptRlpDecoder         = new DataDeliveryReceiptDetailsDecoder();
            var sessionRlpDecoder         = new ConsumerSessionDecoder();
            var receiptRequestValidator   = new ReceiptRequestValidator(logManager);

            IDepositDetailsRepository          depositRepository;
            IConsumerDepositApprovalRepository depositApprovalRepository;
            IProviderRepository        providerRepository;
            IReceiptRepository         receiptRepository;
            IConsumerSessionRepository sessionRepository;

            switch (ndmConfig.Persistence?.ToLowerInvariant())
            {
            case "mongo":
                var database = services.RequiredServices.MongoProvider.GetDatabase();
                depositRepository         = new DepositDetailsMongoRepository(database);
                depositApprovalRepository = new ConsumerDepositApprovalMongoRepository(database);
                providerRepository        = new ProviderMongoRepository(database);
                receiptRepository         = new ReceiptMongoRepository(database, "consumerReceipts");
                sessionRepository         = new ConsumerSessionMongoRepository(database);
                break;

            default:
                depositRepository = new DepositDetailsRocksRepository(rocksDbProvider.DepositsDb,
                                                                      depositDetailsRlpDecoder);
                depositApprovalRepository = new ConsumerDepositApprovalRocksRepository(

                    rocksDbProvider.ConsumerDepositApprovalsDb, depositApprovalRlpDecoder);
                providerRepository = new ProviderRocksRepository(rocksDbProvider.DepositsDb,
                                                                 depositDetailsRlpDecoder);
                receiptRepository = new ReceiptRocksRepository(rocksDbProvider.ConsumerReceiptsDb,
                                                               receiptRlpDecoder);
                sessionRepository = new ConsumerSessionRocksRepository(rocksDbProvider.ConsumerSessionsDb,
                                                                       sessionRlpDecoder);
                break;
            }

            var requiredBlockConfirmations = ndmConfig.BlockConfirmations;
            var abiEncoder                = services.CreatedServices.AbiEncoder;
            var blockchainBridge          = services.CreatedServices.BlockchainBridge;
            var blockProcessor            = services.RequiredServices.BlockProcessor;
            var configManager             = services.RequiredServices.ConfigManager;
            var consumerAddress           = services.CreatedServices.ConsumerAddress;
            var cryptoRandom              = services.RequiredServices.CryptoRandom;
            var depositService            = services.CreatedServices.DepositService;
            var gasPriceService           = services.CreatedServices.GasPriceService;
            var ecdsa                     = services.RequiredServices.Ecdsa;
            var ethRequestService         = services.RequiredServices.EthRequestService;
            var jsonRpcNdmConsumerChannel = services.CreatedServices.JsonRpcNdmConsumerChannel;
            var ndmNotifier               = services.RequiredServices.Notifier;
            var nodePublicKey             = services.RequiredServices.Enode.PublicKey;
            var timestamper               = services.RequiredServices.Timestamper;
            var wallet                    = services.RequiredServices.Wallet;
            var httpClient                = services.RequiredServices.HttpClient;
            var jsonRpcClientProxy        = services.RequiredServices.JsonRpcClientProxy;
            var ethJsonRpcClientProxy     = services.RequiredServices.EthJsonRpcClientProxy;
            var transactionService        = services.CreatedServices.TransactionService;

            var dataRequestFactory     = new DataRequestFactory(wallet, nodePublicKey);
            var transactionVerifier    = new TransactionVerifier(blockchainBridge, requiredBlockConfirmations);
            var depositUnitsCalculator = new DepositUnitsCalculator(sessionRepository, timestamper);
            var depositProvider        = new DepositProvider(depositRepository, depositUnitsCalculator, logManager);
            var kycVerifier            = new KycVerifier(depositApprovalRepository, logManager);
            var consumerNotifier       = new ConsumerNotifier(ndmNotifier);

            var dataAssetService   = new DataAssetService(providerRepository, consumerNotifier, logManager);
            var providerService    = new ProviderService(providerRepository, consumerNotifier, logManager);
            var dataRequestService = new DataRequestService(dataRequestFactory, depositProvider, kycVerifier, wallet,
                                                            providerService, timestamper, sessionRepository, consumerNotifier, logManager);

            var sessionService = new SessionService(providerService, depositProvider, dataAssetService,
                                                    sessionRepository, timestamper, consumerNotifier, logManager);
            var dataConsumerService = new DataConsumerService(depositProvider, sessionService,
                                                              consumerNotifier, timestamper, sessionRepository, logManager);
            var dataStreamService = new DataStreamService(dataAssetService, depositProvider,
                                                          providerService, sessionService, wallet, consumerNotifier, sessionRepository, logManager);
            var depositApprovalService = new DepositApprovalService(dataAssetService, providerService,
                                                                    depositApprovalRepository, timestamper, consumerNotifier, logManager);
            var depositConfirmationService = new DepositConfirmationService(blockchainBridge, consumerNotifier,
                                                                            depositRepository, depositService, logManager, requiredBlockConfirmations);
            var depositManager = new DepositManager(depositService, depositUnitsCalculator, dataAssetService,
                                                    kycVerifier, providerService, abiEncoder, cryptoRandom, wallet, gasPriceService, depositRepository,
                                                    timestamper, logManager, requiredBlockConfirmations);
            var depositReportService = new DepositReportService(depositRepository, receiptRepository, sessionRepository,
                                                                timestamper);
            var receiptService = new ReceiptService(depositProvider, providerService, receiptRequestValidator,
                                                    sessionService, timestamper, receiptRepository, sessionRepository, abiEncoder, wallet, ecdsa,
                                                    nodePublicKey, logManager);
            var refundService = new RefundService(blockchainBridge, abiEncoder, wallet, depositRepository,
                                                  contractAddress, logManager);
            var refundClaimant = new RefundClaimant(refundService, blockchainBridge, depositRepository,
                                                    transactionVerifier, gasPriceService, timestamper, logManager);
            var accountService = new AccountService(configManager, dataStreamService, providerService,
                                                    sessionService, consumerNotifier, wallet, configId, consumerAddress, logManager);
            var proxyService    = new ProxyService(jsonRpcClientProxy, configManager, configId, logManager);
            var consumerService = new ConsumerService(accountService, dataAssetService, dataRequestService,
                                                      dataConsumerService, dataStreamService, depositManager, depositApprovalService, providerService,
                                                      receiptService, refundService, sessionService, proxyService);
            var ethPriceService             = new EthPriceService(httpClient, timestamper, logManager);
            var consumerTransactionsService = new ConsumerTransactionsService(transactionService, depositRepository,
                                                                              timestamper, logManager);

            IPersonalBridge personalBridge = services.RequiredServices.EnableUnsecuredDevWallet
                ? new PersonalBridge(ecdsa, wallet)
                : null;

            services.RequiredServices.RpcModuleProvider.Register(
                new SingletonModulePool <INdmRpcConsumerModule>(new NdmRpcConsumerModule(consumerService,
                                                                                         depositReportService, jsonRpcNdmConsumerChannel, ethRequestService, ethPriceService,
                                                                                         gasPriceService, consumerTransactionsService, personalBridge, timestamper), true));

            var useDepositTimer = ndmConfig.ProxyEnabled;
            var consumerServicesBackgroundProcessor = new ConsumerServicesBackgroundProcessor(accountService,
                                                                                              refundClaimant, depositConfirmationService, ethPriceService, gasPriceService, blockProcessor,
                                                                                              depositRepository, consumerNotifier, logManager, useDepositTimer: useDepositTimer,
                                                                                              ethJsonRpcClientProxy: ethJsonRpcClientProxy);

            consumerServicesBackgroundProcessor.Init();

            return(new NdmConsumerServices(accountService, consumerService));
        }