Skip to content

Commit

Permalink
Made TableRowsResult optional depending on if there are tables in the…
Browse files Browse the repository at this point in the history
… ABI.
  • Loading branch information
thekevinbrown committed Apr 16, 2019
1 parent 8f0a137 commit aed9a42
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/contracts/typeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ export const generateAllTypes = async () => {
export const generateTypes = async (contractIdentifier: string) => {
console.log(`Generating types for ${contractIdentifier}`);

const result: GeneratorLevel = [
'// =====================================================',
'// WARNING: GENERATED FILE',
'//',
'// Any changes you make will be overwritten by Lamington',
'// =====================================================',
'',
`import { Account, Contract, TableRowsResult } from 'lamington';`,
'',
];

const contractName = path.basename(contractIdentifier);
const abiPath = path.join('.lamington', 'compiled_contracts', `${contractIdentifier}.abi`);
const abi = JSON.parse(fs.readFileSync(path.resolve(abiPath), 'utf8'));
Expand All @@ -61,6 +50,22 @@ export const generateTypes = async (contractIdentifier: string) => {
...abi.structs.map((struct: any) => ({ [struct['name']]: struct }))
);

const result: GeneratorLevel = [
'// =====================================================',
'// WARNING: GENERATED FILE',
'//',
'// Any changes you make will be overwritten by Lamington',
'// =====================================================',
'',
];

// Imports
const imports = ['Account', 'Contract'];
if (contractTables.length > 0) imports.push('TableRowsResult');

result.push(`import { ${imports.join(', ')} } from 'lamington';`);
result.push('');

// Generate table row types from ABI
for (const table of contractTables) {
const tableInterface = {
Expand Down

0 comments on commit aed9a42

Please sign in to comment.