@alephium/web3 0.1.0 → 0.2.0-rc.10

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.
Files changed (93) hide show
  1. package/.eslintignore +2 -2
  2. package/README.md +2 -135
  3. package/contracts/greeter/greeter.ral +7 -0
  4. package/contracts/{greeter_interface.ral → greeter/greeter_interface.ral} +1 -0
  5. package/contracts/greeter_main.ral +2 -4
  6. package/dist/alephium-web3.min.js +1 -1
  7. package/dist/alephium-web3.min.js.LICENSE.txt +0 -17
  8. package/dist/alephium-web3.min.js.map +1 -1
  9. package/dist/scripts/create-project.js +3 -2
  10. package/dist/src/api/api-alephium.d.ts +58 -13
  11. package/dist/src/api/api-alephium.js +19 -3
  12. package/dist/src/api/api-explorer.d.ts +32 -16
  13. package/dist/src/api/api-explorer.js +26 -0
  14. package/dist/src/api/index.d.ts +2 -2
  15. package/dist/src/api/index.js +18 -3
  16. package/dist/src/contract/contract.d.ts +105 -48
  17. package/dist/src/contract/contract.js +362 -189
  18. package/dist/src/contract/events.d.ts +7 -25
  19. package/dist/src/contract/events.js +18 -31
  20. package/dist/src/contract/index.js +5 -1
  21. package/dist/src/global.d.ts +4 -0
  22. package/dist/src/global.js +38 -0
  23. package/dist/src/index.d.ts +3 -0
  24. package/dist/src/index.js +21 -1
  25. package/dist/src/signer/index.d.ts +0 -1
  26. package/dist/src/signer/index.js +5 -2
  27. package/dist/src/signer/signer.d.ts +1 -1
  28. package/dist/src/signer/signer.js +8 -3
  29. package/dist/src/transaction/index.d.ts +1 -0
  30. package/dist/src/{test → transaction}/index.js +6 -13
  31. package/dist/src/transaction/status.d.ts +10 -0
  32. package/dist/src/transaction/status.js +48 -0
  33. package/dist/src/utils/index.d.ts +1 -2
  34. package/dist/src/utils/index.js +6 -3
  35. package/dist/src/utils/subscription.d.ts +23 -0
  36. package/dist/src/utils/subscription.js +53 -0
  37. package/dist/src/utils/utils.d.ts +5 -2
  38. package/dist/src/utils/utils.js +25 -16
  39. package/jest-config.json +11 -0
  40. package/package.json +7 -35
  41. package/scripts/create-project.ts +3 -2
  42. package/src/api/api-alephium.ts +73 -8
  43. package/src/api/api-explorer.ts +30 -0
  44. package/src/api/index.ts +13 -3
  45. package/src/contract/contract.ts +512 -279
  46. package/src/contract/events.ts +21 -48
  47. package/src/{utils/transaction.ts → global.ts} +14 -15
  48. package/src/index.ts +4 -0
  49. package/src/signer/index.ts +0 -1
  50. package/src/signer/signer.ts +4 -3
  51. package/src/{utils/password-crypto.test.ts → transaction/index.ts} +1 -9
  52. package/src/transaction/status.ts +58 -0
  53. package/src/utils/index.ts +1 -2
  54. package/src/utils/subscription.ts +72 -0
  55. package/src/utils/utils.ts +16 -8
  56. package/templates/base/package.json +2 -2
  57. package/templates/base/src/greeter.ts +8 -7
  58. package/templates/react/package.json +2 -2
  59. package/templates/react/src/App.tsx +2 -2
  60. package/.eslintrc.json +0 -21
  61. package/LICENSE +0 -165
  62. package/contracts/add.ral +0 -16
  63. package/contracts/greeter.ral +0 -7
  64. package/contracts/main.ral +0 -6
  65. package/contracts/sub.ral +0 -9
  66. package/dist/src/signer/node-wallet.d.ts +0 -13
  67. package/dist/src/signer/node-wallet.js +0 -60
  68. package/dist/src/test/index.d.ts +0 -7
  69. package/dist/src/test/privatekey-wallet.d.ts +0 -12
  70. package/dist/src/test/privatekey-wallet.js +0 -68
  71. package/dist/src/utils/password-crypto.d.ts +0 -2
  72. package/dist/src/utils/password-crypto.js +0 -69
  73. package/dist/src/utils/transaction.d.ts +0 -2
  74. package/dist/src/utils/transaction.js +0 -58
  75. package/gitignore +0 -10
  76. package/src/contract/ralph.test.ts +0 -178
  77. package/src/fixtures/address.json +0 -36
  78. package/src/fixtures/balance.json +0 -9
  79. package/src/fixtures/self-clique.json +0 -19
  80. package/src/fixtures/transaction.json +0 -13
  81. package/src/fixtures/transactions.json +0 -179
  82. package/src/signer/fixtures/genesis.json +0 -26
  83. package/src/signer/fixtures/wallets.json +0 -26
  84. package/src/signer/node-wallet.ts +0 -74
  85. package/src/test/index.ts +0 -32
  86. package/src/test/privatekey-wallet.ts +0 -58
  87. package/src/utils/address.test.ts +0 -47
  88. package/src/utils/djb2.test.ts +0 -35
  89. package/src/utils/password-crypto.ts +0 -77
  90. package/src/utils/transaction.test.ts +0 -50
  91. package/src/utils/utils.test.ts +0 -160
  92. package/test/contract.test.ts +0 -161
  93. package/test/events.test.ts +0 -139
