Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions e2e-tests/links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const DTON = "https://dton.io/tx/F64C6A3CDF3FAD1D786AACF9A6130F18F3F76EEB71294F5
const DTON_TESTNET =
"https://testnet.dton.io/tx/041293cf00939d8df12badbdf6ab9e2091c8121941dbb170c543595403b5b97b"

const RETRACER =
"https://retracer.ton.org/?tx=7a236ab8bdec69ae46c02a5142dfe0dc45bf03b30607c5f88fdf86daeb8e393b"
const RETRACER_TESTNET =
"https://retracer.ton.org/?tx=041293cf00939d8df12badbdf6ab9e2091c8121941dbb170c543595403b5b97b"

async function startTracing(page: Page, link: string) {
const searchInput = page.getByPlaceholder("Search by transaction hash or explorer link")
await expect(searchInput).toBeVisible()
Expand All @@ -47,6 +52,8 @@ test.describe("TxTracer Viewers Links", () => {
["toncoin testnet", TONCOIN_TESTNET],
["dton", DTON],
["dton testnet", DTON_TESTNET],
["retracer", RETRACER],
["retracer testnet", RETRACER_TESTNET],
]

tracingCases.forEach(([name, link]) => {
Expand Down
20 changes: 19 additions & 1 deletion src/features/txTrace/lib/links.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {BaseTxInfo} from "txtracer-core"
import {Address} from "@ton/core"

export type ExtractionResult = BaseInfo | SingleHash
// eslint-disable-next-line functional/type-declaration-immutability
export type ExtractionResult = BaseInfo | SingleHash | UnknownNetwork

export type BaseInfo = {
readonly $: "BaseInfo"
Expand All @@ -25,6 +26,18 @@ export const SingleHash = (hash: string, testnet: boolean): SingleHash => ({
testnet,
})

// eslint-disable-next-line functional/type-declaration-immutability
export type UnknownNetwork = {
readonly $: "UnknownNetwork"
readonly hash: string
testnet: boolean
}
export const UnknownNetwork = (hash: string): UnknownNetwork => ({
$: "UnknownNetwork",
hash: hash.toLowerCase(),
testnet: false,
})

/**
* Extracts transaction data from a URL pointing to one of the supported TON block explorers.
*
Expand Down Expand Up @@ -99,6 +112,11 @@ export function extractTxInfoFromLink(txLink: string): ExtractionResult | undefi
return SingleHash(hash, testnet)
}

if (txLink.startsWith("https://retracer.ton.org/?tx=")) {
const hash = txLink.slice(29)
return UnknownNetwork(hash)
}

return undefined
}

Expand Down
7 changes: 7 additions & 0 deletions src/features/txTrace/lib/traceTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ async function retraceAny(info: ExtractionResult): Promise<TraceResult> {
if (info.$ === "SingleHash") {
return retrace(info.testnet, info.hash)
}
if (info.$ === "UnknownNetwork") {
return retrace(info.testnet, info.hash)
}

throw new Error("Invalid extraction result")
}
Expand All @@ -65,6 +68,10 @@ async function maybeTestnet(link: string): Promise<{result: TraceResult; network
} catch (error: unknown) {
if (error instanceof Error && error.message.includes("Cannot find transaction info")) {
console.log("Cannot find in mainnet, trying to find in testnet")
if (txLinkInfo?.$ === "UnknownNetwork") {
txLinkInfo.testnet = true
}

const result = await retraceAny(txLinkInfo ?? SingleHash(link, true))
return {result, network: "testnet"}
}
Expand Down