@alephium/web3 0.10.1 → 0.10.3
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 +1 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/contract/contract.d.ts +5 -4
- package/dist/src/contract/contract.js +29 -15
- package/package.json +2 -2
- package/src/api/api-alephium.ts +1 -1
- package/src/contract/contract.ts +38 -11
- package/std/fungible_token_unimplemented.ral +18 -0
|
@@ -929,7 +929,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
929
929
|
}
|
|
930
930
|
/**
|
|
931
931
|
* @title Alephium API
|
|
932
|
-
* @version 2.1.
|
|
932
|
+
* @version 2.1.2
|
|
933
933
|
* @baseUrl ../
|
|
934
934
|
*/
|
|
935
935
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -51,12 +51,13 @@ type CodeInfo = {
|
|
|
51
51
|
};
|
|
52
52
|
declare class ProjectArtifact {
|
|
53
53
|
static readonly artifactFileName = ".project.json";
|
|
54
|
+
fullNodeVersion: string;
|
|
54
55
|
compilerOptionsUsed: node.CompilerOptions;
|
|
55
56
|
infos: Map<string, CodeInfo>;
|
|
56
57
|
static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
|
|
57
|
-
constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>);
|
|
58
|
+
constructor(fullNodeVersion: string, compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>);
|
|
58
59
|
saveToFile(rootPath: string): Promise<void>;
|
|
59
|
-
needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[]): boolean;
|
|
60
|
+
needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[], fullNodeVersion: string): boolean;
|
|
60
61
|
static from(rootPath: string): Promise<ProjectArtifact | undefined>;
|
|
61
62
|
}
|
|
62
63
|
export declare class Project {
|
|
@@ -73,7 +74,7 @@ export declare class Project {
|
|
|
73
74
|
static readonly interfaceMatcher: TypedMatcher<SourceKind.Interface>;
|
|
74
75
|
static readonly scriptMatcher: TypedMatcher<SourceKind.Script>;
|
|
75
76
|
static readonly matchers: TypedMatcher<SourceKind>[];
|
|
76
|
-
static buildProjectArtifact(sourceInfos: SourceInfo[], contracts: Map<string, Compiled<Contract>>, scripts: Map<string, Compiled<Script>>, compilerOptions: node.CompilerOptions): ProjectArtifact;
|
|
77
|
+
static buildProjectArtifact(fullNodeVersion: string, sourceInfos: SourceInfo[], contracts: Map<string, Compiled<Contract>>, scripts: Map<string, Compiled<Script>>, compilerOptions: node.CompilerOptions): ProjectArtifact;
|
|
77
78
|
private constructor();
|
|
78
79
|
static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
|
|
79
80
|
static contract(name: string): Contract;
|
|
@@ -88,7 +89,7 @@ export declare class Project {
|
|
|
88
89
|
private static loadSourceFiles;
|
|
89
90
|
static readonly DEFAULT_CONTRACTS_DIR = "contracts";
|
|
90
91
|
static readonly DEFAULT_ARTIFACTS_DIR = "artifacts";
|
|
91
|
-
static build(compilerOptionsPartial?: Partial<CompilerOptions>, projectRootDir?: string, contractsRootDir?: string, artifactsRootDir?: string): Promise<void>;
|
|
92
|
+
static build(compilerOptionsPartial?: Partial<CompilerOptions>, projectRootDir?: string, contractsRootDir?: string, artifactsRootDir?: string, defaultFullNodeVersion?: string | undefined): Promise<void>;
|
|
92
93
|
}
|
|
93
94
|
export declare abstract class Artifact {
|
|
94
95
|
readonly version: string;
|
|
@@ -130,22 +130,27 @@ class ProjectArtifact {
|
|
|
130
130
|
throw Error(`There are unknown compiler options: ${compilerOptions}`);
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
-
constructor(compilerOptionsUsed, infos) {
|
|
133
|
+
constructor(fullNodeVersion, compilerOptionsUsed, infos) {
|
|
134
134
|
ProjectArtifact.checkCompilerOptionsParameter(compilerOptionsUsed);
|
|
135
|
+
this.fullNodeVersion = fullNodeVersion;
|
|
135
136
|
this.compilerOptionsUsed = compilerOptionsUsed;
|
|
136
137
|
this.infos = infos;
|
|
137
138
|
}
|
|
138
139
|
async saveToFile(rootPath) {
|
|
139
140
|
const filepath = path.join(rootPath, ProjectArtifact.artifactFileName);
|
|
140
141
|
const artifact = {
|
|
142
|
+
fullNodeVersion: this.fullNodeVersion,
|
|
141
143
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
142
144
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
143
145
|
};
|
|
144
146
|
const content = JSON.stringify(artifact, null, 2);
|
|
145
147
|
return fs_2.promises.writeFile(filepath, content);
|
|
146
148
|
}
|
|
147
|
-
needToReCompile(compilerOptions, sourceInfos) {
|
|
149
|
+
needToReCompile(compilerOptions, sourceInfos, fullNodeVersion) {
|
|
148
150
|
ProjectArtifact.checkCompilerOptionsParameter(compilerOptions);
|
|
151
|
+
if (this.fullNodeVersion !== fullNodeVersion) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
149
154
|
const optionsMatched = Object.entries(compilerOptions).every(([key, inputOption]) => {
|
|
150
155
|
const usedOption = this.compilerOptionsUsed[`${key}`];
|
|
151
156
|
return usedOption === inputOption;
|
|
@@ -169,16 +174,23 @@ class ProjectArtifact {
|
|
|
169
174
|
if (!fs_1.default.existsSync(filepath)) {
|
|
170
175
|
return undefined;
|
|
171
176
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
try {
|
|
178
|
+
const content = await fs_2.promises.readFile(filepath);
|
|
179
|
+
const json = JSON.parse(content.toString());
|
|
180
|
+
const fullNodeVersion = json.fullNodeVersion;
|
|
181
|
+
const compilerOptionsUsed = json.compilerOptionsUsed;
|
|
182
|
+
const files = new Map(Object.entries(json.infos));
|
|
183
|
+
return new ProjectArtifact(fullNodeVersion, compilerOptionsUsed, files);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
console.log(`Failed to load project artifact, error: ${error}`);
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
177
189
|
}
|
|
178
190
|
}
|
|
179
191
|
ProjectArtifact.artifactFileName = '.project.json';
|
|
180
192
|
class Project {
|
|
181
|
-
static buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions) {
|
|
193
|
+
static buildProjectArtifact(fullNodeVersion, sourceInfos, contracts, scripts, compilerOptions) {
|
|
182
194
|
const files = new Map();
|
|
183
195
|
contracts.forEach((c) => {
|
|
184
196
|
files.set(c.artifact.name, {
|
|
@@ -208,7 +220,7 @@ class Project {
|
|
|
208
220
|
warnings: []
|
|
209
221
|
});
|
|
210
222
|
});
|
|
211
|
-
return new ProjectArtifact(compilerOptions, files);
|
|
223
|
+
return new ProjectArtifact(fullNodeVersion, compilerOptions, files);
|
|
212
224
|
}
|
|
213
225
|
constructor(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact) {
|
|
214
226
|
this.contractsRootDir = contractsRootDir;
|
|
@@ -272,7 +284,7 @@ class Project {
|
|
|
272
284
|
}
|
|
273
285
|
return contract.artifact;
|
|
274
286
|
}
|
|
275
|
-
static async compile(provider, sourceInfos, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
287
|
+
static async compile(fullNodeVersion, provider, sourceInfos, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
276
288
|
const sourceStr = sourceInfos.map((f) => f.sourceCode).join('\n');
|
|
277
289
|
const result = await provider.contracts.postContractsCompileProject({
|
|
278
290
|
code: sourceStr,
|
|
@@ -290,7 +302,7 @@ class Project {
|
|
|
290
302
|
const script = Script.fromCompileResult(scriptResult);
|
|
291
303
|
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings));
|
|
292
304
|
});
|
|
293
|
-
const projectArtifact = Project.buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions);
|
|
305
|
+
const projectArtifact = Project.buildProjectArtifact(fullNodeVersion, sourceInfos, contracts, scripts, compilerOptions);
|
|
294
306
|
const project = new Project(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
295
307
|
await project.saveArtifactsToFile(projectRootDir);
|
|
296
308
|
return project;
|
|
@@ -319,7 +331,7 @@ class Project {
|
|
|
319
331
|
}
|
|
320
332
|
catch (error) {
|
|
321
333
|
console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
|
|
322
|
-
return Project.compile(provider, sourceInfos, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
334
|
+
return Project.compile(projectArtifact.fullNodeVersion, provider, sourceInfos, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
323
335
|
}
|
|
324
336
|
}
|
|
325
337
|
static getImportSourcePath(projectRootDir, importPath) {
|
|
@@ -404,14 +416,16 @@ class Project {
|
|
|
404
416
|
}
|
|
405
417
|
return sourceInfos.sort((a, b) => a.type - b.type);
|
|
406
418
|
}
|
|
407
|
-
static async build(compilerOptionsPartial = {}, projectRootDir = '.', contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR) {
|
|
419
|
+
static async build(compilerOptionsPartial = {}, projectRootDir = '.', contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR, defaultFullNodeVersion = undefined) {
|
|
408
420
|
const provider = (0, global_1.getCurrentNodeProvider)();
|
|
421
|
+
const fullNodeVersion = defaultFullNodeVersion ?? (await provider.infos.getInfosNode()).buildInfo.releaseVersion;
|
|
409
422
|
const sourceFiles = await Project.loadSourceFiles(projectRootDir, contractsRootDir);
|
|
410
423
|
const { errorOnWarnings, ...nodeCompilerOptions } = { ...exports.DEFAULT_COMPILER_OPTIONS, ...compilerOptionsPartial };
|
|
411
424
|
const projectArtifact = await ProjectArtifact.from(projectRootDir);
|
|
412
|
-
if (
|
|
425
|
+
if (projectArtifact === undefined ||
|
|
426
|
+
projectArtifact.needToReCompile(nodeCompilerOptions, sourceFiles, fullNodeVersion)) {
|
|
413
427
|
console.log(`Compiling contracts in folder "${contractsRootDir}"`);
|
|
414
|
-
Project.currentProject = await Project.compile(provider, sourceFiles, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
428
|
+
Project.currentProject = await Project.compile(fullNodeVersion, provider, sourceFiles, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
415
429
|
}
|
|
416
430
|
else {
|
|
417
431
|
console.log(`Contracts are compiled already. Loading them from folder "${artifactsRootDir}"`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "2.1.
|
|
30
|
+
"alephium_version": "2.1.2",
|
|
31
31
|
"explorer_backend_version": "1.13.4"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -1217,7 +1217,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1217
1217
|
|
|
1218
1218
|
/**
|
|
1219
1219
|
* @title Alephium API
|
|
1220
|
-
* @version 2.1.
|
|
1220
|
+
* @version 2.1.2
|
|
1221
1221
|
* @baseUrl ../
|
|
1222
1222
|
*/
|
|
1223
1223
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/contract/contract.ts
CHANGED
|
@@ -183,6 +183,7 @@ type CodeInfo = {
|
|
|
183
183
|
class ProjectArtifact {
|
|
184
184
|
static readonly artifactFileName = '.project.json'
|
|
185
185
|
|
|
186
|
+
fullNodeVersion: string
|
|
186
187
|
compilerOptionsUsed: node.CompilerOptions
|
|
187
188
|
infos: Map<string, CodeInfo>
|
|
188
189
|
|
|
@@ -197,8 +198,9 @@ class ProjectArtifact {
|
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
|
|
200
|
-
constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>) {
|
|
201
|
+
constructor(fullNodeVersion: string, compilerOptionsUsed: node.CompilerOptions, infos: Map<string, CodeInfo>) {
|
|
201
202
|
ProjectArtifact.checkCompilerOptionsParameter(compilerOptionsUsed)
|
|
203
|
+
this.fullNodeVersion = fullNodeVersion
|
|
202
204
|
this.compilerOptionsUsed = compilerOptionsUsed
|
|
203
205
|
this.infos = infos
|
|
204
206
|
}
|
|
@@ -206,6 +208,7 @@ class ProjectArtifact {
|
|
|
206
208
|
async saveToFile(rootPath: string): Promise<void> {
|
|
207
209
|
const filepath = path.join(rootPath, ProjectArtifact.artifactFileName)
|
|
208
210
|
const artifact = {
|
|
211
|
+
fullNodeVersion: this.fullNodeVersion,
|
|
209
212
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
210
213
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
211
214
|
}
|
|
@@ -213,8 +216,11 @@ class ProjectArtifact {
|
|
|
213
216
|
return fsPromises.writeFile(filepath, content)
|
|
214
217
|
}
|
|
215
218
|
|
|
216
|
-
needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[]): boolean {
|
|
219
|
+
needToReCompile(compilerOptions: node.CompilerOptions, sourceInfos: SourceInfo[], fullNodeVersion: string): boolean {
|
|
217
220
|
ProjectArtifact.checkCompilerOptionsParameter(compilerOptions)
|
|
221
|
+
if (this.fullNodeVersion !== fullNodeVersion) {
|
|
222
|
+
return true
|
|
223
|
+
}
|
|
218
224
|
|
|
219
225
|
const optionsMatched = Object.entries(compilerOptions).every(([key, inputOption]) => {
|
|
220
226
|
const usedOption = this.compilerOptionsUsed[`${key}`]
|
|
@@ -242,11 +248,17 @@ class ProjectArtifact {
|
|
|
242
248
|
if (!fs.existsSync(filepath)) {
|
|
243
249
|
return undefined
|
|
244
250
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
251
|
+
try {
|
|
252
|
+
const content = await fsPromises.readFile(filepath)
|
|
253
|
+
const json = JSON.parse(content.toString())
|
|
254
|
+
const fullNodeVersion = json.fullNodeVersion as string
|
|
255
|
+
const compilerOptionsUsed = json.compilerOptionsUsed as node.CompilerOptions
|
|
256
|
+
const files = new Map(Object.entries<CodeInfo>(json.infos))
|
|
257
|
+
return new ProjectArtifact(fullNodeVersion, compilerOptionsUsed, files)
|
|
258
|
+
} catch (error) {
|
|
259
|
+
console.log(`Failed to load project artifact, error: ${error}`)
|
|
260
|
+
return undefined
|
|
261
|
+
}
|
|
250
262
|
}
|
|
251
263
|
}
|
|
252
264
|
|
|
@@ -277,6 +289,7 @@ export class Project {
|
|
|
277
289
|
]
|
|
278
290
|
|
|
279
291
|
static buildProjectArtifact(
|
|
292
|
+
fullNodeVersion: string,
|
|
280
293
|
sourceInfos: SourceInfo[],
|
|
281
294
|
contracts: Map<string, Compiled<Contract>>,
|
|
282
295
|
scripts: Map<string, Compiled<Script>>,
|
|
@@ -311,7 +324,7 @@ export class Project {
|
|
|
311
324
|
warnings: []
|
|
312
325
|
})
|
|
313
326
|
})
|
|
314
|
-
return new ProjectArtifact(compilerOptions, files)
|
|
327
|
+
return new ProjectArtifact(fullNodeVersion, compilerOptions, files)
|
|
315
328
|
}
|
|
316
329
|
|
|
317
330
|
private constructor(
|
|
@@ -396,6 +409,7 @@ export class Project {
|
|
|
396
409
|
}
|
|
397
410
|
|
|
398
411
|
private static async compile(
|
|
412
|
+
fullNodeVersion: string,
|
|
399
413
|
provider: NodeProvider,
|
|
400
414
|
sourceInfos: SourceInfo[],
|
|
401
415
|
projectRootDir: string,
|
|
@@ -421,7 +435,13 @@ export class Project {
|
|
|
421
435
|
const script = Script.fromCompileResult(scriptResult)
|
|
422
436
|
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings))
|
|
423
437
|
})
|
|
424
|
-
const projectArtifact = Project.buildProjectArtifact(
|
|
438
|
+
const projectArtifact = Project.buildProjectArtifact(
|
|
439
|
+
fullNodeVersion,
|
|
440
|
+
sourceInfos,
|
|
441
|
+
contracts,
|
|
442
|
+
scripts,
|
|
443
|
+
compilerOptions
|
|
444
|
+
)
|
|
425
445
|
const project = new Project(
|
|
426
446
|
contractsRootDir,
|
|
427
447
|
artifactsRootDir,
|
|
@@ -476,6 +496,7 @@ export class Project {
|
|
|
476
496
|
} catch (error) {
|
|
477
497
|
console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`)
|
|
478
498
|
return Project.compile(
|
|
499
|
+
projectArtifact.fullNodeVersion,
|
|
479
500
|
provider,
|
|
480
501
|
sourceInfos,
|
|
481
502
|
projectRootDir,
|
|
@@ -604,15 +625,21 @@ export class Project {
|
|
|
604
625
|
compilerOptionsPartial: Partial<CompilerOptions> = {},
|
|
605
626
|
projectRootDir = '.',
|
|
606
627
|
contractsRootDir = Project.DEFAULT_CONTRACTS_DIR,
|
|
607
|
-
artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR
|
|
628
|
+
artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR,
|
|
629
|
+
defaultFullNodeVersion: string | undefined = undefined
|
|
608
630
|
): Promise<void> {
|
|
609
631
|
const provider = getCurrentNodeProvider()
|
|
632
|
+
const fullNodeVersion = defaultFullNodeVersion ?? (await provider.infos.getInfosNode()).buildInfo.releaseVersion
|
|
610
633
|
const sourceFiles = await Project.loadSourceFiles(projectRootDir, contractsRootDir)
|
|
611
634
|
const { errorOnWarnings, ...nodeCompilerOptions } = { ...DEFAULT_COMPILER_OPTIONS, ...compilerOptionsPartial }
|
|
612
635
|
const projectArtifact = await ProjectArtifact.from(projectRootDir)
|
|
613
|
-
if (
|
|
636
|
+
if (
|
|
637
|
+
projectArtifact === undefined ||
|
|
638
|
+
projectArtifact.needToReCompile(nodeCompilerOptions, sourceFiles, fullNodeVersion)
|
|
639
|
+
) {
|
|
614
640
|
console.log(`Compiling contracts in folder "${contractsRootDir}"`)
|
|
615
641
|
Project.currentProject = await Project.compile(
|
|
642
|
+
fullNodeVersion,
|
|
616
643
|
provider,
|
|
617
644
|
sourceFiles,
|
|
618
645
|
projectRootDir,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
@std(enabled = false)
|
|
2
|
+
Abstract Contract FungibleTokenUnimplemented() implements IFungibleToken {
|
|
3
|
+
pub fn getSymbol() -> ByteVec {
|
|
4
|
+
panic!()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
pub fn getName() -> ByteVec {
|
|
8
|
+
panic!()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
pub fn getDecimals() -> U256 {
|
|
12
|
+
panic!()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
pub fn getTotalSupply() -> U256 {
|
|
16
|
+
panic!()
|
|
17
|
+
}
|
|
18
|
+
}
|