UNPKG

mnee

Version:

Legacy package for interacting with MNEE USD stablecoin. Includes experimental features.

117 lines (116 loc) 3.69 kB
/** * Batch operations for MNEE SDK * Provides a clean API for batch processing with automatic chunking, rate limiting, and error recovery */ import { MNEEService } from './mneeService.js'; import { MNEEUtxo, MNEEBalance, TxHistoryResponse, AddressHistoryParams, ParseTxResponse, ParseTxExtendedResponse, ParseOptions } from './mnee.types.js'; export interface BatchOptions { /** Maximum items per API call (default: 20) */ chunkSize?: number; /** API requests per second limit (default: 3). If your API key has a higher limit, set this accordingly */ requestsPerSecond?: number; /** Continue processing if an error occurs (default: false) */ continueOnError?: boolean; /** Maximum retries per chunk (default: 3) */ maxRetries?: number; /** Retry delay in milliseconds (default: 1000) */ retryDelay?: number; /** Progress callback */ onProgress?: (completed: number, total: number, errors: number) => void; } export interface BatchError { items: string[]; error: { message: string; code?: string; }; retryCount: number; } export interface BatchResult<T> { results: T[]; errors: BatchError[]; totalProcessed: number; totalErrors: number; } export interface BatchUtxoResult { address: string; utxos: MNEEUtxo[]; } export interface BatchParseTxResult { txid: string; parsed: ParseTxResponse | ParseTxExtendedResponse; } /** * Batch operations class for MNEE SDK * @example * const batch = mnee.batch(); * const result = await batch.getBalances(addresses, { onProgress: ... }); */ export declare class Batch { private service; constructor(service: MNEEService); /** * Get UTXOs for multiple addresses * @example * const result = await mnee.batch().getUtxos(addresses, { * onProgress: (completed, total, errors) => { * console.log(`Progress: ${completed}/${total}, Errors: ${errors}`); * } * }); */ getUtxos(addresses: string[], options?: BatchOptions): Promise<BatchResult<BatchUtxoResult>>; /** * Get balances for multiple addresses * @example * const result = await mnee.batch().getBalances(addresses); * const totalBalance = result.results.reduce((sum, b) => sum + b.decimalAmount, 0); */ getBalances(addresses: string[], options?: BatchOptions): Promise<BatchResult<MNEEBalance>>; /** * Get transaction histories for multiple addresses * @example * const params = addresses.map(addr => ({ address: addr, limit: 100 })); * const result = await mnee.batch().getTxHistories(params); */ getTxHistories(params: AddressHistoryParams[], options?: BatchOptions): Promise<BatchResult<TxHistoryResponse>>; /** * Parse multiple transactions * @example * const result = await mnee.batch().parseTx(txids, { * parseOptions: { includeRaw: true } * }); */ parseTx(txids: string[], options?: BatchOptions & { parseOptions?: ParseOptions; }): Promise<BatchResult<BatchParseTxResult>>; /** * Generic batch processor */ private processBatch; /** * Process with retry logic */ private processWithRetry; /** * Split array into chunks */ private chunkArray; /** * Delay execution */ private delay; } /** * Rate limiter for API calls */ export declare class RateLimiter { private maxConcurrent; private minDelay; private queue; private running; constructor(maxConcurrent: number, minDelay: number); execute<T>(fn: () => Promise<T>): Promise<T>; private waitForSlot; private processQueue; private delay; }