Exemple #1
0
        protected async Task Prepare()
        {
            _wallet          = new DevWallet(new WalletConfig(), _logManager);
            _feeAccount      = _wallet.GetAccounts()[0];
            _consumerAccount = _wallet.GetAccounts()[1];
            _providerAccount = _wallet.GetAccounts()[2];
            _ndmConfig       = new NdmConfig();

            IReleaseSpec  spec         = _releaseSpec;
            ISpecProvider specProvider = new SingleReleaseSpecProvider(spec, 99);
            StateDb       stateDb      = new StateDb();

            _state = new StateProvider(stateDb, new StateDb(), _logManager);
            StorageProvider storageProvider = new StorageProvider(stateDb, _state, _logManager);

            _state.CreateAccount(_consumerAccount, 1000.Ether());
            _state.CreateAccount(_providerAccount, 1.Ether());
            _state.Commit(spec);
            _state.CommitTree();

            VirtualMachine machine = new VirtualMachine(_state, storageProvider, Substitute.For <IBlockhashProvider>(),
                                                        specProvider, _logManager);
            TransactionProcessor processor = new TransactionProcessor(specProvider, _state, storageProvider, machine, _logManager);

            _bridge = new BlockchainBridge(processor);

            TxReceipt receipt = await DeployContract(Bytes.FromHexString(ContractData.GetInitCode(_feeAccount)));

            ((NdmConfig)_ndmConfig).ContractAddress = receipt.ContractAddress.ToString();
            _contractAddress = receipt.ContractAddress;
            _txPool          = new TxPool.TxPool(new InMemoryTxStorage(),
                                                 new EthereumEcdsa(specProvider.ChainId, _logManager), specProvider, new TxPoolConfig(), _state, _logManager);
            _ndmBridge = new NdmBlockchainBridge(_bridge, _bridge, _bridge, _bridge);
        }
 public DepositService(INdmBlockchainBridge blockchainBridge, IAbiEncoder abiEncoder, IWallet wallet,
                       Address contractAddress)
 {
     _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
     _abiEncoder       = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     _wallet           = wallet ?? throw new ArgumentNullException(nameof(wallet));
     _contractAddress  = contractAddress ?? throw new ArgumentNullException(nameof(contractAddress));
 }
Exemple #3
0
 public void Setup()
 {
     _blockchainBridge = Substitute.For <IBlockchainBridge>();
     _txPoolBridge     = Substitute.For <ITxPoolBridge>();
     _txPoolBridge     = Substitute.For <ITxPoolBridge>();
     _txPool           = Substitute.For <ITxPool>();
     _ndmBridge        = new NdmBlockchainBridge(_txPoolBridge, _blockchainBridge, _txPool);
 }
 public TransactionService(INdmBlockchainBridge blockchainBridge, IWallet wallet, IConfigManager configManager,
                           string configId, ILogManager logManager)
 {
     _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
     _wallet           = wallet ?? throw new ArgumentNullException(nameof(wallet));
     _configManager    = configManager ?? throw new ArgumentNullException(nameof(configManager));
     _configId         = configId ?? throw new ArgumentNullException(nameof(configId));
     _logger           = logManager.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
 }
 public RefundService(INdmBlockchainBridge blockchainBridge, IAbiEncoder abiEncoder,
                      IDepositDetailsRepository depositRepository, Address contractAddress, ILogManager logManager)
 {
     _blockchainBridge  = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
     _abiEncoder        = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     _depositRepository = depositRepository;
     _contractAddress   = contractAddress ?? throw new ArgumentNullException(nameof(contractAddress));
     _logger            = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
 }
Exemple #6
0
        public void Setup()
        {
            _blockchainBridge = Substitute.For <IBlockchainBridge>();
            _txPool           = Substitute.For <ITxPool>();
            _blockFinder      = Substitute.For <IBlockFinder>();
            _stateReader      = Substitute.For <IStateReader>();
            _txSender         = Substitute.For <ITxSender>();

            _ndmBridge = new NdmBlockchainBridge(_blockchainBridge, _blockFinder, _stateReader, _txSender);
        }
 public void Setup()
 {
     _blockchainBridge = Substitute.For <INdmBlockchainBridge>();
     _wallet           = Substitute.For <IWallet>();
     _wallet.Sign(Arg.Any <Keccak>(), Arg.Any <Address>()).Returns(new Signature(new byte[65]));
     _configManager = Substitute.For <IConfigManager>();
     _config        = new NdmConfig();
     _configManager.GetAsync(ConfigId).Returns(_config);
     _transactionService = new TransactionService(_blockchainBridge, _wallet, _configManager, ConfigId, LimboLogs.Instance);
 }
 public void Setup()
 {
     _blockchainBridge           = Substitute.For <INdmBlockchainBridge>();
     _consumerNotifier           = Substitute.For <IConsumerNotifier>();
     _depositRepository          = Substitute.For <IDepositDetailsRepository>();
     _depositService             = Substitute.For <IDepositService>();
     _requiredBlockConfirmations = 2;
     _depositConfirmationService = new DepositConfirmationService(_blockchainBridge, _consumerNotifier,
                                                                  _depositRepository, _depositService, LimboLogs.Instance, _requiredBlockConfirmations);
 }
