/// /// import { BN } from 'ethereumjs-util'; import type { LevelUp } from 'levelup'; import { Block, BlockHeader, BlockBodyBuffer, Transaction, Receipt } from '@rei-network/structure'; import { Common } from '@rei-network/common'; import { CliqueLatestSignerStates, CliqueLatestVotes, CliqueLatestBlockSigners } from './clique'; import Cache from './cache'; import { DatabaseKey, DBOp, DBTarget } from './operation'; /** * @hidden */ export interface GetOpts { keyEncoding?: string; valueEncoding?: string; cache?: string; } export type CacheMap = { [key: string]: Cache; }; /** * Abstraction over a DB to facilitate storing/fetching blockchain-related * data, such as blocks and headers, indices, and the head block. * @hidden */ export declare class DBManager { private _cache; private _common; private _db; constructor(db: LevelUp, common: Common); get rawdb(): LevelUp; /** * Fetches iterator heads from the db. */ getHeads(): Promise<{ [key: string]: Buffer; }>; /** * Fetches header of the head block. */ getHeadHeader(): Promise; /** * Fetches head block. */ getHeadBlock(): Promise; /** * Fetches clique signers. */ getCliqueLatestSignerStates(): Promise; /** * Fetches clique votes. */ getCliqueLatestVotes(): Promise; /** * Fetches snapshot of clique signers. */ getCliqueLatestBlockSigners(): Promise; /** * Fetches a block (header and body) given a block id, * which can be either its hash or its number. */ getBlock(blockId: Buffer | BN | number): Promise; /** * Fetches body of a block given its hash and number. */ getBody(blockHash: Buffer, blockNumber: BN): Promise; /** * Fetches header of a block given its hash and number. */ getHeader(blockHash: Buffer, blockNumber: BN): Promise; /** * Fetches total difficulty for a block given its hash and number. */ getTotalDifficulty(blockHash: Buffer, blockNumber: BN): Promise; /** * Performs a block hash to block number lookup. */ hashToNumber(blockHash: Buffer): Promise; /** * Performs a block number to block hash lookup. */ numberToHash(blockNumber: BN): Promise; /** * Fetches a key from the db. If `opts.cache` is specified * it first tries to load from cache, and on cache miss will * try to put the fetched item on cache afterwards. */ get(dbOperationTarget: DBTarget, key?: DatabaseKey): Promise; /** * Performs a batch operation on db. */ batch(ops: DBOp[]): Promise; /** * Get transaction by transaction hash * @param txHash - Transaction hash * @returns Transaction */ getTransaction(txHash: Buffer): Promise; /** * Get transaction receipt by transaction hash * @param txHash - Transaction hash * @returns Receipt */ getReceipt(txHash: Buffer): Promise; /** * Get receipts by block hash and number * @param number - Block number * @param hash - Block hash * @returns Receipts */ getReceipts(number: BN, hash: Buffer, block?: Block): Promise; /** * Get transaction receipt by block hash and block number * @param txHash - Transaction hash * @param blockHash - Block hash * @param blockNumber - Block number * @returns Transaction */ getReceiptByHashAndNumber(txHash: Buffer, blockHash: Buffer, blockNumber: BN): Promise; /** * Get block by block hash and block number * @param blockHash - Block hash * @param blockNumber - Block number * @returns Block */ getBlockByHashAndNumber(blockHash: Buffer, blockNumber: BN): Promise; /** * Get bloom bits by section information * @param bit - Bit index of target section * @param section - Section number * @param hash - Hash of the last block header of the target section * @param length - Used for decompressing * @returns Decompressed bloom bits data */ getBloomBits(bit: number, section: BN, hash: Buffer, length: number): Promise; /** * Get canonical chain block header by block number * @param num - Target block number * @returns Block header */ getCanonicalHeader(num: BN): Promise; /** * Get section count of database * @returns section count or undefined(if doesn't exist) */ getStoredSectionCount(): Promise; /** * Get snapshot account * @param accountHash - Account address hash * @returns Serialized account */ getSerializedSnapAccount(accountHash: Buffer): Promise; /** * Get snapshot account storage * @param accountHash - Account address hash * @param storageHash - Account storage hash * @returns Account Storage value */ getSnapStorage(accountHash: Buffer, storageHash: Buffer): Promise; /** * Get snapshot root */ getSnapRoot(): Promise; /** * Get snapshot journal */ getSnapJournal(): Promise; /** * Get snapshot generator */ getSnapGenerator(): Promise; /** * Get snapshot recovery number */ /** * Get snapshot sync progress */ getSnapSyncProgress(): Promise; /** * Get contract code by hash * @param codeHash - Code hash */ getCode(codeHash: Buffer): Promise; /** * Get trie node by hash * @param hash - Node hash */ getTrieNode(hash: Buffer): Promise; /** * Check whether the contract code exists * @param codeHash */ hasCode(codeHash: Buffer): Promise; /** * Check whether the trie node exists * @param hash */ hasTrieNode(hash: Buffer): Promise; }