private void CreateNewStore(NetworkParameters @params, FileInfo file)
{
// Create a new block store if the file wasn't found or anything went wrong whilst reading.
_blockCache.Clear();
try
{
if (_channel != null)
{
_channel.Dispose();
_channel = null;
}
if (file.Exists)
{
try
{
file.Delete();
}
catch (IOException)
{
throw new BlockStoreException("Could not delete old store in order to recreate it");
}
}
_channel = file.Create(); // Create fresh.
_channel.Write(_fileFormatVersion);
}
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;
_channel.Write(_chainHead.Bytes);
Put(storedGenesis);
}
catch (IOException e)
{
throw new BlockStoreException(e);
}
}