Example #1
0
        public bool GetNextAddressToAnalyze(out AddressToAnalyze addressToAnalyze)
        {
            string selectCommand = "SELECT TOP(1) [AddressHash], [IsDirectFind] FROM [AddressQueue] WHERE [IsProcessed] = 0";
            var    command       = CreateCommand(selectCommand);

            using (var reader = command.ExecuteReader())
            {
                bool hasRow = reader.Read();
                if (!hasRow)
                {
                    addressToAnalyze = null;
                    return(false);
                }

                string hash         = (string)reader["AddressHash"];
                bool   isDirectFind = (bool)reader["IsDirectFind"];
                addressToAnalyze = new AddressToAnalyze
                {
                    Hash         = hash,
                    IsDirectFind = isDirectFind
                };
            }

            return(true);
        }
Example #2
0
        public static Address GetAddressData(Datastore datastore, WebClient webClient, AddressToAnalyze address)
        {
            try
            {
                var sw = new Stopwatch();
                sw.Start();
                string addressJsonData = webClient.DownloadString(string.Format(AddressUrl, address.Hash));
                sw.Stop();
                ConsoleOnly.Debug("Downloaded address data in in {0}ms", sw.ElapsedMilliseconds);
                sw.Reset();

                Address addressObject = JsonConvert.DeserializeObject<Address>(addressJsonData);
                addressObject.IsDirectFind = address.IsDirectFind;
                addressObject.Transactions = new List<Transaction>();

                sw.Start();
                foreach (var transactionHash in addressObject.TransactionHashes)
                {
                    if (!datastore.TransactionExists(transactionHash))
                    {
                        try
                        {
                            string transactionJsonData =
                            webClient.DownloadString(string.Format(TransactionsUrl, transactionHash));
                            var transaction =
                                JsonConvert.DeserializeObject<Transaction>(transactionJsonData);
                            addressObject.Transactions.Add(transaction);
                        }
                        catch (WebException we)
                        {
                            Log.Warn(string.Format("WebException while downloading transaction {0}, skipping", transactionHash), we);
                        }                        
                    }
                    else
                    {
                        ConsoleOnly.Debug("Skipping transaction {0} because it already existed", transactionHash);
                    }
                }
                sw.Stop();
                ConsoleOnly.Debug("Downloaded transaction data in in {0}ms", sw.ElapsedMilliseconds);

                return addressObject;
            }
            catch (JsonSerializationException e)
            {
                Log.Warn(string.Format("Error when deserializing address {0}, skipping.", address), e);
                SuspiciousAddressLog.Warn(string.Format("Could not deserialize {0}", address), e);
                return null;
            }            
        }