Skip to content

Commit

Permalink
refactor: make codegen of IPFS ABI and interfaces getters optional (t…
Browse files Browse the repository at this point in the history
…act-lang#534)

Two per-project options are introduced to tact.config.json
to enable the previous behavior:
- ipfsAbiGetter
- interfacesGetter
  • Loading branch information
anton-trunov authored Jul 5, 2024
1 parent b119b7b commit d8893ca
Show file tree
Hide file tree
Showing 22 changed files with 140 additions and 113 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- External receivers are enabled for single file compilation: PR [#495](https://github.com/tact-lang/tact/pull/495)
- `[DEBUG]` prefix was removed from debug prints because a similar prefix was already present: PR [#506](https://github.com/tact-lang/tact/pull/506)
- File paths in debug prints always use POSIX file paths (even on Windows): PR [#523](https://github.com/tact-lang/tact/pull/523)
- The IPFS ABI and supported interfaces getters are not generated by default; to generate those, set to `true` the two newly introduced per-project options in `tact.config.json`: `ipfsAbiGetter` and `interfacesGetter`: PR [#534](https://github.com/tact-lang/tact/pull/534)

### Fixed

Expand Down
10 changes: 1 addition & 9 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,15 @@
"*.boc",
"*.fif",
"**/*/output",
"*.spec.ts.snap",
"node_modules",
"dist",
"examples/__snapshots__/multisig-3.spec.ts.snap",
"func",
"grammar/sample.json",
"src/generator/writers/writeStdlib.ts",
"src/generator/writers/__snapshots__/writeSerialization.spec.ts.snap",
"src/grammar/grammar.ohm-bundle.d.ts",
"src/imports/stdlib.ts",
"/src/test/compilation-failed/const-eval-failed.spec.ts",
"src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/deep.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/implicit-init.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/masterchain.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/sample-jetton.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/try-catch.spec.ts.snap",
"src/test/e2e-emulated/__snapshots__/initof.spec.ts.snap",
"src/test/e2e-emulated/address.spec.ts",
"src/test/e2e-emulated/intrinsics.spec.ts",
"src/test/e2e-emulated/optionals.spec.ts",
Expand Down
6 changes: 3 additions & 3 deletions examples/__snapshots__/increment.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`increment should deploy 1`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQD6nAKeXIDwsXvmoLzvgplYcBDQIev4lyf1hznCywYBtZwE",
"to": "kQCFVwtFcoSZ-muVDfXKSpI0fzDrWMuzTgXqo4_QDKKycmXS",
"type": "internal",
"value": "10",
},
Expand All @@ -41,7 +41,7 @@ exports[`increment should deploy 1`] = `
},
},
"bounce": false,
"from": "kQD6nAKeXIDwsXvmoLzvgplYcBDQIev4lyf1hznCywYBtZwE",
"from": "kQCFVwtFcoSZ-muVDfXKSpI0fzDrWMuzTgXqo4_QDKKycmXS",
"to": "@treasure(treasure)",
"type": "internal",
"value": "9.990313",
Expand Down Expand Up @@ -71,7 +71,7 @@ exports[`increment should deploy 2`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQD6nAKeXIDwsXvmoLzvgplYcBDQIev4lyf1hznCywYBtZwE",
"to": "kQCFVwtFcoSZ-muVDfXKSpI0fzDrWMuzTgXqo4_QDKKycmXS",
"type": "internal",
"value": "10",
},
Expand Down
2 changes: 1 addition & 1 deletion examples/__snapshots__/multisig-3.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`multisig-3 should deploy 1`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQBXbQ5TLfxfUX18NuZ6xVRfHett-T_4o8LEea5wStaBGa9n",
"to": "kQCM9SxGev2rN3tzzK8TMNBB0Rhbr-1wc9DKPJoJUzSGM3jm",
"type": "internal",
"value": "10",
},
Expand Down
16 changes: 8 additions & 8 deletions examples/__snapshots__/wallet.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports[`wallet should deploy 1`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQCR5iC3JwCwj6f0xBFwvLeYS8sZvKRQbtXJRpajfqVarbq6",
"to": "kQBkJMYSKVKU-3Ow5coQiKI0gKV--vUYHsJC1g_RbzJk2MF3",
"type": "internal",
"value": "10",
},
Expand All @@ -33,7 +33,7 @@ exports[`wallet should deploy 1`] = `
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
"amount": "0.000000005",
},
{
"$type": "received",
Expand All @@ -45,7 +45,7 @@ exports[`wallet should deploy 1`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQCR5iC3JwCwj6f0xBFwvLeYS8sZvKRQbtXJRpajfqVarbq6",
"to": "kQBkJMYSKVKU-3Ow5coQiKI0gKV--vUYHsJC1g_RbzJk2MF3",
"type": "internal",
"value": "1",
},
Expand All @@ -62,7 +62,7 @@ exports[`wallet should deploy 1`] = `
"type": "empty",
},
"bounce": true,
"from": "kQCR5iC3JwCwj6f0xBFwvLeYS8sZvKRQbtXJRpajfqVarbq6",
"from": "kQBkJMYSKVKU-3Ow5coQiKI0gKV--vUYHsJC1g_RbzJk2MF3",
"to": "@treasure(treasure)",
"type": "internal",
"value": "10",
Expand All @@ -81,7 +81,7 @@ exports[`wallet should deploy 2`] = `
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
"amount": "0.000000005",
},
{
"$type": "received",
Expand All @@ -92,7 +92,7 @@ exports[`wallet should deploy 2`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQCR5iC3JwCwj6f0xBFwvLeYS8sZvKRQbtXJRpajfqVarbq6",
"to": "kQBkJMYSKVKU-3Ow5coQiKI0gKV--vUYHsJC1g_RbzJk2MF3",
"type": "internal",
"value": "1",
},
Expand All @@ -113,7 +113,7 @@ exports[`wallet should deploy 3`] = `
"events": [
{
"$type": "storage-charged",
"amount": "0.000000006",
"amount": "0.000000005",
},
{
"$type": "received",
Expand All @@ -123,7 +123,7 @@ exports[`wallet should deploy 3`] = `
},
"bounce": true,
"from": "@treasure(treasure)",
"to": "kQCR5iC3JwCwj6f0xBFwvLeYS8sZvKRQbtXJRpajfqVarbq6",
"to": "kQBkJMYSKVKU-3Ow5coQiKI0gKV--vUYHsJC1g_RbzJk2MF3",
"type": "internal",
"value": "1",
},
Expand Down
10 changes: 10 additions & 0 deletions schemas/configSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
"default": false,
"description": "False by default. If set to true, enables support of external message receivers.\n\nRead more about external message receivers: https://docs.tact-lang.org/book/external."
},
"ipfsAbiGetter": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, enables generation of a getter with IPFS links describing the contract's ABI.\n\nRead more about IPFS ABI links: https://docs.tact-lang.org/ref/evolution/OTP-003."
},
"interfacesGetter": {
"type": "boolean",
"default": false,
"description": "False by default. If set to true, enables generation of a getter the information on the interfaces provided by the contract.\n\nRead more about supported interfaces: https://docs.tact-lang.org/ref/evolution/OTP-001."
},
"experimental": {
"type": "object",
"description": "Experimental options that might be removed in the future. Use with caution!",
Expand Down
4 changes: 2 additions & 2 deletions src/benchmarks/benchmarks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("benchmarks", () => {
);
expect(gasUsed).toMatchInlineSnapshot(`3648n`);
expect(functions.init!.code.toBoc().length).toMatchInlineSnapshot(
`429`,
`281`,
);
});
it("benchmark functions(inline)", async () => {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe("benchmarks", () => {
);
expect(gasUsed).toMatchInlineSnapshot(`3517n`);
expect(functions.init!.code.toBoc().length).toMatchInlineSnapshot(
`422`,
`274`,
);
});
});
8 changes: 8 additions & 0 deletions src/config/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export function enabledExternals(ctx: CompilerContext) {
return featureEnabled(ctx, "external");
}

