// Seek to the end and then append magic bytes there.
writer.Seek(0, SeekOrigin.End);
writer.Write(magicBytes, 0, magicBytes.Length);
+ writer.Write(blkLenBytes, 0, blkLenBytes.Length);
// Save block size and current position in the block cursor fields.
nBlockPos = writer.Position;
nBlockSize = blockBytes.Length;
// Write block and flush the stream.
- writer.Write(blkLenBytes, 0, blkLenBytes.Length);
writer.Write(blockBytes, 0, blockBytes.Length);
writer.Flush();
/// <summary>
/// Block file stream with read access
/// </summary>
- private Stream reader;
-
- /// <summary>
- /// Block file stream with write access
- /// </summary>
- private Stream writer;
+ private Stream fStreamReadWrite;
/// <summary>
/// Init the block storage manager.
bool firstInit = !File.Exists(strDbFile);
dbConn = new SQLiteConnection(new SQLitePlatformGeneric(), strDbFile);
- var fStreamReadWrite = File.Open(strBlockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
- writer = new BinaryWriter(fStreamReadWrite).BaseStream;
- reader = new BinaryReader(fStreamReadWrite).BaseStream;
+ fStreamReadWrite = File.Open(strBlockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
if (firstInit)
{
public bool GetTransaction(Hash256 TxID, ref CTransaction tx)
{
+ var reader = new BinaryReader(fStreamReadWrite).BaseStream;
var QueryTx = dbConn.Query<CTransactionStoreItem>("select * from [TransactionStorage] where [TransactionHash] = ?", (byte[])TxID);
if (QueryTx.Count == 1)
private bool AddItemToIndex(ref CBlockStoreItem itemTemplate, ref CBlock block)
{
+ var writer = new BinaryWriter(fStreamReadWrite).BaseStream;
var blockHash = new ScryptHash256(itemTemplate.Hash);
if (blockMap.ContainsKey(blockHash))
{
// Handle trasactions
+ if (!block.vtx[i].VerifyScripts())
+ {
+ return false;
+ }
+
var nTxOffset = itemTemplate.nBlockPos + block.GetTxOffset(i);
TxType txnType = TxType.TX_USER;
public bool GetBlock(ScryptHash256 blockHash, ref CBlock block)
{
+ var reader = new BinaryReader(fStreamReadWrite).BaseStream;
+
var QueryBlock = dbConn.Query<CBlockStoreItem>("select * from [BlockStorage] where [Hash] = ?", (byte[])blockHash);
if (QueryBlock.Count == 1)
{
// Free other state (managed objects).
- reader.Dispose();
- writer.Dispose();
+ fStreamReadWrite.Dispose();
}
if (dbConn != null)