@phala/cloud
Version:
TypeScript SDK for Phala Cloud API
81 lines • 3.1 kB
TypeScript
import type { Hash, TransactionReceipt } from "viem";
import { NetworkClients, TransactionOptions, TransactionResult } from "./network";
export type TransactionState = "idle" | "submitting" | "pending" | "success" | "error" | "timeout";
export interface TransactionStatus {
state: TransactionState;
hash?: Hash;
receipt?: TransactionReceipt;
error?: string;
startTime?: number;
submitTime?: number;
confirmTime?: number;
aborted?: boolean;
}
export interface TransactionTracker {
readonly status: TransactionStatus;
readonly isIdle: boolean;
readonly isSubmitting: boolean;
readonly isPending: boolean;
readonly isSuccess: boolean;
readonly isError: boolean;
readonly isTimeout: boolean;
readonly isAborted: boolean;
readonly isComplete: boolean;
abort(): void;
reset(): void;
execute<T extends unknown[]>(operation: (clients: NetworkClients, ...args: T) => Promise<Hash>, clients: NetworkClients, args: T, options?: TransactionOptions & {
signal?: AbortSignal;
}): Promise<TransactionResult>;
}
/**
* Create a transaction tracker for monitoring transaction state
*/
export declare function createTransactionTracker(): TransactionTracker;
/**
* Batch transaction executor with sequential or parallel execution
*/
export interface BatchTransactionOptions {
mode: "sequential" | "parallel";
failFast?: boolean;
timeout?: number;
onProgress?: (completed: number, total: number, results: (TransactionResult | Error)[]) => void;
}
export interface BatchTransactionResult {
results: (TransactionResult | Error)[];
successCount: number;
errorCount: number;
allSuccessful: boolean;
}
/**
* Execute multiple transactions in batch
*/
export declare function executeBatchTransactions<T extends unknown[]>(operations: Array<{
operation: (clients: NetworkClients, ...args: T) => Promise<Hash>;
args: T;
options?: TransactionOptions;
}>, clients: NetworkClients, batchOptions: BatchTransactionOptions): Promise<BatchTransactionResult>;
/**
* Transaction retry utility with exponential backoff
*/
export interface RetryOptions {
maxRetries?: number;
initialDelay?: number;
maxDelay?: number;
backoffFactor?: number;
retryCondition?: (error: Error) => boolean;
}
export declare function executeTransactionWithRetry<T extends unknown[]>(operation: (clients: NetworkClients, ...args: T) => Promise<Hash>, clients: NetworkClients, args: T, options?: TransactionOptions, retryOptions?: RetryOptions): Promise<TransactionResult>;
/**
* Smart gas estimation and transaction optimization
*/
export interface GasEstimationOptions {
gasLimitMultiplier?: number;
maxFeePerGasMultiplier?: number;
priorityFeeMultiplier?: number;
}
export declare function estimateTransactionGas(clients: NetworkClients, transaction: Parameters<typeof clients.publicClient.estimateGas>[0], options?: GasEstimationOptions): Promise<{
gasLimit: bigint;
maxFeePerGas?: bigint;
maxPriorityFeePerGas?: bigint;
}>;
//# sourceMappingURL=transaction.d.ts.map