@bsv/wallet-toolbox-client
Version:
Client only Wallet Storage
90 lines • 2.77 kB
TypeScript
import { BlockHeader } from '../../../../sdk/WalletServices.interfaces';
export interface HeightRangeApi {
minHeight: number;
maxHeight: number;
}
export interface HeightRanges {
bulk: HeightRange;
live: HeightRange;
}
/**
* Represents a range of block heights.
*
* Operations support integrating contiguous batches of headers,
*/
export declare class HeightRange implements HeightRangeApi {
minHeight: number;
maxHeight: number;
constructor(minHeight: number, maxHeight: number);
/**
* All ranges where maxHeight is less than minHeight are considered empty.
* The canonical empty range is (0, -1).
*/
static readonly empty: HeightRange;
/**
* @returns true iff minHeight is greater than maxHeight.
*/
get isEmpty(): boolean;
/**
* @param headers an array of objects with a non-negative integer `height` property.
* @returns range of height values from the given headers, or the empty range if there are no headers.
*/
static from(headers: BlockHeader[]): HeightRange;
/**
* @returns the number of heights in the range, or 0 if the range is empty.
*/
get length(): number;
/**
* @returns an easy to read string representation of the height range.
*/
toString(): string;
/**
* @param range HeightRange or single height value.
* @returns true if `range` is entirely within this range.
*/
contains(range: HeightRange | number): boolean;
/**
* Return the intersection with another height range.
*
* Intersection with an empty range is always empty.
*
* The result is always a single, possibly empty, range.
* @param range
* @returns
*/
intersect(range: HeightRange): HeightRange;
/**
* Return the union with another height range.
*
* Only valid if the two ranges overlap or touch, or one is empty.
*
* Throws an error if the union would create two disjoint ranges.
*
* @param range
* @returns
*/
union(range: HeightRange): HeightRange;
/**
* Returns `range` subtracted from this range.
*
* Throws an error if the subtraction would create two disjoint ranges.
*
* @param range
* @returns
*/
subtract(range: HeightRange): HeightRange;
/**
* If `range` is not empty and this is not empty, returns a new range minHeight
* replaced by to range.maxHeight + 1.
*
* Otherwise returns a copy of this range.
*
* This returns the portion of this range that is strictly above `range`.
*/
above(range: HeightRange): HeightRange;
/**
* Return a copy of this range.
*/
copy(): HeightRange;
}
//# sourceMappingURL=HeightRange.d.ts.map