Ejemplo n.º 1
0
 public NdmRpcConsumerModule(
     IConsumerService consumerService,
     IDepositReportService depositReportService,
     IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
     IEthRequestService ethRequestService,
     IEthPriceService ethPriceService,
     IDaiPriceService daiPriceService,
     IGasPriceService gasPriceService,
     IConsumerTransactionsService transactionsService,
     IConsumerGasLimitsService gasLimitsService,
     IWallet personalBridge,
     ITimestamper timestamper)
 {
     _consumerService           = consumerService ?? throw new ArgumentNullException(nameof(consumerService));
     _depositReportService      = depositReportService ?? throw new ArgumentNullException(nameof(depositReportService));
     _jsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel ?? throw new ArgumentNullException(nameof(jsonRpcNdmConsumerChannel));
     _ethRequestService         = ethRequestService ?? throw new ArgumentNullException(nameof(ethRequestService));
     _ethPriceService           = ethPriceService ?? throw new ArgumentNullException(nameof(ethPriceService));
     _daiPriceService           = daiPriceService ?? throw new ArgumentNullException(nameof(daiPriceService));
     _gasPriceService           = gasPriceService ?? throw new ArgumentNullException(nameof(gasPriceService));
     _transactionsService       = transactionsService ?? throw new ArgumentNullException(nameof(transactionsService));
     _gasLimitsService          = gasLimitsService ?? throw new ArgumentNullException(nameof(gasLimitsService));
     _wallet      = personalBridge ?? throw new ArgumentNullException(nameof(personalBridge));
     _timestamper = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
 }
 public NdmRpcConsumerModule(IConsumerService consumerService, IReportService reportService,
                             IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel, IEthRequestService ethRequestService,
                             IPersonalBridge personalBridge, ILogManager logManager)
     : base(logManager)
 {
     _consumerService           = consumerService;
     _reportService             = reportService;
     _jsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     _ethRequestService         = ethRequestService;
     _personalBridge            = personalBridge;
 }
 public void Setup()
 {
     _consumerService           = Substitute.For <IConsumerService>();
     _depositReportService      = Substitute.For <IDepositReportService>();
     _jsonRpcNdmConsumerChannel = Substitute.For <IJsonRpcNdmConsumerChannel>();
     _ethRequestService         = Substitute.For <IEthRequestService>();
     _personalBridge            = Substitute.For <IPersonalBridge>();
     _timestamper = new Timestamper(Date);
     _rpc         = new NdmRpcConsumerModule(_consumerService, _depositReportService, _jsonRpcNdmConsumerChannel,
                                             _ethRequestService, _personalBridge, _timestamper);
 }
Ejemplo n.º 4
0
 public NdmRpcConsumerModule(IConsumerService consumerService, IDepositReportService depositReportService,
                             IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel, IEthRequestService ethRequestService,
                             IPersonalBridge personalBridge, ITimestamper timestamper)
 {
     _consumerService           = consumerService;
     _depositReportService      = depositReportService;
     _jsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     _ethRequestService         = ethRequestService;
     _personalBridge            = personalBridge;
     _timestamper = timestamper;
 }
Ejemplo n.º 5
0
 public CreatedServices(Address consumerAddress,
                        IAbiEncoder abiEncoder, IRlpDecoder <DataHeader> dataHeaderRlpDecoder, IDepositService depositService,
                        INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                        INdmConsumerChannelManager ndmConsumerChannelManager, IBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataHeaderRlpDecoder      = dataHeaderRlpDecoder;
     DepositService            = depositService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
 }
 public void Setup()
 {
     _consumerService             = Substitute.For <IConsumerService>();
     _depositReportService        = Substitute.For <IDepositReportService>();
     _jsonRpcNdmConsumerChannel   = Substitute.For <IJsonRpcNdmConsumerChannel>();
     _ethRequestService           = Substitute.For <IEthRequestService>();
     _ethPriceService             = Substitute.For <IEthPriceService>();
     _gasPriceService             = Substitute.For <IGasPriceService>();
     _gasLimitsService            = Substitute.For <IConsumerGasLimitsService>();
     _consumerTransactionsService = Substitute.For <IConsumerTransactionsService>();
     _wallet      = Substitute.For <IWallet>();
     _timestamper = new Timestamper(Date);
     _rpc         = new NdmRpcConsumerModule(_consumerService, _depositReportService, _jsonRpcNdmConsumerChannel,
                                             _ethRequestService, _ethPriceService, _gasPriceService, _consumerTransactionsService, _gasLimitsService,
                                             _wallet, _timestamper);
 }
