caravan-x
Version:
A terminal-based utility for managing Caravan multisig wallets in regtest mode. This tool simplifies development and testing with Caravan by providing an easy-to-use interface
143 lines (142 loc) • 4.37 kB
TypeScript
import { DockerConfig, SharedConfig } from "../types/config";
interface ContainerStatus {
running: boolean;
containerId?: string;
ports?: {
rpc: number;
p2p: number;
};
network?: string;
}
/**
* Docker service for managing Bitcoin Core containers
*
* This service handles:
* - Port conflict detection and auto-adjustment
* - Bitcoin Core container lifecycle
* - Nginx proxy setup for CORS-enabled RPC access
* - Watch-only wallet creation
* - Connection testing and validation
*/
export declare class DockerService {
private config;
private dataDir;
private rpcUser;
private rpcPassword;
constructor(config: DockerConfig, dataDir: string);
/**
* Check if Docker is available and running
*/
checkDockerAvailable(): Promise<boolean>;
/**
* Detect system architecture (important for ARM64/M1 Macs)
*/
detectArchitecture(): Promise<string>;
/**
* Check if a specific port is in use
*/
isPortInUse(port: number): Promise<boolean>;
/**
* Find an available port starting from a base port
* Tries up to 50 ports sequentially
*/
findAvailablePort(basePort: number): Promise<number>;
/**
* Find available ports for both RPC and P2P
* This is the helper that finds alternative ports
*/
private findAvailablePorts;
/**
* Check if default ports are available
*/
private checkPortsAvailable;
/**
* Ensure ports are available - auto-adjust if conflicts exist
* This is the MAIN port management method called during setup
*
* If default ports (18443, 18444) are taken, it automatically finds alternatives
* and updates the config accordingly. No manual intervention needed!
*/
ensurePortsAvailable(): Promise<{
rpc: number;
p2p: number;
}>;
/**
* Get current container status
*/
getContainerStatus(): Promise<ContainerStatus>;
/**
* Ensure Docker network exists
*/
ensureNetwork(): Promise<void>;
/**
* Generate bitcoin.conf file with proper credentials
*/
private generateBitcoinConf;
/**
* Start Bitcoin Core container with progress UI
* This handles the Bitcoin Core container only - nginx is separate
*/
startContainer(sharedConfig?: SharedConfig): Promise<void>;
/**
* Wait for RPC to be ready with retry logic
*/
private waitForRpcReady;
/**
* Generate initial blocks for testing
*/
private generateInitialBlocks;
/**
* Generate nginx configuration that proxies to Bitcoin Core
*/
private generateNginxConfig;
/**
* Setup nginx proxy with automatic port detection
* Returns the actual nginx port used (may differ from 8080 if port was taken)
*/
setupNginxProxy(sharedConfig?: SharedConfig, force?: boolean): Promise<number>;
/**
* Create watch-only wallet for Caravan
*/
createWatchOnlyWallet(walletName: string): Promise<void>;
/**
* Complete Docker setup - orchestrates all components
*
* This is the MAIN entry point for Docker mode setup. It:
* 1. Checks and auto-adjusts ports if needed
* 2. Starts Bitcoin Core container
* 3. Sets up nginx proxy for CORS-enabled RPC access
* 4. Creates watch-only wallet
* 5. Tests the connection
* 6. Displays connection info
*
* @returns The actual nginx port used
*/
completeSetup(sharedConfig?: SharedConfig): Promise<number>;
/**
* Test RPC connection through nginx proxy
*/
testConnection(host?: string, port?: number): Promise<boolean>;
/**
* Get Bitcoin blockchain info
*/
getBitcoinInfo(): Promise<{
blocks: number;
chain: string;
wallets: string[];
}>;
/**
* Display comprehensive connection information and instructions
*/
displayConnectionInfo(sharedConfig?: SharedConfig, nginxPort?: number, bitcoinRpcPort?: number): Promise<void>;
stopContainer(): Promise<void>;
restartContainer(): Promise<void>;
removeContainer(): Promise<void>;
/**
* Execute bitcoin-cli command inside container
*/
execBitcoinCli(command: string): Promise<string>;
getLogs(tail?: number): Promise<string>;
openShell(): Promise<void>;
}
export {};