private DepositWallet NormalizeWalletOrDefault(DepositWallet wallet)
        {
            if (string.IsNullOrWhiteSpace(wallet.Address) ||
                string.IsNullOrWhiteSpace(wallet.CryptoCurrency) ||
                wallet.UserId == Guid.Empty)
            {
                return(null);
            }

            var address = _addressNormalizer.NormalizeOrDefault(wallet.Address, wallet.CryptoCurrency);

            if (address == null)
            {
                _log.Warning
                (
                    "It is not a valid address, skipping",
                    context: new
                {
                    Address        = wallet.Address,
                    CryptoCurrency = wallet.CryptoCurrency
                }
                );
                return(null);
            }

            return(new DepositWallet(wallet.UserId, address, wallet.CryptoCurrency));
        }
 private bool IsDeposit(string depositWalletAddress, string operationToAddress)
 {
     return(string.Equals
            (
                _addressNormalizer.NormalizeOrDefault(operationToAddress, _ethereum.CryptoCurrency),
                depositWalletAddress,
                StringComparison.InvariantCultureIgnoreCase
            ));
 }
        private Transaction NormalizeTransactionOrDefault(Transaction tx)
        {
            if (string.IsNullOrWhiteSpace(tx.Hash) ||
                string.IsNullOrWhiteSpace(tx.CryptoCurrency) ||
                tx.UserId == Guid.Empty)
            {
                return(null);
            }

            var outputAddress = _addressNormalizer.NormalizeOrDefault(tx.OutputAddress, tx.CryptoCurrency, isTransactionNormalization: true);

            if (outputAddress == null)
            {
                _log.Warning("It is not a valid address, skipping", context: new
                {
                    Address         = tx.OutputAddress,
                    CryptoCurrencty = tx.CryptoCurrency
                });
                return(null);
            }

            return(new Transaction(tx.CryptoCurrency, tx.Hash, tx.UserId, outputAddress, tx.Type));
        }
 private bool IsDeposit(InsightApiTransaction tx, string address)
 {
     return(tx.Inputs.All(input => !string.Equals(_addressNormalizer.NormalizeOrDefault(input.Address, _liteCoin.CryptoCurrency), address, StringComparison.InvariantCultureIgnoreCase)));
 }