Ejemplo n.º 7
0
 public NdmCreatedServices(Address consumerAddress,
                           IAbiEncoder abiEncoder, IRlpDecoder <DataAsset> dataAssetRlpDecoder, IDepositService depositService,
                           INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                           INdmConsumerChannelManager ndmConsumerChannelManager, INdmBlockchainBridge blockchainBridge,
                           IEthJsonRpcClientProxy ethJsonRpcClientProxy)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataAssetRlpDecoder       = dataAssetRlpDecoder;
     DepositService            = depositService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
     EthJsonRpcClientProxy     = ethJsonRpcClientProxy;
 }
Ejemplo n.º 8
0
 public NdmCreatedServices(Address consumerAddress,
                           IAbiEncoder abiEncoder, IRlpDecoder <DataAsset> dataAssetRlpDecoder, IDepositService depositService,
                           GasPriceService gasPriceService, TransactionService transactionService,
                           INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                           INdmConsumerChannelManager ndmConsumerChannelManager, INdmBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataAssetRlpDecoder       = dataAssetRlpDecoder;
     DepositService            = depositService;
     GasPriceService           = gasPriceService;
     TransactionService        = transactionService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
 }
Ejemplo n.º 9
0
 public NdmRpcConsumerModule(IConsumerService consumerService, IDepositReportService depositReportService,
                             IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel, IEthRequestService ethRequestService,
                             IEthPriceService ethPriceService, IGasPriceService gasPriceService,
                             IConsumerTransactionsService transactionsService, IConsumerGasLimitsService gasLimitsService,
                             IPersonalBridge personalBridge, ITimestamper timestamper)
 {
     _consumerService           = consumerService;
     _depositReportService      = depositReportService;
     _jsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     _ethRequestService         = ethRequestService;
     _ethPriceService           = ethPriceService;
     _gasPriceService           = gasPriceService;
     _transactionsService       = transactionsService;
     _gasLimitsService          = gasLimitsService;
     _personalBridge            = personalBridge;
     _timestamper = timestamper;
 }
Ejemplo n.º 10
0
 public NdmCreatedServices(
     Address consumerAddress,
     IAbiEncoder abiEncoder,
     IRlpDecoder <DataAsset> dataAssetRlpDecoder,
     IDepositService depositService,
     GasPriceService gasPriceService,
     TransactionService transactionService,
     INdmDataPublisher ndmDataPublisher,
     IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
     INdmConsumerChannelManager ndmConsumerChannelManager,
     INdmBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress ?? throw new ArgumentNullException(nameof(consumerAddress));
     AbiEncoder                = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     DataAssetRlpDecoder       = dataAssetRlpDecoder ?? throw new ArgumentNullException(nameof(dataAssetRlpDecoder));
     DepositService            = depositService ?? throw new ArgumentNullException(nameof(depositService));
     GasPriceService           = gasPriceService ?? throw new ArgumentNullException(nameof(gasPriceService));
     TransactionService        = transactionService ?? throw new ArgumentNullException(nameof(transactionService));
     NdmDataPublisher          = ndmDataPublisher ?? throw new ArgumentNullException(nameof(ndmDataPublisher));
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel ?? throw new ArgumentNullException(nameof(jsonRpcNdmConsumerChannel));
     NdmConsumerChannelManager = ndmConsumerChannelManager ?? throw new ArgumentNullException(nameof(ndmConsumerChannelManager));
     BlockchainBridge          = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
 }
