@alephium/web3 0.2.0-rc.12 → 0.2.0-rc.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/api-alephium.d.ts +72 -11
- package/dist/src/api/api-alephium.js +64 -5
- package/dist/src/contract/contract.d.ts +6 -4
- package/dist/src/contract/contract.js +32 -30
- package/package.json +4 -13
- package/src/api/api-alephium.ts +112 -14
- package/src/contract/contract.ts +43 -40
- package/src/utils/utils.ts +0 -2
- package/contracts/greeter/greeter.ral +0 -7
- package/contracts/greeter/greeter_interface.ral +0 -4
- package/contracts/greeter_main.ral +0 -7
- package/dev/user.conf +0 -29
- package/dist/scripts/create-project.d.ts +0 -2
- package/dist/scripts/create-project.js +0 -125
- package/dist/scripts/start-devnet.d.ts +0 -1
- package/dist/scripts/start-devnet.js +0 -131
- package/dist/scripts/stop-devnet.d.ts +0 -1
- package/dist/scripts/stop-devnet.js +0 -32
- package/scripts/create-project.ts +0 -137
- package/scripts/start-devnet.js +0 -141
- package/scripts/stop-devnet.js +0 -32
- package/templates/base/README.md +0 -34
- package/templates/base/package.json +0 -35
- package/templates/base/src/greeter.ts +0 -42
- package/templates/base/tsconfig.json +0 -19
- package/templates/react/README.md +0 -34
- package/templates/react/config-overrides.js +0 -18
- package/templates/react/package.json +0 -66
- package/templates/react/src/App.tsx +0 -42
- package/templates/react/src/artifacts/greeter.ral.json +0 -26
- package/templates/react/src/artifacts/greeter_main.ral.json +0 -22
- package/templates/shared/.eslintrc.json +0 -12
- package/templates/shared/scripts/header.js +0 -0
|
@@ -85,6 +85,10 @@ export interface Banned {
|
|
|
85
85
|
until: number;
|
|
86
86
|
type: string;
|
|
87
87
|
}
|
|
88
|
+
export interface BlockAndEvents {
|
|
89
|
+
block: BlockEntry;
|
|
90
|
+
events: ContractEventByBlockHash[];
|
|
91
|
+
}
|
|
88
92
|
export interface BlockEntry {
|
|
89
93
|
/** @format block-hash */
|
|
90
94
|
hash: string;
|
|
@@ -121,6 +125,12 @@ export interface BlockHeaderEntry {
|
|
|
121
125
|
height: number;
|
|
122
126
|
deps: string[];
|
|
123
127
|
}
|
|
128
|
+
export interface BlocksAndEventsPerTimeStampRange {
|
|
129
|
+
blocksAndEvents: BlockAndEvents[][];
|
|
130
|
+
}
|
|
131
|
+
export interface BlocksPerTimeStampRange {
|
|
132
|
+
blocks: BlockEntry[][];
|
|
133
|
+
}
|
|
124
134
|
export interface BrokerInfo {
|
|
125
135
|
/** @format clique-id */
|
|
126
136
|
cliqueId: string;
|
|
@@ -359,6 +369,15 @@ export interface ContractEvent {
|
|
|
359
369
|
eventIndex: number;
|
|
360
370
|
fields: Val[];
|
|
361
371
|
}
|
|
372
|
+
export interface ContractEventByBlockHash {
|
|
373
|
+
/** @format 32-byte-hash */
|
|
374
|
+
txId: string;
|
|
375
|
+
/** @format address */
|
|
376
|
+
contractAddress: string;
|
|
377
|
+
/** @format int32 */
|
|
378
|
+
eventIndex: number;
|
|
379
|
+
fields: Val[];
|
|
380
|
+
}
|
|
362
381
|
export interface ContractEventByTxId {
|
|
363
382
|
/** @format block-hash */
|
|
364
383
|
blockHash: string;
|
|
@@ -373,10 +392,11 @@ export interface ContractEvents {
|
|
|
373
392
|
/** @format int32 */
|
|
374
393
|
nextStart: number;
|
|
375
394
|
}
|
|
395
|
+
export interface ContractEventsByBlockHash {
|
|
396
|
+
events: ContractEventByBlockHash[];
|
|
397
|
+
}
|
|
376
398
|
export interface ContractEventsByTxId {
|
|
377
399
|
events: ContractEventByTxId[];
|
|
378
|
-
/** @format int32 */
|
|
379
|
-
nextStart: number;
|
|
380
400
|
}
|
|
381
401
|
export interface ContractOutput {
|
|
382
402
|
/** @format int32 */
|
|
@@ -429,9 +449,6 @@ export interface EventSig {
|
|
|
429
449
|
fieldNames: string[];
|
|
430
450
|
fieldTypes: string[];
|
|
431
451
|
}
|
|
432
|
-
export interface FetchResponse {
|
|
433
|
-
blocks: BlockEntry[][];
|
|
434
|
-
}
|
|
435
452
|
export interface FieldsSig {
|
|
436
453
|
names: string[];
|
|
437
454
|
types: string[];
|
|
@@ -1178,14 +1195,26 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1178
1195
|
* No description
|
|
1179
1196
|
*
|
|
1180
1197
|
* @tags Blockflow
|
|
1181
|
-
* @name
|
|
1198
|
+
* @name GetBlockflowBlocks
|
|
1182
1199
|
* @summary List blocks on the given time interval
|
|
1183
|
-
* @request GET:/blockflow
|
|
1200
|
+
* @request GET:/blockflow/blocks
|
|
1184
1201
|
*/
|
|
1185
|
-
|
|
1202
|
+
getBlockflowBlocks: (query: {
|
|
1186
1203
|
fromTs: number;
|
|
1187
1204
|
toTs?: number;
|
|
1188
|
-
}, params?: RequestParams) => Promise<
|
|
1205
|
+
}, params?: RequestParams) => Promise<BlocksPerTimeStampRange>;
|
|
1206
|
+
/**
|
|
1207
|
+
* No description
|
|
1208
|
+
*
|
|
1209
|
+
* @tags Blockflow
|
|
1210
|
+
* @name GetBlockflowBlocksWithEvents
|
|
1211
|
+
* @summary List blocks with events on the given time interval
|
|
1212
|
+
* @request GET:/blockflow/blocks-with-events
|
|
1213
|
+
*/
|
|
1214
|
+
getBlockflowBlocksWithEvents: (query: {
|
|
1215
|
+
fromTs: number;
|
|
1216
|
+
toTs?: number;
|
|
1217
|
+
}, params?: RequestParams) => Promise<BlocksAndEventsPerTimeStampRange>;
|
|
1189
1218
|
/**
|
|
1190
1219
|
* No description
|
|
1191
1220
|
*
|
|
@@ -1195,6 +1224,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1195
1224
|
* @request GET:/blockflow/blocks/{block_hash}
|
|
1196
1225
|
*/
|
|
1197
1226
|
getBlockflowBlocksBlockHash: (blockHash: string, params?: RequestParams) => Promise<BlockEntry>;
|
|
1227
|
+
/**
|
|
1228
|
+
* No description
|
|
1229
|
+
*
|
|
1230
|
+
* @tags Blockflow
|
|
1231
|
+
* @name GetBlockflowBlocksWithEventsBlockHash
|
|
1232
|
+
* @summary Get a block and events with hash
|
|
1233
|
+
* @request GET:/blockflow/blocks-with-events/{block_hash}
|
|
1234
|
+
*/
|
|
1235
|
+
getBlockflowBlocksWithEventsBlockHash: (blockHash: string, params?: RequestParams) => Promise<BlockAndEvents>;
|
|
1198
1236
|
/**
|
|
1199
1237
|
* No description
|
|
1200
1238
|
*
|
|
@@ -1467,6 +1505,18 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1467
1505
|
postMinersCpuMining: (query: {
|
|
1468
1506
|
action: string;
|
|
1469
1507
|
}, params?: RequestParams) => Promise<boolean>;
|
|
1508
|
+
/**
|
|
1509
|
+
* No description
|
|
1510
|
+
*
|
|
1511
|
+
* @tags Miners
|
|
1512
|
+
* @name PostMinersCpuMiningMineOneBlock
|
|
1513
|
+
* @summary Mine a block on CPU miner. !!! for test only !!!
|
|
1514
|
+
* @request POST:/miners/cpu-mining/mine-one-block
|
|
1515
|
+
*/
|
|
1516
|
+
postMinersCpuMiningMineOneBlock: (query: {
|
|
1517
|
+
fromGroup: number;
|
|
1518
|
+
toGroup: number;
|
|
1519
|
+
}, params?: RequestParams) => Promise<boolean>;
|
|
1470
1520
|
/**
|
|
1471
1521
|
* No description
|
|
1472
1522
|
*
|
|
@@ -1497,7 +1547,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1497
1547
|
*/
|
|
1498
1548
|
getEventsContractContractaddress: (contractAddress: string, query: {
|
|
1499
1549
|
start: number;
|
|
1500
|
-
|
|
1550
|
+
limit?: number;
|
|
1501
1551
|
group?: number;
|
|
1502
1552
|
}, params?: RequestParams) => Promise<ContractEvents>;
|
|
1503
1553
|
/**
|
|
@@ -1514,12 +1564,23 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1514
1564
|
*
|
|
1515
1565
|
* @tags Events
|
|
1516
1566
|
* @name GetEventsTxIdTxid
|
|
1517
|
-
* @summary Get events for a
|
|
1567
|
+
* @summary Get contract events for a transaction
|
|
1518
1568
|
* @request GET:/events/tx-id/{txId}
|
|
1519
1569
|
*/
|
|
1520
1570
|
getEventsTxIdTxid: (txId: string, query?: {
|
|
1521
1571
|
group?: number;
|
|
1522
1572
|
}, params?: RequestParams) => Promise<ContractEventsByTxId>;
|
|
1573
|
+
/**
|
|
1574
|
+
* No description
|
|
1575
|
+
*
|
|
1576
|
+
* @tags Events
|
|
1577
|
+
* @name GetEventsBlockHashBlockhash
|
|
1578
|
+
* @summary Get contract events for a block
|
|
1579
|
+
* @request GET:/events/block-hash/{blockHash}
|
|
1580
|
+
*/
|
|
1581
|
+
getEventsBlockHashBlockhash: (blockHash: string, query?: {
|
|
1582
|
+
group?: number;
|
|
1583
|
+
}, params?: RequestParams) => Promise<ContractEventsByBlockHash>;
|
|
1523
1584
|
};
|
|
1524
1585
|
}
|
|
1525
1586
|
export {};
|
|
@@ -619,12 +619,27 @@ class Api extends HttpClient {
|
|
|
619
619
|
* No description
|
|
620
620
|
*
|
|
621
621
|
* @tags Blockflow
|
|
622
|
-
* @name
|
|
622
|
+
* @name GetBlockflowBlocks
|
|
623
623
|
* @summary List blocks on the given time interval
|
|
624
|
-
* @request GET:/blockflow
|
|
624
|
+
* @request GET:/blockflow/blocks
|
|
625
625
|
*/
|
|
626
|
-
|
|
627
|
-
path: `/blockflow`,
|
|
626
|
+
getBlockflowBlocks: (query, params = {}) => this.request({
|
|
627
|
+
path: `/blockflow/blocks`,
|
|
628
|
+
method: 'GET',
|
|
629
|
+
query: query,
|
|
630
|
+
format: 'json',
|
|
631
|
+
...params
|
|
632
|
+
}).then(utils_1.convertHttpResponse),
|
|
633
|
+
/**
|
|
634
|
+
* No description
|
|
635
|
+
*
|
|
636
|
+
* @tags Blockflow
|
|
637
|
+
* @name GetBlockflowBlocksWithEvents
|
|
638
|
+
* @summary List blocks with events on the given time interval
|
|
639
|
+
* @request GET:/blockflow/blocks-with-events
|
|
640
|
+
*/
|
|
641
|
+
getBlockflowBlocksWithEvents: (query, params = {}) => this.request({
|
|
642
|
+
path: `/blockflow/blocks-with-events`,
|
|
628
643
|
method: 'GET',
|
|
629
644
|
query: query,
|
|
630
645
|
format: 'json',
|
|
@@ -644,6 +659,20 @@ class Api extends HttpClient {
|
|
|
644
659
|
format: 'json',
|
|
645
660
|
...params
|
|
646
661
|
}).then(utils_1.convertHttpResponse),
|
|
662
|
+
/**
|
|
663
|
+
* No description
|
|
664
|
+
*
|
|
665
|
+
* @tags Blockflow
|
|
666
|
+
* @name GetBlockflowBlocksWithEventsBlockHash
|
|
667
|
+
* @summary Get a block and events with hash
|
|
668
|
+
* @request GET:/blockflow/blocks-with-events/{block_hash}
|
|
669
|
+
*/
|
|
670
|
+
getBlockflowBlocksWithEventsBlockHash: (blockHash, params = {}) => this.request({
|
|
671
|
+
path: `/blockflow/blocks-with-events/${blockHash}`,
|
|
672
|
+
method: 'GET',
|
|
673
|
+
format: 'json',
|
|
674
|
+
...params
|
|
675
|
+
}).then(utils_1.convertHttpResponse),
|
|
647
676
|
/**
|
|
648
677
|
* No description
|
|
649
678
|
*
|
|
@@ -1069,6 +1098,21 @@ class Api extends HttpClient {
|
|
|
1069
1098
|
format: 'json',
|
|
1070
1099
|
...params
|
|
1071
1100
|
}).then(utils_1.convertHttpResponse),
|
|
1101
|
+
/**
|
|
1102
|
+
* No description
|
|
1103
|
+
*
|
|
1104
|
+
* @tags Miners
|
|
1105
|
+
* @name PostMinersCpuMiningMineOneBlock
|
|
1106
|
+
* @summary Mine a block on CPU miner. !!! for test only !!!
|
|
1107
|
+
* @request POST:/miners/cpu-mining/mine-one-block
|
|
1108
|
+
*/
|
|
1109
|
+
postMinersCpuMiningMineOneBlock: (query, params = {}) => this.request({
|
|
1110
|
+
path: `/miners/cpu-mining/mine-one-block`,
|
|
1111
|
+
method: 'POST',
|
|
1112
|
+
query: query,
|
|
1113
|
+
format: 'json',
|
|
1114
|
+
...params
|
|
1115
|
+
}).then(utils_1.convertHttpResponse),
|
|
1072
1116
|
/**
|
|
1073
1117
|
* No description
|
|
1074
1118
|
*
|
|
@@ -1134,7 +1178,7 @@ class Api extends HttpClient {
|
|
|
1134
1178
|
*
|
|
1135
1179
|
* @tags Events
|
|
1136
1180
|
* @name GetEventsTxIdTxid
|
|
1137
|
-
* @summary Get events for a
|
|
1181
|
+
* @summary Get contract events for a transaction
|
|
1138
1182
|
* @request GET:/events/tx-id/{txId}
|
|
1139
1183
|
*/
|
|
1140
1184
|
getEventsTxIdTxid: (txId, query, params = {}) => this.request({
|
|
@@ -1143,6 +1187,21 @@ class Api extends HttpClient {
|
|
|
1143
1187
|
query: query,
|
|
1144
1188
|
format: 'json',
|
|
1145
1189
|
...params
|
|
1190
|
+
}).then(utils_1.convertHttpResponse),
|
|
1191
|
+
/**
|
|
1192
|
+
* No description
|
|
1193
|
+
*
|
|
1194
|
+
* @tags Events
|
|
1195
|
+
* @name GetEventsBlockHashBlockhash
|
|
1196
|
+
* @summary Get contract events for a block
|
|
1197
|
+
* @request GET:/events/block-hash/{blockHash}
|
|
1198
|
+
*/
|
|
1199
|
+
getEventsBlockHashBlockhash: (blockHash, query, params = {}) => this.request({
|
|
1200
|
+
path: `/events/block-hash/${blockHash}`,
|
|
1201
|
+
method: 'GET',
|
|
1202
|
+
query: query,
|
|
1203
|
+
format: 'json',
|
|
1204
|
+
...params
|
|
1146
1205
|
}).then(utils_1.convertHttpResponse)
|
|
1147
1206
|
};
|
|
1148
1207
|
}
|
|
@@ -27,7 +27,7 @@ declare class SourceFile {
|
|
|
27
27
|
contractPath: string;
|
|
28
28
|
sourceCode: string;
|
|
29
29
|
sourceCodeHash: string;
|
|
30
|
-
getArtifactPath(
|
|
30
|
+
getArtifactPath(artifactsRootDir: string): string;
|
|
31
31
|
constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
|
|
32
32
|
static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
|
|
33
33
|
}
|
|
@@ -58,8 +58,8 @@ export declare class Project {
|
|
|
58
58
|
contracts: Compiled<Contract>[];
|
|
59
59
|
scripts: Compiled<Script>[];
|
|
60
60
|
projectArtifact: ProjectArtifact;
|
|
61
|
-
readonly
|
|
62
|
-
readonly
|
|
61
|
+
readonly contractsRootDir: string;
|
|
62
|
+
readonly artifactsRootDir: string;
|
|
63
63
|
readonly nodeProvider: NodeProvider;
|
|
64
64
|
static currentProject: Project;
|
|
65
65
|
static readonly abstractContractMatcher: TypedMatcher<SourceType>;
|
|
@@ -79,7 +79,9 @@ export declare class Project {
|
|
|
79
79
|
private static loadArtifacts;
|
|
80
80
|
private static loadSourceFile;
|
|
81
81
|
private static loadSourceFiles;
|
|
82
|
-
static
|
|
82
|
+
static readonly DEFAULT_CONTRACTS_DIR = "contracts";
|
|
83
|
+
static readonly DEFAULT_ARTIFACTS_DIR = "artifacts";
|
|
84
|
+
static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootDir?: string, artifactsRootDir?: string): Promise<void>;
|
|
83
85
|
}
|
|
84
86
|
export declare abstract class Artifact {
|
|
85
87
|
readonly name: string;
|
|
@@ -85,8 +85,8 @@ class SourceFile {
|
|
|
85
85
|
this.sourceCodeHash = sourceCodeHash;
|
|
86
86
|
this.contractPath = contractPath;
|
|
87
87
|
}
|
|
88
|
-
getArtifactPath(
|
|
89
|
-
return
|
|
88
|
+
getArtifactPath(artifactsRootDir) {
|
|
89
|
+
return artifactsRootDir + this.contractPath.slice(this.contractPath.indexOf('/')) + '.json';
|
|
90
90
|
}
|
|
91
91
|
static async from(type, sourceCode, contractPath) {
|
|
92
92
|
const sourceCodeHash = await crypto_1.webcrypto.subtle.digest('SHA-256', buffer_1.Buffer.from(sourceCode));
|
|
@@ -155,10 +155,10 @@ class ProjectArtifact {
|
|
|
155
155
|
}
|
|
156
156
|
ProjectArtifact.artifactFileName = '.project.json';
|
|
157
157
|
class Project {
|
|
158
|
-
constructor(provider,
|
|
158
|
+
constructor(provider, contractsRootDir, artifactsRootDir, sourceFiles, contracts, scripts, errorOnWarnings, projectArtifact) {
|
|
159
159
|
this.nodeProvider = provider;
|
|
160
|
-
this.
|
|
161
|
-
this.
|
|
160
|
+
this.contractsRootDir = contractsRootDir;
|
|
161
|
+
this.artifactsRootDir = artifactsRootDir;
|
|
162
162
|
this.sourceFiles = sourceFiles;
|
|
163
163
|
this.contracts = contracts;
|
|
164
164
|
this.scripts = scripts;
|
|
@@ -191,11 +191,11 @@ class Project {
|
|
|
191
191
|
return new ProjectArtifact(compilerOptions, files);
|
|
192
192
|
}
|
|
193
193
|
getContractPath(path) {
|
|
194
|
-
return path.startsWith(`./${this.
|
|
194
|
+
return path.startsWith(`./${this.contractsRootDir}`)
|
|
195
195
|
? path.slice(2)
|
|
196
|
-
: path.startsWith(this.
|
|
196
|
+
: path.startsWith(this.contractsRootDir)
|
|
197
197
|
? path
|
|
198
|
-
: this.
|
|
198
|
+
: this.contractsRootDir + '/' + path;
|
|
199
199
|
}
|
|
200
200
|
static checkCompilerWarnings(warnings, errorOnWarnings) {
|
|
201
201
|
if (warnings.length !== 0) {
|
|
@@ -225,14 +225,14 @@ class Project {
|
|
|
225
225
|
return script.artifact;
|
|
226
226
|
}
|
|
227
227
|
async saveArtifactsToFile() {
|
|
228
|
-
const
|
|
228
|
+
const artifactsRootDir = this.artifactsRootDir;
|
|
229
229
|
const saveToFile = async function (compiled) {
|
|
230
|
-
const
|
|
231
|
-
const folder =
|
|
230
|
+
const artifactDir = compiled.sourceFile.getArtifactPath(artifactsRootDir);
|
|
231
|
+
const folder = artifactDir.slice(0, artifactDir.lastIndexOf('/'));
|
|
232
232
|
if (!fs_1.default.existsSync(folder)) {
|
|
233
233
|
fs_1.default.mkdirSync(folder, { recursive: true });
|
|
234
234
|
}
|
|
235
|
-
return fs_2.promises.writeFile(
|
|
235
|
+
return fs_2.promises.writeFile(artifactDir, compiled.artifact.toString());
|
|
236
236
|
};
|
|
237
237
|
for (const contract of this.contracts) {
|
|
238
238
|
await saveToFile(contract);
|
|
@@ -240,7 +240,7 @@ class Project {
|
|
|
240
240
|
for (const script of this.scripts) {
|
|
241
241
|
await saveToFile(script);
|
|
242
242
|
}
|
|
243
|
-
await this.projectArtifact.saveToFile(this.
|
|
243
|
+
await this.projectArtifact.saveToFile(this.artifactsRootDir);
|
|
244
244
|
}
|
|
245
245
|
contractByCodeHash(codeHash) {
|
|
246
246
|
const contract = this.contracts.find((c) => c.artifact.codeHash === codeHash);
|
|
@@ -249,7 +249,7 @@ class Project {
|
|
|
249
249
|
}
|
|
250
250
|
return contract.artifact;
|
|
251
251
|
}
|
|
252
|
-
static async compile(provider, files,
|
|
252
|
+
static async compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
253
253
|
const sourceStr = files.map((f) => f.sourceCode).join('\n');
|
|
254
254
|
const result = await provider.contracts.postContractsCompileProject({
|
|
255
255
|
code: sourceStr,
|
|
@@ -268,11 +268,11 @@ class Project {
|
|
|
268
268
|
scripts.push(new Compiled(sourceFile, script, scriptResult.warnings));
|
|
269
269
|
});
|
|
270
270
|
const projectArtifact = Project.buildProjectArtifact(files, contracts, scripts, compilerOptions);
|
|
271
|
-
const project = new Project(provider,
|
|
271
|
+
const project = new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
272
272
|
await project.saveArtifactsToFile();
|
|
273
273
|
return project;
|
|
274
274
|
}
|
|
275
|
-
static async loadArtifacts(provider, files, projectArtifact,
|
|
275
|
+
static async loadArtifacts(provider, files, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions) {
|
|
276
276
|
try {
|
|
277
277
|
const contracts = [];
|
|
278
278
|
const scripts = [];
|
|
@@ -282,21 +282,21 @@ class Project {
|
|
|
282
282
|
throw Error(`Unable to find project info for ${file.contractPath}, please rebuild the project`);
|
|
283
283
|
}
|
|
284
284
|
const warnings = info.warnings;
|
|
285
|
-
const
|
|
285
|
+
const artifactDir = file.getArtifactPath(artifactsRootDir);
|
|
286
286
|
if (file.type === SourceType.Contract) {
|
|
287
|
-
const artifact = await Contract.fromArtifactFile(
|
|
287
|
+
const artifact = await Contract.fromArtifactFile(artifactDir);
|
|
288
288
|
contracts.push(new Compiled(file, artifact, warnings));
|
|
289
289
|
}
|
|
290
290
|
else if (file.type === SourceType.Script) {
|
|
291
|
-
const artifact = await Script.fromArtifactFile(
|
|
291
|
+
const artifact = await Script.fromArtifactFile(artifactDir);
|
|
292
292
|
scripts.push(new Compiled(file, artifact, warnings));
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
return new Project(provider,
|
|
295
|
+
return new Project(provider, contractsRootDir, artifactsRootDir, files, contracts, scripts, errorOnWarnings, projectArtifact);
|
|
296
296
|
}
|
|
297
297
|
catch (error) {
|
|
298
298
|
console.log(`Failed to load artifacts, error: ${error}, try to re-compile contracts...`);
|
|
299
|
-
return Project.compile(provider, files,
|
|
299
|
+
return Project.compile(provider, files, contractsRootDir, artifactsRootDir, errorOnWarnings, compilerOptions);
|
|
300
300
|
}
|
|
301
301
|
}
|
|
302
302
|
static async loadSourceFile(dirPath, filename) {
|
|
@@ -318,7 +318,7 @@ class Project {
|
|
|
318
318
|
const type = this.matchers[`${matcherIndex}`].type;
|
|
319
319
|
return SourceFile.from(type, sourceStr, contractPath);
|
|
320
320
|
}
|
|
321
|
-
static async loadSourceFiles(
|
|
321
|
+
static async loadSourceFiles(contractsRootDir) {
|
|
322
322
|
const loadDir = async function (dirPath, results) {
|
|
323
323
|
const dirents = await fs_2.promises.readdir(dirPath, { withFileTypes: true });
|
|
324
324
|
for (const dirent of dirents) {
|
|
@@ -333,25 +333,25 @@ class Project {
|
|
|
333
333
|
}
|
|
334
334
|
};
|
|
335
335
|
const sourceFiles = [];
|
|
336
|
-
await loadDir(
|
|
336
|
+
await loadDir(contractsRootDir, sourceFiles);
|
|
337
337
|
const contractAndScriptSize = sourceFiles.filter((f) => f.type === SourceType.Contract || f.type === SourceType.Script).length;
|
|
338
338
|
if (sourceFiles.length === 0 || contractAndScriptSize === 0) {
|
|
339
339
|
throw new Error('Project have no source files');
|
|
340
340
|
}
|
|
341
341
|
return sourceFiles.sort((a, b) => a.type - b.type);
|
|
342
342
|
}
|
|
343
|
-
static async build(compilerOptionsPartial = {},
|
|
343
|
+
static async build(compilerOptionsPartial = {}, contractsRootDir = Project.DEFAULT_CONTRACTS_DIR, artifactsRootDir = Project.DEFAULT_ARTIFACTS_DIR) {
|
|
344
344
|
const provider = (0, global_1.getCurrentNodeProvider)();
|
|
345
|
-
const sourceFiles = await Project.loadSourceFiles(
|
|
345
|
+
const sourceFiles = await Project.loadSourceFiles(contractsRootDir);
|
|
346
346
|
const { errorOnWarnings, ...nodeCompilerOptions } = { ...exports.DEFAULT_COMPILER_OPTIONS, ...compilerOptionsPartial };
|
|
347
|
-
const projectArtifact = await ProjectArtifact.from(
|
|
347
|
+
const projectArtifact = await ProjectArtifact.from(artifactsRootDir);
|
|
348
348
|
if (typeof projectArtifact === 'undefined' || projectArtifact.needToReCompile(nodeCompilerOptions, sourceFiles)) {
|
|
349
|
-
console.log(`Compile contracts in folder "${
|
|
350
|
-
Project.currentProject = await Project.compile(provider, sourceFiles,
|
|
349
|
+
console.log(`Compile contracts in folder "${contractsRootDir}"`);
|
|
350
|
+
Project.currentProject = await Project.compile(provider, sourceFiles, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
351
351
|
}
|
|
352
352
|
else {
|
|
353
|
-
console.log(`Load compiled contracts from folder "${
|
|
354
|
-
Project.currentProject = await Project.loadArtifacts(provider, sourceFiles, projectArtifact,
|
|
353
|
+
console.log(`Load compiled contracts from folder "${artifactsRootDir}"`);
|
|
354
|
+
Project.currentProject = await Project.loadArtifacts(provider, sourceFiles, projectArtifact, contractsRootDir, artifactsRootDir, errorOnWarnings, nodeCompilerOptions);
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
}
|
|
@@ -366,6 +366,8 @@ Project.matchers = [
|
|
|
366
366
|
Project.interfaceMatcher,
|
|
367
367
|
Project.scriptMatcher
|
|
368
368
|
];
|
|
369
|
+
Project.DEFAULT_CONTRACTS_DIR = 'contracts';
|
|
370
|
+
Project.DEFAULT_ARTIFACTS_DIR = 'artifacts';
|
|
369
371
|
class Artifact {
|
|
370
372
|
constructor(name, functions) {
|
|
371
373
|
this.name = name;
|
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.14",
|
|
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": "1.5.0-
|
|
30
|
+
"alephium_version": "1.5.0-rc8",
|
|
31
31
|
"explorer_backend_version": "1.7.1"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
@@ -36,24 +36,15 @@
|
|
|
36
36
|
"update-schemas": "npm run update-schema:alephium && npm run update-schema:explorer",
|
|
37
37
|
"update-schema:alephium": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-alephium.ts -p https://raw.githubusercontent.com/alephium/alephium/v${npm_package_config_alephium_version}/api/src/main/resources/openapi.json",
|
|
38
38
|
"update-schema:explorer": "npx swagger-typescript-api --disable-throw-on-error -t ./configs -o ./src/api -n api-explorer.ts -p https://raw.githubusercontent.com/alephium/explorer-backend/v${npm_package_config_explorer_backend_version}/app/src/main/resources/explorer-backend-openapi.json",
|
|
39
|
-
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}"
|
|
40
|
-
"start-devnet": "node scripts/start-devnet.js ${npm_package_config_alephium_version}",
|
|
41
|
-
"restart-devnet": "npm run start-devnet",
|
|
42
|
-
"stop-devnet": "node scripts/stop-devnet.js"
|
|
39
|
+
"check-versions": "node scripts/check-versions.js ${npm_package_config_alephium_version} ${npm_package_config_explorer_backend_version}"
|
|
43
40
|
},
|
|
44
41
|
"type": "commonjs",
|
|
45
|
-
"bin": {
|
|
46
|
-
"alephium": "dist/scripts/create-project.js"
|
|
47
|
-
},
|
|
48
42
|
"dependencies": {
|
|
49
43
|
"base-x": "4.0.0",
|
|
50
44
|
"blakejs": "1.2.1",
|
|
51
45
|
"buffer": "^6.0.3",
|
|
52
|
-
"commander": "^9.1.0",
|
|
53
46
|
"cross-fetch": "^3.1.5",
|
|
54
|
-
"eventemitter3": "^4.0.7"
|
|
55
|
-
"find-up": "^2.1.0",
|
|
56
|
-
"fs-extra": "^10.0.1"
|
|
47
|
+
"eventemitter3": "^4.0.7"
|
|
57
48
|
},
|
|
58
49
|
"devDependencies": {
|
|
59
50
|
"@babel/eslint-parser": "^7.18.9",
|