forked from ton-blockchain/wallet-contract
-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.ts
50 lines (44 loc) · 1.65 KB
/
build.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
import {compileFunc, compilerVersion} from '@ton-community/func-js';
import {readFile, writeFile} from 'fs/promises';
import {fromCode} from 'tvm-disassembler';
import {Cell} from '@ton/core';
export async function disasm(c: Cell): Promise<string> {
let s = await fromCode(c);
return s.replaceAll('s0 s1 XCHG', 'SWAP')
.replaceAll('s0 PUSH', 'DUP');
}
export async function compile(outFile: boolean = true, postprocess: boolean = true) {
console.log(await compilerVersion());
let result = await compileFunc({
targets: ['stdlib.fc', 'wallet.fc'],
sources: {
'stdlib.fc': await readFile('./func/stdlib.fc', {encoding: 'utf-8'}),
'wallet.fc': await readFile('./func/wallet.fc', {encoding: 'utf-8'}),
}
});
if (result.status === 'error') {
console.error(result.message)
return null;
}
if (result.warnings)
console.warn(result.warnings);
if (outFile) {
await writeFile('./dist/wallet.fif', result.fiftCode);
await writeFile('./dist/wallet.boc', result.codeBoc);
if (postprocess)
await writeFile('./dist/wallet-da.fif', await disasm(Cell.fromBase64(result.codeBoc)));
}
return result.codeBoc;
}
export async function compilePlugin() {
let result = await compileFunc({
targets: ['stdlib.fc', 'plugin.fc'],
sources: {
'stdlib.fc': await readFile('./func/stdlib.fc', {encoding: 'utf-8'}),
'plugin.fc': await readFile('./func/plugin.fc', {encoding: 'utf-8'}),
}
});
if (result.status === 'ok') return result.codeBoc;
return null;
}
export const walletBoc = compile();