Unit Noso.Headers

Description

Standalone unit to control headers file.

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Packed Record TBlockSummary Record to hold summary data for a block

Functions and Procedures

function AddRecordToHeaders(const BlockNumber: Int64; const BlockHash, SumHash: String): Boolean;
function CreateHeadersFile(): Boolean;
function GetHeadersAsMemoryStream(var Stream: TMemoryStream): Int64;
function GetHeadersAsStringFromBlock(FromBlock: Integer): String;
function GetHeadersCount(): Integer;
function GetLastHeaderBlock(): Integer;
function GetSummaryFileHash(): String;
function RemoveLastHeaderRecord(): Boolean;
function SaveMemoryStreamAsHeaders(var Stream: TMemoryStream): Boolean;
function SetHeadersFileName(const Filename: String): Boolean;
procedure SetSummaryFileHash();

Variables

CurrentSummaryFileHash: String = '';
HeadersFileCriticalSection: TRTLCriticalSection;
SummaryFile: file of TBlockSummary;
SummaryFilename: String = 'blchhead.nos';

Description

Functions and Procedures

function AddRecordToHeaders(const BlockNumber: Int64; const BlockHash, SumHash: String): Boolean;

Adds a new record to the headers file.

Parameters
BlockNumber
The block number to be added.
BlockHash
The hash of the block.
SumHash
The sum hash associated with the block.
Returns

True if the record was added successfully; otherwise, False.

function CreateHeadersFile(): Boolean;

Creates a new headers file or overwrites an existing one.

Returns

True if the headers file was created successfully; otherwise, False.

function GetHeadersAsMemoryStream(var Stream: TMemoryStream): Int64;

Loads the headers file into a memory stream.

Parameters
Stream
The memory stream to load the headers into.
Returns

The size of the loaded headers in bytes.

function GetHeadersAsStringFromBlock(FromBlock: Integer): String;

Retrieves headers data as a string starting from a specified block.

Parameters
FromBlock
The block number from which to start retrieving headers.
Returns

A string representing the headers data from the specified block.

function GetHeadersCount(): Integer;

Retrieves the number of records in the headers file.

Returns

The number of records in the headers file.

function GetLastHeaderBlock(): Integer;

Retrieves the block number of the last record in the headers file.

Returns

The block number of the last record.

function GetSummaryFileHash(): String;

Retrieves the current hash of the summary file.

Returns

The hash of the summary file.

function RemoveLastHeaderRecord(): Boolean;

Removes the last record from the headers file.

Returns

True if the record was removed successfully; otherwise, False.

function SaveMemoryStreamAsHeaders(var Stream: TMemoryStream): Boolean;

Saves the contents of a memory stream as the headers file.

Parameters
Stream
The memory stream containing the headers data.
Returns

True if the stream was saved successfully; otherwise, False.

function SetHeadersFileName(const Filename: String): Boolean;

Sets the path and name of the headers file.

Parameters
Filename
The path and name of the headers file.
Returns

True if the file name was set successfully; otherwise, False.

procedure SetSummaryFileHash();

Sets the hash of the summary file to reflect the current file state.

Variables

CurrentSummaryFileHash: String = '';

The current hash of the summary file.

HeadersFileCriticalSection: TRTLCriticalSection;

Critical section for synchronizing access to the headers file.

SummaryFile: file of TBlockSummary;

The file handle for the summary file.

SummaryFilename: String = 'blchhead.nos';

The path and name of the summary file.


Generated by PasDoc 0.16.0-snapshot.