{"version":3,"sources":["../src/program-error.ts"],"names":["isSolanaError","SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM"],"mappings":";;;;;AA8BO,SAAS,cAAA,CACZ,KAAA,EACA,kBAAA,EACA,cAAA,EACA,IAAA,EAE4D;AAC5D,EAAA,IAAI,CAACA,oBAAA,CAAc,KAAA,EAAOC,8CAAuC,CAAA,EAAG;AAChE,IAAA,OAAO,KAAA;AAAA,EACX;AACA,EAAA,MAAM,4BAA4B,kBAAA,CAAmB,YAAA,CAAa,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG,cAAA;AACxF,EAAA,IAAI,CAAC,yBAAA,IAA6B,yBAAA,KAA8B,cAAA,EAAgB;AAC5E,IAAA,OAAO,KAAA;AAAA,EACX;AACA,EAAA,OAAO,OAAO,IAAA,KAAS,WAAA,IAAe,KAAA,CAAM,QAAQ,IAAA,KAAS,IAAA;AACjE","file":"index.node.cjs","sourcesContent":["import type { Address } from '@solana/addresses';\nimport { isSolanaError, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, SolanaError } from '@solana/errors';\n\n/**\n * Identifies whether an error -- typically caused by a transaction failure -- is a custom program\n * error from the provided program address.\n *\n * @param transactionMessage The transaction message that failed to execute. Since the RPC response\n * only provides the index of the failed instruction, the transaction message is required to\n * determine its program address\n * @param programAddress The address of the program from which the error is expected to have\n * originated\n * @param code The expected error code of the custom program error. When provided, the function will\n * check that the custom program error code matches the given value.\n *\n * @example\n * ```ts\n * try {\n * // Send and confirm your transaction.\n * } catch (error) {\n * if (isProgramError(error, transactionMessage, myProgramAddress, 42)) {\n * // Handle custom program error 42 from this program.\n * } else if (isProgramError(error, transactionMessage, myProgramAddress)) {\n * // Handle all other custom program errors from this program.\n * } else {\n * throw error;\n * }\n * }\n * ```\n */\nexport function isProgramError(\n error: unknown,\n transactionMessage: { instructions: Record },\n programAddress: Address,\n code?: TProgramErrorCode,\n): error is Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> &\n SolanaError {\n if (!isSolanaError(error, SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM)) {\n return false;\n }\n const instructionProgramAddress = transactionMessage.instructions[error.context.index]?.programAddress;\n if (!instructionProgramAddress || instructionProgramAddress !== programAddress) {\n return false;\n }\n return typeof code === 'undefined' || error.context.code === code;\n}\n"]}