export function enabledIpfsAbiGetter(ctx: CompilerContext) {
return featureEnabled(ctx, "ipfsAbiGetter");
}

export function enabledInterfacesGetter(ctx: CompilerContext) {
return featureEnabled(ctx, "interfacesGetter");
}

export function featureEnabled(ctx: CompilerContext, key: string) {
return featureStore.get(ctx, key) === true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/config/parseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const optionsSchema = z
debug: z.boolean().optional(),
masterchain: z.boolean().optional(),
external: z.boolean().optional(),
ipfsAbiGetter: z.boolean().optional(),
interfacesGetter: z.boolean().optional(),
experimental: z
.object({
inline: z.boolean().optional(),
Expand Down
25 changes: 17 additions & 8 deletions src/generator/writers/writeContract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { contractErrors } from "../../abi/errors";
import { enabledInline, enabledMasterchain } from "../../config/features";
import {
enabledInline,
enabledInterfacesGetter,
enabledIpfsAbiGetter,
enabledMasterchain,
} from "../../config/features";
import { ItemOrigin } from "../../grammar/grammar";
import { InitDescription, TypeDescription } from "../../types/types";
import { WriterContext } from "../Writer";
Expand Down Expand Up @@ -248,15 +253,19 @@ export function writeMainContract(
}

// Interfaces
writeInterfaces(type, ctx);
if (enabledInterfacesGetter(ctx.ctx)) {
writeInterfaces(type, ctx);
}

// ABI
ctx.append(`_ get_abi_ipfs() method_id {`);
ctx.inIndent(() => {
ctx.append(`return "${abiLink}";`);
});
ctx.append(`}`);
ctx.append();
if (enabledIpfsAbiGetter(ctx.ctx)) {
ctx.append(`_ get_abi_ipfs() method_id {`);
ctx.inIndent(() => {
ctx.append(`return "${abiLink}";`);
});
ctx.append(`}`);
ctx.append();
}

// Deployed
ctx.append(`_ lazy_deployment_completed() method_id {`);
Expand Down
7 changes: 6 additions & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ function configForSingleFile(fileName: string): ConfigWithRootPath {
name: path.basename(fileName, ".tact"),
path: fileName,
output: path.dirname(fileName),
options: { debug: true, external: true },
options: {
debug: true,
external: true,
ipfsAbiGetter: false,
interfacesGetter: false,
},
mode: "full",
},
],
Expand Down
8 changes: 8 additions & 0 deletions src/pipeline/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ export async function build(args: {
logger.error(" > 👀 Enabling inline");
ctx = featureEnable(ctx, "inline");
}
if (config.options.ipfsAbiGetter) {
logger.error(" > 👀 Enabling IPFS ABI getter");
ctx = featureEnable(ctx, "ipfsAbiGetter");
}
if (config.options.interfacesGetter) {
logger.error(" > 👀 Enabling contract interfaces getter");
ctx = featureEnable(ctx, "interfacesGetter");
}
}

// Precompile
Expand Down
42 changes: 17 additions & 25 deletions src/test/e2e-emulated/__snapshots__/constants.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ ConstantTester {
},
],
},
"address": kQBgzQPc9i9gX1N6ouvYrrsJXpSfdpVxh6poWq9vD8gjOCN_,
"address": kQC1tr9E8NNDdnsvyLWPBaXhdX_hhp8x5khdXUOtjWo-v04i,
"init": {
"code": x{FF00F4A413F4BCF2C80B}
x{62_}
Expand Down Expand Up @@ -887,12 +887,10 @@ ConstantTester {
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{75}
x{5}
x{BF5DB3CDB3C31}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{70}
x{BD182705CEC3D5D2CAE7B1E84EC39D64A851B6682709DD6352D2B647CB322D3AF2DFDF1623982702055C01B80676394CE583AAE4725B2C382701BD49DEF954596F1C753D3DE0559C32682709D974E5AB34ECB733A0E966D9466E8A4}
x{A6EBB679B67863_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{70}
x{AA83DB3CDB3C31}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
Expand Down Expand Up @@ -927,12 +925,10 @@ ConstantTester {
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{6D}
x{6A_}
x{ACB6CF36CF0C6_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{800B}
x{AEE3435697066733A2F2F516D64786B474251726F77703652356156704659664C4838555657364C7946414B4D7334614C653234413171343882_}
x{A24B6CF36CF0C6_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{800B}
x{A767B679B67863_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
Expand Down Expand Up @@ -1141,12 +1137,10 @@ ConstantTester {
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{75}
x{5}
x{BF5DB3CDB3C31}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{70}
x{BD182705CEC3D5D2CAE7B1E84EC39D64A851B6682709DD6352D2B647CB322D3AF2DFDF1623982702055C01B80676394CE583AAE4725B2C382701BD49DEF954596F1C753D3DE0559C32682709D974E5AB34ECB733A0E966D9466E8A4}
x{A6EBB679B67863_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{70}
x{AA83DB3CDB3C31}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
Expand Down Expand Up @@ -1181,12 +1175,10 @@ ConstantTester {
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{6D}
x{6A_}
x{ACB6CF36CF0C6_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{800B}
x{AEE3435697066733A2F2F516D64786B474251726F77703652356156704659664C4838555657364C7946414B4D7334614C653234413171343882_}
x{A24B6CF36CF0C6_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
x{800B}
x{A767B679B67863_}
x{ED44D0D401F863D20030916DE0F828D70B0A8309BAF2E089DB3C}
x{6D}
Expand Down
Loading

0 comments on commit d8893ca

Please sign in to comment.