Exemple #9
0
 public PaymentService(INdmBlockchainBridge bridge, IAbiEncoder abiEncoder, IWallet wallet,
                       Address contractAddress, ILogManager logManager, ITxPool txPool)
 {
     _bridge          = bridge ?? throw new ArgumentNullException(nameof(bridge));
     _abiEncoder      = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
     _wallet          = wallet ?? throw new ArgumentNullException(nameof(abiEncoder));
     _contractAddress = contractAddress ?? throw new ArgumentNullException(nameof(contractAddress));
     _logger          = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _txPool          = txPool ?? throw new ArgumentNullException(nameof(txPool));
 }
Exemple #10
0
 public void Setup()
 {
     _blockchainBridge = Substitute.For <INdmBlockchainBridge>();
     _wallet           = Substitute.For <IWallet>();
     _configManager    = Substitute.For <IConfigManager>();
     _config           = new NdmConfig();
     _configManager.GetAsync(ConfigId).Returns(_config);
     _transactionService = new TransactionService(_blockchainBridge, _wallet, _configManager, ConfigId,
                                                  LimboLogs.Instance);
 }
Exemple #11
0
 public DepositConfirmationService(INdmBlockchainBridge blockchainBridge, IConsumerNotifier consumerNotifier,
                                   IDepositDetailsRepository depositRepository, IDepositService depositService, ILogManager logManager,
                                   uint requiredBlockConfirmations)
 {
     _blockchainBridge           = blockchainBridge;
     _consumerNotifier           = consumerNotifier;
     _depositRepository          = depositRepository;
     _depositService             = depositService;
     _logger                     = logManager.GetClassLogger();
     _requiredBlockConfirmations = requiredBlockConfirmations;
 }
Exemple #12
0
 private void SetUpSubstitutes()
 {
     transactionVerifier               = Substitute.For <ITransactionVerifier>();
     paymentClaimProcessor             = Substitute.For <IPaymentClaimProcessor>();
     depositManager                    = Substitute.For <IDepositManager>();
     providerDepositApprovalRepository = Substitute.For <IProviderDepositApprovalRepository>();
     gasPriceService                   = Substitute.For <IGasPriceService>();
     wallet           = NullWallet.Instance;
     blockchainBridge = Substitute.For <INdmBlockchainBridge>();
     refundPolicy     = Substitute.For <IRefundPolicy>();
 }
