Skip to content

Commit

Permalink
Fix constructor for upgradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Nov 28, 2023
1 parent 46788bb commit 45ac69d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
12 changes: 0 additions & 12 deletions packages/core-cairo/src/options.ts

This file was deleted.

11 changes: 4 additions & 7 deletions packages/core-cairo/src/print.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'array.prototype.flatmap/auto';

import type { Contract, Component, Argument, Value, Impl, ContractFunction, } from './contract';
import { Helpers, withHelpers } from './options';

import { formatLines, spaceBetween, Lines } from './utils/format-lines';
// import { getImportsMap } from './utils/imports-map';
Expand All @@ -13,8 +12,6 @@ export function printContract(contract: Contract): string {

console.log('printing contract', contract);

const helpers = withHelpers(contract);

const fns = contract.functions.map(fn => printFunction(fn));

// const hasViews = fns.views.some(l => l.length > 0);
Expand Down Expand Up @@ -44,7 +41,7 @@ export function printContract(contract: Contract): string {
// contract.variables,


printConstructor(contract, helpers),
printConstructor(contract),

...fns,

Expand Down Expand Up @@ -199,15 +196,15 @@ function printImportLines(importStatements: Map<string, Set<string>>) {
return lines;
}

function printConstructor(contract: Contract, helpers: Helpers): Lines[] {
function printConstructor(contract: Contract): Lines[] {
const hasParentParams = contract.components.some(p => p.initializer !== undefined && p.initializer.params.length > 0);
const hasConstructorCode = contract.constructorCode.length > 0;
if (hasParentParams || hasConstructorCode) {
const parents = contract.components
.filter(hasInitializer)
.flatMap(p => printParentConstructor(p));
const modifier = helpers.upgradeable ? 'external' : 'constructor';
const head = helpers.upgradeable ? 'func initializer' : 'fn constructor';
const modifier = 'constructor';
const head = 'fn constructor';
const args = [ getSelfArg(), ...contract.constructorArgs ];

const body = spaceBetween(
Expand Down

0 comments on commit 45ac69d

Please sign in to comment.