@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.
- 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 +21 -21
- package/dist/src/contract/contract.js +103 -108
- package/dist/src/signer/index.d.ts +1 -0
- package/dist/src/signer/index.js +1 -0
- package/dist/src/signer/signer.d.ts +19 -101
- package/dist/src/signer/signer.js +47 -19
- package/dist/src/signer/types.d.ts +109 -0
- package/dist/src/signer/types.js +30 -0
- package/dist/src/transaction/index.d.ts +1 -0
- package/dist/src/transaction/index.js +1 -0
- package/dist/src/transaction/sign-verify.d.ts +2 -0
- package/dist/src/transaction/sign-verify.js +62 -0
- package/package.json +3 -2
- package/src/api/api-alephium.ts +1 -1
- package/src/contract/contract.ts +143 -121
- package/src/signer/index.ts +1 -0
- package/src/signer/signer.ts +80 -130
- package/src/signer/types.ts +148 -0
- package/src/transaction/index.ts +1 -0
- package/src/transaction/sign-verify.ts +38 -0
- package/webpack.config.js +1 -0
|
@@ -908,7 +908,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
908
908
|
}
|
|
909
909
|
/**
|
|
910
910
|
* @title Alephium API
|
|
911
|
-
* @version 1.6.
|
|
911
|
+
* @version 1.6.1
|
|
912
912
|
* @baseUrl ../
|
|
913
913
|
*/
|
|
914
914
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -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
|
|
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
|
|
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
|
|
26
|
-
type:
|
|
27
|
-
|
|
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:
|
|
32
|
-
static from(type:
|
|
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
|
-
|
|
35
|
+
sourceInfo: SourceInfo;
|
|
36
36
|
artifact: T;
|
|
37
37
|
warnings: string[];
|
|
38
|
-
constructor(
|
|
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,
|
|
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
|
-
|
|
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<
|
|
65
|
-
static readonly contractMatcher: TypedMatcher<
|
|
66
|
-
static readonly interfaceMatcher: TypedMatcher<
|
|
67
|
-
static readonly scriptMatcher: TypedMatcher<
|
|
68
|
-
static readonly matchers: TypedMatcher<
|
|
69
|
-
static buildProjectArtifact(
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
83
|
-
constructor(type, sourceCode, sourceCodeHash,
|
|
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.
|
|
85
|
+
this.contractRelativePath = contractRelativePath;
|
|
88
86
|
}
|
|
89
87
|
getArtifactPath(artifactsRootDir) {
|
|
90
|
-
return artifactsRootDir
|
|
88
|
+
return path.join(artifactsRootDir, this.contractRelativePath) + '.json';
|
|
91
89
|
}
|
|
92
|
-
static async from(type, sourceCode,
|
|
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
|
|
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(
|
|
99
|
-
this.
|
|
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
|
|
121
|
-
const artifact = {
|
|
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,
|
|
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 (
|
|
135
|
+
if (sourceInfos.length !== this.infos.size) {
|
|
135
136
|
return true;
|
|
136
137
|
}
|
|
137
|
-
for (const
|
|
138
|
-
const info = this.infos.get(
|
|
139
|
-
if (typeof info === 'undefined' || info.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
|
|
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,
|
|
160
|
+
constructor(contractsRootDir, artifactsRootDir, sourceInfos, contracts, scripts, errorOnWarnings, projectArtifact) {
|
|
160
161
|
this.contractsRootDir = contractsRootDir;
|
|
161
162
|
this.artifactsRootDir = artifactsRootDir;
|
|
162
|
-
this.
|
|
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([
|
|
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(
|
|
174
|
+
static buildProjectArtifact(sourceInfos, contracts, scripts, compilerOptions) {
|
|
171
175
|
const files = new Map();
|
|
172
176
|
contracts.forEach((c) => {
|
|
173
|
-
files.set(c.
|
|
174
|
-
|
|
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.
|
|
182
|
-
|
|
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.
|
|
189
|
-
|
|
190
|
-
files.set(c.
|
|
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.
|
|
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.
|
|
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
|
|
237
|
-
const
|
|
238
|
-
if (!fs_1.default.existsSync(
|
|
239
|
-
fs_1.default.mkdirSync(
|
|
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(
|
|
241
|
+
return fs_2.promises.writeFile(artifactPath, compiled.artifact.toString());
|
|
242
242
|
};
|
|
243
|
-
|
|
244
|
-
|
|
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,
|
|
259
|
-
const sourceStr =
|
|
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
|
|
263
|
+
const sourceInfo = sourceInfos[`${index}`];
|
|
268
264
|
const contract = Contract.fromCompileResult(contractResult);
|
|
269
|
-
contracts.
|
|
265
|
+
contracts.set(contract.name, new Compiled(sourceInfo, contract, contractResult.warnings));
|
|
270
266
|
});
|
|
271
267
|
result.scripts.forEach((scriptResult, index) => {
|
|
272
|
-
const
|
|
268
|
+
const sourceInfo = sourceInfos[index + contracts.size];
|
|
273
269
|
const script = Script.fromCompileResult(scriptResult);
|
|
274
|
-
scripts.
|
|
270
|
+
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings));
|
|
275
271
|
});
|
|
276
|
-
const projectArtifact = Project.buildProjectArtifact(
|
|
277
|
-
const project = new Project(contractsRootDir, artifactsRootDir,
|
|
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,
|
|
277
|
+
static async loadArtifacts(provider, sourceInfos, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
282
278
|
try {
|
|
283
|
-
const contracts =
|
|
284
|
-
const scripts =
|
|
285
|
-
for (const
|
|
286
|
-
const info = projectArtifact.infos.get(
|
|
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 ${
|
|
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 =
|
|
292
|
-
if (
|
|
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.
|
|
290
|
+
contracts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
|
|
295
291
|
}
|
|
296
|
-
else if (
|
|
292
|
+
else if (sourceInfo.type === SourceKind.Script) {
|
|
297
293
|
const artifact = await Script.fromArtifactFile(artifactDir, info.bytecodeDebugPatch);
|
|
298
|
-
scripts.
|
|
294
|
+
scripts.set(artifact.name, new Compiled(sourceInfo, artifact, warnings));
|
|
299
295
|
}
|
|
300
296
|
}
|
|
301
|
-
return new Project(contractsRootDir, artifactsRootDir,
|
|
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,
|
|
301
|
+
return Project.compile(provider, sourceInfos, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
306
302
|
}
|
|
307
303
|
}
|
|
308
|
-
static async loadSourceFile(dirPath, filename) {
|
|
309
|
-
const contractPath = dirPath
|
|
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
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
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
|
|
333
|
-
results.push(
|
|
327
|
+
const sourceInfos = await Project.loadSourceFile(contractsRootDir, dirPath, dirent.name);
|
|
328
|
+
results.push(...sourceInfos);
|
|
334
329
|
}
|
|
335
330
|
else {
|
|
336
|
-
const newPath = dirPath
|
|
331
|
+
const newPath = path.join(dirPath, dirent.name);
|
|
337
332
|
await loadDir(newPath, results);
|
|
338
333
|
}
|
|
339
334
|
}
|
|
340
335
|
};
|
|
341
|
-
const
|
|
342
|
-
await loadDir(contractsRootDir,
|
|
343
|
-
const contractAndScriptSize =
|
|
344
|
-
if (
|
|
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
|
|
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]*',
|
|
366
|
-
Project.contractMatcher = new TypedMatcher('^Contract [A-Z][a-zA-Z0-9]*',
|
|
367
|
-
Project.interfaceMatcher = new TypedMatcher('^Interface [A-Z][a-zA-Z0-9]* \\{',
|
|
368
|
-
Project.scriptMatcher = new TypedMatcher('^TxScript [A-Z][a-zA-Z0-9]*',
|
|
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:
|
|
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:
|
|
656
|
+
signerAddress: await signer.getSelectedAddress(),
|
|
662
657
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
|
|
663
658
|
attoAlphAmount: params.attoAlphAmount,
|
|
664
659
|
tokens: params.tokens,
|
package/dist/src/signer/index.js
CHANGED