Esempio n. 1
0
 /// <summary>
 ///     The public hub
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry</param>
 /// <param name="groupNameGenerator">The group name generator</param>
 /// <param name="environment">Execution environment</param>
 /// <param name="subscriptionManager">Subscription manager</param>
 /// <param name="logger">Logger</param>
 public PublicHub(IEthereumNetworkRegistry ethereumNetworkRegistry,
                  IGroupNameGenerator groupNameGenerator,
                  ExecutionEnvironment environment,
                  ISubscriptionManager subscriptionManager,
                  ILogger <PublicHub> logger)
     : base(ethereumNetworkRegistry: ethereumNetworkRegistry, groupNameGenerator: groupNameGenerator, environment: environment, subscriptionManager: subscriptionManager, logger: logger)
 {
 }
        private static (bool success, EthereumNetwork?found) LookupNetworkByName(IEthereumNetworkRegistry registry, string value)
        {
            if (registry.TryGetByName(name: value, out EthereumNetwork? foundByName))
            {
                return(success: true, found : foundByName);
            }

            return(success : false, found : null);
        }
Esempio n. 3
0
        private static void RegisterEthereumNetworkConverter(IServiceProvider serviceProvider)
        {
            IEthereumNetworkRegistry networkRegistry = serviceProvider.GetRequiredService <IEthereumNetworkRegistry>();

            IOptions <JsonOptions> mvcJsonOptions = serviceProvider.GetRequiredService <IOptions <JsonOptions> >();

            EthereumNetworkConverter ethereumNetworkConverter = new(networkRegistry);

            mvcJsonOptions.Value.JsonSerializerOptions.Converters.Add(ethereumNetworkConverter);
        }
 protected HubBase(IEthereumNetworkRegistry ethereumNetworkRegistry,
                   IGroupNameGenerator groupNameGenerator,
                   ExecutionEnvironment environment,
                   ISubscriptionManager subscriptionManager,
                   ILogger logger)
 {
     this.NetworkManager      = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
     this._groupNameGenerator = groupNameGenerator ?? throw new ArgumentNullException(nameof(groupNameGenerator));
     this._environment        = environment;
     this._subscribedGroups   = subscriptionManager ?? throw new ArgumentNullException(nameof(subscriptionManager));
     this.Logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Esempio n. 5
0
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry</param>
 /// <param name="groupNameGenerator">The group name generator</param>
 /// <param name="environment">Execution environment</param>
 /// <param name="subscriptionManager">Subscription manager</param>
 /// <param name="playerCountManager">Player counter.</param>
 /// <param name="rateLimiter">Rate limiter</param>
 /// <param name="logger">Logger</param>
 public AuthenticatedHub(IEthereumNetworkRegistry ethereumNetworkRegistry,
                         IGroupNameGenerator groupNameGenerator,
                         ExecutionEnvironment environment,
                         ISubscriptionManager subscriptionManager,
                         IPlayerCountManager playerCountManager,
                         IRateLimiter rateLimiter,
                         ILogger <AuthenticatedHub> logger)
     : base(ethereumNetworkRegistry: ethereumNetworkRegistry, groupNameGenerator: groupNameGenerator, environment: environment, subscriptionManager: subscriptionManager, logger: logger)
 {
     this._playerCountManager = playerCountManager ?? throw new ArgumentNullException(nameof(playerCountManager));
     this._rateLimiter        = rateLimiter ?? throw new ArgumentNullException(nameof(rateLimiter));
 }
Esempio n. 6
0
        private static void RegisterSignalRJsonSerializerOptions(IServiceProvider serviceProvider)
        {
            IEthereumNetworkRegistry networkRegistry = serviceProvider.GetRequiredService <IEthereumNetworkRegistry>();

            IOptions <JsonOptions>            mvcJsonOptions     = serviceProvider.GetRequiredService <IOptions <JsonOptions> >();
            IOptions <JsonHubProtocolOptions> signalrJsonOptions = serviceProvider.GetRequiredService <IOptions <JsonHubProtocolOptions> >();

            EthereumNetworkConverter ethereumNetworkConverter = new(networkRegistry);

            mvcJsonOptions.Value.JsonSerializerOptions.Converters.Add(ethereumNetworkConverter);
            signalrJsonOptions.Value.PayloadSerializerOptions.Converters.Add(ethereumNetworkConverter);
        }
Esempio n. 7
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="faucetManager">The Faucet manager.</param>
 /// <param name="ethereumAccountManager">The Ethereum Account Manager</param>
 /// <param name="networkManager">Network manager</param>
 /// <param name="requestIpAddressManager">IP Address manager.</param>
 /// <param name="contractInfoRegistry">Contract info registry</param>
 /// <param name="ethereumBlockStatus">Ethereum Block Status</param>
 public FaucetController(IFaucetManager faucetManager,
                         IEthereumAccountManager ethereumAccountManager,
                         IEthereumNetworkRegistry networkManager,
                         IRemoteIpAddressRetriever requestIpAddressManager,
                         IContractInfoRegistry contractInfoRegistry,
                         IEthereumBlockStatus ethereumBlockStatus)
 {
     this._faucetManager            = faucetManager ?? throw new ArgumentNullException(nameof(faucetManager));
     this._ethereumAccountManager   = ethereumAccountManager ?? throw new ArgumentNullException(nameof(ethereumAccountManager));
     this._networkManager           = networkManager ?? throw new ArgumentNullException(nameof(networkManager));
     this._remoteIpAddressRetriever = requestIpAddressManager ?? throw new ArgumentNullException(nameof(requestIpAddressManager));
     this._ethereumBlockStatus      = ethereumBlockStatus ?? throw new ArgumentNullException(nameof(ethereumBlockStatus));
     this._faucetContractInfo       = (contractInfoRegistry ?? throw new ArgumentNullException(nameof(contractInfoRegistry))).FindContractInfo(WellKnownContracts.Faucet);
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry</param>
 /// <param name="groupNameGenerator">The group name generator</param>
 /// <param name="environment">Execution environment</param>
 /// <param name="subscriptionManager">Subscription manager</param>
 /// <param name="playerCountManager">Player counter.</param>
 /// <param name="gameRoundDataManager">Game Round Manager.</param>
 /// <param name="gameRoundTimeCalculator">Game round time calculator.</param>
 /// <param name="startRoundGameHistoryBuilder">Game Round history builder.</param>
 /// <param name="ethereumBlockStatus">Ethereum block status.</param>
 /// <param name="rateLimiter">Rate limiter</param>
 /// <param name="logger">Logger</param>
 public AuthenticatedHub(IEthereumNetworkRegistry ethereumNetworkRegistry,
                         IGroupNameGenerator groupNameGenerator,
                         ExecutionEnvironment environment,
                         ISubscriptionManager subscriptionManager,
                         IPlayerCountManager playerCountManager,
                         IGameRoundDataManager gameRoundDataManager,
                         IGameRoundTimeCalculator gameRoundTimeCalculator,
                         IStartRoundGameHistoryBuilder startRoundGameHistoryBuilder,
                         IEthereumBlockStatus ethereumBlockStatus,
                         IRateLimiter rateLimiter,
                         ILogger <AuthenticatedHub> logger)
     : base(ethereumNetworkRegistry: ethereumNetworkRegistry, groupNameGenerator: groupNameGenerator, environment: environment, subscriptionManager: subscriptionManager, logger: logger)
 {
     this._playerCountManager           = playerCountManager ?? throw new ArgumentNullException(nameof(playerCountManager));
     this._gameRoundDataManager         = gameRoundDataManager ?? throw new ArgumentNullException(nameof(gameRoundDataManager));
     this._gameRoundTimeCalculator      = gameRoundTimeCalculator ?? throw new ArgumentNullException(nameof(gameRoundTimeCalculator));
     this._startRoundGameHistoryBuilder = startRoundGameHistoryBuilder ?? throw new ArgumentNullException(nameof(startRoundGameHistoryBuilder));
     this._ethereumBlockStatus          = ethereumBlockStatus ?? throw new ArgumentNullException(nameof(ethereumBlockStatus));
     this._rateLimiter = rateLimiter ?? throw new ArgumentNullException(nameof(rateLimiter));
 }
        /// <inheritdoc />
        public IModelBinder?GetBinder(ModelBinderProviderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Metadata.ModelType == typeof(EthereumNetwork))
            {
                IEthereumNetworkRegistry registry = this._serviceProvider.GetRequiredService <IEthereumNetworkRegistry>();

                (bool success, EthereumNetwork?found) TryParse(string value)
                {
                    return(LookupNetworkByName(registry: registry, value: value));
                }

                return(new GenericModelBinder <EthereumNetwork>(TryParse));
            }

            return(null);
        }
Esempio n. 10
0
        private static async Task EnableNetworksAsync(IServiceProvider serviceProvider, ILogger <Startup> logger)
        {
            IWeb3Factory web3Factory = serviceProvider.GetRequiredService <IWeb3Factory>();
            IReadOnlyList <EthereumNetwork> networks = await web3Factory.GetNetworksAsync(CancellationToken.None);

            logger.LogInformation($"There are {networks.Count} networks enabled in proxy.");

            IEthereumNetworkRegistry        ethereumNetworkRegistry = serviceProvider.GetRequiredService <IEthereumNetworkRegistry>();
            IReadOnlyList <EthereumNetwork> registeredNetworks      = ethereumNetworkRegistry.Supported;

            logger.LogInformation($"There are {registeredNetworks.Count} networks registered in server.");

            IDynamicEthereumNetworkConfigurationManager ethereumNetworkConfigurationManager = serviceProvider.GetRequiredService <IDynamicEthereumNetworkConfigurationManager>();

            foreach (EthereumNetwork network in ethereumNetworkRegistry.Supported)
            {
                ethereumNetworkConfigurationManager.Enable(network);
            }

            IReadOnlyList <EthereumNetwork> configuredNetworks = ethereumNetworkConfigurationManager.EnabledNetworks;

            logger.LogInformation($"There are {configuredNetworks.Count} networks enabled in server.");
        }
Esempio n. 11
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry.</param>
 public PendingTransactionBuilder(IEthereumNetworkRegistry ethereumNetworkRegistry)
 {
     this._ethereumNetworkRegistry = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
 }
Esempio n. 12
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry.</param>
 public GameRoundBuilder(IEthereumNetworkRegistry ethereumNetworkRegistry)
 {
     this._ethereumNetworkRegistry = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
 }
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry.</param>
 public TransactionSubmissionStatusBuilder(IEthereumNetworkRegistry ethereumNetworkRegistry)
 {
     this._ethereumNetworkRegistry = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
 }
Esempio n. 14
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum network registry.</param>
 public ConfiguredAccountBuilder(IEthereumNetworkRegistry ethereumNetworkRegistry)
 {
     this._ethereumNetworkRegistry = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
 }
Esempio n. 15
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="ethereumNetworkRegistry">Ethereum Network Registry</param>
 public AwaitingConfirmationsTransactionBuilder(IEthereumNetworkRegistry ethereumNetworkRegistry)
 {
     this._ethereumNetworkRegistry = ethereumNetworkRegistry ?? throw new ArgumentNullException(nameof(ethereumNetworkRegistry));
 }