Skip to content

Commit 29cce94

Browse files
committed
feat: simplify c5 extraction
1 parent 241764c commit 29cce94

File tree

2 files changed

+13
-31
lines changed

2 files changed

+13
-31
lines changed

src/methods.ts

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -589,40 +589,22 @@ export const computeFinalData = (res: EmulationResultSuccess, balanceBefore: big
589589
}
590590

591591
/**
592-
* Parse the verbose VM log, extract the final `c5` register
593-
* (action list), decode it into an array of `OutAction`s and
592+
* Extract the final `c5` register (action list) from emulation results,
593+
* decode it into an array of `OutAction`s and
594594
* return both the list and the original `c5` cell.
595595
*
596-
* @param logs Multi‑line VM log string from sandbox.
597-
* @returns `{ finalActions, c5 }`
596+
* @param res Successful emulation result.
597+
* @returns `{ finalActions, c5 }`
598598
*/
599-
export const findFinalActions = (logs: string) => {
600-
let finalActions: OutAction[] = []
601-
let c5: Cell | undefined = undefined
602-
for (const line of logs.split("\n")) {
603-
if (line.startsWith("final c5:")) {
604-
const [thisFinalActions, thisC5] = parseC5(line)
605-
finalActions = thisFinalActions
606-
c5 = thisC5
607-
}
599+
export const findFinalActions = (res: EmulationResultSuccess) => {
600+
const actions = res.actions
601+
if (actions === null) {
602+
return {finalActions: [], c5: undefined}
608603
}
609-
return {finalActions, c5}
610-
}
611604

612-
/**
613-
* Convert a single log line that starts with `"final c5:"` into a
614-
* tuple `[actions, c5Cell]`, where `actions` is the decoded list of
615-
* `OutAction`s present in the TVM register `c5`.
616-
*
617-
* @param line One line of VM log containing the hex‑encoded cell.
618-
* @returns Parsed actions array and the raw `Cell`.
619-
*/
620-
export const parseC5 = (line: string): [(OutAction | OutActionReserve)[], Cell] => {
621-
// final c5: C{B5EE9C7...8877FA} -> B5EE9C7...8877FA
622-
const cellBoc = Buffer.from(line.slice("final c5: C{".length, -1), "hex")
623-
const c5 = Cell.fromBoc(cellBoc)[0]
624-
const slice = c5.beginParse()
625-
return [loadOutList(slice), c5]
605+
const c5 = Cell.fromBase64(actions)
606+
const finalActions = loadOutList(c5.asSlice())
607+
return {finalActions, c5}
626608
}
627609

628610
/**

src/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ export const retrace = async (testnet: boolean, txLink: string): Promise<TraceRe
122122
throw new Error("Transaction failed")
123123
}
124124

125-
// find and parse out actions from the c5 control register
126-
const {finalActions, c5} = findFinalActions(txRes.result.vmLog)
125+
// extract out actions from the c5 control register
126+
const {finalActions, c5} = findFinalActions(txRes.result)
127127

128128
const {sender, contract, amount, money, emulatedTx, computeInfo} = computeFinalData(
129129
txRes.result,

0 commit comments

Comments
 (0)