Skip to content

Commit

Permalink
feat: user data for compile hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
krigga committed Feb 15, 2024
1 parent f7c1e79 commit 1b2a134
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/compile/CompilerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { SourceResolver, SourcesMap, SourcesArray } from '@ton-community/func-js
import { Cell } from '@ton/core';
import { ConfigProject } from '@tact-lang/compiler';

export type HookParams = {
userData?: any;
};

export type CommonCompilerConfig = {
preCompileHook?: () => Promise<void>;
postCompileHook?: (code: Cell) => Promise<void>;
preCompileHook?: (params: HookParams) => Promise<void>;
postCompileHook?: (code: Cell, params: HookParams) => Promise<void>;
};

export type TactCompilerConfig = {
Expand Down
18 changes: 13 additions & 5 deletions src/compile/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,32 @@ async function doCompileInner(name: string, config: CompilerConfig): Promise<Com
} as FuncCompilerConfig);
}

export async function doCompile(name: string): Promise<CompileResult> {
export async function doCompile(name: string, opts?: CompileOpts): Promise<CompileResult> {
const config = await getCompilerConfigForContract(name);

if (config.preCompileHook !== undefined) {
await config.preCompileHook();
await config.preCompileHook({
userData: opts?.hookUserData,
});
}

const res = await doCompileInner(name, config);

if (config.postCompileHook !== undefined) {
await config.postCompileHook(res.code);
await config.postCompileHook(res.code, {
userData: opts?.hookUserData,
});
}

return res;
}

export async function compile(name: string): Promise<Cell> {
const result = await doCompile(name);
export type CompileOpts = {
hookUserData?: any;
};

export async function compile(name: string, opts?: CompileOpts): Promise<Cell> {
const result = await doCompile(name, opts);

return result.code;
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export { NetworkProvider } from './network/NetworkProvider';

export { createNetworkProvider } from './network/createNetworkProvider';

export { compile } from './compile/compile';
export { compile, CompileOpts } from './compile/compile';

export { CompilerConfig } from './compile/CompilerConfig';
export { CompilerConfig, HookParams } from './compile/CompilerConfig';

export { UIProvider } from './ui/UIProvider';

Expand Down

0 comments on commit 1b2a134

Please sign in to comment.