|
1 | 1 | <script lang="ts"> |
2 | 2 | import type { SendMessageResult } from "@ton-community/sandbox"; |
3 | | - import { Address, fromNano, type Contract } from "ton-core"; |
| 3 | + import { Address, Cell, fromNano, type Contract } from "ton-core"; |
4 | 4 | import { Split, DefaultSplitter } from "@geoffcox/svelte-splitter"; |
5 | 5 | import { Button } from "@svelteuidev/core"; |
6 | 6 | import { Buffer } from "buffer"; |
|
14 | 14 | import "../../loader.css"; |
15 | 15 | import "../../app.css"; |
16 | 16 | import "../../shiki.css"; |
| 17 | + import { slide } from "svelte/transition"; |
17 | 18 |
|
18 | 19 | BigInt.prototype.toJSON = function () { |
19 | 20 | return this.toString(); |
|
24 | 25 | let markdownHtml = ""; |
25 | 26 | let tactHtml = ""; |
26 | 27 | let terminalContent = ""; |
27 | | - let contractInstance: Contract; |
| 28 | + let contractInstances: Contract[]; |
28 | 29 | let addressesNames: { [address: string]: string } = {}; |
29 | 30 | let next: { name: string; id: string } | undefined, prev: { name: string; id: string } | undefined; |
30 | 31 |
|
|
61 | 62 | `Transaction executed: ${compute.success ? "success" : "error"}, ` + |
62 | 63 | `exit code ${compute.exitCode}, gas ${shorten(compute.gasFees, "coins")}`, |
63 | 64 | ); |
64 | | - if (transaction.inMessage?.info.dest.equals(contractInstance.address)) { |
65 | | - if (compute.exitCode == -14) compute.exitCode = 13; |
66 | | - const message = contractInstance?.abi?.errors?.[compute.exitCode]?.message; |
67 | | - if (message) terminalLog(`Error message: ${message}`); |
| 65 | + for (const contractInstance of contractInstances) { |
| 66 | + if (transaction.inMessage?.info.dest.equals(contractInstance.address)) { |
| 67 | + if (compute.exitCode == -14) compute.exitCode = 13; |
| 68 | + const message = contractInstance?.abi?.errors?.[compute.exitCode]?.message; |
| 69 | + if (message) terminalLog(`Error message: ${message}`); |
| 70 | + } |
68 | 71 | } |
69 | 72 | } |
70 | 73 | } |
71 | 74 | } |
72 | 75 | for (const event of transaction.events) { |
73 | 76 | if (event.type == "message_sent") { |
| 77 | + const name = messageName(event.body); |
74 | 78 | terminalLog( |
75 | | - `Message sent: from ${shorten(event.from)}, to ${shorten(event.to)}, ` + |
| 79 | + `Message sent: ${name}, from ${shorten(event.from)}, to ${shorten(event.to)}, ` + |
76 | 80 | `value ${shorten(event.value, "coins")}, ${event.bounced ? "" : "not "}bounced`, |
77 | 81 | ); |
78 | 82 | } |
|
82 | 86 | } |
83 | 87 | } |
84 | 88 |
|
| 89 | + function messageName(body: Cell): string { |
| 90 | + try { |
| 91 | + const slice = body.beginParse(); |
| 92 | + let op = slice.loadInt(32); |
| 93 | + if (op == 0) { |
| 94 | + return `"${slice.loadStringTail()}"`; |
| 95 | + } |
| 96 | + if (op < 0) op += 4294967296; |
| 97 | + for (const contractInstance of contractInstances) { |
| 98 | + for (const type of contractInstance?.abi?.types ?? []) { |
| 99 | + if (op == type.header) return type.name; |
| 100 | + } |
| 101 | + } |
| 102 | + return `unknown (0x${op.toString(16)})`; |
| 103 | + } catch (e) {} |
| 104 | + return "empty"; |
| 105 | + } |
| 106 | +
|
85 | 107 | function shorten(long: Address | bigint, format: "default" | "coins" = "default"): string { |
86 | 108 | if (long instanceof Address) { |
87 | 109 | if (addressesNames[long.toString()]) return addressesNames[long.toString()]; |
|
108 | 130 | }); |
109 | 131 | } |
110 | 132 |
|
111 | | - async function runDeploy(deploy: () => Promise<[Contract, { [address: string]: string }, SendMessageResult[]]>) { |
| 133 | + async function runDeploy(deploy: () => Promise<[Contract[], { [address: string]: string }, SendMessageResult[]]>) { |
112 | 134 | try { |
113 | 135 | terminalLog(`> Deploying contract:`); |
114 | | - const [contract, addresses, results] = await deploy(); |
115 | | - contractInstance = contract; |
| 136 | + const [contracts, addresses, results] = await deploy(); |
| 137 | + contractInstances = contracts; |
116 | 138 | addressesNames = addresses; |
117 | 139 | terminalLogMessages(results); |
118 | 140 | } catch (e: any) { |
|
0 commit comments