public async Task given_store_config_in_database_equal_false_default_config_should_be_returned() { _defaultConfig.StoreConfigInDatabase = false; var config = await _configManager.GetAsync(_configId); config.Should().Be(_defaultConfig); }
public async Task <CanceledTransactionInfo> CancelAsync(Keccak transactionHash) { NdmConfig?config = await _configManager.GetAsync(_configId); uint multiplier = config?.CancelTransactionGasPricePercentageMultiplier ?? 0; if (multiplier == 0) { throw new InvalidOperationException("Multiplier for gas price when canceling transaction cannot be 0."); } const long gasLimit = Transaction.BaseTxGasCost; UInt256 gasPrice = 0; var hash = await UpdateAsync(transactionHash, transaction => { gasPrice = new UInt256(multiplier * (BigInteger)transaction.GasPrice / 100); transaction.GasPrice = gasPrice; transaction.GasLimit = gasLimit; transaction.Data = null; transaction.Init = null; transaction.Value = 0; if (_logger.IsInfo) { _logger.Info($"Canceling transaction with hash: '{transactionHash}', gas price: {gasPrice} wei ({multiplier}% of original transaction)."); } }); return(new CanceledTransactionInfo(hash, gasPrice, gasLimit)); }
public async Task ChangeAddressAsync(Address address) { if (_consumerAddress == address) { return; } var previousAddress = _consumerAddress; if (_logger.IsInfo) { _logger.Info($"Changing consumer address: '{previousAddress}' -> '{address}'..."); } _consumerAddress = address; AddressChanged?.Invoke(this, new AddressChangedEventArgs(previousAddress, _consumerAddress)); var config = await _configManager.GetAsync(_configId); config.ConsumerAddress = _consumerAddress.ToString(); await _configManager.UpdateAsync(config); foreach (var provider in _providerService.GetPeers()) { provider.ChangeHostConsumerAddress(_consumerAddress); provider.SendConsumerAddressChanged(_consumerAddress); await _sessionService.FinishSessionsAsync(provider, false); } await _consumerNotifier.SendConsumerAddressChangedAsync(address, previousAddress); if (_logger.IsInfo) { _logger.Info($"Changed consumer address: '{previousAddress}' -> '{address}'."); } }
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>(); _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); }
public void Setup() { _client = Substitute.For <IHttpClient>(); _configManager = Substitute.For <IConfigManager>(); _config = new NdmConfig(); _configManager.GetAsync(ConfigId).Returns(_config); _timestamper = new Timestamper(DateTime.UtcNow); _gasPriceService = new GasPriceService(_client, _configManager, ConfigId, _timestamper, LimboLogs.Instance); }
public void Setup() { _receiptRequestThreshold = 10000000000000000; _receiptsMergeThreshold = 100000000000000000; _paymentClaimThreshold = 1000000000000000000; _configManager = Substitute.For <IConfigManager>(); _config = new NdmConfig(); _logManager = LimboLogs.Instance; _configManager.GetAsync(ConfigId).Returns(_config); _providerThresholdsService = new ProviderThresholdsService(_configManager, ConfigId, _logManager); }
public void Setup() { IConfigManager configManager = Substitute.For <IConfigManager>(); configManager.GetAsync(null).ReturnsForAnyArgs(new NdmConfig()); IDataStreamService dataStreamService = Substitute.For <IDataStreamService>(); _providerService = Substitute.For <IProviderService>(); ISessionService sessionService = Substitute.For <ISessionService>(); _ndmNotifier = Substitute.For <INdmNotifier>(); IConsumerNotifier consumerNotifier = new ConsumerNotifier(_ndmNotifier); _wallet = new DevWallet(new WalletConfig(), LimboLogs.Instance); _consumerAddress = _wallet.GetAccounts()[0]; _accountService = new AccountService(configManager, dataStreamService, _providerService, sessionService, consumerNotifier, _wallet, "configId", _consumerAddress, LimboLogs.Instance); }
public Task <Keccak> CancelAsync(Keccak transactionHash) => UpdateAsync(transactionHash, async transaction => { var config = await _configManager.GetAsync(_configId); var multiplier = config.CancelTransactionGasPricePercentageMultiplier; if (multiplier == 0) { throw new InvalidOperationException("Multiplier for gas price when canceling transaction cannot be 0."); } var gasPrice = multiplier * (BigInteger)transaction.GasPrice / 100; transaction.GasPrice = new UInt256(gasPrice); transaction.Value = 0; if (_logger.IsInfo) { _logger.Info($"Canceling transaction with hash: '{transactionHash}', gas price: {gasPrice} wei ({multiplier}% of original transaction)."); } });
public async Task <UInt256> GetCurrentAsync() { var config = await _configManager.GetAsync(_configId); return(config.GasPrice); }
public async Task <NdmProxy?> GetAsync() { NdmConfig?config = await _configManager.GetAsync(_configId); return(new NdmProxy(config?.ProxyEnabled ?? false, config?.JsonRpcUrlProxies ?? Enumerable.Empty <string>())); }
public async Task <UInt256> GetCurrentAsync() { NdmConfig?config = await _configManager.GetAsync(_configId); return(config?.GasPrice ?? 20.GWei()); }
public async Task <UInt256> GetCurrentReceiptRequestAsync() { NdmConfig?config = await _configManager.GetAsync(_configId); return(config?.ReceiptRequestThreshold ?? 10000000000000000); }
public async Task <NdmProxy> GetAsync() { var config = await _configManager.GetAsync(_configId); return(new NdmProxy(config.ProxyEnabled, config.JsonRpcUrlProxies)); }