UNPKG

chronik-cache

Version:

A cache helper for chronik-client

147 lines (146 loc) 3.58 kB
export declare enum CacheStatus { UNKNOWN = 0, UPDATING = 1, REJECT = 2, LATEST = 3 } export interface ChronikCacheConfig { maxTxLimit?: number; maxCacheSize?: number; failoverOptions?: FailoverOptions; enableLogging?: boolean; enableTimer?: boolean; wsTimeout?: number; wsExtendTimeout?: number; } export interface FailoverOptions { retryCount?: number; retryDelay?: number; fallbackUrls?: string[]; } export interface Transaction { txid: string; version: number; inputs: TransactionInput[]; outputs: TransactionOutput[]; lockTime: number; block?: BlockInfo; timeFirstSeen: number; size: number; isCoinbase: boolean; tokenEntries: TokenEntry[]; tokenFailedParsings: TokenFailedParsing[]; tokenStatus: string; } export interface TransactionInput { prevOut: OutPoint; inputScript: string; outputScript: string; value: string; sequenceNo: number; token?: Token; } export interface TransactionOutput { value: string; outputScript: string; token?: Token; spentBy?: OutPoint; } export interface OutPoint { txid: string; outIdx: number; } export interface BlockInfo { hash: string; height: number; timestamp: string; } export interface Token { tokenId: string; tokenType: TokenType; amount: string; isMintBaton?: boolean; } export interface TokenType { protocol: string; type: string; number: number; } export interface TokenEntry { tokenId: string; tokenType: TokenType; txType: string; isInvalid: boolean; burnSummary: string; failedColorings: FailedColoring[]; actualBurnAmount: string; intentionalBurn: string; burnsMintBatons: boolean; } export interface TokenFailedParsing { pushdataIdx: number; bytes: string; error: string; } export interface FailedColoring { pushdataIdx: number; error: string; } export interface HistoryResponse { txs: Transaction[]; numPages: number; numTxs: number; status?: number; message?: string; } export interface CacheData { txMap: Record<string, Transaction>; txOrder: string[]; numTxs?: number; } export interface CacheMetadata { accessCount: number; createdAt: number; lastAccessAt?: number; updatedAt?: number; dataHash?: string; numTxs?: number; } export interface CacheStatusInfo { status: CacheStatus; cacheTimestamp: number; } export type WebSocketMessageType = 'TX_ADDED_TO_MEMPOOL' | 'TX_FINALIZED'; export type WebSocketCallback = (identifier: string, txid: string, msgType: WebSocketMessageType) => Promise<void>; export type ScriptType = 'p2pkh' | 'p2sh'; export interface CacheStatistics { totalAddresses: number; totalTokens: number; totalCacheSize: number; memoryUsage: { addressCache: number; tokenCache: number; globalMetadata: number; }; hitRates: { addressHitRate: number; tokenHitRate: number; }; } export interface ChronikClientInterface { address(address: string): { history(pageOffset?: number, pageSize?: number): Promise<HistoryResponse>; }; tokenId(tokenId: string): { history(pageOffset?: number, pageSize?: number): Promise<HistoryResponse>; }; script(type: string, hash: string): { history(pageOffset?: number, pageSize?: number): Promise<HistoryResponse>; }; tx(txid: string): Promise<Transaction>; ws?: any; } export interface MemoryCacheEntry<T> { data: T; expiry: number; }