Skip to content

Commit

Permalink
Check libs also in data and msg body
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueCarry committed Sep 19, 2024
1 parent f50340b commit d7179fd
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/hooks/useEmulatedTxInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { Blockchain } from '@ton/sandbox'
const libs: Record<string, Buffer> = {}
let megaLibsCell = beginCell().endCell()

async function checkForLibraries(cell: Cell, liteClient: LiteClient) {
const toCheck = [cell]
async function checkForLibraries(cells: Cell[], liteClient: LiteClient) {
const toCheck = [...cells]
let libFound = false
while (toCheck.length > 0) {
const current = toCheck.pop()
Expand All @@ -25,6 +25,13 @@ async function checkForLibraries(cell: Cell, liteClient: LiteClient) {
}

const libData = await liteClient.getLibraries([libHash])
if (libData.result.length === 0) {
console.log('lib not found', libHash.toString('hex'))
continue
} else {
console.log('lib found', libHash.toString('hex'))
}

for (const lib of libData.result) {
libs[lib.hash.toString('hex')] = lib.data
}
Expand Down Expand Up @@ -56,13 +63,21 @@ async function checkAndLoadLibraries(tx: ParsedTransaction, liteClient: LiteClie
) {
// Check lib in init
if (tx.inMessage?.init) {
const code = tx.inMessage.init.code
if (code) {
const libFound = await checkForLibraries(code, liteClient)
if (libFound) {
console.log('lib found in init, restarting emulator')
return true
}
const messageCells: Cell[] = []
if (tx?.inMessage?.init?.code) {
messageCells.push(tx.inMessage.init.code)
}
if (tx?.inMessage?.init?.data) {
messageCells.push(tx.inMessage.init.data)
}
if (tx?.inMessage?.body) {
messageCells.push(tx.inMessage.body)
}

const libFound = await checkForLibraries(messageCells, liteClient)
if (libFound) {
console.log('lib found in init, restarting emulator')
return true
}
}

Expand All @@ -75,7 +90,7 @@ async function checkAndLoadLibraries(tx: ParsedTransaction, liteClient: LiteClie
if (destinationState?.state?.storage?.state?.type === 'active') {
const code = destinationState?.state?.storage?.state?.state?.code
if (code) {
const libFound = await checkForLibraries(code, liteClient)
const libFound = await checkForLibraries([code], liteClient)
if (libFound) {
console.log('lib found in destination, restarting emulator')
return true
Expand Down

0 comments on commit d7179fd

Please sign in to comment.