public async Task <string> AssignContract(string userAddress)
        {
            var contractAddress = await GetContractAddress(userAddress);

            if (string.IsNullOrEmpty(contractAddress))
            {
                var pool = _poolFactory.Get(Constants.Erc20DepositContractPoolQueue);

                contractAddress = await pool.GetContractAddress();

                var command = new AssignErc223DepositToUserCommand()
                {
                    UserAddress     = userAddress,
                    ContractAddress = contractAddress
                };

                try
                {
                    _cqrsEngine.SendCommand(command,
                                            "blockchain.ethereum.core.api",
                                            EthereumBoundedContext.Name);
                }
                catch (Exception e)
                {
                    await pool.PushContractAddress(contractAddress);

                    throw;
                }
            }

            return(contractAddress);
        }
Пример #2
0
        public async Task Execute()
        {
            await _logger.WriteInfoAsync(nameof(Erc20DepositContractPoolRenewJob), nameof(Execute), "", "Job has been started ", DateTime.UtcNow);

            var pool  = _poolFactory.Get(Constants.Erc20DepositContractPoolQueue);
            var count = await pool.Count();

            for (var i = 0; i < count; i++)
            {
                var contract = await pool.GetContractAddress();

                if (contract == null)
                {
                    break;
                }

                await pool.PushContractAddress(contract);
            }
        }
        public async Task <string> AssignContract(string userAddress)
        {
            var contractAddress = await GetContractAddress(userAddress);

            if (string.IsNullOrEmpty(contractAddress))
            {
                var pool = _poolFactory.Get(Constants.Erc20DepositContractPoolQueue);

                contractAddress = await pool.GetContractAddress();

                await _contractRepository.AddOrReplace(new Erc20DepositContract
                {
                    ContractAddress = contractAddress,
                    UserAddress     = userAddress
                });
            }

            return(contractAddress);
        }
Пример #4
0
        public async Task ReplenishPool()
        {
            var pool         = _poolFactory.Get(Constants.LykkePayErc20DepositContractPoolQueue);
            var currentCount = await pool.Count();

            if (currentCount < _settings.MinContractPoolLength)
            {
                while (currentCount < _settings.MaxContractPoolLength)
                {
                    var tasks             = Enumerable.Range(0, _settings.ContractsPerRequest).Select(x => _contractService.CreateContract());
                    var trHashes          = (await Task.WhenAll(tasks)).Where(x => !string.IsNullOrEmpty(x));
                    var contractAddresses = await _contractService.GetContractAddresses(trHashes);

                    await Task.WhenAll(contractAddresses.Select(pool.PushContractAddress));

                    currentCount += _settings.ContractsPerRequest;
                }
            }
        }