Ejemplo n.º 11
0
        public async Task Init()
        {
            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);
            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;
            IDepositUnitsCalculator    depositUnitsCalculator;

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

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

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

            default:
                var dbInitializer = new ConsumerNdmDbInitializer(_api.DbProvider, ndmConfig, _api.RocksDbFactory, _api.MemDbFactory);
                await dbInitializer.InitAsync();

                sessionRepository = new ConsumerSessionRocksRepository(_api.Db <IDb>(ConsumerNdmDbNames.ConsumerSessions),
                                                                       sessionRlpDecoder);
                depositUnitsCalculator = new DepositUnitsCalculator(sessionRepository, _api.Timestamper);
                depositRepository      = new DepositDetailsRocksRepository(_api.Db <IDb>(ConsumerNdmDbNames.Deposits),
                                                                           depositDetailsRlpDecoder, depositUnitsCalculator);
                depositApprovalRepository = new ConsumerDepositApprovalRocksRepository(
                    _api.Db <IDb>(ConsumerNdmDbNames.ConsumerDepositApprovals), depositApprovalRlpDecoder);
                providerRepository = new ProviderRocksRepository(_api.Db <IDb>(ConsumerNdmDbNames.Deposits),
                                                                 depositDetailsRlpDecoder);
                receiptRepository = new ReceiptRocksRepository(_api.Db <IDb>(ConsumerNdmDbNames.ConsumerReceipts),
                                                               receiptRlpDecoder);

                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 = _api.GasPriceService;
            IEthereumEcdsa ecdsa = _api.EthereumEcdsa;

            ethRequestService         = _api.EthRequestService;
            jsonRpcNdmConsumerChannel = _api.JsonRpcNdmConsumerChannel;
            INdmNotifier ndmNotifier   = _api.NdmNotifier;
            PublicKey    nodePublicKey = _api.Enode.PublicKey;

            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;
            IWebSocketsModule      ndmWebSocketsModule   = _api.WebSocketsManager.GetModule("ndm");

            monitoringService?.RegisterMetrics(typeof(Metrics));

            DataRequestFactory  dataRequestFactory  = new DataRequestFactory(wallet, nodePublicKey);
            TransactionVerifier transactionVerifier = new TransactionVerifier(blockchainBridge, requiredBlockConfirmations);
            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 = new DepositReportService(depositRepository, depositUnitsCalculator, 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, wallet);
            RefundClaimant refundClaimant = new RefundClaimant(refundService, blockchainBridge, depositRepository,
                                                               transactionVerifier, gasPriceService, timestamper, logManager);

            _api.AccountService = new AccountService(configManager, dataStreamService, providerService,
                                                     sessionService, consumerNotifier, wallet, configId, consumerAddress, logManager);
            _api.NdmAccountUpdater = new NdmAccountUpdater(ndmWebSocketsModule, consumerAddress, _api.MainBlockProcessor, _api.ChainHeadStateProvider);
            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             = new EthPriceService(httpClient, timestamper, logManager);
            daiPriceService             = new DaiPriceService(httpClient, timestamper, logManager);
            consumerTransactionsService = new ConsumerTransactionsService(transactionService, depositRepository,
                                                                          timestamper, logManager);
            gasLimitsService = new ConsumerGasLimitsService(depositService, refundService);

            if (!backgroundServicesDisabled)
            {
                bool useDepositTimer = ndmConfig.ProxyEnabled;
                ConsumerServicesBackgroundProcessor consumerServicesBackgroundProcessor =
                    new ConsumerServicesBackgroundProcessor(
                        _api.AccountService,
                        refundClaimant,
                        depositConfirmationService,
                        ethPriceService,
                        daiPriceService,
                        _api.GasPriceService,
                        _api.MainBlockProcessor,
                        depositRepository,
                        consumerNotifier,
                        logManager,
                        useDepositTimer,
                        ethJsonRpcClientProxy);
                consumerServicesBackgroundProcessor.Init();
            }
        }