Exemplo n.º 1
0
        private async Task SaveTransfersAndAuditAllUserBalances(Dictionary <Guid, CEFSBalance> userIds, List <TransferHistory> transfers, List <int> Currencies, IExchangeDataContext context)
        {
            Log.Message(LogLevel.Info, "SaveTransfersAndSuditUserBalances entered.");

            await context.Database.BulkInsertAsync(transfers);

            await context.SaveChangesAsync();

            // audit all users for all currencies involved.
            foreach (var currencyId in Currencies)
            {
                foreach (var id in userIds.Keys)
                {
                    await context.AuditUserBalance(id, currencyId);
                }

                await context.AuditUserBalance(Constant.SYSTEM_USER_PAYTOPIA, currencyId);

                await context.AuditUserBalance(Constant.SYSTEM_USER_STAGING, currencyId);

                await context.AuditUserBalance(Constant.SYSTEM_USER_CEFS, currencyId);
            }

            await context.SaveChangesAsync();

            Log.Message(LogLevel.Info, "SaveTransfersAndSuditUserBalances exited.");
        }
Exemplo n.º 2
0
        private async Task PerformWalletTransactionsAndUpdateDepositsWithIds(List <string> transactionIds, IExchangeDataContext context)
        {
            Log.Message(LogLevel.Info, "PerformWalletTransactionsAndUpdateDepositsWithIds entered.");

            // send transactions to the wallets for System_User cefs payments and update the deposits with the real txId.
            var cefsDeposits = await context.Deposit.Where(x => transactionIds.Contains(x.Txid)).ToListAsync().ConfigureAwait(false);

            foreach (var txId in transactionIds)
            {
                try
                {
                    var deposit  = cefsDeposits.FirstOrDefault(x => x.Txid == txId);
                    var currency = await context.Currency.FirstOrDefaultAsync(c => c.Id == deposit.CurrencyId).ConfigureAwait(false);

                    var currencyAddress = await context.Address.FirstOrDefaultAsync(a => a.UserId == Constant.SYSTEM_USER_STAGING && a.CurrencyId == deposit.CurrencyId).ConfigureAwait(false);

                    if (currencyAddress == null)
                    {
                        Log.Message(LogLevel.Error, $"No address exists for currency {currency.Symbol}. Unable to process CEF deposit.");
                        continue;
                    }

                    var connector = new WalletConnector(currency.WalletHost, currency.WalletPort, currency.WalletUser, currency.WalletPass, WALLET_TIMEOUT);
                    var result    = await connector.SendToAddressAsync(currencyAddress.AddressHash, deposit.Amount);

                    if (result != null)
                    {
                        deposit.Txid = result.Txid;
                        await context.SaveChangesAsync();
                    }
                }
                catch (Exception ex)
                {
                    Log.Message(LogLevel.Error, $"Wallet Transaction blew up.\r\n{ex.Message}");
                }
            }

            Log.Message(LogLevel.Info, "PerformWalletTransactionsAndUpdateDepositsWithIds exited.");
        }