UNPKG

@gorbchain-xyz/chaindecode

Version:

GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.

99 lines (98 loc) 5.53 kB
import { SDKError, ErrorSeverity, ErrorCategory } from './base.js'; /** * Transaction not found */ export class TransactionNotFoundError extends SDKError { constructor(signature, context = {}, options = {}) { super(`Transaction not found: ${signature}`, 'TRANSACTION_NOT_FOUND', ErrorSeverity.MEDIUM, ErrorCategory.TRANSACTION, Object.assign(Object.assign({}, context), { transactionSignature: signature }), Object.assign(Object.assign({}, options), { retryable: true, solution: 'The transaction may not have been processed yet. Try again in a few seconds, or check if the signature is correct.' })); this.signature = signature; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { signature: this.signature }); } } /** * Transaction failed to process */ export class TransactionFailedError extends SDKError { constructor(message, signature, errorCode, logs, context = {}, options = {}) { super(message, 'TRANSACTION_FAILED', ErrorSeverity.HIGH, ErrorCategory.TRANSACTION, Object.assign(Object.assign({}, context), { transactionSignature: signature }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The transaction failed during execution. Check the transaction logs for more details about the failure.' })); this.signature = signature; this.errorCode = errorCode; this.logs = logs; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { signature: this.signature, errorCode: this.errorCode, logs: this.logs }); } } /** * Transaction signature invalid */ export class InvalidTransactionSignatureError extends SDKError { constructor(signature, context = {}, options = {}) { super(`Invalid transaction signature format: ${signature}`, 'INVALID_TRANSACTION_SIGNATURE', ErrorSeverity.MEDIUM, ErrorCategory.VALIDATION, Object.assign(Object.assign({}, context), { transactionSignature: signature }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'The transaction signature is not in the correct format. It should be a base58-encoded string.' })); this.signature = signature; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { signature: this.signature }); } } /** * Transaction processing timeout */ export class TransactionTimeoutError extends SDKError { constructor(timeoutMs, signature, context = {}, options = {}) { super(`Transaction processing timed out after ${timeoutMs}ms`, 'TRANSACTION_TIMEOUT', ErrorSeverity.MEDIUM, ErrorCategory.TIMEOUT, Object.assign(Object.assign({}, context), { transactionSignature: signature }), Object.assign(Object.assign({}, options), { retryable: true, solution: 'The transaction is taking longer than expected to process. It may still complete successfully.' })); this.signature = signature; this.timeoutMs = timeoutMs; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { signature: this.signature, timeoutMs: this.timeoutMs }); } } /** * Transaction simulation failed */ export class TransactionSimulationError extends SDKError { constructor(message, error, logs, context = {}, options = {}) { super(`Transaction simulation failed: ${message}`, 'TRANSACTION_SIMULATION_ERROR', ErrorSeverity.MEDIUM, ErrorCategory.TRANSACTION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'The transaction simulation failed. Check the transaction parameters and account states.' })); this.error = error; this.logs = logs; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { error: this.error, logs: this.logs }); } } /** * Insufficient funds for transaction */ export class InsufficientFundsError extends SDKError { constructor(required, available, account, context = {}, options = {}) { const message = required && available ? `Insufficient funds. Required: ${required}, Available: ${available}` : 'Insufficient funds for transaction'; super(message, 'INSUFFICIENT_FUNDS', ErrorSeverity.MEDIUM, ErrorCategory.TRANSACTION, Object.assign(Object.assign({}, context), { account }), Object.assign(Object.assign({}, options), { retryable: false, solution: 'Ensure the account has sufficient funds to cover the transaction cost and any token transfers.' })); this.required = required; this.available = available; this.account = account; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { required: this.required, available: this.available, account: this.account }); } } /** * Transaction too large */ export class TransactionTooLargeError extends SDKError { constructor(size, maxSize, context = {}, options = {}) { const message = size && maxSize ? `Transaction too large. Size: ${size} bytes, Max: ${maxSize} bytes` : 'Transaction exceeds maximum size limit'; super(message, 'TRANSACTION_TOO_LARGE', ErrorSeverity.MEDIUM, ErrorCategory.TRANSACTION, context, Object.assign(Object.assign({}, options), { retryable: false, solution: 'Reduce the number of instructions or accounts in the transaction, or split it into multiple transactions.' })); this.size = size; this.maxSize = maxSize; } toJSON() { return Object.assign(Object.assign({}, super.toJSON()), { size: this.size, maxSize: this.maxSize }); } }