@alephium/web3 0.2.0-rc.0 → 0.2.0-rc.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/contracts/add/add.ral +1 -1
- package/contracts/greeter/greeter.ral +1 -1
- package/contracts/greeter_main.ral +2 -2
- package/contracts/sub/sub.ral +1 -1
- package/contracts/test/metadata.ral +17 -0
- package/contracts/test/warnings.ral +5 -0
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/scripts/create-project.js +2 -1
- package/dist/src/api/api-alephium.d.ts +11 -7
- package/dist/src/api/api-alephium.js +3 -3
- package/dist/src/api/api-explorer.d.ts +16 -0
- package/dist/src/api/api-explorer.js +26 -0
- package/dist/src/contract/contract.d.ts +23 -14
- package/dist/src/contract/contract.js +35 -13
- package/dist/src/utils/utils.d.ts +2 -2
- package/dist/src/utils/utils.js +2 -2
- package/package.json +3 -3
- package/scripts/create-project.ts +2 -1
- package/src/api/api-alephium.ts +12 -8
- package/src/api/api-explorer.ts +30 -0
- package/src/contract/contract.ts +75 -34
- package/src/contract/events.ts +2 -2
- package/src/contract/ralph.test.ts +4 -4
- package/src/transaction/status.ts +1 -1
- package/src/utils/subscription.ts +1 -1
- package/src/utils/utils.test.ts +1 -1
- package/src/utils/utils.ts +4 -4
- package/templates/base/package.json +2 -2
- package/templates/react/package.json +2 -2
- package/test/contract.test.ts +19 -0
- package/test/transaction.test.ts +1 -1
|
@@ -86,7 +86,8 @@ function prepareShared(packageRoot, projectRoot) {
|
|
|
86
86
|
}
|
|
87
87
|
function prepareBase(packageRoot, projectRoot) {
|
|
88
88
|
prepareShared(packageRoot, projectRoot);
|
|
89
|
-
copy('contracts', ['
|
|
89
|
+
copy('contracts', ['greeter_main.ral']);
|
|
90
|
+
copy('contracts/greeter', ['greeter.ral', 'greeter_interface.ral']);
|
|
90
91
|
fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/base'), projectRoot);
|
|
91
92
|
}
|
|
92
93
|
function prepareReact(packageRoot, projectRoot, projectName) {
|
|
@@ -311,11 +311,13 @@ export interface CompileContractResult {
|
|
|
311
311
|
fields: FieldsSig;
|
|
312
312
|
functions: FunctionSig[];
|
|
313
313
|
events: EventSig[];
|
|
314
|
+
warnings: string[];
|
|
314
315
|
}
|
|
315
316
|
export interface CompileScriptResult {
|
|
316
317
|
bytecodeTemplate: string;
|
|
317
318
|
fields: FieldsSig;
|
|
318
319
|
functions: FunctionSig[];
|
|
320
|
+
warnings: string[];
|
|
319
321
|
}
|
|
320
322
|
export interface Confirmed {
|
|
321
323
|
/** @format block-hash */
|
|
@@ -409,7 +411,6 @@ export interface Destination {
|
|
|
409
411
|
export declare type DiscoveryAction = Reachable | Unreachable;
|
|
410
412
|
export interface EventSig {
|
|
411
413
|
name: string;
|
|
412
|
-
signature: string;
|
|
413
414
|
fieldNames: string[];
|
|
414
415
|
fieldTypes: string[];
|
|
415
416
|
}
|
|
@@ -417,9 +418,9 @@ export interface FetchResponse {
|
|
|
417
418
|
blocks: BlockEntry[][];
|
|
418
419
|
}
|
|
419
420
|
export interface FieldsSig {
|
|
420
|
-
signature: string;
|
|
421
421
|
names: string[];
|
|
422
422
|
types: string[];
|
|
423
|
+
isMutable: boolean[];
|
|
423
424
|
}
|
|
424
425
|
export interface FixedAssetOutput {
|
|
425
426
|
/** @format int32 */
|
|
@@ -438,9 +439,12 @@ export interface FixedAssetOutput {
|
|
|
438
439
|
}
|
|
439
440
|
export interface FunctionSig {
|
|
440
441
|
name: string;
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
442
|
+
usePreapprovedAssets: boolean;
|
|
443
|
+
useAssetsInContract: boolean;
|
|
444
|
+
isPublic: boolean;
|
|
445
|
+
paramNames: string[];
|
|
446
|
+
paramTypes: string[];
|
|
447
|
+
paramIsMutable: boolean[];
|
|
444
448
|
returnTypes: string[];
|
|
445
449
|
}
|
|
446
450
|
export interface Group {
|
|
@@ -855,8 +859,8 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
855
859
|
}
|
|
856
860
|
/**
|
|
857
861
|
* @title Alephium API
|
|
858
|
-
* @version 1.5.0
|
|
859
|
-
* @baseUrl
|
|
862
|
+
* @version 1.5.0
|
|
863
|
+
* @baseUrl ../
|
|
860
864
|
*/
|
|
861
865
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
862
866
|
wallets: {
|
|
@@ -28,7 +28,7 @@ var ContentType;
|
|
|
28
28
|
})(ContentType = exports.ContentType || (exports.ContentType = {}));
|
|
29
29
|
class HttpClient {
|
|
30
30
|
constructor(apiConfig = {}) {
|
|
31
|
-
this.baseUrl = '
|
|
31
|
+
this.baseUrl = '../';
|
|
32
32
|
this.securityData = null;
|
|
33
33
|
this.abortControllers = new Map();
|
|
34
34
|
this.customFetch = (...fetchParams) => fetch(...fetchParams);
|
|
@@ -158,8 +158,8 @@ class HttpClient {
|
|
|
158
158
|
exports.HttpClient = HttpClient;
|
|
159
159
|
/**
|
|
160
160
|
* @title Alephium API
|
|
161
|
-
* @version 1.5.0
|
|
162
|
-
* @baseUrl
|
|
161
|
+
* @version 1.5.0
|
|
162
|
+
* @baseUrl ../
|
|
163
163
|
*/
|
|
164
164
|
class Api extends HttpClient {
|
|
165
165
|
constructor() {
|
|
@@ -470,6 +470,22 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
470
470
|
* @request PUT:/utils/sanity-check
|
|
471
471
|
*/
|
|
472
472
|
putUtilsSanityCheck: (params?: RequestParams) => Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
|
|
475
|
+
*
|
|
476
|
+
* @tags Utils
|
|
477
|
+
* @name PutUtilsUpdateGlobalLoglevel
|
|
478
|
+
* @request PUT:/utils/update-global-loglevel
|
|
479
|
+
*/
|
|
480
|
+
putUtilsUpdateGlobalLoglevel: (data: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR', params?: RequestParams) => Promise<void>;
|
|
481
|
+
/**
|
|
482
|
+
* @description Update logging file, only logback.xml is accepted
|
|
483
|
+
*
|
|
484
|
+
* @tags Utils
|
|
485
|
+
* @name PutUtilsUpdateLogConfig
|
|
486
|
+
* @request PUT:/utils/update-log-config
|
|
487
|
+
*/
|
|
488
|
+
putUtilsUpdateLogConfig: (data: string, params?: RequestParams) => Promise<void>;
|
|
473
489
|
};
|
|
474
490
|
}
|
|
475
491
|
export {};
|
|
@@ -450,6 +450,32 @@ class Api extends HttpClient {
|
|
|
450
450
|
path: `/utils/sanity-check`,
|
|
451
451
|
method: 'PUT',
|
|
452
452
|
...params
|
|
453
|
+
}).then(convertHttpResponse),
|
|
454
|
+
/**
|
|
455
|
+
* @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
|
|
456
|
+
*
|
|
457
|
+
* @tags Utils
|
|
458
|
+
* @name PutUtilsUpdateGlobalLoglevel
|
|
459
|
+
* @request PUT:/utils/update-global-loglevel
|
|
460
|
+
*/
|
|
461
|
+
putUtilsUpdateGlobalLoglevel: (data, params = {}) => this.request({
|
|
462
|
+
path: `/utils/update-global-loglevel`,
|
|
463
|
+
method: 'PUT',
|
|
464
|
+
body: data,
|
|
465
|
+
...params
|
|
466
|
+
}).then(convertHttpResponse),
|
|
467
|
+
/**
|
|
468
|
+
* @description Update logging file, only logback.xml is accepted
|
|
469
|
+
*
|
|
470
|
+
* @tags Utils
|
|
471
|
+
* @name PutUtilsUpdateLogConfig
|
|
472
|
+
* @request PUT:/utils/update-log-config
|
|
473
|
+
*/
|
|
474
|
+
putUtilsUpdateLogConfig: (data, params = {}) => this.request({
|
|
475
|
+
path: `/utils/update-log-config`,
|
|
476
|
+
method: 'PUT',
|
|
477
|
+
body: data,
|
|
478
|
+
...params
|
|
453
479
|
}).then(convertHttpResponse)
|
|
454
480
|
};
|
|
455
481
|
}
|
|
@@ -8,9 +8,12 @@ declare class SourceFile {
|
|
|
8
8
|
readonly artifactPath: string;
|
|
9
9
|
constructor(dirs: string[], fileName: string);
|
|
10
10
|
}
|
|
11
|
+
declare type FieldsSig = node.FieldsSig;
|
|
12
|
+
declare type EventSig = node.EventSig;
|
|
13
|
+
declare type FunctionSig = node.FunctionSig;
|
|
11
14
|
export declare abstract class Common {
|
|
12
15
|
readonly sourceCodeSha256: string;
|
|
13
|
-
readonly functions:
|
|
16
|
+
readonly functions: FunctionSig[];
|
|
14
17
|
static readonly importRegex: RegExp;
|
|
15
18
|
static readonly contractRegex: RegExp;
|
|
16
19
|
static readonly interfaceRegex: RegExp;
|
|
@@ -19,7 +22,7 @@ export declare abstract class Common {
|
|
|
19
22
|
static artifactCacheCapacity: number;
|
|
20
23
|
protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
|
|
21
24
|
protected static _putArtifactToCache(contract: Contract): void;
|
|
22
|
-
constructor(sourceCodeSha256: string, functions:
|
|
25
|
+
constructor(sourceCodeSha256: string, functions: FunctionSig[]);
|
|
23
26
|
protected static _artifactsFolder(): string;
|
|
24
27
|
static getSourceFile(path: string, _dirs: string[]): SourceFile;
|
|
25
28
|
protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
|
|
@@ -27,19 +30,25 @@ export declare abstract class Common {
|
|
|
27
30
|
static checkFileNameExtension(fileName: string): void;
|
|
28
31
|
protected static _from<T extends {
|
|
29
32
|
sourceCodeSha256: string;
|
|
30
|
-
}>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string) => Promise<T
|
|
33
|
+
}>(provider: NodeProvider, sourceFile: SourceFile, loadContractStr: (sourceFile: SourceFile, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, sourceFile: SourceFile, contractStr: string, contractHash: string, errorOnWarnings: boolean) => Promise<T>, errorOnWarnings: boolean): Promise<T>;
|
|
31
34
|
protected _saveToFile(sourceFile: SourceFile): Promise<void>;
|
|
32
35
|
abstract buildByteCodeToDeploy(initialFields?: Fields): string;
|
|
36
|
+
publicFunctions(): string[];
|
|
37
|
+
usingPreapprovedAssetsFunctions(): string[];
|
|
38
|
+
usingAssetsInContractFunctions(): string[];
|
|
39
|
+
protected static checkCompilerWarnings(compiled: {
|
|
40
|
+
warnings: string[];
|
|
41
|
+
}, errorOnWarnings: boolean): void;
|
|
33
42
|
}
|
|
34
43
|
export declare class Contract extends Common {
|
|
35
44
|
readonly bytecode: string;
|
|
36
45
|
readonly codeHash: string;
|
|
37
|
-
readonly fieldsSig:
|
|
38
|
-
readonly eventsSig:
|
|
39
|
-
constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig:
|
|
46
|
+
readonly fieldsSig: FieldsSig;
|
|
47
|
+
readonly eventsSig: EventSig[];
|
|
48
|
+
constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
|
|
40
49
|
static checkCodeType(fileName: string, contractStr: string): void;
|
|
41
50
|
private static loadContractStr;
|
|
42
|
-
static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
|
|
51
|
+
static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean): Promise<Contract>;
|
|
43
52
|
private static compile;
|
|
44
53
|
static fromJson(artifact: any): Contract;
|
|
45
54
|
static fromArtifactFile(path: string): Promise<Contract>;
|
|
@@ -56,10 +65,10 @@ export declare class Contract extends Common {
|
|
|
56
65
|
toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
|
|
57
66
|
toTestContract(funcName: string, params: TestContractParams): node.TestContract;
|
|
58
67
|
static fromCodeHash(codeHash: string): Promise<Contract>;
|
|
59
|
-
static getFieldsSig(state: node.ContractState): Promise<
|
|
68
|
+
static getFieldsSig(state: node.ContractState): Promise<FieldsSig>;
|
|
60
69
|
fromApiContractState(state: node.ContractState): Promise<ContractState>;
|
|
61
|
-
static ContractCreatedEvent:
|
|
62
|
-
static ContractDestroyedEvent:
|
|
70
|
+
static ContractCreatedEvent: EventSig;
|
|
71
|
+
static ContractDestroyedEvent: EventSig;
|
|
63
72
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
|
|
64
73
|
fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
|
|
65
74
|
paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
|
|
@@ -68,11 +77,11 @@ export declare class Contract extends Common {
|
|
|
68
77
|
}
|
|
69
78
|
export declare class Script extends Common {
|
|
70
79
|
readonly bytecodeTemplate: string;
|
|
71
|
-
readonly fieldsSig:
|
|
72
|
-
constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig:
|
|
80
|
+
readonly fieldsSig: FieldsSig;
|
|
81
|
+
constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
|
|
73
82
|
static checkCodeType(fileName: string, contractStr: string): void;
|
|
74
83
|
private static loadContractStr;
|
|
75
|
-
static fromSource(provider: NodeProvider, path: string): Promise<Script>;
|
|
84
|
+
static fromSource(provider: NodeProvider, path: string, errorOnWarnings?: boolean): Promise<Script>;
|
|
76
85
|
private static compile;
|
|
77
86
|
static fromJson(artifact: any): Script;
|
|
78
87
|
static fromArtifactFile(path: string): Promise<Script>;
|
|
@@ -107,7 +116,7 @@ export interface ContractState {
|
|
|
107
116
|
initialStateHash?: string;
|
|
108
117
|
codeHash: string;
|
|
109
118
|
fields: Fields;
|
|
110
|
-
fieldsSig:
|
|
119
|
+
fieldsSig: FieldsSig;
|
|
111
120
|
asset: Asset;
|
|
112
121
|
}
|
|
113
122
|
export interface TestContractParams {
|
|
@@ -135,7 +135,7 @@ class Common {
|
|
|
135
135
|
throw new Error('Smart contract file name should end with ".ral"');
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
|
-
static async _from(provider, sourceFile, loadContractStr, compile) {
|
|
138
|
+
static async _from(provider, sourceFile, loadContractStr, compile, errorOnWarnings) {
|
|
139
139
|
Common.checkFileNameExtension(sourceFile.contractPath);
|
|
140
140
|
const contractStr = await loadContractStr(sourceFile, []);
|
|
141
141
|
const contractHash = cryptojs.SHA256(contractStr).toString();
|
|
@@ -144,7 +144,7 @@ class Common {
|
|
|
144
144
|
return existingContract;
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
147
|
-
return compile(provider, sourceFile, contractStr, contractHash);
|
|
147
|
+
return compile(provider, sourceFile, contractStr, contractHash, errorOnWarnings);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
_saveToFile(sourceFile) {
|
|
@@ -154,10 +154,32 @@ class Common {
|
|
|
154
154
|
}
|
|
155
155
|
return fs_2.promises.writeFile(sourceFile.artifactPath, this.toString());
|
|
156
156
|
}
|
|
157
|
+
publicFunctions() {
|
|
158
|
+
return this.functions.filter((func) => func.isPublic).map((func) => func.name);
|
|
159
|
+
}
|
|
160
|
+
usingPreapprovedAssetsFunctions() {
|
|
161
|
+
return this.functions.filter((func) => func.usePreapprovedAssets).map((func) => func.name);
|
|
162
|
+
}
|
|
163
|
+
usingAssetsInContractFunctions() {
|
|
164
|
+
return this.functions.filter((func) => func.useAssetsInContract).map((func) => func.name);
|
|
165
|
+
}
|
|
166
|
+
static checkCompilerWarnings(compiled, errorOnWarnings) {
|
|
167
|
+
if (compiled.warnings.length !== 0) {
|
|
168
|
+
const prefixPerWarning = ' - ';
|
|
169
|
+
const warningString = prefixPerWarning + compiled.warnings.join('\n' + prefixPerWarning);
|
|
170
|
+
const output = 'Compilation warnings:\n' + warningString + '\n';
|
|
171
|
+
if (errorOnWarnings) {
|
|
172
|
+
throw new Error(output);
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
console.log(output);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
157
179
|
}
|
|
158
180
|
exports.Common = Common;
|
|
159
181
|
Common.importRegex = new RegExp('^import "([^"/]+/(([^"]+)/)?)?[a-z][a-z_0-9]*.ral"', 'mg');
|
|
160
|
-
Common.contractRegex = new RegExp('^
|
|
182
|
+
Common.contractRegex = new RegExp('^(Abstract[ ]+)?Contract [A-Z][a-zA-Z0-9]*', 'mg');
|
|
161
183
|
Common.interfaceRegex = new RegExp('^Interface [A-Z][a-zA-Z0-9]* \\{', 'mg');
|
|
162
184
|
Common.scriptRegex = new RegExp('^TxScript [A-Z][a-zA-Z0-9]*', 'mg');
|
|
163
185
|
Common._artifactCache = new Map();
|
|
@@ -193,17 +215,18 @@ class Contract extends Common {
|
|
|
193
215
|
static async loadContractStr(sourceFile) {
|
|
194
216
|
return Common._loadContractStr(sourceFile, [], (code) => Contract.checkCodeType(sourceFile.contractPath, code));
|
|
195
217
|
}
|
|
196
|
-
static async fromSource(provider, path) {
|
|
218
|
+
static async fromSource(provider, path, errorOnWarnings = true) {
|
|
197
219
|
if (!fs_1.default.existsSync(Common._artifactsFolder())) {
|
|
198
220
|
fs_1.default.mkdirSync(Common._artifactsFolder(), { recursive: true });
|
|
199
221
|
}
|
|
200
222
|
const sourceFile = this.getSourceFile(path, []);
|
|
201
|
-
const contract = await Common._from(provider, sourceFile, (sourceFile) => Contract.loadContractStr(sourceFile), Contract.compile);
|
|
223
|
+
const contract = await Common._from(provider, sourceFile, (sourceFile) => Contract.loadContractStr(sourceFile), Contract.compile, errorOnWarnings);
|
|
202
224
|
this._putArtifactToCache(contract);
|
|
203
225
|
return contract;
|
|
204
226
|
}
|
|
205
|
-
static async compile(provider, sourceFile, contractStr, contractHash) {
|
|
227
|
+
static async compile(provider, sourceFile, contractStr, contractHash, errorOnWarnings) {
|
|
206
228
|
const compiled = await provider.contracts.postContractsCompileContract({ code: contractStr });
|
|
229
|
+
Common.checkCompilerWarnings(compiled, errorOnWarnings);
|
|
207
230
|
const artifact = new Contract(contractHash, compiled.bytecode, compiled.codeHash, compiled.fields, compiled.events, compiled.functions);
|
|
208
231
|
await artifact._saveToFile(sourceFile);
|
|
209
232
|
return artifact;
|
|
@@ -265,7 +288,7 @@ class Contract extends Common {
|
|
|
265
288
|
const apiParams = this.toTestContract(funcName, params);
|
|
266
289
|
const apiResult = await provider.contracts.postContractsTestContract(apiParams);
|
|
267
290
|
const methodIndex = typeof params.testMethodIndex !== 'undefined' ? params.testMethodIndex : this.getMethodIndex(funcName);
|
|
268
|
-
const isPublic = this.functions[`${methodIndex}`].
|
|
291
|
+
const isPublic = this.functions[`${methodIndex}`].isPublic;
|
|
269
292
|
if (isPublic === expectPublic) {
|
|
270
293
|
const result = await this.fromTestContractResult(methodIndex, apiResult);
|
|
271
294
|
return result;
|
|
@@ -424,13 +447,11 @@ class Contract extends Common {
|
|
|
424
447
|
exports.Contract = Contract;
|
|
425
448
|
Contract.ContractCreatedEvent = {
|
|
426
449
|
name: 'ContractCreated',
|
|
427
|
-
signature: 'event ContractCreated(address:Address)',
|
|
428
450
|
fieldNames: ['address'],
|
|
429
451
|
fieldTypes: ['Address']
|
|
430
452
|
};
|
|
431
453
|
Contract.ContractDestroyedEvent = {
|
|
432
454
|
name: 'ContractDestroyed',
|
|
433
|
-
signature: 'event ContractDestroyed(address:Address)',
|
|
434
455
|
fieldNames: ['address'],
|
|
435
456
|
fieldTypes: ['Address']
|
|
436
457
|
};
|
|
@@ -455,12 +476,13 @@ class Script extends Common {
|
|
|
455
476
|
static async loadContractStr(sourceFile) {
|
|
456
477
|
return Common._loadContractStr(sourceFile, [], (code) => Script.checkCodeType(sourceFile.contractPath, code));
|
|
457
478
|
}
|
|
458
|
-
static async fromSource(provider, path) {
|
|
479
|
+
static async fromSource(provider, path, errorOnWarnings = true) {
|
|
459
480
|
const sourceFile = this.getSourceFile(path, []);
|
|
460
|
-
return Common._from(provider, sourceFile, (sourceFile) => Script.loadContractStr(sourceFile), Script.compile);
|
|
481
|
+
return Common._from(provider, sourceFile, (sourceFile) => Script.loadContractStr(sourceFile), Script.compile, errorOnWarnings);
|
|
461
482
|
}
|
|
462
|
-
static async compile(provider, sourceFile, scriptStr, contractHash) {
|
|
483
|
+
static async compile(provider, sourceFile, scriptStr, contractHash, errorOnWarnings = true) {
|
|
463
484
|
const compiled = await provider.contracts.postContractsCompileScript({ code: scriptStr });
|
|
485
|
+
Common.checkCompilerWarnings(compiled, errorOnWarnings);
|
|
464
486
|
const artifact = new Script(contractHash, compiled.bytecodeTemplate, compiled.fields, compiled.functions);
|
|
465
487
|
await artifact._saveToFile(sourceFile);
|
|
466
488
|
return artifact;
|
|
@@ -752,7 +774,7 @@ function toApiFields(fields, fieldsSig) {
|
|
|
752
774
|
return toApiVals(fields, fieldsSig.names, fieldsSig.types);
|
|
753
775
|
}
|
|
754
776
|
function toApiArgs(args, funcSig) {
|
|
755
|
-
return toApiVals(args, funcSig.
|
|
777
|
+
return toApiVals(args, funcSig.paramNames, funcSig.paramTypes);
|
|
756
778
|
}
|
|
757
779
|
function toApiVals(fields, names, types) {
|
|
758
780
|
return names.map((name, index) => {
|
|
@@ -20,8 +20,8 @@ export declare function addressFromContractId(contractId: string): string;
|
|
|
20
20
|
export declare function contractIdFromTx(txId: string, outputIndex: number): string;
|
|
21
21
|
export declare function subContractId(parentContractId: string, pathInHex: string): string;
|
|
22
22
|
export declare function stringToHex(str: string): string;
|
|
23
|
-
export declare function hexToString(str:
|
|
24
|
-
export declare function timeout(ms: number): Promise<
|
|
23
|
+
export declare function hexToString(str: string): string;
|
|
24
|
+
export declare function timeout(ms: number): Promise<void>;
|
|
25
25
|
declare type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
26
26
|
export declare type Eq<X, Y> = _Eq<{
|
|
27
27
|
[P in keyof X]: X[P];
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -182,7 +182,7 @@ function contractIdFromTx(txId, outputIndex) {
|
|
|
182
182
|
}
|
|
183
183
|
exports.contractIdFromTx = contractIdFromTx;
|
|
184
184
|
function subContractId(parentContractId, pathInHex) {
|
|
185
|
-
const data = buffer_1.Buffer.concat([hexToBinUnsafe(
|
|
185
|
+
const data = buffer_1.Buffer.concat([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)]);
|
|
186
186
|
return binToHex(blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32));
|
|
187
187
|
}
|
|
188
188
|
exports.subContractId = subContractId;
|
|
@@ -195,7 +195,7 @@ function stringToHex(str) {
|
|
|
195
195
|
}
|
|
196
196
|
exports.stringToHex = stringToHex;
|
|
197
197
|
function hexToString(str) {
|
|
198
|
-
return buffer_1.Buffer.from(str
|
|
198
|
+
return buffer_1.Buffer.from(str, 'hex').toString();
|
|
199
199
|
}
|
|
200
200
|
exports.hexToString = hexToString;
|
|
201
201
|
function timeout(ms) {
|
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.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,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": "Alephium dev <dev@alephium.org>",
|
|
29
29
|
"config": {
|
|
30
|
-
"alephium_version": "1.5.0-
|
|
31
|
-
"explorer_backend_version": "1.7.
|
|
30
|
+
"alephium_version": "1.5.0-rc4",
|
|
31
|
+
"explorer_backend_version": "1.7.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"build": "rm -rf dist/* && npx tsc --build . && webpack",
|
|
@@ -87,7 +87,8 @@ function prepareShared(packageRoot: string, projectRoot: string) {
|
|
|
87
87
|
|
|
88
88
|
function prepareBase(packageRoot: string, projectRoot: string) {
|
|
89
89
|
prepareShared(packageRoot, projectRoot)
|
|
90
|
-
copy('contracts', ['
|
|
90
|
+
copy('contracts', ['greeter_main.ral'])
|
|
91
|
+
copy('contracts/greeter', ['greeter.ral', 'greeter_interface.ral'])
|
|
91
92
|
fsExtra.copySync(path.join(packageRoot, 'templates/base'), projectRoot)
|
|
92
93
|
}
|
|
93
94
|
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -429,12 +429,14 @@ export interface CompileContractResult {
|
|
|
429
429
|
fields: FieldsSig
|
|
430
430
|
functions: FunctionSig[]
|
|
431
431
|
events: EventSig[]
|
|
432
|
+
warnings: string[]
|
|
432
433
|
}
|
|
433
434
|
|
|
434
435
|
export interface CompileScriptResult {
|
|
435
436
|
bytecodeTemplate: string
|
|
436
437
|
fields: FieldsSig
|
|
437
438
|
functions: FunctionSig[]
|
|
439
|
+
warnings: string[]
|
|
438
440
|
}
|
|
439
441
|
|
|
440
442
|
export interface Confirmed {
|
|
@@ -561,7 +563,6 @@ export type DiscoveryAction = Reachable | Unreachable
|
|
|
561
563
|
|
|
562
564
|
export interface EventSig {
|
|
563
565
|
name: string
|
|
564
|
-
signature: string
|
|
565
566
|
fieldNames: string[]
|
|
566
567
|
fieldTypes: string[]
|
|
567
568
|
}
|
|
@@ -571,9 +572,9 @@ export interface FetchResponse {
|
|
|
571
572
|
}
|
|
572
573
|
|
|
573
574
|
export interface FieldsSig {
|
|
574
|
-
signature: string
|
|
575
575
|
names: string[]
|
|
576
576
|
types: string[]
|
|
577
|
+
isMutable: boolean[]
|
|
577
578
|
}
|
|
578
579
|
|
|
579
580
|
export interface FixedAssetOutput {
|
|
@@ -599,9 +600,12 @@ export interface FixedAssetOutput {
|
|
|
599
600
|
|
|
600
601
|
export interface FunctionSig {
|
|
601
602
|
name: string
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
603
|
+
usePreapprovedAssets: boolean
|
|
604
|
+
useAssetsInContract: boolean
|
|
605
|
+
isPublic: boolean
|
|
606
|
+
paramNames: string[]
|
|
607
|
+
paramTypes: string[]
|
|
608
|
+
paramIsMutable: boolean[]
|
|
605
609
|
returnTypes: string[]
|
|
606
610
|
}
|
|
607
611
|
|
|
@@ -1114,7 +1118,7 @@ export enum ContentType {
|
|
|
1114
1118
|
}
|
|
1115
1119
|
|
|
1116
1120
|
export class HttpClient<SecurityDataType = unknown> {
|
|
1117
|
-
public baseUrl: string = '
|
|
1121
|
+
public baseUrl: string = '../'
|
|
1118
1122
|
private securityData: SecurityDataType | null = null
|
|
1119
1123
|
private securityWorker?: ApiConfig<SecurityDataType>['securityWorker']
|
|
1120
1124
|
private abortControllers = new Map<CancelToken, AbortController>()
|
|
@@ -1279,8 +1283,8 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1279
1283
|
|
|
1280
1284
|
/**
|
|
1281
1285
|
* @title Alephium API
|
|
1282
|
-
* @version 1.5.0
|
|
1283
|
-
* @baseUrl
|
|
1286
|
+
* @version 1.5.0
|
|
1287
|
+
* @baseUrl ../
|
|
1284
1288
|
*/
|
|
1285
1289
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
1286
1290
|
wallets = {
|
package/src/api/api-explorer.ts
CHANGED
|
@@ -847,6 +847,36 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
847
847
|
path: `/utils/sanity-check`,
|
|
848
848
|
method: 'PUT',
|
|
849
849
|
...params
|
|
850
|
+
}).then(convertHttpResponse),
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @description Update global log level, accepted: TRACE, DEBUG, INFO, WARN, ERROR
|
|
854
|
+
*
|
|
855
|
+
* @tags Utils
|
|
856
|
+
* @name PutUtilsUpdateGlobalLoglevel
|
|
857
|
+
* @request PUT:/utils/update-global-loglevel
|
|
858
|
+
*/
|
|
859
|
+
putUtilsUpdateGlobalLoglevel: (data: 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR', params: RequestParams = {}) =>
|
|
860
|
+
this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
861
|
+
path: `/utils/update-global-loglevel`,
|
|
862
|
+
method: 'PUT',
|
|
863
|
+
body: data,
|
|
864
|
+
...params
|
|
865
|
+
}).then(convertHttpResponse),
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* @description Update logging file, only logback.xml is accepted
|
|
869
|
+
*
|
|
870
|
+
* @tags Utils
|
|
871
|
+
* @name PutUtilsUpdateLogConfig
|
|
872
|
+
* @request PUT:/utils/update-log-config
|
|
873
|
+
*/
|
|
874
|
+
putUtilsUpdateLogConfig: (data: string, params: RequestParams = {}) =>
|
|
875
|
+
this.request<void, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
876
|
+
path: `/utils/update-log-config`,
|
|
877
|
+
method: 'PUT',
|
|
878
|
+
body: data,
|
|
879
|
+
...params
|
|
850
880
|
}).then(convertHttpResponse)
|
|
851
881
|
}
|
|
852
882
|
}
|