@@ -9,6 +9,7 @@ export interface Contract {
99 constructorCode : string [ ] ;
1010 constructorImplicitArgs ?: Argument [ ] ;
1111 constructorArgs : Argument [ ] ;
12+ variables : string [ ] ;
1213 upgradeable : boolean ;
1314}
1415
@@ -44,11 +45,16 @@ export interface BaseFunction {
4445}
4546
4647export interface ContractFunction extends BaseFunction {
47- libraryCalls : BaseFunction [ ] ;
48+ libraryCalls : LibraryCall [ ] ;
4849 code : string [ ] ;
4950 final : boolean ;
5051}
5152
53+ export interface LibraryCall {
54+ callFn : BaseFunction ;
55+ args : string [ ] ;
56+ }
57+
5258export type FunctionKind = 'view' | 'external' ;
5359
5460export interface Argument {
@@ -67,6 +73,7 @@ export class ContractBuilder implements Contract {
6773
6874 readonly constructorArgs : Argument [ ] = [ ] ;
6975 readonly constructorCode : string [ ] = [ ] ;
76+ readonly variableSet : Set < string > = new Set ( ) ;
7077
7178 private librariesMap : Map < Module , Library > = new Map < Module , Library > ( ) ;
7279 private functionMap : Map < string , ContractFunction > = new Map ( ) ;
@@ -80,6 +87,10 @@ export class ContractBuilder implements Contract {
8087 return [ ...this . functionMap . values ( ) ] ;
8188 }
8289
90+ get variables ( ) : string [ ] {
91+ return [ ...this . variableSet ] ;
92+ }
93+
8394 addModule ( module : Module , params : Value [ ] = [ ] , functions : BaseFunction [ ] = [ ] , initializable : boolean = true ) : boolean {
8495 const key = module ;
8596 const present = this . librariesMap . has ( key ) ;
@@ -116,15 +127,13 @@ export class ContractBuilder implements Contract {
116127 }
117128 }
118129
119- addLibraryCall ( callFn : BaseFunction , baseFn : BaseFunction ) {
130+ addLibraryCall ( callFn : BaseFunction , baseFn : BaseFunction , args : string [ ] = [ ] ) {
120131 const fn = this . addFunction ( baseFn ) ;
121132 if ( callFn . module !== undefined ) {
122133 this . addModuleFunction ( callFn . module , getImportName ( callFn ) ) ;
123134 }
124- if ( callFn . args . length > 0 ) {
125- throw new Error ( `Library call with functions is not supported yet` ) ;
126- }
127- fn . libraryCalls . push ( callFn ) ;
135+ const libraryCall : LibraryCall = { callFn, args } ;
136+ fn . libraryCalls . push ( libraryCall ) ;
128137 }
129138
130139 addFunction ( baseFn : BaseFunction ) : ContractFunction {
@@ -178,4 +187,9 @@ export class ContractBuilder implements Contract {
178187 fn . final = true ;
179188 }
180189
190+ addVariable ( code : string ) : boolean {
191+ const present = this . variableSet . has ( code ) ;
192+ this . variableSet . add ( code ) ;
193+ return ! present ;
194+ }
181195}
0 commit comments