{"version":3,"file":"logic-error.mjs","sources":["../../src/types/logic-error.ts"],"sourcesContent":["const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/\n// inner tx 0 failed: logic eval error: err opcode executed. Details: app=6248, pc=29, opcodes=tx\nconst INNER_LOGIC_ERROR = /inner tx (\\d+) failed:.*?pc=([0-9]+)/\n\n/**\n * Details about a smart contract logic error\n */\nexport interface LogicErrorDetails {\n  /** The ID of the transaction with the logic error */\n  txId: string\n  /** The program counter where the error was */\n  pc: number\n  /** The error message */\n  msg: string\n  /** The full error description */\n  desc: string\n  /** Any trace information included in the error */\n  traces: Record<string, unknown>[]\n}\n\n/** Wraps key functionality around processing logic errors */\nexport class LogicError extends Error {\n  /** Takes an error message and parses out the details of any logic errors in there.\n   * @param error The error message to parse\n   * @returns The logic error details if any, or undefined\n   */\n  // eslint-disable-next-line @typescript-eslint/no-explicit-any\n  static parseLogicError(error: any): LogicErrorDetails | undefined {\n    const errorMessage = error.message\n    const res = LOGIC_ERROR.exec(errorMessage)\n    const innerRes = INNER_LOGIC_ERROR.exec(errorMessage)\n\n    if (res === null || res.length <= 3) return undefined\n\n    return {\n      txId: res[1],\n      msg: res[2],\n      desc: errorMessage,\n      pc: parseInt(innerRes?.[2] ?? res[3] ?? '0'),\n      traces: error.traces,\n    } as LogicErrorDetails\n  }\n\n  public led: LogicErrorDetails\n  public program: string[]\n  public lines = 5\n  public teal_line = 0\n  override stack?: string\n\n  /**\n   * Create a new logic error object.\n   * @param errorDetails The details of the logic error\n   * @param program The TEAL source code, split by line\n   * @param getLineForPc The source map of the TEAL source code\n   */\n  constructor(errorDetails: LogicErrorDetails, program: string[], getLineForPc: (pc: number) => number | undefined) {\n    super()\n    this.led = errorDetails\n    this.program = program\n\n    const line = getLineForPc(errorDetails.pc)\n    this.teal_line = line === undefined ? 0 : line\n\n    this.message = `${this.led.msg}. at:${line}. ${this.led.desc}`\n\n    if (this.teal_line > 0) {\n      const start = this.teal_line > this.lines ? this.teal_line - this.lines : 0\n      const stop = program.length > this.teal_line + this.lines ? this.teal_line + this.lines : program.length\n\n      const stack_lines = program.slice(start, stop)\n\n      stack_lines[stack_lines.length / 2] += ' <--- Error'\n\n      this.stack = stack_lines.join('\\n')\n    }\n  }\n}\n"],"names":[],"mappings":"AAAA,MAAM,WAAW,GAAG,2EAA2E;AAC/F;AACA,MAAM,iBAAiB,GAAG,sCAAsC;AAkBhE;AACM,MAAO,UAAW,SAAQ,KAAK,CAAA;AACnC;;;AAGG;;IAEH,OAAO,eAAe,CAAC,KAAU,EAAA;AAC/B,QAAA,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO;QAClC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC;QAC1C,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,YAAY,CAAC;QAErD,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC;AAAE,YAAA,OAAO,SAAS;QAErD,OAAO;AACL,YAAA,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;AACZ,YAAA,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACX,YAAA,IAAI,EAAE,YAAY;AAClB,YAAA,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;YAC5C,MAAM,EAAE,KAAK,CAAC,MAAM;SACA;;AASxB;;;;;AAKG;AACH,IAAA,WAAA,CAAY,YAA+B,EAAE,OAAiB,EAAE,YAAgD,EAAA;AAC9G,QAAA,KAAK,EAAE;QAXF,IAAK,CAAA,KAAA,GAAG,CAAC;QACT,IAAS,CAAA,SAAA,GAAG,CAAC;AAWlB,QAAA,IAAI,CAAC,GAAG,GAAG,YAAY;AACvB,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO;QAEtB,MAAM,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC,E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