@@ -73,7 +73,7 @@ function prepareShared(packageRoot, projectRoot) {
73
73
  console.log(` to ${projectRoot}`);
74
74
  console.log('...');
75
75
  fs_extra_1.default.copySync(path_1.default.join(packageRoot, 'templates/shared'), projectRoot);
76
- copy('', ['.editorconfig', '.eslintignore', '.gitattributes', 'LICENSE']);
76
+ copy('', ['.editorconfig', '.eslintignore', '.gitattributes']);
77
77
  copy('dev', ['user.conf']);
78
78
  copy('scripts', ['start-devnet.js', 'stop-devnet.js']);
79
79
  if (fs_extra_1.default.existsSync(path_1.default.join(packageRoot, 'gitignore'))) {
@@ -86,7 +86,8 @@ function prepareShared(packageRoot, projectRoot) {
86
86
  }
87
87
  function prepareBase(packageRoot, projectRoot) {
88
88
  prepareShared(packageRoot, projectRoot);
89
- copy('contracts', ['greeter.ral', 'greeter_interface.ral', 'greeter_main.ral']);
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) {
@@ -63,6 +63,8 @@ export interface Balance {
63
63
  lockedBalance: string;
64
64
  /** @format x.x ALPH */
65
65
  lockedBalanceHint: string;
66
+ tokenBalances?: Token[];
67
+ lockedTokenBalances?: Token[];
66
68
  /** @format int32 */
67
69
  utxoNum: number;
68
70
  warning?: string;
@@ -146,6 +148,8 @@ export interface BuildDeployContractTx {
146
148
  gasAmount?: number;
147
149
  /** @format uint256 */
148
150
  gasPrice?: string;
151
+ /** @format block-hash */
152
+ targetBlockHash?: string;
149
153
  }
150
154
  export interface BuildDeployContractTxResult {
151
155
  /** @format int32 */
@@ -174,6 +178,8 @@ export interface BuildExecuteScriptTx {
174
178
  gasAmount?: number;
175
179
  /** @format uint256 */
176
180
  gasPrice?: string;
181
+ /** @format block-hash */
182
+ targetBlockHash?: string;
177
183
  }
178
184
  export interface BuildExecuteScriptTxResult {
179
185
  /** @format int32 */
@@ -222,6 +228,8 @@ export interface BuildSweepAddressTransactions {
222
228
  gasAmount?: number;
223
229
  /** @format uint256 */
224
230
  gasPrice?: string;
231
+ /** @format block-hash */
232
+ targetBlockHash?: string;
225
233
  }
226
234
  export interface BuildSweepAddressTransactionsResult {
227
235
  unsignedTxs: SweepAddressTransaction[];
@@ -239,6 +247,8 @@ export interface BuildTransaction {
239
247
  gasAmount?: number;
240
248
  /** @format uint256 */
241
249
  gasPrice?: string;
250
+ /** @format block-hash */
251
+ targetBlockHash?: string;
242
252
  }
243
253
  export interface BuildTransactionResult {
244
254
  unsignedTx: string;
@@ -295,17 +305,33 @@ export interface ChangeActiveAddress {
295
305
  address: string;
296
306
  }
297
307
  export interface CompileContractResult {
308
+ name: string;
298
309
  bytecode: string;
299
310
  /** @format 32-byte-hash */
300
311
  codeHash: string;
301
312
  fields: FieldsSig;
302
313
  functions: FunctionSig[];
303
314
  events: EventSig[];
315
+ warnings: string[];
316
+ }
317
+ export interface CompileProjectResult {
318
+ contracts: CompileContractResult[];
319
+ scripts: CompileScriptResult[];
304
320
  }
305
321
  export interface CompileScriptResult {
322
+ name: string;
306
323
  bytecodeTemplate: string;
307
324
  fields: FieldsSig;
308
325
  functions: FunctionSig[];
326
+ warnings: string[];
327
+ }
328
+ export interface CompilerOptions {
329
+ ignoreUnusedConstantsWarnings?: boolean;
330
+ ignoreUnusedVariablesWarnings?: boolean;
331
+ ignoreUnusedFieldsWarnings?: boolean;
332
+ ignoreUnusedPrivateFunctionsWarnings?: boolean;
333
+ ignoreReadonlyCheckWarnings?: boolean;
334
+ ignoreExternalCallCheckWarnings?: boolean;
309
335
  }
310
336
  export interface Confirmed {
311
337
  /** @format block-hash */
@@ -322,6 +348,7 @@ export interface Confirmed {
322
348
  }
323
349
  export interface Contract {
324
350
  code: string;
351
+ compilerOptions?: CompilerOptions;
325
352
  }
326
353
  export interface ContractEvent {
327
354
  /** @format block-hash */
@@ -399,7 +426,6 @@ export interface Destination {
399
426
  export declare type DiscoveryAction = Reachable | Unreachable;
400
427
  export interface EventSig {
401
428
  name: string;
402
- signature: string;
403
429
  fieldNames: string[];
404
430
  fieldTypes: string[];
405
431
  }
@@ -407,9 +433,9 @@ export interface FetchResponse {
407
433
  blocks: BlockEntry[][];
408
434
  }
409
435
  export interface FieldsSig {
410
- signature: string;
411
436
  names: string[];
412
437
  types: string[];
438
+ isMutable: boolean[];
413
439
  }
414
440
  export interface FixedAssetOutput {
415
441
  /** @format int32 */
@@ -428,9 +454,12 @@ export interface FixedAssetOutput {
428
454
  }
429
455
  export interface FunctionSig {
430
456
  name: string;
431
- signature: string;
432
- argNames: string[];
433
- argTypes: string[];
457
+ usePreapprovedAssets: boolean;
458
+ useAssetsInContract: boolean;
459
+ isPublic: boolean;
460
+ paramNames: string[];
461
+ paramTypes: string[];
462
+ paramIsMutable: boolean[];
434
463
  returnTypes: string[];
435
464
  }
436
465
  export interface Group {
@@ -512,6 +541,10 @@ export interface Penalty {
512
541
  value: number;
513
542
  type: string;
514
543
  }
544
+ export interface Project {
545
+ code: string;
546
+ compilerOptions?: CompilerOptions;
547
+ }
515
548
  export interface Reachable {
516
549
  peers: string[];
517
550
  type: string;
@@ -532,6 +565,7 @@ export interface RevealMnemonicResult {
532
565
  }
533
566
  export interface Script {
534
567
  code: string;
568
+ compilerOptions?: CompilerOptions;
535
569
  }
536
570
  export interface SelfClique {
537
571
  /** @format clique-id */
@@ -578,6 +612,8 @@ export interface Sweep {
578
612
  gasPrice?: string;
579
613
  /** @format int32 */
580
614
  utxosLimit?: number;
615
+ /** @format block-hash */
616
+ targetBlockHash?: string;
581
617
  }
582
618
  export interface SweepAddressTransaction {
583
619
  /** @format 32-byte-hash */
@@ -843,8 +879,8 @@ export declare class HttpClient<SecurityDataType = unknown> {
843
879
  }
844
880
  /**
845
881
  * @title Alephium API
846
- * @version 1.4.2
847
- * @baseUrl {protocol}://{host}:{port}
882
+ * @version 1.5.0
883
+ * @baseUrl ../
848
884
  */
849
885
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
850
886
  wallets: {
@@ -1001,8 +1037,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1001
1037
  * @request POST:/wallets/{wallet_name}/derive-next-address
1002
1038
  */
1003
1039
  postWalletsWalletNameDeriveNextAddress: (walletName: string, query?: {
1004
- group?: number | undefined;
1005
- } | undefined, params?: RequestParams) => Promise<AddressInfo>;
1040
+ group?: number;
1041
+ }, params?: RequestParams) => Promise<AddressInfo>;
1006
1042
  /**
1007
1043
  * @description Your wallet need to have been created with the miner flag set to true
1008
1044
  *
@@ -1134,8 +1170,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1134
1170
  * @request GET:/infos/current-hashrate
1135
1171
  */
1136
1172
  getInfosCurrentHashrate: (query?: {
1137
- timespan?: number | undefined;
1138
- } | undefined, params?: RequestParams) => Promise<string>;
1173
+ timespan?: number;
1174
+ }, params?: RequestParams) => Promise<string>;
1139
1175
  };
1140
1176
  blockflow: {
1141
1177
  /**
@@ -1322,6 +1358,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1322
1358
  * @request POST:/contracts/compile-contract
1323
1359
  */
1324
1360
  postContractsCompileContract: (data: Contract, params?: RequestParams) => Promise<CompileContractResult>;
1361
+ /**
1362
+ * No description
1363
+ *
1364
+ * @tags Contracts
1365
+ * @name PostContractsCompileProject
1366
+ * @summary Compile a project
1367
+ * @request POST:/contracts/compile-project
1368
+ */
1369
+ postContractsCompileProject: (data: Project, params?: RequestParams) => Promise<CompileProjectResult>;
1325
1370
  /**
1326
1371
  * No description
1327
1372
  *
@@ -1473,8 +1518,8 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1473
1518
  * @request GET:/events/tx-id/{txId}
1474
1519
  */
1475
1520
  getEventsTxIdTxid: (txId: string, query?: {
1476
- group?: number | undefined;
1477
- } | undefined, params?: RequestParams) => Promise<ContractEventsByTxId>;
1521
+ group?: number;
1522
+ }, params?: RequestParams) => Promise<ContractEventsByTxId>;
1478
1523
  };
1479
1524
  }
1480
1525
  export {};
@@ -28,7 +28,7 @@ var ContentType;
28
28
  })(ContentType = exports.ContentType || (exports.ContentType = {}));
29
29
  class HttpClient {
30
30
  constructor(apiConfig = {}) {
31
- this.baseUrl = '{protocol}://{host}:{port}';
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.4.2
162
- * @baseUrl {protocol}://{host}:{port}
161
+ * @version 1.5.0
162
+ * @baseUrl ../
163
163
  */
164
164
  class Api extends HttpClient {
165
165
  constructor() {
@@ -901,6 +901,22 @@ class Api extends HttpClient {
901
901
  format: 'json',
902
902
  ...params
903
903
  }).then(convertHttpResponse),
904
+ /**
905
+ * No description
906
+ *
907
+ * @tags Contracts
908
+ * @name PostContractsCompileProject
909
+ * @summary Compile a project
910
+ * @request POST:/contracts/compile-project
911
+ */
912
+ postContractsCompileProject: (data, params = {}) => this.request({
913
+ path: `/contracts/compile-project`,
914
+ method: 'POST',
915
+ body: data,
916
+ type: ContentType.Json,
917
+ format: 'json',
918
+ ...params
919
+ }).then(convertHttpResponse),
904
920
  /**
905
921
  * No description
906
922
  *
@@ -269,10 +269,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
269
269
  * @request GET:/blocks
270
270
  */
271
271
  getBlocks: (query?: {
272
- page?: number | undefined;
273
- limit?: number | undefined;
274
- reverse?: boolean | undefined;
275
- } | undefined, params?: RequestParams) => Promise<ListBlocks>;
272
+ page?: number;
273
+ limit?: number;
274
+ reverse?: boolean;
275
+ }, params?: RequestParams) => Promise<ListBlocks>;
276
276
  /**
277
277
  * @description Get a block with hash
278
278
  *
@@ -289,10 +289,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
289
289
  * @request GET:/blocks/{block-hash}/transactions
290
290
  */
291
291
  getBlocksBlockHashTransactions: (blockHash: string, query?: {
292
- page?: number | undefined;
293
- limit?: number | undefined;
294
- reverse?: boolean | undefined;
295
- } | undefined, params?: RequestParams) => Promise<Transaction[]>;
292
+ page?: number;
293
+ limit?: number;
294
+ reverse?: boolean;
295
+ }, params?: RequestParams) => Promise<Transaction[]>;
296
296
  };
297
297
  transactions: {
298
298
  /**
@@ -321,10 +321,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
321
321
  * @request GET:/addresses/{address}/transactions
322
322
  */
323
323
  getAddressesAddressTransactions: (address: string, query?: {
324
- page?: number | undefined;
325
- limit?: number | undefined;
326
- reverse?: boolean | undefined;
327
- } | undefined, params?: RequestParams) => Promise<Transaction[]>;
324
+ page?: number;
325
+ limit?: number;
326
+ reverse?: boolean;
327
+ }, params?: RequestParams) => Promise<Transaction[]>;
328
328
  /**
329
329
  * @description Get total transactions of a given address
330
330
  *
@@ -367,10 +367,10 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
367
367
  * @request GET:/infos/supply
368
368
  */
369
369
  getInfosSupply: (query?: {
370
- page?: number | undefined;
371
- limit?: number | undefined;
372
- reverse?: boolean | undefined;
373
- } | undefined, params?: RequestParams) => Promise<TokenSupply[]>;
370
+ page?: number;
371
+ limit?: number;
372
+ reverse?: boolean;
373
+ }, params?: RequestParams) => Promise<TokenSupply[]>;
374
374
  /**
375
375
  * @description Get the ALPH total supply
376
376
  *
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  import { Api as NodeApi } from './api-alephium';
2
2
  import { Api as ExplorerApi } from './api-explorer';
3
- export declare class NodeProvider extends NodeApi<null> {
4
- constructor(baseUrl: string);
3
+ export declare class NodeProvider extends NodeApi<string> {
4
+ constructor(baseUrl: string, apiKey?: string);
5
5
  }
6
6
  export declare class ExplorerProvider extends ExplorerApi<null> {
7
7
  constructor(baseUrl: string);
@@ -18,7 +18,11 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
20
  if (k2 === undefined) k2 = k;
21
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
22
26
  }) : (function(o, m, k, k2) {
23
27
  if (k2 === undefined) k2 = k;
24
28
  o[k2] = m[k];
@@ -40,8 +44,19 @@ exports.explorer = exports.node = exports.ExplorerProvider = exports.NodeProvide
40
44
  const api_alephium_1 = require("./api-alephium");
41
45
  const api_explorer_1 = require("./api-explorer");
42
46
  class NodeProvider extends api_alephium_1.Api {
43
- constructor(baseUrl) {
44
- super({ baseUrl: baseUrl });
47
+ constructor(baseUrl, apiKey) {
48
+ // eslint-disable-next-line security/detect-possible-timing-attacks
49
+ if (apiKey === undefined) {
50
+ super({ baseUrl: baseUrl });
51
+ }
52
+ else {
53
+ super({
54
+ baseUrl: baseUrl,
55
+ baseApiParams: { secure: true },
56
+ securityWorker: (accessToken) => (accessToken !== null ? { headers: { 'X-API-KEY': `${accessToken}` } } : {})
57
+ });
58
+ this.setSecurityData(apiKey);
59
+ }
45
60
  }
46
61
  }
47
62
  exports.NodeProvider = NodeProvider;
@@ -1,74 +1,130 @@
1
- import { NodeProvider } from '../api';
2
- import { node } from '../api';
1
+ import { node, NodeProvider } from '../api';
3
2
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
4
- export declare abstract class Common {
5
- readonly sourceCodeSha256: string;
6
- readonly functions: node.FunctionSig[];
7
- static readonly importRegex: RegExp;
8
- static readonly contractRegex: RegExp;
9
- static readonly interfaceRegex: RegExp;
10
- static readonly scriptRegex: RegExp;
11
- private static _artifactCache;
12
- static artifactCacheCapacity: number;
13
- protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
14
- protected static _putArtifactToCache(contract: Contract): void;
15
- constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
16
- protected static _contractPath(fileName: string): string;
17
- protected static _artifactPath(fileName: string): string;
18
- protected static _artifactsFolder(): string;
19
- protected static _handleImports(contractStr: string, importsCache: string[]): Promise<string>;
20
- protected static _loadContractStr(fileName: string, importsCache: string[], validate: (fileName: string) => void): Promise<string>;
21
- static checkFileNameExtension(fileName: string): void;
22
- protected static _from<T extends {
23
- sourceCodeSha256: string;
24
- }>(provider: NodeProvider, fileName: string, loadContractStr: (fileName: string, importsCache: string[]) => Promise<string>, compile: (provider: NodeProvider, fileName: string, contractStr: string, contractHash: string) => Promise<T>): Promise<T>;
25
- protected _saveToFile(fileName: string): Promise<void>;
3
+ import { CompileContractResult, CompileScriptResult } from '../api/api-alephium';
4
+ declare type FieldsSig = node.FieldsSig;
5
+ declare type EventSig = node.EventSig;
6
+ declare type FunctionSig = node.FunctionSig;
7
+ declare enum SourceType {
8
+ Contract = 0,
9
+ Script = 1,
10
+ AbstractContract = 2,
11
+ Interface = 3
12
+ }
13
+ export declare type CompilerOptions = node.CompilerOptions & {
14
+ errorOnWarnings: boolean;
15
+ };
16
+ export declare const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions;
17
+ export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
18
+ declare class TypedMatcher<T extends SourceType> {
19
+ matcher: RegExp;
20
+ type: T;
21
+ constructor(pattern: string, type: T);
22
+ match(str: string): number;
23
+ }
24
+ declare class SourceFile {
25
+ type: SourceType;
26
+ contractPath: string;
27
+ sourceCode: string;
28
+ sourceCodeHash: string;
29
+ getArtifactPath(artifactsRootPath: string): string;
30
+ constructor(type: SourceType, sourceCode: string, sourceCodeHash: string, contractPath: string);
31
+ static from(type: SourceType, sourceCode: string, contractPath: string): Promise<SourceFile>;
32
+ }
33
+ declare class Compiled<T extends Artifact> {
34
+ sourceFile: SourceFile;
35
+ artifact: T;
36
+ warnings: string[];
37
+ constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
38
+ }
39
+ declare class ProjectArtifact {
40
+ static readonly artifactFileName = ".project.json";
41
+ compilerOptionsUsed: node.CompilerOptions;
42
+ infos: Map<string, {
43
+ sourceCodeHash: string;
44
+ warnings: string[];
45
+ }>;
46
+ static checkCompilerOptionsParameter(compilerOptions: node.CompilerOptions): void;
47
+ constructor(compilerOptionsUsed: node.CompilerOptions, infos: Map<string, {
48
+ sourceCodeHash: string;
49
+ warnings: string[];
50
+ }>);
51
+ saveToFile(rootPath: string): Promise<void>;
52
+ needToReCompile(compilerOptions: node.CompilerOptions, files: SourceFile[]): boolean;
53
+ static from(rootPath: string): Promise<ProjectArtifact | undefined>;
54
+ }
55
+ export declare class Project {
56
+ sourceFiles: SourceFile[];
57
+ contracts: Compiled<Contract>[];
58
+ scripts: Compiled<Script>[];
59
+ projectArtifact: ProjectArtifact;
60
+ readonly contractsRootPath: string;
61
+ readonly artifactsRootPath: string;
62
+ readonly nodeProvider: NodeProvider;
63
+ static currentProject: Project;
64
+ static readonly abstractContractMatcher: TypedMatcher<SourceType>;
65
+ static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
66
+ static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
67
+ static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
68
+ static readonly matchers: TypedMatcher<SourceType>[];
69
+ static buildProjectArtifact(sourceFiles: SourceFile[], contracts: Compiled<Contract>[], scripts: Compiled<Script>[], compilerOptions: node.CompilerOptions): ProjectArtifact;
70
+ private constructor();
71
+ private getContractPath;
72
+ static checkCompilerWarnings(warnings: string[], errorOnWarnings: boolean): void;
73
+ static contract(path: string): Contract;
74
+ static script(path: string): Script;
75
+ private saveArtifactsToFile;
76
+ contractByCodeHash(codeHash: string): Contract;
77
+ private static compile;
78
+ private static loadArtifacts;
79
+ private static loadSourceFile;
80
+ private static loadSourceFiles;
81
+ static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootPath?: string, artifactsRootPath?: string): Promise<void>;
82
+ }
83
+ export declare abstract class Artifact {
84
+ readonly functions: FunctionSig[];
85
+ constructor(functions: FunctionSig[]);
26
86
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
87
+ publicFunctions(): string[];
88
+ usingPreapprovedAssetsFunctions(): string[];
89
+ usingAssetsInContractFunctions(): string[];
27
90
  }
28
- export declare class Contract extends Common {
91
+ export declare class Contract extends Artifact {
29
92
  readonly bytecode: string;
30
93
  readonly codeHash: string;
31
- readonly fieldsSig: node.FieldsSig;
32
- readonly eventsSig: node.EventSig[];
33
- constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
34
- static checkCodeType(fileName: string, contractStr: string): void;
35
- private static loadContractStr;
36
- static fromSource(provider: NodeProvider, fileName: string): Promise<Contract>;
37
- private static compile;
94
+ readonly fieldsSig: FieldsSig;
95
+ readonly eventsSig: EventSig[];
96
+ constructor(bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
38
97
  static fromJson(artifact: any): Contract;
39
- static fromArtifactFile(fileName: string): Promise<Contract>;
98
+ static fromCompileResult(result: CompileContractResult): Contract;
99
+ static fromArtifactFile(path: string): Promise<Contract>;
100
+ fetchState(address: string, group: number): Promise<ContractState>;
40
101
  toString(): string;
41
102
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
42
103
  static randomAddress(): string;
43
104
  private _test;
44
- testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
45
- testPrivateMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
105
+ testPublicMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
106
+ testPrivateMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
46
107
  toApiFields(fields?: Fields): node.Val[];
47
108
  toApiArgs(funcName: string, args?: Arguments): node.Val[];
48
109
  getMethodIndex(funcName: string): number;
49
110
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
50
111
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
51
- static fromCodeHash(codeHash: string): Promise<Contract>;
52
- static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
53
112
  fromApiContractState(state: node.ContractState): Promise<ContractState>;
54
- static ContractCreatedEvent: node.EventSig;
55
- static ContractDestroyedEvent: node.EventSig;
113
+ static ContractCreatedEvent: EventSig;
114
+ static ContractDestroyedEvent: EventSig;
56
115
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
57
116
  fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
58
117
  paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
59
118
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
60
119
  buildByteCodeToDeploy(initialFields: Fields): string;
61
120
  }
62
- export declare class Script extends Common {
121
+ export declare class Script extends Artifact {
63
122
  readonly bytecodeTemplate: string;
64
- readonly fieldsSig: node.FieldsSig;
65
- constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
66
- static checkCodeType(fileName: string, contractStr: string): void;
67
- private static loadContractStr;
68
- static fromSource(provider: NodeProvider, fileName: string): Promise<Script>;
69
- private static compile;
123
+ readonly fieldsSig: FieldsSig;
124
+ constructor(bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
125
+ static fromCompileResult(result: CompileScriptResult): Script;
70
126
  static fromJson(artifact: any): Script;
71
- static fromArtifactFile(fileName: string): Promise<Script>;
127
+ static fromArtifactFile(path: string): Promise<Script>;
72
128
  toString(): string;
73
129
  paramsForDeployment(params: BuildExecuteScriptTx): Promise<SignExecuteScriptTxParams>;
74
130
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
@@ -100,7 +156,7 @@ export interface ContractState {
100
156
  initialStateHash?: string;
101
157
  codeHash: string;
102
158
  fields: Fields;
103
- fieldsSig: node.FieldsSig;
159
+ fieldsSig: FieldsSig;
104
160
  asset: Asset;
105
161
  }
106
162
  export interface TestContractParams {
@@ -180,3 +236,4 @@ export interface BuildScriptTxResult {
180
236
  unsignedTx: string;
181
237
  txId: string;
182
238
  }
239
+ export {};