@@ -115,67 +115,67 @@ class ContractBoilerplateGenerator {
115115 let params : any [ ] ;
116116 let functionName : string ;
117117
118- for ( [ functionName , parameterList ] of Object . entries ( circuitParams ) ) {
119- for ( [ paramtype , params ] of Object . entries ( parameterList ) ) {
120- const returnpara = { } ;
121- if ( paramtype === 'returnParameters' ) {
122- returnpara [ paramtype ] = params ;
123- delete parameterList [ paramtype ] ;
124- }
125- const newList : string [ ] = [ ] ;
126-
127- params ?. forEach ( circuitParamNode => {
128- switch ( circuitParamNode . bpType ) {
129- case 'nullification' :
130- if ( circuitParamNode . isNullified ) {
131- newList . push ( 'nullifier' ) ;
132- } else {
133- // we use a nullification node for accessed, not nullified, states
134- newList . push ( 'checkNullifier' )
135- }
136- break ;
137- case 'newCommitment' :
138- newList . push ( circuitParamNode . bpType ) ;
139- break ;
140- case 'oldCommitmentExistence' :
141- if ( ! newList . includes ( circuitParamNode . bpType ) ) newList . push ( circuitParamNode . bpType ) ;
142- break ;
143- case 'encryption' :
144-
145- returnpara [ 'encryptionParameters' ] ??= [ ] ;
146- returnpara [ 'encryptionParameters' ] . push ( circuitParamNode . bpType ) ;
147- break ;
148- case undefined : {
149- if (
150- circuitParamNode . nodeType === 'VariableDeclaration' &&
151- ! circuitParamNode . isPrivate &&
152- ! newList . some ( str => str === circuitParamNode . name )
153- ) {
154- if ( circuitParamNode . typeName ?. members ) {
155- newList . push ( ...circuitParamNode . typeName . members . map ( m => `${ circuitParamNode . name } .${ m . name } ` ) ) ;
118+ if ( circuitParams ) {
119+ for ( [ functionName , parameterList ] of Object . entries ( circuitParams ) ) {
120+ for ( [ paramtype , params ] of Object . entries ( parameterList ) ) {
121+ const returnpara = { } ;
122+ if ( paramtype === 'returnParameters' ) {
123+ returnpara [ paramtype ] = params ;
124+ delete parameterList [ paramtype ] ;
125+ }
126+ const newList : string [ ] = [ ] ;
127+ params ?. forEach ( circuitParamNode => {
128+ switch ( circuitParamNode . bpType ) {
129+ case 'nullification' :
130+ if ( circuitParamNode . isNullified ) {
131+ newList . push ( 'nullifier' ) ;
132+ } else {
133+ // we use a nullification node for accessed, not nullified, states
134+ newList . push ( 'checkNullifier' )
135+ }
136+ break ;
137+ case 'newCommitment' :
138+ newList . push ( circuitParamNode . bpType ) ;
139+ break ;
140+ case 'oldCommitmentExistence' :
141+ if ( ! newList . includes ( circuitParamNode . bpType ) ) newList . push ( circuitParamNode . bpType ) ;
156142 break ;
157- } else if ( circuitParamNode . typeName ?. name . includes ( `[` ) ) {
158- // TODO arrays of structs/structs of arrays/more robust soln
159- const arrayLen = circuitParamNode . typeName ?. name . match ( / (?< = \[ ) ( \d + ) (? = \] ) / ) ;
160- for ( let index = 0 ; index < + arrayLen [ 0 ] ; index ++ ) {
161- newList . push ( `${ circuitParamNode . name } [${ index } ]` ) ;
143+ case 'encryption' :
144+ returnpara [ 'encryptionParameters' ] ??= [ ] ;
145+ returnpara [ 'encryptionParameters' ] . push ( circuitParamNode . bpType ) ;
146+ break ;
147+ case undefined :
148+ {
149+ if (
150+ circuitParamNode . nodeType === 'VariableDeclaration' &&
151+ ! circuitParamNode . isPrivate &&
152+ ! newList . some ( str => str === circuitParamNode . name )
153+ ) {
154+ if ( circuitParamNode . typeName ?. members ) {
155+ newList . push ( ...circuitParamNode . typeName . members . map ( m => `${ circuitParamNode . name } .${ m . name } ` ) ) ;
156+ break ;
157+ } else if ( circuitParamNode . typeName ?. name . includes ( `[` ) ) {
158+ // TODO arrays of structs/structs of arrays/more robust soln
159+ const arrayLen = circuitParamNode . typeName ?. name . match ( / (?< = \[ ) ( \d + ) (? = \] ) / ) ;
160+ for ( let index = 0 ; index < + arrayLen [ 0 ] ; index ++ ) {
161+ newList . push ( `${ circuitParamNode . name } [${ index } ]` ) ;
162+ }
163+ break ;
164+ } else newList . push ( circuitParamNode . name ) ;
162165 }
166+ }
167+ break ;
168+
169+ default :
163170 break ;
164- } else newList . push ( circuitParamNode . name ) ;
165171 }
166- }
167- break ;
168-
169- default :
170- break ;
172+ } ) ;
173+ parameterList [ paramtype ] = newList ;
174+ parameterList = { ...parameterList , ...returnpara } ;
171175 }
172- } ) ;
173- parameterList [ paramtype ] = newList ;
174- parameterList = { ...parameterList , ...returnpara } ;
176+ circuitParams [ functionName ] = parameterList ;
177+ }
175178 }
176- circuitParams [ functionName ] = parameterList ;
177-
178- }
179179 const constructorContainsSecret = Object . values ( this . scope . bindings ) . some ( ( binding : any ) => binding . node . kind === 'constructor' ) ;
180180 return { nullifiersRequired, oldCommitmentAccessRequired, newCommitmentsRequired, containsAccessedOnlyState, encryptionRequired, constructorContainsSecret, circuitParams, isjoinSplitCommitmentsFunction} ;
181181 } ,
0 commit comments