UNPKG

@pod-protocol/cli

Version:

Command-line interface for PoD Protocol (Prompt or Die) AI Agent Communication Protocol

44 lines (43 loc) 1.39 kB
import chalk from "chalk"; import { PublicKey } from "@solana/web3.js"; import { handleDryRun, createSpinner, showSuccess, } from "../../utils/shared.js"; export class BaseChannelHandler { constructor(context) { this.context = context; } createPublicKey(id) { try { return new PublicKey(id); } catch { throw new Error(`Invalid public key: ${id}`); } } async executeWithSpinner(message, operation, dryRunData) { const spinner = createSpinner(message); if (this.context.globalOpts.dryRun && dryRunData) { if (handleDryRun(this.context.globalOpts, spinner, message, dryRunData)) { return; } } try { const result = await operation(); return result; } catch (error) { spinner.fail(`Failed: ${error.message}`); throw error; } } handleError(operation, error) { console.error(chalk.red(`Failed to ${operation}:`), error.message); process.exit(1); throw new Error(); // This line will never be reached but satisfies TypeScript } showSuccessWithTransaction(spinner, message, signature, additionalData) { showSuccess(spinner, message, { Transaction: signature, ...additionalData, }); } }