Skip to content

Commit

Permalink
feature: generate initialization parameters from compiler context (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulyadav-57 authored Jul 19, 2024
1 parent 6923353 commit 2114df1
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/utility/abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ContractLanguage } from '@/interfaces/workspace.interface';
import { CompilerContext } from '@tact-lang/compiler/dist/context';
import { getType } from '@tact-lang/compiler/dist/types/resolveDescriptors';
import {
ABIArgument,
ABIField,
Expand Down Expand Up @@ -152,3 +154,55 @@ export class ABIParser {
});
}
}

export function getContractInitParams(
ctx: CompilerContext,
contractName: string,
) {
const contactType = getType(ctx, contractName);

if (!contactType.init?.args) return [];
return contactType.init.args.map((item) => {
let additionalProps = {};
switch (item.type.kind) {
case 'ref':
additionalProps = {
type: item.type.name,
optinal: item.type.optional,
};
break;
case 'map':
additionalProps = {
key: item.type.value,
type: undefined,
value: item.type.value,
};
break;
case 'void':
additionalProps = {
name: item.name,
type: 'void',
};
break;
case 'null':
additionalProps = {
name: item.name,
type: 'null',
};
break;
default:
additionalProps = {
name: 'unknown',
type: 'null',
};
break;
}
return {
name: item.name,
type: {
...additionalProps,
kind: item.type.kind === 'map' ? 'dict' : 'simple',
},
};
});
}

0 comments on commit 2114df1

Please sign in to comment.