@alephium/web3 0.3.0-rc.3 → 0.3.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -908,7 +908,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
908
908
  }
909
909
  /**
910
910
  * @title Alephium API
911
- * @version 1.6.0
911
+ * @version 1.6.1
912
912
  * @baseUrl ../
913
913
  */
914
914
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -149,7 +149,7 @@ class HttpClient {
149
149
  exports.HttpClient = HttpClient;
150
150
  /**
151
151
  * @title Alephium API
152
- * @version 1.6.0
152
+ * @version 1.6.1
153
153
  * @baseUrl ../
154
154
  */
155
155
  class Api extends HttpClient {
@@ -5,7 +5,7 @@ export declare type EventSig = node.EventSig;
5
5
  export declare type FunctionSig = node.FunctionSig;
6
6
  export declare type Fields = NamedVals;
7
7
  export declare type Arguments = NamedVals;
8
- declare enum SourceType {
8
+ declare enum SourceKind {
9
9
  Contract = 0,
10
10
  Script = 1,
11
11
  AbstractContract = 2,
@@ -16,28 +16,29 @@ export declare type CompilerOptions = node.CompilerOptions & {
16
16
  };
17
17
  export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
18
18
  export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
19
- declare class TypedMatcher<T extends SourceType> {
19
+ declare class TypedMatcher<T extends SourceKind> {
20
20
  matcher: RegExp;
21
21
  type: T;
22
22
  constructor(pattern: string, type: T);
23
- match(str: string): number;
24
23
  }
25
- declare class SourceFile {
26
- type: SourceType;
27
- contractPath: string;
24
+ declare class SourceInfo {
25
+ type: SourceKind;
26
+ name: string;
27
+ contractRelativePath: string;
28
28
  sourceCode: string;
29
29
  sourceCodeHash: string;
30
30
  getArtifactPath(artifactsRootDir: string): string;
31
- constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
32
- static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
31
+ constructor(type: SourceKind, name: string, sourceCode: string, sourceCodeHash: string, contractRelativePath: string);
32
+ static from(type: SourceKind, name: string, sourceCode: string, contractRelativePath: string): Promise<SourceInfo>;
33
33
  }
34
34
  declare class Compiled<T extends Artifact> {
35
- sourceFile: SourceFile;
35
+ sourceInfo: SourceInfo;
36
36
  artifact: T;
37
37
  warnings: string[];
38
- constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
38
+ constructor(sourceInfo: SourceInfo, artifact: T, warnings: string[]);
39
39
  }
40
40
  declare type CodeInfo = {
41
+ sourceFile: string;
41
42
  sourceCodeHash: string;
42
43
  bytecodeDebugPatch: string;
43
44
  codeHashDebug: string;
@@ -50,25 +51,24 @@ declare class ProjectArtifact {
50
51
  static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
51
52
  constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>);
52
53
  saveToFile(rootPath: string): Promise<void>;
53
- needToReCompile(compilerOptions: node.CompilerOptions, files: SourceFile[]): boolean;
54
+ needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[]): boolean;
54
55
  static from(rootPath: string): Promise<ProjectArtifact | undefined>;
55
56
  }
56
57
  export declare class Project {
57
- sourceFiles: SourceFile[];
58
- contracts: Compiled<Contract>[];
59
- scripts: Compiled<Script>[];
58
+ sourceInfos: SourceInfo[];
59
+ contracts: Map<string, Compiled<Contract>>;
60
+ scripts: Map<string, Compiled<Script>>;
60
61
  projectArtifact: ProjectArtifact;
61
62
  readonly contractsRootDir: string;
62
63
  readonly artifactsRootDir: string;
63
64
  static currentProject: Project;
64
- static readonly abstractContractMatcher: TypedMatcher<SourceType>;
65
- static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
66
- static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
67
- static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
68
- static readonly matchers: TypedMatcher<SourceType>[];
69
- static buildProjectArtifact(sourceFiles: SourceFile[], contracts: Compiled<Contract>[], scripts: Compiled<Script>[], compilerOptions: node.CompilerOptions): ProjectArtifact;
65
+ static readonly abstractContractMatcher: TypedMatcher<SourceKind>;
66
+ static readonly contractMatcher: TypedMatcher<SourceKind.Contract>;
67
+ static readonly interfaceMatcher: TypedMatcher<SourceKind.Interface>;
68
+ static readonly scriptMatcher: TypedMatcher<SourceKind.Script>;
69
+ static readonly matchers: TypedMatcher<SourceKind>[];
70
+ static buildProjectArtifact(sourceInfos: SourceInfo[], contracts: Map<string, Compiled<Contract>>, scripts: Map<string, Compiled<Script>>, compilerOptions: node.CompilerOptions): ProjectArtifact;
70
71
  private constructor();
71
- private getContractPath;
72
72
  static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
73
73
  static contract(name: string): Contract;
74
74
  static script(name: string): Script;
@@ -53,13 +53,14 @@ const ralph = __importStar(require("./ralph"));
53
53
  const utils_1 = require("../utils");
54
54
  const global_1 = require("../global");
55
55
  const __1 = require("..");
56
- var SourceType;
57
- (function (SourceType) {
58
- SourceType[SourceType["Contract"] = 0] = "Contract";
59
- SourceType[SourceType["Script"] = 1] = "Script";
60
- SourceType[SourceType["AbstractContract"] = 2] = "AbstractContract";
61
- SourceType[SourceType["Interface"] = 3] = "Interface";
62
- })(SourceType || (SourceType = {}));
56
+ const path = __importStar(require("path"));
57
+ var SourceKind;
58
+ (function (SourceKind) {
59
+ SourceKind[SourceKind["Contract"] = 0] = "Contract";
60
+ SourceKind[SourceKind["Script"] = 1] = "Script";
61
+ SourceKind[SourceKind["AbstractContract"] = 2] = "AbstractContract";
62
+ SourceKind[SourceKind["Interface"] = 3] = "Interface";
63
+ })(SourceKind || (SourceKind = {}));
63
64
  exports.DEFAULT_NODE_COMPILER_OPTIONS = {
64
65
  ignoreUnusedConstantsWarnings: false,
65
66
  ignoreUnusedVariablesWarnings: false,
@@ -74,29 +75,26 @@ class TypedMatcher {
74
75
  this.matcher = new RegExp(pattern, 'mg');
75
76
  this.type = type;
76
77
  }
77
- match(str) {
78
- const results = str.match(this.matcher);
79
- return results === null ? 0 : results.length;
80
- }
81
78
  }
82
- class SourceFile {
83
- constructor(type, sourceCode, sourceCodeHash, contractPath) {
79
+ class SourceInfo {
80
+ constructor(type, name, sourceCode, sourceCodeHash, contractRelativePath) {
84
81
  this.type = type;
82
+ this.name = name;
85
83
  this.sourceCode = sourceCode;
86
84
  this.sourceCodeHash = sourceCodeHash;
87
- this.contractPath = contractPath;
85
+ this.contractRelativePath = contractRelativePath;
88
86
  }
89
87
  getArtifactPath(artifactsRootDir) {
90
- return artifactsRootDir + this.contractPath.slice(this.contractPath.indexOf('/')) + '.json';
88
+ return path.join(artifactsRootDir, this.contractRelativePath) + '.json';
91
89
  }
92
- static async from(type, sourceCode, contractPath) {
90
+ static async from(type, name, sourceCode, contractRelativePath) {
93
91
  const sourceCodeHash = await crypto_1.webcrypto.subtle.digest('SHA-256', buffer_1.Buffer.from(sourceCode));
94
- return new SourceFile(type, sourceCode, buffer_1.Buffer.from(sourceCodeHash).toString('hex'), contractPath);
92
+ return new SourceInfo(type, name, sourceCode, buffer_1.Buffer.from(sourceCodeHash).toString('hex'), contractRelativePath);
95
93
  }
96
94
  }
97
95
  class Compiled {
98
- constructor(sourceFile, artifact, warnings) {
99
- this.sourceFile = sourceFile;
96
+ constructor(sourceInfo, artifact, warnings) {
97
+ this.sourceInfo = sourceInfo;
100
98
  this.artifact = artifact;
101
99
  this.warnings = warnings;
102
100
  }
@@ -117,12 +115,15 @@ class ProjectArtifact {
117
115
  }
118
116
  }
119
117
  async saveToFile(rootPath) {
120
- const filepath = rootPath + '/' + ProjectArtifact.artifactFileName;
121
- const artifact = { compilerOptionsUsed: this.compilerOptionsUsed, infos: Object.fromEntries(this.infos) };
118
+ const filepath = path.join(rootPath, ProjectArtifact.artifactFileName);
119
+ const artifact = {
120
+ compilerOptionsUsed: this.compilerOptionsUsed,
121
+ infos: Object.fromEntries(new Map([...this.infos].sort()))
122
+ };
122
123
  const content = JSON.stringify(artifact, null, 2);
123
124
  return fs_2.promises.writeFile(filepath, content);
124
125
  }
125
- needToReCompile(compilerOptions, files) {
126
+ needToReCompile(compilerOptions, sourceInfos) {
126
127
  ProjectArtifact.checkCompilerOptionsParameter(compilerOptions);
127
128
  const optionsMatched = Object.entries(compilerOptions).every(([key, inputOption]) => {
128
129
  const usedOption = this.compilerOptionsUsed[`${key}`];
@@ -131,19 +132,19 @@ class ProjectArtifact {
131
132
  if (!optionsMatched) {
132
133
  return true;
133
134
  }
134
- if (files.length !== this.infos.size) {
135
+ if (sourceInfos.length !== this.infos.size) {
135
136
  return true;
136
137
  }
137
- for (const file of files) {
138
- const info = this.infos.get(file.contractPath);
139
- if (typeof info === 'undefined' || info.sourceCodeHash !== file.sourceCodeHash) {
138
+ for (const sourceInfo of sourceInfos) {
139
+ const info = this.infos.get(sourceInfo.name);
140
+ if (typeof info === 'undefined' || info.sourceCodeHash !== sourceInfo.sourceCodeHash) {
140
141
  return true;
141
142
  }
142
143
  }
143
144
  return false;
144
145
  }
145
146
  static async from(rootPath) {
146
- const filepath = rootPath + '/' + ProjectArtifact.artifactFileName;
147
+ const filepath = path.join(rootPath, ProjectArtifact.artifactFileName);
147
148
  if (!fs_1.default.existsSync(filepath)) {
148
149
  return undefined;
149
150
  }
@@ -156,38 +157,44 @@ class ProjectArtifact {
156
157
  }
157
158
  ProjectArtifact.artifactFileName = '.project.json';
158
159
  class Project {
159
- constructor(contractsRootDir, artifactsRootDir, sourceFiles, contracts, scripts, errorOnWarnings, projectArtifact) {
160
+ constructor(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact) {
160
161
  this.contractsRootDir = contractsRootDir;
161
162
  this.artifactsRootDir = artifactsRootDir;
162
- this.sourceFiles = sourceFiles;
163
+ this.sourceInfos = sourceInfos;
163
164
  this.contracts = contracts;
164
165
  this.scripts = scripts;
165
166
  this.projectArtifact = projectArtifact;
166
167
  if (errorOnWarnings) {
167
- Project.checkCompilerWarnings([...contracts.map((c) => c.warnings).flat(), ...scripts.map((s) => s.warnings).flat()], errorOnWarnings);
168
+ Project.checkCompilerWarnings([
169
+ ...[...contracts.entries()].map((c) => c[1].warnings).flat(),
170
+ ...[...scripts.entries()].map((s) => s[1].warnings).flat()
171
+ ], errorOnWarnings);
168
172
  }
169
173
  }
170
- static buildProjectArtifact(sourceFiles, contracts, scripts, compilerOptions) {
174
+ static buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions) {
171
175
  const files = new Map();
172
176
  contracts.forEach((c) => {
173
- files.set(c.sourceFile.contractPath, {
174
- sourceCodeHash: c.sourceFile.sourceCodeHash,
177
+ files.set(c.artifact.name, {
178
+ sourceFile: c.sourceInfo.contractRelativePath,
179
+ sourceCodeHash: c.sourceInfo.sourceCodeHash,
175
180
  bytecodeDebugPatch: c.artifact.bytecodeDebugPatch,
176
181
  codeHashDebug: c.artifact.codeHashDebug,
177
182
  warnings: c.warnings
178
183
  });
179
184
  });
180
185
  scripts.forEach((s) => {
181
- files.set(s.sourceFile.contractPath, {
182
- sourceCodeHash: s.sourceFile.sourceCodeHash,
186
+ files.set(s.artifact.name, {
187
+ sourceFile: s.sourceInfo.contractRelativePath,
188
+ sourceCodeHash: s.sourceInfo.sourceCodeHash,
183
189
  bytecodeDebugPatch: s.artifact.bytecodeDebugPatch,
184
190
  codeHashDebug: '',
185
191
  warnings: s.warnings
186
192
  });
187
193
  });
188
- const compiledSize = contracts.length + scripts.length;
189
- sourceFiles.slice(compiledSize).forEach((c) => {
190
- files.set(c.contractPath, {
194
+ const compiledSize = contracts.size + scripts.size;
195
+ sourceInfos.slice(compiledSize).forEach((c) => {
196
+ files.set(c.name, {
197
+ sourceFile: c.contractRelativePath,
191
198
  sourceCodeHash: c.sourceCodeHash,
192
199
  bytecodeDebugPatch: '',
193
200
  codeHashDebug: '',
@@ -196,13 +203,6 @@ class Project {
196
203
  });
197
204
  return new ProjectArtifact(compilerOptions, files);
198
205
  }
199
- getContractPath(path) {
200
- return path.startsWith(`./${this.contractsRootDir}`)
201
- ? path.slice(2)
202
- : path.startsWith(this.contractsRootDir)
203
- ? path
204
- : this.contractsRootDir + '/' + path;
205
- }
206
206
  static checkCompilerWarnings(warnings, errorOnWarnings) {
207
207
  if (warnings.length !== 0) {
208
208
  const prefixPerWarning = ' - ';
@@ -217,14 +217,14 @@ class Project {
217
217
  }
218
218
  }
219
219
  static contract(name) {
220
- const contract = Project.currentProject.contracts.find((c) => c.artifact.name === name);
220
+ const contract = Project.currentProject.contracts.get(name);
221
221
  if (typeof contract === 'undefined') {
222
222
  throw new Error(`Contract "${name}" does not exist`);
223
223
  }
224
224
  return contract.artifact;
225
225
  }
226
226
  static script(name) {
227
- const script = Project.currentProject.scripts.find((c) => c.artifact.name === name);
227
+ const script = Project.currentProject.scripts.get(name);
228
228
  if (typeof script === 'undefined') {
229
229
  throw new Error(`Script "${name}" does not exist`);
230
230
  }
@@ -233,118 +233,113 @@ class Project {
233
233
  async saveArtifactsToFile() {
234
234
  const artifactsRootDir = this.artifactsRootDir;
235
235
  const saveToFile = async function (compiled) {
236
- const artifactDir = compiled.sourceFile.getArtifactPath(artifactsRootDir);
237
- const folder = artifactDir.slice(0, artifactDir.lastIndexOf('/'));
238
- if (!fs_1.default.existsSync(folder)) {
239
- fs_1.default.mkdirSync(folder, { recursive: true });
236
+ const artifactPath = compiled.sourceInfo.getArtifactPath(artifactsRootDir);
237
+ const dirname = path.dirname(artifactPath);
238
+ if (!fs_1.default.existsSync(dirname)) {
239
+ fs_1.default.mkdirSync(dirname, { recursive: true });
240
240
  }
241
- return fs_2.promises.writeFile(artifactDir, compiled.artifact.toString());
241
+ return fs_2.promises.writeFile(artifactPath, compiled.artifact.toString());
242
242
  };
243
- for (const contract of this.contracts) {
244
- saveToFile(contract);
245
- }
246
- for (const script of this.scripts) {
247
- await saveToFile(script);
248
- }
243
+ this.contracts.forEach((contract) => saveToFile(contract));
244
+ this.scripts.forEach((script) => saveToFile(script));
249
245
  await this.projectArtifact.saveToFile(this.artifactsRootDir);
250
246
  }
251
247
  contractByCodeHash(codeHash) {
252
- const contract = this.contracts.find((c) => c.artifact.codeHash === codeHash || c.artifact.codeHashDebug == codeHash);
248
+ const contract = [...this.contracts.values()].find((c) => c.artifact.codeHash === codeHash || c.artifact.codeHashDebug == codeHash);
253
249
  if (typeof contract === 'undefined') {
254
250
  throw new Error(`Unknown code with code hash: ${codeHash}`);
255
251
  }
256
252
  return contract.artifact;
257
253
  }
258
- static async compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
259
- const sourceStr = files.map((f) => f.sourceCode).join('\n');
254
+ static async compile(provider, sourceInfos, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
255
+ const sourceStr = sourceInfos.map((f) => f.sourceCode).join('\n');
260
256
  const result = await provider.contracts.postContractsCompileProject({
261
257
  code: sourceStr,
262
258
  compilerOptions: compilerOptions
263
259
  });
264
- const contracts = [];
265
- const scripts = [];
260
+ const contracts = new Map();
261
+ const scripts = new Map();
266
262
  result.contracts.forEach((contractResult, index) => {
267
- const sourceFile = files[`${index}`];
263
+ const sourceInfo = sourceInfos[`${index}`];
268
264
  const contract = Contract.fromCompileResult(contractResult);
269
- contracts.push(new Compiled(sourceFile, contract, contractResult.warnings));
265
+ contracts.set(contract.name, new Compiled(sourceInfo, contract, contractResult.warnings));
270
266
  });
271
267
  result.scripts.forEach((scriptResult, index) => {
272
- const sourceFile = files[index + contracts.length];
268
+ const sourceInfo = sourceInfos[index + contracts.size];
273
269
  const script = Script.fromCompileResult(scriptResult);
274
- scripts.push(new Compiled(sourceFile, script, scriptResult.warnings));
270
+ scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings));
275
271
  });
276
- const projectArtifact = Project.buildProjectArtifact(files, contracts, scripts, compilerOptions);
277
- const project = new Project(contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
272
+ const projectArtifact = Project.buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions);
273
+ const project = new Project(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact);
278
274
  await project.saveArtifactsToFile();
279
275
  return project;
280
276
  }
281
- static async loadArtifacts(provider, files, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
277
+ static async loadArtifacts(provider, sourceInfos, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
282
278
  try {
283
- const contracts = [];
284
- const scripts = [];
285
- for (const file of files) {
286
- const info = projectArtifact.infos.get(file.contractPath);
279
+ const contracts = new Map();
280
+ const scripts = new Map();
281
+ for (const sourceInfo of sourceInfos) {
282
+ const info = projectArtifact.infos.get(sourceInfo.name);
287
283
  if (typeof info === 'undefined') {
288
- throw Error(`Unable to find project info for ${file.contractPath}, please rebuild the project`);
284
+ throw Error(`Unable to find project info for ${sourceInfo.name}, please rebuild the project`);
289
285
  }
290
286
  const warnings = info.warnings;
291
- const artifactDir = file.getArtifactPath(artifactsRootDir);
292
- if (file.type === SourceType.Contract) {
287
+ const artifactDir = sourceInfo.getArtifactPath(artifactsRootDir);
288
+ if (sourceInfo.type === SourceKind.Contract) {
293
289
  const artifact = await Contract.fromArtifactFile(artifactDir, info.bytecodeDebugPatch, info.codeHashDebug);
294
- contracts.push(new Compiled(file, artifact, warnings));
290
+ contracts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
295
291
  }
296
- else if (file.type === SourceType.Script) {
292
+ else if (sourceInfo.type === SourceKind.Script) {
297
293
  const artifact = await Script.fromArtifactFile(artifactDir, info.bytecodeDebugPatch);
298
- scripts.push(new Compiled(file, artifact, warnings));
294
+ scripts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
299
295
  }
300
296
  }
301
- return new Project(contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
297
+ return new Project(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact);
302
298
  }
303
299
  catch (error) {
304
300
  console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
305
- return Project.compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
301
+ return Project.compile(provider, sourceInfos, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
306
302
  }
307
303
  }
308
- static async loadSourceFile(dirPath, filename) {
309
- const contractPath = dirPath + '/' + filename;
304
+ static async loadSourceFile(contractsRootDir, dirPath, filename) {
305
+ const contractPath = path.join(dirPath, filename);
306
+ const contractRelativePath = path.relative(contractsRootDir, contractPath);
310
307
  if (!filename.endsWith('.ral')) {
311
308
  throw new Error(`Invalid filename: ${contractPath}, smart contract file name should end with ".ral"`);
312
309
  }
313
310
  const sourceBuffer = await fs_2.promises.readFile(contractPath);
314
311
  const sourceStr = sourceBuffer.toString();
315
- const results = this.matchers.map((m) => m.match(sourceStr));
316
- const matchNumber = results.reduce((a, b) => a + b, 0);
317
- if (matchNumber === 0) {
318
- throw new Error(`No contract defined in file: ${contractPath}`);
319
- }
320
- if (matchNumber > 1) {
321
- throw new Error(`Multiple definitions in file: ${contractPath}`);
312
+ const sourceInfos = [];
313
+ for (const matcher of this.matchers) {
314
+ const results = sourceStr.matchAll(matcher.matcher);
315
+ for (const result of results) {
316
+ const sourceInfo = await SourceInfo.from(matcher.type, result[1], sourceStr, contractRelativePath);
317
+ sourceInfos.push(sourceInfo);
318
+ }
322
319
  }
323
- const matcherIndex = results.indexOf(1);
324
- const type = this.matchers[`${matcherIndex}`].type;
325
- return SourceFile.from(type, sourceStr, contractPath);
320
+ return sourceInfos;
326
321
  }
327
322
  static async loadSourceFiles(contractsRootDir) {
328
323
  const loadDir = async function (dirPath, results) {
329
324
  const dirents = await fs_2.promises.readdir(dirPath, { withFileTypes: true });
330
325
  for (const dirent of dirents) {
331
326
  if (dirent.isFile()) {
332
- const file = await Project.loadSourceFile(dirPath, dirent.name);
333
- results.push(file);
327
+ const sourceInfos = await Project.loadSourceFile(contractsRootDir, dirPath, dirent.name);
328
+ results.push(...sourceInfos);
334
329
  }
335
330
  else {
336
- const newPath = dirPath + '/' + dirent.name;
331
+ const newPath = path.join(dirPath, dirent.name);
337
332
  await loadDir(newPath, results);
338
333
  }
339
334
  }
340
335
  };
341
- const sourceFiles = [];
342
- await loadDir(contractsRootDir, sourceFiles);
343
- const contractAndScriptSize = sourceFiles.filter((f) => f.type === SourceType.Contract || f.type === SourceType.Script).length;
344
- if (sourceFiles.length === 0 || contractAndScriptSize === 0) {
336
+ const sourceInfos = [];
337
+ await loadDir(contractsRootDir, sourceInfos);
338
+ const contractAndScriptSize = sourceInfos.filter((f) => f.type === SourceKind.Contract || f.type === SourceKind.Script).length;
339
+ if (sourceInfos.length === 0 || contractAndScriptSize === 0) {
345
340
  throw new Error('Project have no source files');
346
341
  }
347
- return sourceFiles.sort((a, b) => a.type - b.type);
342
+ return sourceInfos.sort((a, b) => a.type - b.type);
348
343
  }
349
344
  static async build(compilerOptionsPartial = {}, contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR) {
350
345
  const provider = (0, global_1.getCurrentNodeProvider)();
@@ -362,10 +357,10 @@ class Project {
362
357
  }
363
358
  }
364
359
  exports.Project = Project;
365
- Project.abstractContractMatcher = new TypedMatcher('^Abstract Contract [A-Z][a-zA-Z0-9]*', SourceType.AbstractContract);
366
- Project.contractMatcher = new TypedMatcher('^Contract [A-Z][a-zA-Z0-9]*', SourceType.Contract);
367
- Project.interfaceMatcher = new TypedMatcher('^Interface [A-Z][a-zA-Z0-9]* \\{', SourceType.Interface);
368
- Project.scriptMatcher = new TypedMatcher('^TxScript [A-Z][a-zA-Z0-9]*', SourceType.Script);
360
+ Project.abstractContractMatcher = new TypedMatcher('^Abstract Contract ([A-Z][a-zA-Z0-9]*)', SourceKind.AbstractContract);
361
+ Project.contractMatcher = new TypedMatcher('^Contract ([A-Z][a-zA-Z0-9]*)', SourceKind.Contract);
362
+ Project.interfaceMatcher = new TypedMatcher('^Interface ([A-Z][a-zA-Z0-9]*) \\{', SourceKind.Interface);
363
+ Project.scriptMatcher = new TypedMatcher('^TxScript ([A-Z][a-zA-Z0-9]*)', SourceKind.Script);
369
364
  Project.matchers = [
370
365
  Project.abstractContractMatcher,
371
366
  Project.contractMatcher,
@@ -591,7 +586,7 @@ class Contract extends Artifact {
591
586
  async txParamsForDeployment(signer, params) {
592
587
  const bytecode = this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {});
593
588
  const signerParams = {
594
- signerAddress: (await signer.getSelectedAccount()).address,
589
+ signerAddress: await signer.getSelectedAddress(),
595
590
  bytecode: bytecode,
596
591
  initialAttoAlphAmount: params.initialAttoAlphAmount,
597
592
  issueTokenAmount: params.issueTokenAmount,
@@ -658,7 +653,7 @@ class Script extends Artifact {
658
653
  }
659
654
  async txParamsForExecution(signer, params) {
660
655
  const signerParams = {
661
- signerAddress: (await signer.getSelectedAccount()).address,
656
+ signerAddress: await signer.getSelectedAddress(),
662
657
  bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
663
658
  attoAlphAmount: params.attoAlphAmount,
664
659
  tokens: params.tokens,
@@ -1 +1,2 @@
1
1
  export * from './signer';
2
+ export * from './types';
@@ -32,3 +32,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  __exportStar(require("./signer"), exports);
35
+ __exportStar(require("./types"), exports);