private void CreateNewStore(NetworkParameters @params, FileInfo file)
{
// Create a new block store if the file wasn't found or anything went wrong whilst reading.
_blockMap.Clear();
try
{
if (_stream != null)
{
_stream.Dispose();
}
_stream = file.OpenWrite(); // Do not append, create fresh.
_stream.Write(1); // Version.
}
catch (IOException e1)
{
// We could not load a block store nor could we create a new one!
throw new BlockStoreException(e1);
}
try
{
// Set up the genesis block. When we start out fresh, it is by definition the top of the chain.
var genesis = @params.GenesisBlock.CloneAsHeader();
var storedGenesis = new StoredBlock(genesis, genesis.GetWork(), 0);
_chainHead = storedGenesis.Header.Hash;
_stream.Write(_chainHead.Bytes);
Put(storedGenesis);
}
catch (IOException e)
{
throw new BlockStoreException(e);
}
}