public IEnumerable <IPersistedBlock> GetBlocks(BlockStatus status) { var blocks = new List <IPersistedBlock>(); try { if (!IsEnabled) { return(blocks); } string filter = string.Empty; switch (status) { case BlockStatus.Pending: filter = "orphaned = false and confirmed = false"; break; case BlockStatus.Orphaned: filter = "orphaned = true"; break; case BlockStatus.Confirmed: filter = "confirmed = true"; break; } using (var connection = new MySqlConnection(_mySqlProvider.ConnectionString)) { var results = connection.Query <PersistedBlock>(string.Format( "select height, orphaned, confirmed, blockHash, txHash, amount, time from blocks where {0} order by height DESC LIMIT 20", filter)); blocks.AddRange(results); } } catch (Exception e) { _logger.Error("An exception occured while getting blocks: {0:l} blocks: {1:l}", status.ToString().ToLower(), e.Message); } return(blocks); }
public IEnumerable <IPersistedBlock> GetBlocks(BlockStatus status) { var blocks = new Dictionary <UInt32, IPersistedBlock>(); try { if (!IsEnabled || !IsConnected) { return(blocks.Values.ToList()); } var key = string.Empty; switch (status) { case BlockStatus.Pending: key = string.Format("{0}:blocks:pending", _coin); break; case BlockStatus.Orphaned: key = string.Format("{0}:blocks:orphaned", _coin); break; case BlockStatus.Confirmed: key = string.Format("{0}:blocks:confirmed", _coin); break; } var results = _client.ZRevRangeByScoreWithScores(key, double.PositiveInfinity, 0, true); foreach (var result in results) { var item = result.Item1; var score = result.Item2; var data = item.Split(':'); var blockHash = data[0]; var transactionHash = data[1]; var amount = decimal.Parse(data[2]); blocks.Add((UInt32)score, new PersistedBlock(status, (UInt32)score, blockHash, transactionHash, amount)); } } catch (Exception e) { _logger.Error("An exception occured while getting {0:l} blocks: {1:l}", status.ToString().ToLower(), e.Message); } return(blocks.Values.ToList()); }