public bool TryRemoveBlockTransactions(UInt256 blockHash)
{
using (var handle = this.cursorCache.TakeItem())
{
var cursor = handle.Item;
using (var jetTx = cursor.jetSession.BeginTransaction())
{
int blockIndex;
if (!TryGetBlockIndex(cursor, blockHash, out blockIndex))
return false;
DeleteBlockIndex(cursor, blockHash);
Api.JetSetCurrentIndex(cursor.jetSession, cursor.blocksTableId, "IX_BlockIndexTxIndex");
Api.MakeKey(cursor.jetSession, cursor.blocksTableId, blockIndex, MakeKeyGrbit.NewKey);
Api.MakeKey(cursor.jetSession, cursor.blocksTableId, 0, MakeKeyGrbit.None);
if (!Api.TrySeek(cursor.jetSession, cursor.blocksTableId, SeekGrbit.SeekGE))
return false;
Api.MakeKey(cursor.jetSession, cursor.blocksTableId, blockIndex, MakeKeyGrbit.NewKey);
Api.MakeKey(cursor.jetSession, cursor.blocksTableId, int.MaxValue, MakeKeyGrbit.None);
if (!Api.TrySetIndexRange(cursor.jetSession, cursor.blocksTableId, SetIndexRangeGrbit.RangeUpperLimit))
return false;
// remove transactions
do
{
Api.JetDelete(cursor.jetSession, cursor.blocksTableId);
}
while (Api.TryMoveNext(cursor.jetSession, cursor.blocksTableId));
// decrease block count
Api.EscrowUpdate(cursor.jetSession, cursor.globalsTableId, cursor.blockCountColumnId, -1);
jetTx.CommitLazy();
return true;
}
}
}