Exemple #13
0
 public RefundClaimant(IRefundService refundService, INdmBlockchainBridge blockchainBridge,
                       IDepositDetailsRepository depositRepository, ITransactionVerifier transactionVerifier,
                       ITimestamper timestamper, ILogManager logManager)
 {
     _refundService       = refundService;
     _blockchainBridge    = blockchainBridge;
     _depositRepository   = depositRepository;
     _transactionVerifier = transactionVerifier;
     _timestamper         = timestamper;
     _logger = logManager.GetClassLogger();
 }
 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;
 }
 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;
 }
        protected async Task Prepare()
        {
            _wallet          = new DevWallet(new WalletConfig(), _logManager);
            _feeAccount      = _wallet.GetAccounts()[0];
            _consumerAccount = _wallet.GetAccounts()[1];
            _providerAccount = _wallet.GetAccounts()[2];
            _ndmConfig       = new NdmConfig();

            IReleaseSpec  spec         = _releaseSpec;
            ISpecProvider specProvider = new SingleReleaseSpecProvider(spec, 99);
            MemDb         stateDb      = new MemDb();
            TrieStore     trieStore    = new TrieStore(stateDb, _logManager);

            _state = new StateProvider(trieStore, new MemDb(), _logManager);
            StorageProvider storageProvider = new StorageProvider(trieStore, _state, _logManager);

            _state.CreateAccount(_consumerAccount, 1000.Ether());
            _state.CreateAccount(_providerAccount, 1.Ether());
            _state.Commit(spec);
            _state.CommitTree(0);

            VirtualMachine machine =
                new VirtualMachine(Substitute.For <IBlockhashProvider>(), specProvider, _logManager);
            TransactionProcessor processor = new TransactionProcessor(specProvider, _state, storageProvider, machine, _logManager);

            _bridge = new BlockchainBridge(processor);

            TxReceipt receipt = await DeployContract(Bytes.FromHexString(ContractData.GetInitCode(_feeAccount)));

            ((NdmConfig)_ndmConfig).ContractAddress = receipt.ContractAddress.ToString();
            _contractAddress = receipt.ContractAddress;
            IBlockTree blockTree = Substitute.For <IBlockTree>();
            Block      block     = Build.A.Block.WithNumber(0).TestObject;

            blockTree.Head.Returns(block);
            TransactionComparerProvider transactionComparerProvider = new TransactionComparerProvider(specProvider, blockTree);

            _txPool = new TxPool.TxPool(
                new EthereumEcdsa(specProvider.ChainId, _logManager),
                new ChainHeadInfoProvider(specProvider, blockTree, _state),
                new TxPoolConfig(),
                new TxValidator(specProvider.ChainId),
                _logManager,
                transactionComparerProvider.GetDefaultComparer());
            _ndmBridge = new NdmBlockchainBridge(_bridge, _bridge, _bridge, _bridge);
        }
