export interface SwitchBlock { number: number; hash: string; previousHash: string; medianTime: number; } export interface SwitcherDao { getCurrent(): Promise; getPotentials(numberStart: number, timeStart: number, maxNumber: number): Promise; getBlockchainBlock(number: number, hash: string): Promise; getAbsoluteBlockInForkWindow(number: number, hash: string): Promise; revertTo(number: number): Promise; addBlock(block: T): Promise; } export declare class Switcher { private dao; private invalidForks; private avgGenTime; private forkWindowSize; private switchOnHeadAdvance; private logger; constructor(dao: SwitcherDao, invalidForks: string[], avgGenTime: number, forkWindowSize: number, switchOnHeadAdvance: number, logger?: any); /** * Looks at known blocks in the sandbox and try to follow the longest resulting chain that has at least both 3 blocks of * advance and 3 * avgGenTime of medianTime advancce. */ tryToFork(): Promise; /** * Find all the suites' HEAD that we could potentially fork on, in the current fork window. * @param current */ findPotentialSuitesHeads(current: { number: number; medianTime: number; }): Promise; /** * Looks at the potential blocks that could form fork chains in the sandbox, and sort them to have a maximum of unique * chains. * @param numberStart The minimum number of a fork block. * @param timeStart The minimum medianTime of a fork block. * @returns {SwitchBlock[][]} The suites found. */ private findPotentialSuites; /** * Find the longest chain among a suite of chains. Tests the validity of each block against the current blockchain. * The length of a chain is the number of blocks successfuly added to current blockchain. * @param {SwitchBlock} current * @param {SwitchBlock[][]} suites * @returns {SwitchBlock[]} */ private findLongestChain; /** * Switch current blockchain on another chain, by poping top blocks and replacing them by new ones. * @param {SwitchBlock[]} chain */ private switchOnChain; /** * Checks if a suite of chains contains a particular block in one of its chains. * @param {SwitchBlock[][]} suites * @param {SwitchBlock} block */ static suitesContains(suites: T[][], block: T): boolean; }