Skip to content

Commit e116b69

Browse files
committed
Added message types to console output
1 parent 53de4fc commit e116b69

File tree

30 files changed

+82
-43
lines changed

30 files changed

+82
-43
lines changed

post-tact-build.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@ for (const file of files) {
1111
console.log(` > WARNING: route (examples)/${example} not found in src`);
1212
continue;
1313
}
14-
let content = fs.readFileSync(`./tact-output/${file}`).toString();
14+
let content = editWrapper(file, fs.readFileSync(`./tact-output/${file}`).toString());
1515
fs.writeFileSync(`./src/routes/(examples)/${example}/${contract}.ts`, content);
1616
console.log(` > Moved ${file}`);
1717
}
18+
19+
function editWrapper(file, content) {
20+
// add missing abi types into the wrapper (currently contains only errors)
21+
const abiFile = file.split(".")[0] + ".abi";
22+
const abi = JSON.parse(fs.readFileSync(`./tact-output/${abiFile}`).toString());
23+
const smallAbi = { types: [] };
24+
for (const type of abi.types) {
25+
smallAbi.types.push({ name: type.name, header: type.header, fields: [] });
26+
}
27+
const abiTypes = JSON.stringify(smallAbi.types);
28+
content = content.replace(`readonly abi: ContractABI = {`, `readonly abi: ContractABI = {\n types: ${abiTypes},`);
29+
30+
// return content
31+
return content;
32+
}

src/lib/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Contract } from "ton-core";
55
interface Store {
66
markdown: string;
77
tactCode: string;
8-
deploy: () => Promise<[Contract, { [address: string]: string }, SendMessageResult[]]>;
8+
deploy: () => Promise<[Contract[], { [address: string]: string }, SendMessageResult[]]>;
99
messages: { [message: string]: () => Promise<SendMessageResult[]> };
1010
getters: { [getter: string]: () => Promise<any> };
1111
prev?: {

src/routes/(examples)/+layout.svelte

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script lang="ts">
22
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";
44
import { Split, DefaultSplitter } from "@geoffcox/svelte-splitter";
55
import { Button } from "@svelteuidev/core";
66
import { Buffer } from "buffer";
@@ -14,6 +14,7 @@
1414
import "../../loader.css";
1515
import "../../app.css";
1616
import "../../shiki.css";
17+
import { slide } from "svelte/transition";
1718
1819
BigInt.prototype.toJSON = function () {
1920
return this.toString();
@@ -24,7 +25,7 @@
2425
let markdownHtml = "";
2526
let tactHtml = "";
2627
let terminalContent = "";
27-
let contractInstance: Contract;
28+
let contractInstances: Contract[];
2829
let addressesNames: { [address: string]: string } = {};
2930
let next: { name: string; id: string } | undefined, prev: { name: string; id: string } | undefined;
3031
@@ -61,18 +62,21 @@
6162
`Transaction executed: ${compute.success ? "success" : "error"}, ` +
6263
`exit code ${compute.exitCode}, gas ${shorten(compute.gasFees, "coins")}`,
6364
);
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+
}
6871
}
6972
}
7073
}
7174
}
7275
for (const event of transaction.events) {
7376
if (event.type == "message_sent") {
77+
const name = messageName(event.body);
7478
terminalLog(
75-
`Message sent: from ${shorten(event.from)}, to ${shorten(event.to)}, ` +
79+
`Message sent: ${name}, from ${shorten(event.from)}, to ${shorten(event.to)}, ` +
7680
`value ${shorten(event.value, "coins")}, ${event.bounced ? "" : "not "}bounced`,
7781
);
7882
}
@@ -82,6 +86,24 @@
8286
}
8387
}
8488
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+
85107
function shorten(long: Address | bigint, format: "default" | "coins" = "default"): string {
86108
if (long instanceof Address) {
87109
if (addressesNames[long.toString()]) return addressesNames[long.toString()];
@@ -108,11 +130,11 @@
108130
});
109131
}
110132
111-
async function runDeploy(deploy: () => Promise<[Contract, { [address: string]: string }, SendMessageResult[]]>) {
133+
async function runDeploy(deploy: () => Promise<[Contract[], { [address: string]: string }, SendMessageResult[]]>) {
112134
try {
113135
terminalLog(`> Deploying contract:`);
114-
const [contract, addresses, results] = await deploy();
115-
contractInstance = contract;
136+
const [contracts, addresses, results] = await deploy();
137+
contractInstances = contracts;
116138
addressesNames = addresses;
117139
terminalLogMessages(results);
118140
} catch (e: any) {

src/routes/(examples)/01-a-simple-counter/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, null)]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, null)]];
2727
},
2828
messages: {
2929
increment: async () => {

src/routes/(examples)/01-hello-world/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, null)]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, null)]];
2727
},
2828
messages: {},
2929
getters: {

src/routes/(examples)/01-the-deployable-trait/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
2727
},
2828
messages: {
2929
increment: async () => {

src/routes/(examples)/02-addresses/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
2727
},
2828
messages: {
2929
"show all": async () => {

src/routes/(examples)/02-bools/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
2727
},
2828
messages: {
2929
"show all": async () => {

src/routes/(examples)/02-constants/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
2727
},
2828
messages: {},
2929
getters: {

src/routes/(examples)/02-integer-ops/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[deployer.address.toString()]: "deployer",
2424
[contract.address.toString()]: "contract",
2525
};
26-
return [contract, addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
26+
return [[contract], addresses, [await contract.send(deployer.getSender(), { value: toNano(1) }, { $$type: "Deploy", queryId: 0n })]];
2727
},
2828
messages: {
2929
"show ops": async () => {

0 commit comments

Comments
 (0)