@alephium/web3 0.2.0-rc.11 → 0.2.0-rc.13
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.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +72 -11
- package/dist/src/api/api-alephium.js +130 -80
- package/dist/src/api/api-explorer.js +24 -33
- package/dist/src/api/utils.d.ts +6 -0
- package/dist/{scripts/stop-devnet.js → src/api/utils.js} +9 -12
- package/dist/src/contract/contract.d.ts +6 -4
- package/dist/src/contract/contract.js +32 -30
- package/dist/src/utils/utils.d.ts +0 -7
- package/dist/src/utils/utils.js +1 -10
- package/package.json +6 -15
- package/src/api/api-alephium.ts +113 -25
- package/src/api/api-explorer.ts +1 -11
- package/{scripts/stop-devnet.js → src/api/utils.ts} +5 -12
- package/src/contract/contract.ts +43 -40
- package/src/utils/utils.ts +0 -12
- package/contracts/greeter/greeter.ral +0 -7
- package/contracts/greeter/greeter_interface.ral +0 -4
- package/contracts/greeter_main.ral +0 -7
- package/dev/user.conf +0 -29
- package/dist/scripts/create-project.d.ts +0 -2
- package/dist/scripts/create-project.js +0 -125
- package/dist/scripts/start-devnet.d.ts +0 -1
- package/dist/scripts/start-devnet.js +0 -131
- package/dist/scripts/stop-devnet.d.ts +0 -1
- package/scripts/create-project.ts +0 -137
- package/scripts/start-devnet.js +0 -141
- package/templates/base/README.md +0 -34
- package/templates/base/package.json +0 -35
- package/templates/base/src/greeter.ts +0 -42
- package/templates/base/tsconfig.json +0 -19
- package/templates/react/README.md +0 -34
- package/templates/react/config-overrides.js +0 -18
- package/templates/react/package.json +0 -66
- package/templates/react/src/App.tsx +0 -42
- package/templates/react/src/artifacts/greeter.ral.json +0 -26
- package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
- package/templates/shared/.eslintrc.json +0 -12
- package/templates/shared/scripts/header.js +0 -0
|
@@ -12,14 +12,7 @@
|
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
exports.Api = exports.HttpClient = exports.ContentType = void 0;
|
|
14
14
|
require("cross-fetch/polyfill");
|
|
15
|
-
|
|
16
|
-
if (response.error) {
|
|
17
|
-
throw new Error(response.error.detail);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
return response.data;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
15
|
+
const utils_1 = require("./utils");
|
|
23
16
|
var ContentType;
|
|
24
17
|
(function (ContentType) {
|
|
25
18
|
ContentType["Json"] = "application/json";
|
|
@@ -113,8 +106,6 @@ class HttpClient {
|
|
|
113
106
|
if (cancelToken) {
|
|
114
107
|
this.abortControllers.delete(cancelToken);
|
|
115
108
|
}
|
|
116
|
-
if (!response.ok)
|
|
117
|
-
throw data;
|
|
118
109
|
return data;
|
|
119
110
|
});
|
|
120
111
|
};
|
|
@@ -177,7 +168,7 @@ class Api extends HttpClient {
|
|
|
177
168
|
query: query,
|
|
178
169
|
format: 'json',
|
|
179
170
|
...params
|
|
180
|
-
}).then(convertHttpResponse),
|
|
171
|
+
}).then(utils_1.convertHttpResponse),
|
|
181
172
|
/**
|
|
182
173
|
* @description Get a block with hash
|
|
183
174
|
*
|
|
@@ -190,7 +181,7 @@ class Api extends HttpClient {
|
|
|
190
181
|
method: 'GET',
|
|
191
182
|
format: 'json',
|
|
192
183
|
...params
|
|
193
|
-
}).then(convertHttpResponse),
|
|
184
|
+
}).then(utils_1.convertHttpResponse),
|
|
194
185
|
/**
|
|
195
186
|
* @description Get block's transactions
|
|
196
187
|
*
|
|
@@ -204,7 +195,7 @@ class Api extends HttpClient {
|
|
|
204
195
|
query: query,
|
|
205
196
|
format: 'json',
|
|
206
197
|
...params
|
|
207
|
-
}).then(convertHttpResponse)
|
|
198
|
+
}).then(utils_1.convertHttpResponse)
|
|
208
199
|
};
|
|
209
200
|
this.transactions = {
|
|
210
201
|
/**
|
|
@@ -219,7 +210,7 @@ class Api extends HttpClient {
|
|
|
219
210
|
method: 'GET',
|
|
220
211
|
format: 'json',
|
|
221
212
|
...params
|
|
222
|
-
}).then(convertHttpResponse)
|
|
213
|
+
}).then(utils_1.convertHttpResponse)
|
|
223
214
|
};
|
|
224
215
|
this.addresses = {
|
|
225
216
|
/**
|
|
@@ -234,7 +225,7 @@ class Api extends HttpClient {
|
|
|
234
225
|
method: 'GET',
|
|
235
226
|
format: 'json',
|
|
236
227
|
...params
|
|
237
|
-
}).then(convertHttpResponse),
|
|
228
|
+
}).then(utils_1.convertHttpResponse),
|
|
238
229
|
/**
|
|
239
230
|
* @description List transactions of a given address
|
|
240
231
|
*
|
|
@@ -248,7 +239,7 @@ class Api extends HttpClient {
|
|
|
248
239
|
query: query,
|
|
249
240
|
format: 'json',
|
|
250
241
|
...params
|
|
251
|
-
}).then(convertHttpResponse),
|
|
242
|
+
}).then(utils_1.convertHttpResponse),
|
|
252
243
|
/**
|
|
253
244
|
* @description Get total transactions of a given address
|
|
254
245
|
*
|
|
@@ -261,7 +252,7 @@ class Api extends HttpClient {
|
|
|
261
252
|
method: 'GET',
|
|
262
253
|
format: 'json',
|
|
263
254
|
...params
|
|
264
|
-
}).then(convertHttpResponse),
|
|
255
|
+
}).then(utils_1.convertHttpResponse),
|
|
265
256
|
/**
|
|
266
257
|
* @description Get address balance
|
|
267
258
|
*
|
|
@@ -274,7 +265,7 @@ class Api extends HttpClient {
|
|
|
274
265
|
method: 'GET',
|
|
275
266
|
format: 'json',
|
|
276
267
|
...params
|
|
277
|
-
}).then(convertHttpResponse)
|
|
268
|
+
}).then(utils_1.convertHttpResponse)
|
|
278
269
|
};
|
|
279
270
|
this.infos = {
|
|
280
271
|
/**
|
|
@@ -289,7 +280,7 @@ class Api extends HttpClient {
|
|
|
289
280
|
method: 'GET',
|
|
290
281
|
format: 'json',
|
|
291
282
|
...params
|
|
292
|
-
}).then(convertHttpResponse),
|
|
283
|
+
}).then(utils_1.convertHttpResponse),
|
|
293
284
|
/**
|
|
294
285
|
* @description List latest height for each chain
|
|
295
286
|
*
|
|
@@ -302,7 +293,7 @@ class Api extends HttpClient {
|
|
|
302
293
|
method: 'GET',
|
|
303
294
|
format: 'json',
|
|
304
295
|
...params
|
|
305
|
-
}).then(convertHttpResponse),
|
|
296
|
+
}).then(utils_1.convertHttpResponse),
|
|
306
297
|
/**
|
|
307
298
|
* @description Get token supply list
|
|
308
299
|
*
|
|
@@ -316,7 +307,7 @@ class Api extends HttpClient {
|
|
|
316
307
|
query: query,
|
|
317
308
|
format: 'json',
|
|
318
309
|
...params
|
|
319
|
-
}).then(convertHttpResponse),
|
|
310
|
+
}).then(utils_1.convertHttpResponse),
|
|
320
311
|
/**
|
|
321
312
|
* @description Get the ALPH total supply
|
|
322
313
|
*
|
|
@@ -328,7 +319,7 @@ class Api extends HttpClient {
|
|
|
328
319
|
path: `/infos/supply/total-alph`,
|
|
329
320
|
method: 'GET',
|
|
330
321
|
...params
|
|
331
|
-
}).then(convertHttpResponse),
|
|
322
|
+
}).then(utils_1.convertHttpResponse),
|
|
332
323
|
/**
|
|
333
324
|
* @description Get the ALPH circulating supply
|
|
334
325
|
*
|
|
@@ -340,7 +331,7 @@ class Api extends HttpClient {
|
|
|
340
331
|
path: `/infos/supply/circulating-alph`,
|
|
341
332
|
method: 'GET',
|
|
342
333
|
...params
|
|
343
|
-
}).then(convertHttpResponse),
|
|
334
|
+
}).then(utils_1.convertHttpResponse),
|
|
344
335
|
/**
|
|
345
336
|
* @description Get the ALPH reserved supply
|
|
346
337
|
*
|
|
@@ -352,7 +343,7 @@ class Api extends HttpClient {
|
|
|
352
343
|
path: `/infos/supply/reserved-alph`,
|
|
353
344
|
method: 'GET',
|
|
354
345
|
...params
|
|
355
|
-
}).then(convertHttpResponse),
|
|
346
|
+
}).then(utils_1.convertHttpResponse),
|
|
356
347
|
/**
|
|
357
348
|
* @description Get the ALPH locked supply
|
|
358
349
|
*
|
|
@@ -364,7 +355,7 @@ class Api extends HttpClient {
|
|
|
364
355
|
path: `/infos/supply/locked-alph`,
|
|
365
356
|
method: 'GET',
|
|
366
357
|
...params
|
|
367
|
-
}).then(convertHttpResponse),
|
|
358
|
+
}).then(utils_1.convertHttpResponse),
|
|
368
359
|
/**
|
|
369
360
|
* @description Get the total number of transactions
|
|
370
361
|
*
|
|
@@ -376,7 +367,7 @@ class Api extends HttpClient {
|
|
|
376
367
|
path: `/infos/total-transactions`,
|
|
377
368
|
method: 'GET',
|
|
378
369
|
...params
|
|
379
|
-
}).then(convertHttpResponse),
|
|
370
|
+
}).then(utils_1.convertHttpResponse),
|
|
380
371
|
/**
|
|
381
372
|
* @description Get the average block time for each chain
|
|
382
373
|
*
|
|
@@ -389,7 +380,7 @@ class Api extends HttpClient {
|
|
|
389
380
|
method: 'GET',
|
|
390
381
|
format: 'json',
|
|
391
382
|
...params
|
|
392
|
-
}).then(convertHttpResponse)
|
|
383
|
+
}).then(utils_1.convertHttpResponse)
|
|
393
384
|
};
|
|
394
385
|
this.charts = {
|
|
395
386
|
/**
|
|
@@ -406,7 +397,7 @@ class Api extends HttpClient {
|
|
|
406
397
|
query: query,
|
|
407
398
|
format: 'json',
|
|
408
399
|
...params
|
|
409
|
-
}).then(convertHttpResponse),
|
|
400
|
+
}).then(utils_1.convertHttpResponse),
|
|
410
401
|
/**
|
|
411
402
|
* @description `interval-type` query param: hourly, daily
|
|
412
403
|
*
|
|
@@ -421,7 +412,7 @@ class Api extends HttpClient {
|
|
|
421
412
|
query: query,
|
|
422
413
|
format: 'json',
|
|
423
414
|
...params
|
|
424
|
-
}).then(convertHttpResponse),
|
|
415
|
+
}).then(utils_1.convertHttpResponse),
|
|
425
416
|
/**
|
|
426
417
|
* @description `interval-type` query param: hourly, daily
|
|
427
418
|
*
|
|
@@ -436,7 +427,7 @@ class Api extends HttpClient {
|
|
|
436
427
|
query: query,
|
|
437
428
|
format: 'json',
|
|
438
429
|
...params
|
|
439
|
-
}).then(convertHttpResponse)
|
|
430
|
+
}).then(utils_1.convertHttpResponse)
|
|
440
431
|
};
|
|
441
432
|
this.utils = {
|
|
442
433
|
/**
|
|
@@ -450,7 +441,7 @@ class Api extends HttpClient {
|
|
|
450
441
|
path: `/utils/sanity-check`,
|
|
451
442
|
method: 'PUT',
|
|
452
443
|
...params
|
|
453
|
-
}).then(convertHttpResponse),
|
|
444
|
+
}).then(utils_1.convertHttpResponse),
|
|
454
445
|
/**
|
|
455
446
|
* @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
|
|
456
447
|
*
|
|
@@ -463,7 +454,7 @@ class Api extends HttpClient {
|
|
|
463
454
|
method: 'PUT',
|
|
464
455
|
body: data,
|
|
465
456
|
...params
|
|
466
|
-
}).then(convertHttpResponse),
|
|
457
|
+
}).then(utils_1.convertHttpResponse),
|
|
467
458
|
/**
|
|
468
459
|
* @description Update logging file, only logback.xml is accepted
|
|
469
460
|
*
|
|
@@ -476,7 +467,7 @@ class Api extends HttpClient {
|
|
|
476
467
|
method: 'PUT',
|
|
477
468
|
body: data,
|
|
478
469
|
...params
|
|
479
|
-
}).then(convertHttpResponse)
|
|
470
|
+
}).then(utils_1.convertHttpResponse)
|
|
480
471
|
};
|
|
481
472
|
}
|
|
482
473
|
}
|
|
@@ -16,17 +16,14 @@ GNU Lesser General Public License for more details.
|
|
|
16
16
|
You should have received a copy of the GNU Lesser General Public License
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
process.kill(pid);
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.convertHttpResponse = void 0;
|
|
21
|
+
function convertHttpResponse(response) {
|
|
22
|
+
if (response.error) {
|
|
23
|
+
throw new Error(`[Node API Error] - ${response.error.detail}`);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return response.data;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
|
|
31
|
-
console.log(`Error in stopping the running devnet: ${e}`);
|
|
32
|
-
}
|
|
29
|
+
exports.convertHttpResponse = convertHttpResponse;
|
|
@@ -27,7 +27,7 @@ declare class SourceFile {
|
|
|
27
27
|
contractPath: string;
|
|
28
28
|
sourceCode: string;
|
|
29
29
|
sourceCodeHash: string;
|
|
30
|
-
getArtifactPath(
|
|
30
|
+
getArtifactPath(artifactsRootDir: string): string;
|
|
31
31
|
constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
|
|
32
32
|
static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
|
|
33
33
|
}
|
|
@@ -58,8 +58,8 @@ export declare class Project {
|
|
|
58
58
|
contracts: Compiled<Contract>[];
|
|
59
59
|
scripts: Compiled<Script>[];
|
|
60
60
|
projectArtifact: ProjectArtifact;
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
61
|
+
readonly contractsRootDir: string;
|
|
62
|
+
readonly artifactsRootDir: string;
|
|
63
63
|
readonly nodeProvider: NodeProvider;
|
|
64
64
|
static currentProject: Project;
|
|
65
65
|
static readonly abstractContractMatcher: TypedMatcher<SourceType>;
|
|
@@ -79,7 +79,9 @@ export declare class Project {
|
|
|
79
79
|
private static loadArtifacts;
|
|
80
80
|
private static loadSourceFile;
|
|
81
81
|
private static loadSourceFiles;
|
|
82
|
-
static
|
|
82
|
+
static readonly DEFAULT_CONTRACTS_DIR = "contracts";
|
|
83
|
+
static readonly DEFAULT_ARTIFACTS_DIR = "artifacts";
|
|
84
|
+
static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootDir?: string, artifactsRootDir?: string): Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
export declare abstract class Artifact {
|
|
85
87
|
readonly name: string;
|
|
@@ -85,8 +85,8 @@ class SourceFile {
|
|
|
85
85
|
this.sourceCodeHash = sourceCodeHash;
|
|
86
86
|
this.contractPath = contractPath;
|
|
87
87
|
}
|
|
88
|
-
getArtifactPath(
|
|
89
|
-
return
|
|
88
|
+
getArtifactPath(artifactsRootDir) {
|
|
89
|
+
return artifactsRootDir + this.contractPath.slice(this.contractPath.indexOf('/')) + '.json';
|
|
90
90
|
}
|
|
91
91
|
static async from(type, sourceCode, contractPath) {
|
|
92
92
|
const sourceCodeHash = await crypto_1.webcrypto.subtle.digest('SHA-256', buffer_1.Buffer.from(sourceCode));
|
|
@@ -155,10 +155,10 @@ class ProjectArtifact {
|
|
|
155
155
|
}
|
|
156
156
|
ProjectArtifact.artifactFileName = '.project.json';
|
|
157
157
|
class Project {
|
|
158
|
-
constructor(provider,
|
|
158
|
+
constructor(provider, contractsRootDir, artifactsRootDir, sourceFiles, contracts, scripts, errorOnWarnings, projectArtifact) {
|
|
159
159
|
this.nodeProvider = provider;
|
|
160
|
-
this.
|
|
161
|
-
this.
|
|
160
|
+
this.contractsRootDir = contractsRootDir;
|
|
161
|
+
this.artifactsRootDir = artifactsRootDir;
|
|
162
162
|
this.sourceFiles = sourceFiles;
|
|
163
163
|
this.contracts = contracts;
|
|
164
164
|
this.scripts = scripts;
|
|
@@ -191,11 +191,11 @@ class Project {
|
|
|
191
191
|
return new ProjectArtifact(compilerOptions, files);
|
|
192
192
|
}
|
|
193
193
|
getContractPath(path) {
|
|
194
|
-
return path.startsWith(`./${this.
|
|
194
|
+
return path.startsWith(`./${this.contractsRootDir}`)
|
|
195
195
|
? path.slice(2)
|
|
196
|
-
: path.startsWith(this.
|
|
196
|
+
: path.startsWith(this.contractsRootDir)
|
|
197
197
|
? path
|
|
198
|
-
: this.
|
|
198
|
+
: this.contractsRootDir + '/' + path;
|
|
199
199
|
}
|
|
200
200
|
static checkCompilerWarnings(warnings, errorOnWarnings) {
|
|
201
201
|
if (warnings.length !== 0) {
|
|
@@ -225,14 +225,14 @@ class Project {
|
|
|
225
225
|
return script.artifact;
|
|
226
226
|
}
|
|
227
227
|
async saveArtifactsToFile() {
|
|
228
|
-
const
|
|
228
|
+
const artifactsRootDir = this.artifactsRootDir;
|
|
229
229
|
const saveToFile = async function (compiled) {
|
|
230
|
-
const
|
|
231
|
-
const folder =
|
|
230
|
+
const artifactDir = compiled.sourceFile.getArtifactPath(artifactsRootDir);
|
|
231
|
+
const folder = artifactDir.slice(0, artifactDir.lastIndexOf('/'));
|
|
232
232
|
if (!fs_1.default.existsSync(folder)) {
|
|
233
233
|
fs_1.default.mkdirSync(folder, { recursive: true });
|
|
234
234
|
}
|
|
235
|
-
return fs_2.promises.writeFile(
|
|
235
|
+
return fs_2.promises.writeFile(artifactDir, compiled.artifact.toString());
|
|
236
236
|
};
|
|
237
237
|
for (const contract of this.contracts) {
|
|
238
238
|
await saveToFile(contract);
|
|
@@ -240,7 +240,7 @@ class Project {
|
|
|
240
240
|
for (const script of this.scripts) {
|
|
241
241
|
await saveToFile(script);
|
|
242
242
|
}
|
|
243
|
-
await this.projectArtifact.saveToFile(this.
|
|
243
|
+
await this.projectArtifact.saveToFile(this.artifactsRootDir);
|
|
244
244
|
}
|
|
245
245
|
contractByCodeHash(codeHash) {
|
|
246
246
|
const contract = this.contracts.find((c) => c.artifact.codeHash === codeHash);
|
|
@@ -249,7 +249,7 @@ class Project {
|
|
|
249
249
|
}
|
|
250
250
|
return contract.artifact;
|
|
251
251
|
}
|
|
252
|
-
static async compile(provider, files,
|
|
252
|
+
static async compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
253
253
|
const sourceStr = files.map((f) => f.sourceCode).join('\n');
|
|
254
254
|
const result = await provider.contracts.postContractsCompileProject({
|
|
255
255
|
code: sourceStr,
|
|
@@ -268,11 +268,11 @@ class Project {
|
|
|
268
268
|
scripts.push(new Compiled(sourceFile, script, scriptResult.warnings));
|
|
269
269
|
});
|
|
270
270
|
const projectArtifact = Project.buildProjectArtifact(files, contracts, scripts, compilerOptions);
|
|
271
|
-
const project = new Project(provider,
|
|
271
|
+
const project = new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
272
272
|
await project.saveArtifactsToFile();
|
|
273
273
|
return project;
|
|
274
274
|
}
|
|
275
|
-
static async loadArtifacts(provider, files, projectArtifact,
|
|
275
|
+
static async loadArtifacts(provider, files, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
276
276
|
try {
|
|
277
277
|
const contracts = [];
|
|
278
278
|
const scripts = [];
|
|
@@ -282,21 +282,21 @@ class Project {
|
|
|
282
282
|
throw Error(`Unable to find project info for ${file.contractPath}, please rebuild the project`);
|
|
283
283
|
}
|
|
284
284
|
const warnings = info.warnings;
|
|
285
|
-
const
|
|
285
|
+
const artifactDir = file.getArtifactPath(artifactsRootDir);
|
|
286
286
|
if (file.type === SourceType.Contract) {
|
|
287
|
-
const artifact = await Contract.fromArtifactFile(
|
|
287
|
+
const artifact = await Contract.fromArtifactFile(artifactDir);
|
|
288
288
|
contracts.push(new Compiled(file, artifact, warnings));
|
|
289
289
|
}
|
|
290
290
|
else if (file.type === SourceType.Script) {
|
|
291
|
-
const artifact = await Script.fromArtifactFile(
|
|
291
|
+
const artifact = await Script.fromArtifactFile(artifactDir);
|
|
292
292
|
scripts.push(new Compiled(file, artifact, warnings));
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
return new Project(provider,
|
|
295
|
+
return new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
296
296
|
}
|
|
297
297
|
catch (error) {
|
|
298
298
|
console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
|
|
299
|
-
return Project.compile(provider, files,
|
|
299
|
+
return Project.compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
static async loadSourceFile(dirPath, filename) {
|
|
@@ -318,7 +318,7 @@ class Project {
|
|
|
318
318
|
const type = this.matchers[`${matcherIndex}`].type;
|
|
319
319
|
return SourceFile.from(type, sourceStr, contractPath);
|
|
320
320
|
}
|
|
321
|
-
static async loadSourceFiles(
|
|
321
|
+
static async loadSourceFiles(contractsRootDir) {
|
|
322
322
|
const loadDir = async function (dirPath, results) {
|
|
323
323
|
const dirents = await fs_2.promises.readdir(dirPath, { withFileTypes: true });
|
|
324
324
|
for (const dirent of dirents) {
|
|
@@ -333,25 +333,25 @@ class Project {
|
|
|
333
333
|
}
|
|
334
334
|
};
|
|
335
335
|
const sourceFiles = [];
|
|
336
|
-
await loadDir(
|
|
336
|
+
await loadDir(contractsRootDir, sourceFiles);
|
|
337
337
|
const contractAndScriptSize = sourceFiles.filter((f) => f.type === SourceType.Contract || f.type === SourceType.Script).length;
|
|
338
338
|
if (sourceFiles.length === 0 || contractAndScriptSize === 0) {
|
|
339
339
|
throw new Error('Project have no source files');
|
|
340
340
|
}
|
|
341
341
|
return sourceFiles.sort((a, b) => a.type - b.type);
|
|
342
342
|
}
|
|
343
|
-
static async build(compilerOptionsPartial = {},
|
|
343
|
+
static async build(compilerOptionsPartial = {}, contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR) {
|
|
344
344
|
const provider = (0, global_1.getCurrentNodeProvider)();
|
|
345
|
-
const sourceFiles = await Project.loadSourceFiles(
|
|
345
|
+
const sourceFiles = await Project.loadSourceFiles(contractsRootDir);
|
|
346
346
|
const { errorOnWarnings, ...nodeCompilerOptions } = { ...exports.DEFAULT_COMPILER_OPTIONS, ...compilerOptionsPartial };
|
|
347
|
-
const projectArtifact = await ProjectArtifact.from(
|
|
347
|
+
const projectArtifact = await ProjectArtifact.from(artifactsRootDir);
|
|
348
348
|
if (typeof projectArtifact === 'undefined' || projectArtifact.needToReCompile(nodeCompilerOptions, sourceFiles)) {
|
|
349
|
-
console.log(`Compile contracts in folder "${
|
|
350
|
-
Project.currentProject = await Project.compile(provider, sourceFiles,
|
|
349
|
+
console.log(`Compile contracts in folder "${contractsRootDir}"`);
|
|
350
|
+
Project.currentProject = await Project.compile(provider, sourceFiles, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
351
351
|
}
|
|
352
352
|
else {
|
|
353
|
-
console.log(`Load compiled contracts from folder "${
|
|
354
|
-
Project.currentProject = await Project.loadArtifacts(provider, sourceFiles, projectArtifact,
|
|
353
|
+
console.log(`Load compiled contracts from folder "${artifactsRootDir}"`);
|
|
354
|
+
Project.currentProject = await Project.loadArtifacts(provider, sourceFiles, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
}
|
|
@@ -366,6 +366,8 @@ Project.matchers = [
|
|
|
366
366
|
Project.interfaceMatcher,
|
|
367
367
|
Project.scriptMatcher
|
|
368
368
|
];
|
|
369
|
+
Project.DEFAULT_CONTRACTS_DIR = 'contracts';
|
|
370
|
+
Project.DEFAULT_ARTIFACTS_DIR = 'artifacts';
|
|
369
371
|
class Artifact {
|
|
370
372
|
constructor(name, functions) {
|
|
371
373
|
this.name = name;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { ec as EC, SignatureInput } from 'elliptic';
|
|
2
|
-
import * as node from '../api/api-alephium';
|
|
3
|
-
import * as explorer from '../api/api-explorer';
|
|
4
|
-
export declare function convertHttpResponse<T>(response: node.HttpResponse<T, {
|
|
5
|
-
detail: string;
|
|
6
|
-
}> | explorer.HttpResponse<T, {
|
|
7
|
-
detail: string;
|
|
8
|
-
}>): T;
|
|
9
2
|
export declare function signatureEncode(signature: EC.Signature): string;
|
|
10
3
|
export declare function signatureDecode(ec: EC, signature: string): SignatureInput;
|
|
11
4
|
export declare function xorByte(intValue: number): number;
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode =
|
|
23
|
+
exports.assertType = exports.timeout = exports.hexToString = exports.stringToHex = exports.subContractId = exports.contractIdFromTx = exports.addressFromContractId = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.signatureEncode = void 0;
|
|
24
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -29,15 +29,6 @@ const buffer_1 = require("buffer/");
|
|
|
29
29
|
const constants_1 = require("../constants");
|
|
30
30
|
const djb2_1 = __importDefault(require("./djb2"));
|
|
31
31
|
const ec = new elliptic_1.ec('secp256k1');
|
|
32
|
-
function convertHttpResponse(response) {
|
|
33
|
-
if (response.error) {
|
|
34
|
-
throw new Error(response.error.detail);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
return response.data;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.convertHttpResponse = convertHttpResponse;
|
|
41
32
|
function signatureEncode(signature) {
|
|
42
33
|
let sNormalized = signature.s;
|
|
43
34
|
if (ec.n && signature.s.cmp(ec.nh) === 1) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.13",
|
|
4
4
|
"description": "A JS/TS library to interact with the Alephium platform",
|
|
5
5
|
"license": "GPL",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -27,33 +27,24 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "1.5.0-
|
|
30
|
+
"alephium_version": "1.5.0-rc8",
|
|
31
31
|
"explorer_backend_version": "1.7.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rm -rf dist/* && npx tsc --build . && webpack",
|
|
35
35
|
"test": "jest -i --config ./jest-config.json",
|
|
36
36
|
"update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
|
|
37
|
-
"update-schema:alephium": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
|
|
38
|
-
"update-schema:explorer": "npx swagger-typescript-api -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
|
|
39
|
-
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}"
|
|
40
|
-
"start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
|
|
41
|
-
"restart-devnet": "npm run start-devnet",
|
|
42
|
-
"stop-devnet": "node scripts/stop-devnet.js"
|
|
37
|
+
"update-schema:alephium": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
|
|
38
|
+
"update-schema:explorer": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
|
|
39
|
+
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}"
|
|
43
40
|
},
|
|
44
41
|
"type": "commonjs",
|
|
45
|
-
"bin": {
|
|
46
|
-
"alephium": "dist/scripts/create-project.js"
|
|
47
|
-
},
|
|
48
42
|
"dependencies": {
|
|
49
43
|
"base-x": "4.0.0",
|
|
50
44
|
"blakejs": "1.2.1",
|
|
51
45
|
"buffer": "^6.0.3",
|
|
52
|
-
"commander": "^9.1.0",
|
|
53
46
|
"cross-fetch": "^3.1.5",
|
|
54
|
-
"eventemitter3": "^4.0.7"
|
|
55
|
-
"find-up": "^2.1.0",
|
|
56
|
-
"fs-extra": "^10.0.1"
|
|
47
|
+
"eventemitter3": "^4.0.7"
|
|
57
48
|
},
|
|
58
49
|
"devDependencies": {
|
|
59
50
|
"@babel/eslint-parser": "^7.18.9",
|