Exemple #5
0
        public async Task TestBtcDepositsHistory()
        {
            // Arrange

            var historyProvider = new BtcDepositsHistoryProvider
                                  (
                _blockchainProvider,
                new BtcSettings
            {
                Network  = "main",
                NinjaUrl = "http://api.qbit.ninja"
            }
                                  );
            var wallet = new DepositWallet
                         (
                Guid.NewGuid(),
                _addressNormalizer.NormalizeOrDefault("3N7cHrmKeEsjuFTx39WyGoZwAikAVSFoWX", "BTC"),
                "BTC"
                         );

            // Act

            var transactions = await historyProvider.GetHistoryAsync(wallet, null);

            Assert.IsNull(transactions.Continuation, "Test should be modified to support continuation");

            var inputTransaction         = transactions.Items.SingleOrDefault(x => x.Hash == "d8f1de74975ff7966c72944b75ac7ec307f58b42019e2206845c78b2f16326ba");
            var coloredInputTransaction1 = transactions.Items.SingleOrDefault(x => x.Hash == "15f04a503a203a7a043d1126750028f3c805624fec38353280df23c85283df04");
            var coloredInputTransaction2 = transactions.Items.SingleOrDefault(x => x.Hash == "c09d8d502d15ce54e61c14a97ef5a59a8ada20c269ac6ef2a065dd615f04247a");
            var outputTransaction1       = transactions.Items.SingleOrDefault(x => x.Hash == "8c3f45a126a9558d393250aa58ca2b8b4b428c948b1ec837578ef1e13f81f6bf");
            var outputTransaction2       = transactions.Items.SingleOrDefault(x => x.Hash == "cde67afceff4f7a4437b520c74f9200d4079f078754be617eafdcece835e9d9c");
            var outputTransaction3       = transactions.Items.SingleOrDefault(x => x.Hash == "a4e793c395fc958cd87769a75411584da1517b6b6e48d7e160a6f19057ede853");
            var outputTransaction4       = transactions.Items.SingleOrDefault(x => x.Hash == "1363846a07e44774ebd9c29f5033894492273b96dca873aab63065064fe00c06");
            var outputTransaction5       = transactions.Items.SingleOrDefault(x => x.Hash == "12971723f3ebc31744693e7db4ba5fc9131c9b446c55a910ac7431b74bb91387");
            var outputTransaction6       = transactions.Items.SingleOrDefault(x => x.Hash == "cdf73195df0b8ec119153c80b29d05944117711ce7570d70e5bcd681522c9521");

            // Assert

            Assert.IsNotNull(inputTransaction);
            Assert.IsNotNull(coloredInputTransaction1);
            Assert.IsNotNull(coloredInputTransaction2);
            Assert.IsNull(outputTransaction1);
            Assert.IsNull(outputTransaction2);
            Assert.IsNull(outputTransaction3);
            Assert.IsNull(outputTransaction4);
            Assert.IsNull(outputTransaction5);
            Assert.IsNull(outputTransaction6);

            Assert.AreEqual("BTC", inputTransaction.CryptoCurrency);
            Assert.AreEqual(wallet.Address, inputTransaction.OutputAddress);
            Assert.AreEqual(wallet.UserId, inputTransaction.UserId);
            Assert.AreEqual(TransactionType.Deposit, inputTransaction.Type);

            Assert.AreEqual("BTC", coloredInputTransaction1.CryptoCurrency);
            Assert.AreEqual(wallet.Address, coloredInputTransaction1.OutputAddress);
            Assert.AreEqual(wallet.UserId, coloredInputTransaction1.UserId);
            Assert.AreEqual(TransactionType.Deposit, coloredInputTransaction1.Type);

            Assert.AreEqual("BTC", coloredInputTransaction2.CryptoCurrency);
            Assert.AreEqual(wallet.Address, coloredInputTransaction2.OutputAddress);
            Assert.AreEqual(wallet.UserId, coloredInputTransaction2.UserId);
            Assert.AreEqual(TransactionType.Deposit, coloredInputTransaction2.Type);
        }
Exemple #6
0
        public async Task <IReadOnlyCollection <Transaction> > ReadAsync(Stream stream, IProgress <int> progress = null, bool leaveOpen = false)
        {
            var transactions = new List <Transaction>(1048576);

            using (var reader = new StreamReader
                                (
                       stream,
                       Encoding.UTF8,
                       detectEncodingFromByteOrderMarks: false,
                       bufferSize: 1024 * 32,
                       leaveOpen: leaveOpen
                                ))
            {
                await reader.ReadLineAsync();

                while (!reader.EndOfStream)
                {
                    var line = await reader.ReadLineAsync();

                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    var parts = line.Split(",");

                    if (parts.Length != 5)
                    {
                        throw new InvalidOperationException($"Invalid record found {line}. 5 Columns are expected, actual count is {parts.Length} ");
                    }

                    if (!Guid.TryParse(parts[0], out var userId))
                    {
                        throw new InvalidOperationException($"User ID {parts[0]} is invalid GUID");
                    }

                    var cryptoCurrency  = parts[1];
                    var transactionType = parts[2] == "sent" ? TransactionType.Withdrawal : TransactionType.Deposit;
                    var transactionHash = parts[3];
                    var outputAddress   = _addressNormalizer.NormalizeOrDefault(parts[4], cryptoCurrency);

                    if (outputAddress == null)
                    {
                        throw new InvalidOperationException($"Address {parts[4]} is invalid for {cryptoCurrency}");
                    }

                    var transaction = new Transaction
                                      (
                        cryptoCurrency,
                        transactionHash,
                        userId,
                        outputAddress,
                        transactionType
                                      );

                    transactions.Add(transaction);

                    progress?.Report(transactions.Count);
                }
            }

            return(transactions);
        }