示例#1
0
        public async Task <string> CreateTransferContract(string userAddress, string coinAdapterAddress)
        {
            ITransferContract contract = await GetTransferContract(userAddress, coinAdapterAddress);

            if (contract != null)
            {
                throw new ClientSideException(ExceptionType.EntityAlreadyExists, $"Transfer account for {userAddress} - {coinAdapterAddress} already exists");
            }

            ICoin coin = await GetCoinWithCheck(coinAdapterAddress);

            string queueName = QueueHelper.GenerateQueueNameForContractPool(coinAdapterAddress);
            ITransferContractQueueService transferContractQueueService = _transferContractQueueServiceFactory.Get(queueName);
            ITransferContract             transferContract             = await transferContractQueueService.GetContract();

            transferContract.UserAddress = userAddress;

            await _transferContractRepository.SaveAsync(transferContract);

            await _transferContractUserAssignmentQueueService.PushContract(new TransferContractUserAssignment()
            {
                TransferContractAddress = transferContract.ContractAddress,
                UserAddress             = userAddress,
                CoinAdapterAddress      = coin.AdapterAddress
            });

            return(transferContract.ContractAddress);
        }
        public async Task Execute()
        {
            await _logger.WriteInfoAsync("PoolRenewJob", "Execute", "", "PoolRenewJob has been started ", DateTime.UtcNow);

            await _coinRepository.ProcessAllAsync(async (coins) =>
            {
                foreach (var coin in coins)
                {
                    try
                    {
                        string coinPoolQueueName = QueueHelper.GenerateQueueNameForContractPool(coin.AdapterAddress);
                        ITransferContractQueueService transferContractQueueService =
                            _transferContractQueueServiceFactory.Get(coinPoolQueueName);
                        var count = await transferContractQueueService.Count();

                        for (int i = 0; i < count; i++)
                        {
                            var contract = await transferContractQueueService.GetContract();
                            if (contract == null)
                            {
                                return;
                            }
                            await transferContractQueueService.PushContract(contract);
                        }

                        await _logger.WriteInfoAsync("PoolRenewJob", "Execute", "", $"PoolRenewJob has been finished for {count} contracts in {coinPoolQueueName} ", DateTime.UtcNow);
                    }
                    catch (Exception e)
                    {
                        await _logger.WriteErrorAsync("PoolRenewJob", "Execute", "", e);
                    }
                }
            });
        }