@alephium/web3 0.12.0-test.2 → 0.12.1
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 +15 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/api/api-explorer.d.ts +5 -5
- package/dist/src/api/api-explorer.js +12 -6
- package/dist/src/api/utils.d.ts +6 -0
- package/dist/src/api/utils.js +10 -1
- package/dist/src/contract/contract.d.ts +5 -1
- package/dist/src/contract/contract.js +35 -11
- package/package.json +2 -2
- package/src/api/api-alephium.ts +18 -1
- package/src/api/api-explorer.ts +13 -7
- package/src/api/utils.ts +11 -0
- package/src/contract/contract.ts +45 -8
|
@@ -334,6 +334,8 @@ export interface CompileContractResult {
|
|
|
334
334
|
codeHashDebug: string;
|
|
335
335
|
fields: FieldsSig;
|
|
336
336
|
functions: FunctionSig[];
|
|
337
|
+
constants: Constant[];
|
|
338
|
+
enums: Enum[];
|
|
337
339
|
events: EventSig[];
|
|
338
340
|
warnings: string[];
|
|
339
341
|
stdInterfaceId?: string;
|
|
@@ -372,6 +374,10 @@ export interface Confirmed {
|
|
|
372
374
|
toGroupConfirmations: number;
|
|
373
375
|
type: string;
|
|
374
376
|
}
|
|
377
|
+
export interface Constant {
|
|
378
|
+
name: string;
|
|
379
|
+
value: Val;
|
|
380
|
+
}
|
|
375
381
|
export interface Contract {
|
|
376
382
|
code: string;
|
|
377
383
|
compilerOptions?: CompilerOptions;
|
|
@@ -466,6 +472,14 @@ export interface Destination {
|
|
|
466
472
|
message?: string;
|
|
467
473
|
}
|
|
468
474
|
export type DiscoveryAction = Reachable | Unreachable;
|
|
475
|
+
export interface Enum {
|
|
476
|
+
name: string;
|
|
477
|
+
fields: EnumField[];
|
|
478
|
+
}
|
|
479
|
+
export interface EnumField {
|
|
480
|
+
name: string;
|
|
481
|
+
value: Val;
|
|
482
|
+
}
|
|
469
483
|
export interface EventSig {
|
|
470
484
|
name: string;
|
|
471
485
|
fieldNames: string[];
|
|
@@ -924,7 +938,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
924
938
|
}
|
|
925
939
|
/**
|
|
926
940
|
* @title Alephium API
|
|
927
|
-
* @version 2.3.
|
|
941
|
+
* @version 2.3.2
|
|
928
942
|
* @baseUrl ../
|
|
929
943
|
*/
|
|
930
944
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -669,7 +669,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
669
669
|
* @name GetInfosSupplyTotalAlph
|
|
670
670
|
* @request GET:/infos/supply/total-alph
|
|
671
671
|
*/
|
|
672
|
-
getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<
|
|
672
|
+
getInfosSupplyTotalAlph: (params?: RequestParams) => Promise<string>;
|
|
673
673
|
/**
|
|
674
674
|
* @description Get the ALPH circulating supply
|
|
675
675
|
*
|
|
@@ -677,7 +677,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
677
677
|
* @name GetInfosSupplyCirculatingAlph
|
|
678
678
|
* @request GET:/infos/supply/circulating-alph
|
|
679
679
|
*/
|
|
680
|
-
getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<
|
|
680
|
+
getInfosSupplyCirculatingAlph: (params?: RequestParams) => Promise<string>;
|
|
681
681
|
/**
|
|
682
682
|
* @description Get the ALPH reserved supply
|
|
683
683
|
*
|
|
@@ -685,7 +685,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
685
685
|
* @name GetInfosSupplyReservedAlph
|
|
686
686
|
* @request GET:/infos/supply/reserved-alph
|
|
687
687
|
*/
|
|
688
|
-
getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<
|
|
688
|
+
getInfosSupplyReservedAlph: (params?: RequestParams) => Promise<string>;
|
|
689
689
|
/**
|
|
690
690
|
* @description Get the ALPH locked supply
|
|
691
691
|
*
|
|
@@ -693,7 +693,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
693
693
|
* @name GetInfosSupplyLockedAlph
|
|
694
694
|
* @request GET:/infos/supply/locked-alph
|
|
695
695
|
*/
|
|
696
|
-
getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<
|
|
696
|
+
getInfosSupplyLockedAlph: (params?: RequestParams) => Promise<string>;
|
|
697
697
|
/**
|
|
698
698
|
* @description Get the total number of transactions
|
|
699
699
|
*
|
|
@@ -701,7 +701,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
701
701
|
* @name GetInfosTotalTransactions
|
|
702
702
|
* @request GET:/infos/total-transactions
|
|
703
703
|
*/
|
|
704
|
-
getInfosTotalTransactions: (params?: RequestParams) => Promise<
|
|
704
|
+
getInfosTotalTransactions: (params?: RequestParams) => Promise<string>;
|
|
705
705
|
/**
|
|
706
706
|
* @description Get the average block time for each chain
|
|
707
707
|
*
|
|
@@ -383,8 +383,9 @@ class Api extends HttpClient {
|
|
|
383
383
|
path: `/addresses/${address}/export-transactions/csv`,
|
|
384
384
|
method: 'GET',
|
|
385
385
|
query: query,
|
|
386
|
+
format: 'text',
|
|
386
387
|
...params
|
|
387
|
-
}).then(utils_1.
|
|
388
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
388
389
|
/**
|
|
389
390
|
* No description
|
|
390
391
|
*
|
|
@@ -451,8 +452,9 @@ class Api extends HttpClient {
|
|
|
451
452
|
getInfosSupplyTotalAlph: (params = {}) => this.request({
|
|
452
453
|
path: `/infos/supply/total-alph`,
|
|
453
454
|
method: 'GET',
|
|
455
|
+
format: 'text',
|
|
454
456
|
...params
|
|
455
|
-
}).then(utils_1.
|
|
457
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
456
458
|
/**
|
|
457
459
|
* @description Get the ALPH circulating supply
|
|
458
460
|
*
|
|
@@ -463,8 +465,9 @@ class Api extends HttpClient {
|
|
|
463
465
|
getInfosSupplyCirculatingAlph: (params = {}) => this.request({
|
|
464
466
|
path: `/infos/supply/circulating-alph`,
|
|
465
467
|
method: 'GET',
|
|
468
|
+
format: 'text',
|
|
466
469
|
...params
|
|
467
|
-
}).then(utils_1.
|
|
470
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
468
471
|
/**
|
|
469
472
|
* @description Get the ALPH reserved supply
|
|
470
473
|
*
|
|
@@ -475,8 +478,9 @@ class Api extends HttpClient {
|
|
|
475
478
|
getInfosSupplyReservedAlph: (params = {}) => this.request({
|
|
476
479
|
path: `/infos/supply/reserved-alph`,
|
|
477
480
|
method: 'GET',
|
|
481
|
+
format: 'text',
|
|
478
482
|
...params
|
|
479
|
-
}).then(utils_1.
|
|
483
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
480
484
|
/**
|
|
481
485
|
* @description Get the ALPH locked supply
|
|
482
486
|
*
|
|
@@ -487,8 +491,9 @@ class Api extends HttpClient {
|
|
|
487
491
|
getInfosSupplyLockedAlph: (params = {}) => this.request({
|
|
488
492
|
path: `/infos/supply/locked-alph`,
|
|
489
493
|
method: 'GET',
|
|
494
|
+
format: 'text',
|
|
490
495
|
...params
|
|
491
|
-
}).then(utils_1.
|
|
496
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
492
497
|
/**
|
|
493
498
|
* @description Get the total number of transactions
|
|
494
499
|
*
|
|
@@ -499,8 +504,9 @@ class Api extends HttpClient {
|
|
|
499
504
|
getInfosTotalTransactions: (params = {}) => this.request({
|
|
500
505
|
path: `/infos/total-transactions`,
|
|
501
506
|
method: 'GET',
|
|
507
|
+
format: 'text',
|
|
502
508
|
...params
|
|
503
|
-
}).then(utils_1.
|
|
509
|
+
}).then(utils_1.convertTextHttpResponse),
|
|
504
510
|
/**
|
|
505
511
|
* @description Get the average block time for each chain
|
|
506
512
|
*
|
package/dist/src/api/utils.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ export declare function convertHttpResponse<T>(response: {
|
|
|
5
5
|
detail: string;
|
|
6
6
|
};
|
|
7
7
|
}): T;
|
|
8
|
+
export declare function convertTextHttpResponse(response: {
|
|
9
|
+
text: () => Promise<string>;
|
|
10
|
+
error?: {
|
|
11
|
+
detail: string;
|
|
12
|
+
};
|
|
13
|
+
}): Promise<string>;
|
|
8
14
|
export declare function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
9
15
|
export declare function throttledFetch(ratePerSec: number): typeof fetch;
|
|
10
16
|
export declare const RETRY_LIMIT_WHEN_429 = 3;
|
package/dist/src/api/utils.js
CHANGED
|
@@ -17,7 +17,7 @@ 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
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.DEFAULT_THROTTLE_FETCH = exports.DEFAULT_RATE_LIMIT = exports.RETRY_LIMIT_WHEN_429 = exports.throttledFetch = exports.retryFetch = exports.convertHttpResponse = void 0;
|
|
20
|
+
exports.DEFAULT_THROTTLE_FETCH = exports.DEFAULT_RATE_LIMIT = exports.RETRY_LIMIT_WHEN_429 = exports.throttledFetch = exports.retryFetch = exports.convertTextHttpResponse = exports.convertHttpResponse = void 0;
|
|
21
21
|
require("cross-fetch/polyfill");
|
|
22
22
|
const utils_1 = require("../utils");
|
|
23
23
|
const async_sema_1 = require("async-sema");
|
|
@@ -30,6 +30,15 @@ function convertHttpResponse(response) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
exports.convertHttpResponse = convertHttpResponse;
|
|
33
|
+
async function convertTextHttpResponse(response) {
|
|
34
|
+
if (response.error) {
|
|
35
|
+
throw new Error(`[API Error] - ${response.error.detail}`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return await response.text();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.convertTextHttpResponse = convertTextHttpResponse;
|
|
33
42
|
async function retryFetch(...fetchParams) {
|
|
34
43
|
const retry = async (retryCount) => {
|
|
35
44
|
const response = await fetch(...fetchParams);
|
|
@@ -8,6 +8,8 @@ export type FunctionSig = node.FunctionSig;
|
|
|
8
8
|
export type Fields = NamedVals;
|
|
9
9
|
export type Arguments = NamedVals;
|
|
10
10
|
export type HexString = string;
|
|
11
|
+
export type Constant = node.Constant;
|
|
12
|
+
export type Enum = node.Enum;
|
|
11
13
|
export declare const StdIdFieldName = "__stdInterfaceId";
|
|
12
14
|
declare enum SourceKind {
|
|
13
15
|
Contract = 0,
|
|
@@ -107,10 +109,12 @@ export declare class Contract extends Artifact {
|
|
|
107
109
|
readonly codeHash: string;
|
|
108
110
|
readonly fieldsSig: FieldsSig;
|
|
109
111
|
readonly eventsSig: EventSig[];
|
|
112
|
+
readonly constants: Constant[];
|
|
113
|
+
readonly enums: Enum[];
|
|
110
114
|
readonly stdInterfaceId?: HexString;
|
|
111
115
|
readonly bytecodeDebug: string;
|
|
112
116
|
readonly codeHashDebug: string;
|
|
113
|
-
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], stdInterfaceId?: HexString);
|
|
117
|
+
constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[], constants: Constant[], enums: Enum[], stdInterfaceId?: HexString);
|
|
114
118
|
static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
|
|
115
119
|
static fromCompileResult(result: node.CompileContractResult): Contract;
|
|
116
120
|
static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
|
|
@@ -92,12 +92,16 @@ function removeParentsPrefix(parts) {
|
|
|
92
92
|
}
|
|
93
93
|
class SourceInfo {
|
|
94
94
|
getArtifactPath(artifactsRootDir) {
|
|
95
|
+
let fullPath;
|
|
95
96
|
if (this.isExternal) {
|
|
96
97
|
const relativePath = removeParentsPrefix(this.contractRelativePath.split(path.sep));
|
|
97
98
|
const externalPath = path.join('.external', relativePath);
|
|
98
|
-
|
|
99
|
+
fullPath = path.join(artifactsRootDir, externalPath);
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
+
else {
|
|
102
|
+
fullPath = path.join(artifactsRootDir, this.contractRelativePath);
|
|
103
|
+
}
|
|
104
|
+
return path.join(path.dirname(fullPath), `${this.name}.ral.json`);
|
|
101
105
|
}
|
|
102
106
|
constructor(type, name, sourceCode, sourceCodeHash, contractRelativePath, isExternal) {
|
|
103
107
|
this.type = type;
|
|
@@ -285,20 +289,34 @@ class Project {
|
|
|
285
289
|
return contract.artifact;
|
|
286
290
|
}
|
|
287
291
|
static async compile(fullNodeVersion, provider, sourceInfos, projectRootDir, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
288
|
-
const
|
|
292
|
+
const removeDuplicates = sourceInfos.reduce((acc, sourceInfo) => {
|
|
293
|
+
if (acc.find((info) => info.sourceCodeHash === sourceInfo.sourceCodeHash) === undefined) {
|
|
294
|
+
acc.push(sourceInfo);
|
|
295
|
+
}
|
|
296
|
+
return acc;
|
|
297
|
+
}, []);
|
|
298
|
+
const sourceStr = removeDuplicates.map((f) => f.sourceCode).join('\n');
|
|
289
299
|
const result = await provider.contracts.postContractsCompileProject({
|
|
290
300
|
code: sourceStr,
|
|
291
301
|
compilerOptions: compilerOptions
|
|
292
302
|
});
|
|
293
303
|
const contracts = new Map();
|
|
294
304
|
const scripts = new Map();
|
|
295
|
-
result.contracts.forEach((contractResult
|
|
296
|
-
const sourceInfo = sourceInfos
|
|
305
|
+
result.contracts.forEach((contractResult) => {
|
|
306
|
+
const sourceInfo = sourceInfos.find((sourceInfo) => sourceInfo.type === SourceKind.Contract && sourceInfo.name === contractResult.name);
|
|
307
|
+
if (sourceInfo === undefined) {
|
|
308
|
+
// this should never happen
|
|
309
|
+
throw new Error(`SourceInfo does not exist for contract ${contractResult.name}`);
|
|
310
|
+
}
|
|
297
311
|
const contract = Contract.fromCompileResult(contractResult);
|
|
298
312
|
contracts.set(contract.name, new Compiled(sourceInfo, contract, contractResult.warnings));
|
|
299
313
|
});
|
|
300
|
-
result.scripts.forEach((scriptResult
|
|
301
|
-
const sourceInfo = sourceInfos
|
|
314
|
+
result.scripts.forEach((scriptResult) => {
|
|
315
|
+
const sourceInfo = sourceInfos.find((sourceInfo) => sourceInfo.type === SourceKind.Script && sourceInfo.name === scriptResult.name);
|
|
316
|
+
if (sourceInfo === undefined) {
|
|
317
|
+
// this should never happen
|
|
318
|
+
throw new Error(`SourceInfo does not exist for script ${scriptResult.name}`);
|
|
319
|
+
}
|
|
302
320
|
const script = Script.fromCompileResult(scriptResult);
|
|
303
321
|
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings));
|
|
304
322
|
});
|
|
@@ -465,13 +483,15 @@ class Artifact {
|
|
|
465
483
|
}
|
|
466
484
|
exports.Artifact = Artifact;
|
|
467
485
|
class Contract extends Artifact {
|
|
468
|
-
constructor(version, name, bytecode, bytecodeDebugPatch, codeHash, codeHashDebug, fieldsSig, eventsSig, functions, stdInterfaceId) {
|
|
486
|
+
constructor(version, name, bytecode, bytecodeDebugPatch, codeHash, codeHashDebug, fieldsSig, eventsSig, functions, constants, enums, stdInterfaceId) {
|
|
469
487
|
super(version, name, functions);
|
|
470
488
|
this.bytecode = bytecode;
|
|
471
489
|
this.bytecodeDebugPatch = bytecodeDebugPatch;
|
|
472
490
|
this.codeHash = codeHash;
|
|
473
491
|
this.fieldsSig = fieldsSig;
|
|
474
492
|
this.eventsSig = eventsSig;
|
|
493
|
+
this.constants = constants;
|
|
494
|
+
this.enums = enums;
|
|
475
495
|
this.stdInterfaceId = stdInterfaceId;
|
|
476
496
|
this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch);
|
|
477
497
|
this.codeHashDebug = codeHashDebug;
|
|
@@ -484,14 +504,16 @@ class Contract extends Artifact {
|
|
|
484
504
|
artifact.codeHash == null ||
|
|
485
505
|
artifact.fieldsSig == null ||
|
|
486
506
|
artifact.eventsSig == null ||
|
|
507
|
+
artifact.constants == null ||
|
|
508
|
+
artifact.enums == null ||
|
|
487
509
|
artifact.functions == null) {
|
|
488
510
|
throw Error('The artifact JSON for contract is incomplete');
|
|
489
511
|
}
|
|
490
|
-
const contract = new Contract(artifact.version, artifact.name, artifact.bytecode, bytecodeDebugPatch, artifact.codeHash, codeHashDebug ? codeHashDebug : artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions, artifact.stdInterfaceId === null ? undefined : artifact.stdInterfaceId);
|
|
512
|
+
const contract = new Contract(artifact.version, artifact.name, artifact.bytecode, bytecodeDebugPatch, artifact.codeHash, codeHashDebug ? codeHashDebug : artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions, artifact.constants, artifact.enums, artifact.stdInterfaceId === null ? undefined : artifact.stdInterfaceId);
|
|
491
513
|
return contract;
|
|
492
514
|
}
|
|
493
515
|
static fromCompileResult(result) {
|
|
494
|
-
return new Contract(result.version, result.name, result.bytecode, result.bytecodeDebugPatch, result.codeHash, result.codeHashDebug, result.fields, result.events, result.functions, result.stdInterfaceId);
|
|
516
|
+
return new Contract(result.version, result.name, result.bytecode, result.bytecodeDebugPatch, result.codeHash, result.codeHashDebug, result.fields, result.events, result.functions, result.constants, result.enums, result.stdInterfaceId);
|
|
495
517
|
}
|
|
496
518
|
// support both 'code.ral' and 'code.ral.json'
|
|
497
519
|
static async fromArtifactFile(path, bytecodeDebugPatch, codeHashDebug) {
|
|
@@ -507,7 +529,9 @@ class Contract extends Artifact {
|
|
|
507
529
|
codeHash: this.codeHash,
|
|
508
530
|
fieldsSig: this.fieldsSig,
|
|
509
531
|
eventsSig: this.eventsSig,
|
|
510
|
-
functions: this.functions
|
|
532
|
+
functions: this.functions,
|
|
533
|
+
constants: this.constants,
|
|
534
|
+
enums: this.enums
|
|
511
535
|
};
|
|
512
536
|
if (this.stdInterfaceId !== undefined) {
|
|
513
537
|
object.stdInterfaceId = this.stdInterfaceId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
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.3.
|
|
30
|
+
"alephium_version": "2.3.2",
|
|
31
31
|
"explorer_backend_version": "1.13.5"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -379,6 +379,8 @@ export interface CompileContractResult {
|
|
|
379
379
|
codeHashDebug: string
|
|
380
380
|
fields: FieldsSig
|
|
381
381
|
functions: FunctionSig[]
|
|
382
|
+
constants: Constant[]
|
|
383
|
+
enums: Enum[]
|
|
382
384
|
events: EventSig[]
|
|
383
385
|
warnings: string[]
|
|
384
386
|
stdInterfaceId?: string
|
|
@@ -422,6 +424,11 @@ export interface Confirmed {
|
|
|
422
424
|
type: string
|
|
423
425
|
}
|
|
424
426
|
|
|
427
|
+
export interface Constant {
|
|
428
|
+
name: string
|
|
429
|
+
value: Val
|
|
430
|
+
}
|
|
431
|
+
|
|
425
432
|
export interface Contract {
|
|
426
433
|
code: string
|
|
427
434
|
compilerOptions?: CompilerOptions
|
|
@@ -530,6 +537,16 @@ export interface Destination {
|
|
|
530
537
|
|
|
531
538
|
export type DiscoveryAction = Reachable | Unreachable
|
|
532
539
|
|
|
540
|
+
export interface Enum {
|
|
541
|
+
name: string
|
|
542
|
+
fields: EnumField[]
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export interface EnumField {
|
|
546
|
+
name: string
|
|
547
|
+
value: Val
|
|
548
|
+
}
|
|
549
|
+
|
|
533
550
|
export interface EventSig {
|
|
534
551
|
name: string
|
|
535
552
|
fieldNames: string[]
|
|
@@ -1211,7 +1228,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1211
1228
|
|
|
1212
1229
|
/**
|
|
1213
1230
|
* @title Alephium API
|
|
1214
|
-
* @version 2.3.
|
|
1231
|
+
* @version 2.3.2
|
|
1215
1232
|
* @baseUrl ../
|
|
1216
1233
|
*/
|
|
1217
1234
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/api/api-explorer.ts
CHANGED
|
@@ -346,7 +346,7 @@ export interface ValU256 {
|
|
|
346
346
|
}
|
|
347
347
|
|
|
348
348
|
import 'cross-fetch/polyfill'
|
|
349
|
-
import { convertHttpResponse } from './utils'
|
|
349
|
+
import { convertHttpResponse, convertTextHttpResponse } from './utils'
|
|
350
350
|
|
|
351
351
|
export type QueryParamsType = Record<string | number, any>
|
|
352
352
|
export type ResponseFormat = keyof Omit<Body, 'body' | 'bodyUsed'>
|
|
@@ -960,8 +960,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
960
960
|
path: `/addresses/${address}/export-transactions/csv`,
|
|
961
961
|
method: 'GET',
|
|
962
962
|
query: query,
|
|
963
|
+
format: 'text',
|
|
963
964
|
...params
|
|
964
|
-
}).then(
|
|
965
|
+
}).then(convertTextHttpResponse),
|
|
965
966
|
|
|
966
967
|
/**
|
|
967
968
|
* No description
|
|
@@ -1069,8 +1070,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1069
1070
|
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1070
1071
|
path: `/infos/supply/total-alph`,
|
|
1071
1072
|
method: 'GET',
|
|
1073
|
+
format: 'text',
|
|
1072
1074
|
...params
|
|
1073
|
-
}).then(
|
|
1075
|
+
}).then(convertTextHttpResponse),
|
|
1074
1076
|
|
|
1075
1077
|
/**
|
|
1076
1078
|
* @description Get the ALPH circulating supply
|
|
@@ -1083,8 +1085,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1083
1085
|
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1084
1086
|
path: `/infos/supply/circulating-alph`,
|
|
1085
1087
|
method: 'GET',
|
|
1088
|
+
format: 'text',
|
|
1086
1089
|
...params
|
|
1087
|
-
}).then(
|
|
1090
|
+
}).then(convertTextHttpResponse),
|
|
1088
1091
|
|
|
1089
1092
|
/**
|
|
1090
1093
|
* @description Get the ALPH reserved supply
|
|
@@ -1097,8 +1100,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1097
1100
|
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1098
1101
|
path: `/infos/supply/reserved-alph`,
|
|
1099
1102
|
method: 'GET',
|
|
1103
|
+
format: 'text',
|
|
1100
1104
|
...params
|
|
1101
|
-
}).then(
|
|
1105
|
+
}).then(convertTextHttpResponse),
|
|
1102
1106
|
|
|
1103
1107
|
/**
|
|
1104
1108
|
* @description Get the ALPH locked supply
|
|
@@ -1111,8 +1115,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1111
1115
|
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1112
1116
|
path: `/infos/supply/locked-alph`,
|
|
1113
1117
|
method: 'GET',
|
|
1118
|
+
format: 'text',
|
|
1114
1119
|
...params
|
|
1115
|
-
}).then(
|
|
1120
|
+
}).then(convertTextHttpResponse),
|
|
1116
1121
|
|
|
1117
1122
|
/**
|
|
1118
1123
|
* @description Get the total number of transactions
|
|
@@ -1125,8 +1130,9 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
1125
1130
|
this.request<number, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
1126
1131
|
path: `/infos/total-transactions`,
|
|
1127
1132
|
method: 'GET',
|
|
1133
|
+
format: 'text',
|
|
1128
1134
|
...params
|
|
1129
|
-
}).then(
|
|
1135
|
+
}).then(convertTextHttpResponse),
|
|
1130
1136
|
|
|
1131
1137
|
/**
|
|
1132
1138
|
* @description Get the average block time for each chain
|
package/src/api/utils.ts
CHANGED
|
@@ -28,6 +28,17 @@ export function convertHttpResponse<T>(response: { data: T; error?: { detail: st
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
export async function convertTextHttpResponse(response: {
|
|
32
|
+
text: () => Promise<string>
|
|
33
|
+
error?: { detail: string }
|
|
34
|
+
}): Promise<string> {
|
|
35
|
+
if (response.error) {
|
|
36
|
+
throw new Error(`[API Error] - ${response.error.detail}`)
|
|
37
|
+
} else {
|
|
38
|
+
return await response.text()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
31
42
|
export async function retryFetch(...fetchParams: Parameters<typeof fetch>): ReturnType<typeof fetch> {
|
|
32
43
|
const retry = async (retryCount: number): ReturnType<typeof fetch> => {
|
|
33
44
|
const response = await fetch(...fetchParams)
|
package/src/contract/contract.ts
CHANGED
|
@@ -67,6 +67,8 @@ export type FunctionSig = node.FunctionSig
|
|
|
67
67
|
export type Fields = NamedVals
|
|
68
68
|
export type Arguments = NamedVals
|
|
69
69
|
export type HexString = string
|
|
70
|
+
export type Constant = node.Constant
|
|
71
|
+
export type Enum = node.Enum
|
|
70
72
|
|
|
71
73
|
export const StdIdFieldName = '__stdInterfaceId'
|
|
72
74
|
|
|
@@ -123,12 +125,15 @@ class SourceInfo {
|
|
|
123
125
|
isExternal: boolean
|
|
124
126
|
|
|
125
127
|
getArtifactPath(artifactsRootDir: string): string {
|
|
128
|
+
let fullPath: string
|
|
126
129
|
if (this.isExternal) {
|
|
127
130
|
const relativePath = removeParentsPrefix(this.contractRelativePath.split(path.sep))
|
|
128
131
|
const externalPath = path.join('.external', relativePath)
|
|
129
|
-
|
|
132
|
+
fullPath = path.join(artifactsRootDir, externalPath)
|
|
133
|
+
} else {
|
|
134
|
+
fullPath = path.join(artifactsRootDir, this.contractRelativePath)
|
|
130
135
|
}
|
|
131
|
-
return path.join(
|
|
136
|
+
return path.join(path.dirname(fullPath), `${this.name}.ral.json`)
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
constructor(
|
|
@@ -418,20 +423,38 @@ export class Project {
|
|
|
418
423
|
errorOnWarnings: boolean,
|
|
419
424
|
compilerOptions: node.CompilerOptions
|
|
420
425
|
): Promise<Project> {
|
|
421
|
-
const
|
|
426
|
+
const removeDuplicates = sourceInfos.reduce((acc: SourceInfo[], sourceInfo: SourceInfo) => {
|
|
427
|
+
if (acc.find((info) => info.sourceCodeHash === sourceInfo.sourceCodeHash) === undefined) {
|
|
428
|
+
acc.push(sourceInfo)
|
|
429
|
+
}
|
|
430
|
+
return acc
|
|
431
|
+
}, [])
|
|
432
|
+
const sourceStr = removeDuplicates.map((f) => f.sourceCode).join('\n')
|
|
422
433
|
const result = await provider.contracts.postContractsCompileProject({
|
|
423
434
|
code: sourceStr,
|
|
424
435
|
compilerOptions: compilerOptions
|
|
425
436
|
})
|
|
426
437
|
const contracts = new Map<string, Compiled<Contract>>()
|
|
427
438
|
const scripts = new Map<string, Compiled<Script>>()
|
|
428
|
-
result.contracts.forEach((contractResult
|
|
429
|
-
const sourceInfo = sourceInfos
|
|
439
|
+
result.contracts.forEach((contractResult) => {
|
|
440
|
+
const sourceInfo = sourceInfos.find(
|
|
441
|
+
(sourceInfo) => sourceInfo.type === SourceKind.Contract && sourceInfo.name === contractResult.name
|
|
442
|
+
)
|
|
443
|
+
if (sourceInfo === undefined) {
|
|
444
|
+
// this should never happen
|
|
445
|
+
throw new Error(`SourceInfo does not exist for contract ${contractResult.name}`)
|
|
446
|
+
}
|
|
430
447
|
const contract = Contract.fromCompileResult(contractResult)
|
|
431
448
|
contracts.set(contract.name, new Compiled(sourceInfo, contract, contractResult.warnings))
|
|
432
449
|
})
|
|
433
|
-
result.scripts.forEach((scriptResult
|
|
434
|
-
const sourceInfo = sourceInfos
|
|
450
|
+
result.scripts.forEach((scriptResult) => {
|
|
451
|
+
const sourceInfo = sourceInfos.find(
|
|
452
|
+
(sourceInfo) => sourceInfo.type === SourceKind.Script && sourceInfo.name === scriptResult.name
|
|
453
|
+
)
|
|
454
|
+
if (sourceInfo === undefined) {
|
|
455
|
+
// this should never happen
|
|
456
|
+
throw new Error(`SourceInfo does not exist for script ${scriptResult.name}`)
|
|
457
|
+
}
|
|
435
458
|
const script = Script.fromCompileResult(scriptResult)
|
|
436
459
|
scripts.set(script.name, new Compiled(sourceInfo, script, scriptResult.warnings))
|
|
437
460
|
})
|
|
@@ -696,6 +719,8 @@ export class Contract extends Artifact {
|
|
|
696
719
|
readonly codeHash: string
|
|
697
720
|
readonly fieldsSig: FieldsSig
|
|
698
721
|
readonly eventsSig: EventSig[]
|
|
722
|
+
readonly constants: Constant[]
|
|
723
|
+
readonly enums: Enum[]
|
|
699
724
|
readonly stdInterfaceId?: HexString
|
|
700
725
|
|
|
701
726
|
readonly bytecodeDebug: string
|
|
@@ -711,6 +736,8 @@ export class Contract extends Artifact {
|
|
|
711
736
|
fieldsSig: FieldsSig,
|
|
712
737
|
eventsSig: EventSig[],
|
|
713
738
|
functions: FunctionSig[],
|
|
739
|
+
constants: Constant[],
|
|
740
|
+
enums: Enum[],
|
|
714
741
|
stdInterfaceId?: HexString
|
|
715
742
|
) {
|
|
716
743
|
super(version, name, functions)
|
|
@@ -719,6 +746,8 @@ export class Contract extends Artifact {
|
|
|
719
746
|
this.codeHash = codeHash
|
|
720
747
|
this.fieldsSig = fieldsSig
|
|
721
748
|
this.eventsSig = eventsSig
|
|
749
|
+
this.constants = constants
|
|
750
|
+
this.enums = enums
|
|
722
751
|
this.stdInterfaceId = stdInterfaceId
|
|
723
752
|
|
|
724
753
|
this.bytecodeDebug = ralph.buildDebugBytecode(this.bytecode, this.bytecodeDebugPatch)
|
|
@@ -734,6 +763,8 @@ export class Contract extends Artifact {
|
|
|
734
763
|
artifact.codeHash == null ||
|
|
735
764
|
artifact.fieldsSig == null ||
|
|
736
765
|
artifact.eventsSig == null ||
|
|
766
|
+
artifact.constants == null ||
|
|
767
|
+
artifact.enums == null ||
|
|
737
768
|
artifact.functions == null
|
|
738
769
|
) {
|
|
739
770
|
throw Error('The artifact JSON for contract is incomplete')
|
|
@@ -748,6 +779,8 @@ export class Contract extends Artifact {
|
|
|
748
779
|
artifact.fieldsSig,
|
|
749
780
|
artifact.eventsSig,
|
|
750
781
|
artifact.functions,
|
|
782
|
+
artifact.constants,
|
|
783
|
+
artifact.enums,
|
|
751
784
|
artifact.stdInterfaceId === null ? undefined : artifact.stdInterfaceId
|
|
752
785
|
)
|
|
753
786
|
return contract
|
|
@@ -764,6 +797,8 @@ export class Contract extends Artifact {
|
|
|
764
797
|
result.fields,
|
|
765
798
|
result.events,
|
|
766
799
|
result.functions,
|
|
800
|
+
result.constants,
|
|
801
|
+
result.enums,
|
|
767
802
|
result.stdInterfaceId
|
|
768
803
|
)
|
|
769
804
|
}
|
|
@@ -783,7 +818,9 @@ export class Contract extends Artifact {
|
|
|
783
818
|
codeHash: this.codeHash,
|
|
784
819
|
fieldsSig: this.fieldsSig,
|
|
785
820
|
eventsSig: this.eventsSig,
|
|
786
|
-
functions: this.functions
|
|
821
|
+
functions: this.functions,
|
|
822
|
+
constants: this.constants,
|
|
823
|
+
enums: this.enums
|
|
787
824
|
}
|
|
788
825
|
if (this.stdInterfaceId !== undefined) {
|
|
789
826
|
object.stdInterfaceId = this.stdInterfaceId
|