-
Notifications
You must be signed in to change notification settings - Fork 161
/
Copy pathwriteReport.ts
104 lines (95 loc) · 2.94 KB
/
writeReport.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import type { ContractABI } from "@ton/core";
import type { CompilerContext } from "../context/context";
import type { PackageFileFormat } from "../packaging/fileFormat";
import { getType } from "../types/resolveDescriptors";
import { Writer } from "../utils/Writer";
import type { TypeDescription } from "../types/types";
export function writeReport(ctx: CompilerContext, pkg: PackageFileFormat) {
const w = new Writer();
const abi = JSON.parse(pkg.abi) as ContractABI;
w.write(`
# Tact compilation report
Contract: ${pkg.name}
BoC Size: ${Buffer.from(pkg.code, "base64").length} bytes
`);
w.append();
// Structures
w.write(`## Structures (Structs and Messages)`);
w.write("Total structures: " + abi.types!.length);
w.append();
for (const t of abi.types!) {
const tt = getType(
ctx,
t.name.endsWith("$Data") ? t.name.slice(0, -5) : t.name,
);
w.write(`### ${t.name}`);
w.write(`TL-B: \`${tt.tlb!}\``);
w.write(`Signature: \`${tt.signature!}\``);
w.append();
}
// Get methods
w.write(`## Get methods`);
w.write("Total get methods: " + abi.getters!.length);
w.append();
for (const t of abi.getters!) {
w.write(`## ${t.name}`);
if (t.arguments!.length === 0) {
w.write(`No arguments`);
} else {
for (const arg of t.arguments!) {
w.write(`Argument: ${arg.name}`);
}
}
w.append();
}
// Exit codes
w.write(`## Exit codes`);
Object.entries(abi.errors!).forEach(([t, abiError]) => {
w.write(`* ${t}: ${abiError.message}`);
});
w.append();
const t = getType(ctx, pkg.name);
const writtenEdges: Set<string> = new Set();
// Trait inheritance diagram
w.write(`## Trait inheritance diagram`);
w.append();
w.write("```mermaid");
w.write("graph TD");
function writeTraits(t: TypeDescription) {
for (const trait of t.traits) {
const edge = `${t.name} --> ${trait.name}`;
if (writtenEdges.has(edge)) {
continue;
}
writtenEdges.add(edge);
w.write(edge);
writeTraits(trait);
}
}
w.write(t.name);
writeTraits(t);
w.write("```");
w.append();
writtenEdges.clear();
// Contract dependency diagram
w.write(`## Contract dependency diagram`);
w.append();
w.write("```mermaid");
w.write("graph TD");
function writeDependencies(t: TypeDescription) {
for (const dep of t.dependsOn) {
const edge = `${t.name} --> ${dep.name}`;
if (writtenEdges.has(edge)) {
continue;
}
writtenEdges.add(edge);
w.write(edge);
writeDependencies(dep);
}
}
writtenEdges.clear();
w.write(t.name);
writeDependencies(t);
w.write("```");
return w.end();
}