Exemple #17
0
        public NdmFaucet(
            INdmBlockchainBridge?blockchainBridge,
            IEthRequestRepository?requestRepository,
            Address?faucetAddress,
            UInt256 maxValue,
            UInt256 dailyRequestsTotalValueEth,
            bool enabled,
            ITimestamper?timestamper,
            IWallet?wallet,
            ILogManager?logManager)
        {
            _blockchainBridge           = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
            _requestRepository          = requestRepository ?? throw new ArgumentNullException(nameof(requestRepository));
            _faucetAddress              = faucetAddress;
            _maxValue                   = maxValue;
            _dailyRequestsTotalValueWei = dailyRequestsTotalValueEth * 1_000_000_000_000_000_000;
            _enabled     = enabled;
            _timestamper = timestamper ?? throw new ArgumentNullException(nameof(timestamper));
            _wallet      = wallet ?? throw new ArgumentNullException(nameof(wallet));
            _today       = _timestamper.UtcNow;
            _logger      = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            if (!_enabled || _faucetAddress is null)
            {
                return;
            }

            if (_logger.IsInfo)
            {
                _logger.Info($"NDM Faucet was enabled for this host, account: {faucetAddress}, request max value: {maxValue} wei");
            }
            _requestRepository.SumDailyRequestsTotalValueAsync(_today).ContinueWith(t =>
            {
                if (t.IsFaulted && _logger.IsError)
                {
                    _logger.Error($"Error during NDM faucet today's ({_today.Date:d}) total value initialization.", t.Exception);
                    return;
                }

                _todayRequestsTotalValueWei = t.Result;
                _initialized = true;
                if (_logger.IsInfo)
                {
                    _logger.Info($"Initialized NDM faucet today's ({_today.Date:d}) total value: {_todayRequestsTotalValueWei} wei");
                }
            });
        }
        public void Setup()
        {
            DataAssetProvider provider = new DataAssetProvider(_providerAddress, "provider");

            _asset                 = new DataAsset(Keccak.Compute("1"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published);
            _closedAsset           = new DataAsset(Keccak.Compute("2"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Closed);
            _assetUnderMaintenance = new DataAsset(Keccak.Compute("3"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.UnderMaintenance);
            _withKyc               = new DataAsset(Keccak.Compute("4"), "name", "desc", 1, DataAssetUnitType.Unit, 1000, 10000, new DataAssetRules(new DataAssetRule(1)), provider, state: DataAssetState.Published, kycRequired: true);

            _deposit = new Deposit(Keccak.Zero, 1, 2, 3);
            _details = new DepositDetails(_deposit, _asset, Address.Zero, new byte[0], 1, new TransactionInfo[0]);

            INdmBlockchainBridge blockchainBridge = BlockchainBridgeBuilder.BuildABridge();

            _wallet = new DevWallet(new WalletConfig(), LimboLogs.Instance);
            DepositService             depositService     = new DepositService(blockchainBridge, new AbiEncoder(), _wallet, Address.Zero);
            IConsumerSessionRepository sessionRepository  = new ConsumerSessionInMemoryRepository();
            DepositUnitsCalculator     unitsCalculator    = new DepositUnitsCalculator(sessionRepository, Timestamper.Default);
            DepositsInMemoryDb         depositsInMemoryDb = new DepositsInMemoryDb();

            depositsInMemoryDb.Add(_details);

            IProviderRepository     providerRepository     = new ProviderInMemoryRepository(depositsInMemoryDb);
            IConsumerNotifier       notifier               = new ConsumerNotifier(Substitute.For <INdmNotifier>());
            DataAssetService        dataAssetService       = new DataAssetService(providerRepository, notifier, LimboLogs.Instance);
            IDepositUnitsCalculator depositUnitsCalculator = Substitute.For <IDepositUnitsCalculator>();
            INdmPeer peer = Substitute.For <INdmPeer>();

            peer.NodeId.Returns(TestItem.PublicKeyB);
            peer.ProviderAddress.Returns(_providerAddress);

            dataAssetService.AddDiscovered(_asset, peer);
            dataAssetService.AddDiscovered(_closedAsset, peer);
            dataAssetService.AddDiscovered(_assetUnderMaintenance, peer);
            dataAssetService.AddDiscovered(_withKyc, peer);

            _kycVerifier = Substitute.For <IKycVerifier>();
            ProviderService providerService = new ProviderService(providerRepository, notifier, LimboLogs.Instance);

            providerService.Add(peer);

            _depositManager = new DepositManager(depositService, unitsCalculator, dataAssetService, _kycVerifier, providerService, new AbiEncoder(), new CryptoRandom(), _wallet, Substitute.For <IGasPriceService>(), new DepositDetailsInMemoryRepository(depositsInMemoryDb, depositUnitsCalculator), Timestamper.Default, LimboLogs.Instance, 6, false);
        }
Exemple #19
0
 public void Setup()
 {
     _blockchainBridge = Substitute.For <INdmBlockchainBridge>();
     _repository       = Substitute.For <IEthRequestRepository>();
     _repository.SumDailyRequestsTotalValueAsync(Arg.Any <DateTime>()).ReturnsForAnyArgs(UInt256.Zero);
     _faucetAddress = Address.FromNumber(1);
     _maxValue      = 1.Ether();
     _dailyRequestsTotalValueEth = 500;
     _enabled         = true;
     _timestamper     = new Timestamper();
     _wallet          = Substitute.For <IWallet>();
     _logManager      = LimboLogs.Instance;
     _host            = "127.0.0.1";
     _address         = Address.FromNumber(2);
     _value           = 1.Ether();
     _faucetAccount   = Account.TotallyEmpty;
     _transactionHash = Keccak.Zero;
     _blockchainBridge.GetNonceAsync(_faucetAddress).Returns(UInt256.Zero);
     _blockchainBridge.SendOwnTransactionAsync(Arg.Any <Transaction>()).Returns(_transactionHash);
 }
 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));
 }
 public void Setup()
 {
     _proxy     = Substitute.For <IEthJsonRpcClientProxy>();
     _ndmBridge = new NdmBlockchainBridgeProxy(_proxy);
 }
Exemple #22
0
        public void constructor_should_throw_exception_if_tx_pool_argument_is_null()
        {
            Action act = () => _ndmBridge = new NdmBlockchainBridge(_txPoolBridge, _blockchainBridge, null);

            act.Should().Throw <ArgumentNullException>();
        }
Exemple #23
0
        public void constructor_should_throw_exception_if_txpool_bridge_argument_is_null()
        {
            Action act = () => _ndmBridge = new NdmBlockchainBridge(null, Substitute.For <IBlockchainBridge>(), _txPool);

            act.Should().Throw <ArgumentNullException>();
        }
        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();
            }
        }
Exemple #25
0
 public void Setup()
 {
     _blockchainBridge           = Substitute.For <INdmBlockchainBridge>();
     _requiredBlockConfirmations = 2;
     _transactionVerifier        = new TransactionVerifier(_blockchainBridge, _requiredBlockConfirmations);
 }
Exemple #26
0
 public TransactionVerifier(INdmBlockchainBridge blockchainBridge, uint requiredBlockConfirmations)
 {
     _blockchainBridge           = blockchainBridge;
     _requiredBlockConfirmations = requiredBlockConfirmations;
 }
        public void constructor_should_throw_exception_if_proxy_argument_is_null()
        {
            Action act = () => _ndmBridge = new NdmBlockchainBridgeProxy(null);

            act.Should().Throw <ArgumentNullException>();
        }