public bool TryReadValue(UInt256 blockHash, out BlockHeader blockHeader) { using (var conn = this.OpenReadConnection()) using (var cmd = conn.CreateCommand()) { cmd.CommandText = @" SELECT HeaderBytes FROM BlockHeaders WHERE BlockHash = @blockHash"; cmd.Parameters.SetValue("@blockHash", DbType.Binary, 32).Value = blockHash.ToDbByteArray(); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { var headerBytes = reader.GetBytes(0); blockHeader = StorageEncoder.DecodeBlockHeader(headerBytes.ToMemoryStream(), blockHash); return(true); } else { blockHeader = default(BlockHeader); return(false); } } } }
public IEnumerable <KeyValuePair <UInt256, BlockHeader> > ReadAllValues() { using (var conn = this.OpenReadConnection()) using (var cmd = conn.CreateCommand()) { cmd.CommandText = @" SELECT BlockHash, HeaderBytes FROM BlockHeaders"; using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var blockHash = reader.GetUInt256(0); var headerBytes = reader.GetBytes(1); yield return(new KeyValuePair <UInt256, BlockHeader>(blockHash, StorageEncoder.DecodeBlockHeader(headerBytes.ToMemoryStream(), blockHash))); } } } }