/// <summary> /// Constructor. /// </summary> /// <param name="transactionExecutorFactory">Transaction execution</param> /// <param name="faucetDataManager">Data manager for faucet.</param> /// <param name="ethereumAccountBalanceSource">Balance source for Ethereum/ERC20 tokens.</param> /// <param name="contractInfoRegistry">Registry of contracts.</param> /// <param name="houseFundingIpWhiteList">IP Whitelist for faucet/funding operations.</param> /// <param name="executionEnvironment">The Execution Environment.</param> /// <param name="faucetConfiguration">Faucet configuration.</param> /// <param name="ethereumAccountManager">Ethereum account manager</param> /// <param name="logger">Logging.</param> public FaucetManager(ITransactionExecutorFactory transactionExecutorFactory, IFaucetDataManager faucetDataManager, IEthereumAccountBalanceSource ethereumAccountBalanceSource, IContractInfoRegistry contractInfoRegistry, IWhiteListedIpAddressIdentifier houseFundingIpWhiteList, ExecutionEnvironment executionEnvironment, IFaucetConfiguration faucetConfiguration, IEthereumAccountManager ethereumAccountManager, ILogger <FaucetManager> logger) { if (contractInfoRegistry == null) { throw new ArgumentNullException(nameof(contractInfoRegistry)); } if (faucetConfiguration == null) { throw new ArgumentNullException(nameof(faucetConfiguration)); } this._faucetDataManager = faucetDataManager ?? throw new ArgumentNullException(nameof(faucetDataManager)); this._ethereumAccountBalanceSource = ethereumAccountBalanceSource ?? throw new ArgumentNullException(nameof(ethereumAccountBalanceSource)); this._transactionExecutorFactory = transactionExecutorFactory ?? throw new ArgumentNullException(nameof(transactionExecutorFactory)); this._fundingWhiteList = houseFundingIpWhiteList ?? throw new ArgumentNullException(nameof(houseFundingIpWhiteList)); this._executionEnvironment = executionEnvironment; this._ethereumAccountManager = ethereumAccountManager ?? throw new ArgumentNullException(nameof(ethereumAccountManager)); this._nativeCurrencyLimits = new Limits <EthereumAmount>(amountToIssue: faucetConfiguration.NativeCurrencyToGive, faucetConfiguration.NativeCurrencyToGive / 2); this._tokenCurrencyLimits = new Limits <Token>(amountToIssue: faucetConfiguration.TokenToGive, faucetConfiguration.TokenToGive / 2); this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._tokenContract = (Erc20TokenContractInfo)contractInfoRegistry.FindContractInfo(WellKnownContracts.Token); this._faucetContract = contractInfoRegistry.FindContractInfo(WellKnownContracts.Faucet); }
private static void RegisterFaucet(IServiceCollection services, IFaucetConfiguration faucetConfiguration, IFaucetBalanceConfiguration faucetBalanceConfiguration, IHouseBalanceConfiguration houseAlerterConfiguration) { services.AddSingleton <IFaucetManager, FaucetManager>(); services.AddSingleton(faucetConfiguration); services.AddSingleton(faucetBalanceConfiguration); services.AddSingleton(houseAlerterConfiguration); }
/// <summary> /// Configures the Server logic /// </summary> /// <param name="services">The services collection to register services in.</param> /// <param name="faucetConfiguration">Faucet configuration</param> /// <param name="faucetBalanceConfiguration">Faucet balance configuration</param> /// <param name="houseAlerterConfiguration">House alerter configuration</param> public static void Configure(IServiceCollection services, IFaucetConfiguration faucetConfiguration, IFaucetBalanceConfiguration faucetBalanceConfiguration, IHouseBalanceConfiguration houseAlerterConfiguration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } RegisterBalances(services); RegisterPlayers(services); RegisterFaucet(services: services, faucetConfiguration: faucetConfiguration, faucetBalanceConfiguration: faucetBalanceConfiguration, houseAlerterConfiguration: houseAlerterConfiguration); RegisterGames(services); }
/// <summary> /// Configures the Ethereum Contracts /// </summary> /// <param name="services">The services collection to register services in.</param> /// <param name="faucetConfiguration">Faucet configuration</param> /// <param name="faucetBalanceConfiguration">Faucet balance configuration</param> /// <param name="houseAlerterConfiguration">House alerter configuration</param> public static void Configure(IServiceCollection services, IFaucetConfiguration faucetConfiguration, IFaucetBalanceConfiguration faucetBalanceConfiguration, IHouseBalanceConfiguration houseAlerterConfiguration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddSingleton <IDrainedFaucetAlerter, DrainedFaucetAlerter>(); services.AddSingleton <IHouseAccountAlerter, HouseAccountAlerter>(); services.AddHostedSingletonService <ILowBalanceWatcherService, LowBalanceWatcherService>(); RegisterPlayers(services); RegisterFaucet(services: services, faucetConfiguration: faucetConfiguration, faucetBalanceConfiguration: faucetBalanceConfiguration, houseAlerterConfiguration: houseAlerterConfiguration); }
/// <summary> /// Constructor. /// </summary> /// <param name="transactionExecutorFactory">Transaction execution</param> /// <param name="faucetDataManager">Data manager for faucet.</param> /// <param name="ethereumAccountBalanceSource">Balance source for Ethereum/ERC20 tokens.</param> /// <param name="contractInfoRegistry">Registry of contracts.</param> /// <param name="houseFundingIpWhiteList">IP Whitelist for faucet/funding operations.</param> /// <param name="executionEnvironment">The Execution Environment.</param> /// <param name="faucetConfiguration">Faucet configuration.</param> /// <param name="ethereumAccountManager">Ethereum account manager</param> /// <param name="logger">Logging.</param> public FaucetManager(ITransactionExecutorFactory transactionExecutorFactory, IFaucetDataManager faucetDataManager, IEthereumAccountBalanceSource ethereumAccountBalanceSource, IContractInfoRegistry contractInfoRegistry, IWhiteListedIpAddressIdentifier houseFundingIpWhiteList, ExecutionEnvironment executionEnvironment, IFaucetConfiguration faucetConfiguration, IEthereumAccountManager ethereumAccountManager, ILogger <FaucetManager> logger) { if (contractInfoRegistry == null) { throw new ArgumentNullException(nameof(contractInfoRegistry)); } if (faucetConfiguration == null) { throw new ArgumentNullException(nameof(faucetConfiguration)); } this._faucetDataManager = faucetDataManager ?? throw new ArgumentNullException(nameof(faucetDataManager)); this._ethereumAccountBalanceSource = ethereumAccountBalanceSource ?? throw new ArgumentNullException(nameof(ethereumAccountBalanceSource)); this._transactionExecutorFactory = transactionExecutorFactory ?? throw new ArgumentNullException(nameof(transactionExecutorFactory)); this._fundingWhiteList = houseFundingIpWhiteList ?? throw new ArgumentNullException(nameof(houseFundingIpWhiteList)); this._executionEnvironment = executionEnvironment; this._ethereumAccountManager = ethereumAccountManager; this._ethToGive = faucetConfiguration.EthToGive; this._tokenToGiven = faucetConfiguration.TokenToGive; this._maximumRecipientEthBalance = this._ethToGive / 2; this._maximumRecipientTokenBalance = this._tokenToGiven / 2; this._logger = logger ?? throw new ArgumentNullException(nameof(logger)); this._tokenContract = (Erc20TokenContractInfo)contractInfoRegistry.FindContractInfo(WellKnownContracts.Token); this._faucetContract = contractInfoRegistry.FindContractInfo(WellKnownContracts.Faucet); }