@alephium/web3 0.2.0-test.0 → 0.2.0-test.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.
Files changed (58) hide show
  1. package/contracts/add/add.ral +5 -8
  2. package/contracts/greeter/greeter.ral +3 -3
  3. package/contracts/greeter/greeter_interface.ral +1 -0
  4. package/contracts/greeter_main.ral +3 -5
  5. package/contracts/main.ral +0 -2
  6. package/contracts/sub/sub.ral +2 -1
  7. package/contracts/test/metadata.ral +18 -0
  8. package/contracts/test/warnings.ral +8 -0
  9. package/dist/alephium-web3.min.js +1 -1
  10. package/dist/alephium-web3.min.js.map +1 -1
  11. package/dist/scripts/create-project.js +2 -1
  12. package/dist/src/api/api-alephium.d.ts +37 -7
  13. package/dist/src/api/api-alephium.js +19 -3
  14. package/dist/src/api/api-explorer.d.ts +16 -0
  15. package/dist/src/api/api-explorer.js +26 -0
  16. package/dist/src/contract/contract.d.ts +86 -52
  17. package/dist/src/contract/contract.js +325 -218
  18. package/dist/src/global.d.ts +3 -0
  19. package/dist/src/global.js +38 -0
  20. package/dist/src/index.d.ts +1 -0
  21. package/dist/src/index.js +1 -0
  22. package/dist/src/signer/node-wallet.d.ts +1 -3
  23. package/dist/src/signer/node-wallet.js +2 -5
  24. package/dist/src/signer/signer.d.ts +1 -1
  25. package/dist/src/signer/signer.js +3 -2
  26. package/dist/src/test/index.d.ts +1 -2
  27. package/dist/src/test/index.js +4 -4
  28. package/dist/src/test/privatekey-wallet.d.ts +2 -3
  29. package/dist/src/test/privatekey-wallet.js +4 -4
  30. package/dist/src/utils/subscription.d.ts +0 -1
  31. package/dist/src/utils/subscription.js +2 -1
  32. package/dist/src/utils/utils.d.ts +2 -2
  33. package/dist/src/utils/utils.js +2 -2
  34. package/gitignore +0 -1
  35. package/package.json +3 -5
  36. package/scripts/create-project.ts +2 -1
  37. package/src/api/api-alephium.ts +57 -8
  38. package/src/api/api-explorer.ts +30 -0
  39. package/src/contract/contract.ts +430 -317
  40. package/src/contract/events.ts +2 -2
  41. package/src/contract/ralph.test.ts +4 -4
  42. package/src/global.ts +36 -0
  43. package/src/index.ts +1 -0
  44. package/src/signer/node-wallet.ts +2 -11
  45. package/src/signer/signer.ts +4 -3
  46. package/src/test/index.ts +2 -3
  47. package/src/test/privatekey-wallet.ts +4 -5
  48. package/src/transaction/status.ts +1 -1
  49. package/src/utils/subscription.ts +3 -3
  50. package/src/utils/utils.test.ts +1 -1
  51. package/src/utils/utils.ts +4 -4
  52. package/templates/base/package.json +2 -2
  53. package/templates/base/src/greeter.ts +8 -7
  54. package/templates/react/package.json +2 -2
  55. package/templates/react/src/App.tsx +2 -2
  56. package/test/contract.test.ts +60 -25
  57. package/test/events.test.ts +20 -17
  58. package/test/transaction.test.ts +10 -9
@@ -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) {
@@ -148,6 +148,8 @@ export interface BuildDeployContractTx {
148
148
  gasAmount?: number;
149
149
  /** @format uint256 */
150
150
  gasPrice?: string;
151
+ /** @format block-hash */
152
+ targetBlockHash?: string;
151
153
  }
152
154
  export interface BuildDeployContractTxResult {
153
155
  /** @format int32 */
@@ -176,6 +178,8 @@ export interface BuildExecuteScriptTx {
176
178
  gasAmount?: number;
177
179
  /** @format uint256 */
178
180
  gasPrice?: string;
181
+ /** @format block-hash */
182
+ targetBlockHash?: string;
179
183
  }
180
184
  export interface BuildExecuteScriptTxResult {
181
185
  /** @format int32 */
@@ -224,6 +228,8 @@ export interface BuildSweepAddressTransactions {
224
228
  gasAmount?: number;
225
229
  /** @format uint256 */
226
230
  gasPrice?: string;
231
+ /** @format block-hash */
232
+ targetBlockHash?: string;
227
233
  }
228
234
  export interface BuildSweepAddressTransactionsResult {
229
235
  unsignedTxs: SweepAddressTransaction[];
@@ -241,6 +247,8 @@ export interface BuildTransaction {
241
247
  gasAmount?: number;
242
248
  /** @format uint256 */
243
249
  gasPrice?: string;
250
+ /** @format block-hash */
251
+ targetBlockHash?: string;
244
252
  }
245
253
  export interface BuildTransactionResult {
246
254
  unsignedTx: string;
@@ -303,11 +311,17 @@ export interface CompileContractResult {
303
311
  fields: FieldsSig;
304
312
  functions: FunctionSig[];
305
313
  events: EventSig[];
314
+ warnings: string[];
315
+ }
316
+ export interface CompileProjectResult {
317
+ contracts: CompileContractResult[];
318
+ scripts: CompileScriptResult[];
306
319
  }
307
320
  export interface CompileScriptResult {
308
321
  bytecodeTemplate: string;
309
322
  fields: FieldsSig;
310
323
  functions: FunctionSig[];
324
+ warnings: string[];
311
325
  }
312
326
  export interface Confirmed {
313
327
  /** @format block-hash */
@@ -401,7 +415,6 @@ export interface Destination {
401
415
  export declare type DiscoveryAction = Reachable | Unreachable;
402
416
  export interface EventSig {
403
417
  name: string;
404
- signature: string;
405
418
  fieldNames: string[];
406
419
  fieldTypes: string[];
407
420
  }
@@ -409,9 +422,9 @@ export interface FetchResponse {
409
422
  blocks: BlockEntry[][];
410
423
  }
411
424
  export interface FieldsSig {
412
- signature: string;
413
425
  names: string[];
414
426
  types: string[];
427
+ isMutable: boolean[];
415
428
  }
416
429
  export interface FixedAssetOutput {
417
430
  /** @format int32 */
@@ -430,9 +443,12 @@ export interface FixedAssetOutput {
430
443
  }
431
444
  export interface FunctionSig {
432
445
  name: string;
433
- signature: string;
434
- argNames: string[];
435
- argTypes: string[];
446
+ usePreapprovedAssets: boolean;
447
+ useAssetsInContract: boolean;
448
+ isPublic: boolean;
449
+ paramNames: string[];
450
+ paramTypes: string[];
451
+ paramIsMutable: boolean[];
436
452
  returnTypes: string[];
437
453
  }
438
454
  export interface Group {
@@ -514,6 +530,9 @@ export interface Penalty {
514
530
  value: number;
515
531
  type: string;
516
532
  }
533
+ export interface Project {
534
+ code: string;
535
+ }
517
536
  export interface Reachable {
518
537
  peers: string[];
519
538
  type: string;
@@ -580,6 +599,8 @@ export interface Sweep {
580
599
  gasPrice?: string;
581
600
  /** @format int32 */
582
601
  utxosLimit?: number;
602
+ /** @format block-hash */
603
+ targetBlockHash?: string;
583
604
  }
584
605
  export interface SweepAddressTransaction {
585
606
  /** @format 32-byte-hash */
@@ -845,8 +866,8 @@ export declare class HttpClient<SecurityDataType = unknown> {
845
866
  }
846
867
  /**
847
868
  * @title Alephium API
848
- * @version 1.4.2
849
- * @baseUrl {protocol}://{host}:{port}
869
+ * @version 1.5.0
870
+ * @baseUrl ../
850
871
  */
851
872
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
852
873
  wallets: {
@@ -1324,6 +1345,15 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1324
1345
  * @request POST:/contracts/compile-contract
1325
1346
  */
1326
1347
  postContractsCompileContract: (data: Contract, params?: RequestParams) => Promise<CompileContractResult>;
1348
+ /**
1349
+ * No description
1350
+ *
1351
+ * @tags Contracts
1352
+ * @name PostContractsCompileProject
1353
+ * @summary Compile a project
1354
+ * @request POST:/contracts/compile-project
1355
+ */
1356
+ postContractsCompileProject: (data: Project, params?: RequestParams) => Promise<CompileProjectResult>;
1327
1357
  /**
1328
1358
  * No description
1329
1359
  *
@@ -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
  *
@@ -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,79 +1,113 @@
1
- import { NodeProvider } from '../api';
2
- import { node } from '../api';
1
+ import { node, NodeProvider } from '../api';
3
2
  import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerWithNodeProvider } from '../signer';
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 = {
14
+ errorOnWarnings: boolean;
15
+ ignoreUnusedConstantsWarnings: boolean;
16
+ };
17
+ export declare const DEFAULT_COMPILER_OPTIONS: CompilerOptions;
18
+ declare class TypedMatcher<T extends SourceType> {
19
+ matcher: RegExp;
20
+ type: T;
21
+ name: string | undefined;
22
+ constructor(pattern: string, type: T);
23
+ match(str: string): number;
24
+ }
4
25
  declare class SourceFile {
5
- readonly dirs: string[];
6
- readonly dirPath: string;
7
- readonly contractPath: string;
8
- readonly artifactPath: string;
9
- constructor(dirs: string[], fileName: string);
10
- }
11
- export declare abstract class Common {
12
- readonly sourceCodeSha256: string;
13
- readonly functions: node.FunctionSig[];
14
- static readonly importRegex: RegExp;
15
- static readonly contractRegex: RegExp;
16
- static readonly interfaceRegex: RegExp;
17
- static readonly scriptRegex: RegExp;
18
- private static _artifactCache;
19
- static artifactCacheCapacity: number;
20
- protected static _getArtifactFromCache(codeHash: string): Contract | Script | undefined;
21
- protected static _putArtifactToCache(contract: Contract): void;
22
- constructor(sourceCodeSha256: string, functions: node.FunctionSig[]);
23
- protected static _artifactsFolder(): string;
24
- static getSourceFile(path: string, _dirs: string[]): SourceFile;
25
- protected static _handleImports(pathes: string[], contractStr: string, importsCache: string[]): Promise<string>;
26
- protected static _loadContractStr(sourceFile: SourceFile, importsCache: string[], validate: (code: string) => void): Promise<string>;
27
- static checkFileNameExtension(fileName: string): void;
28
- protected static _from<T extends {
29
- 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>): Promise<T>;
31
- protected _saveToFile(sourceFile: SourceFile): Promise<void>;
26
+ type: SourceType;
27
+ typeId: string;
28
+ contractPath: string;
29
+ sourceCode: string;
30
+ sourceCodeHash: string;
31
+ getArtifactPath(artifactsRootPath: string): string;
32
+ constructor(type: SourceType, typeId: string, sourceCode: string, contractPath: string);
33
+ }
34
+ declare class Compiled<T extends Artifact> {
35
+ sourceFile: SourceFile;
36
+ artifact: T;
37
+ warnings: string[];
38
+ constructor(sourceFile: SourceFile, artifact: T, warnings: string[]);
39
+ }
40
+ export declare class Project {
41
+ sourceFiles: SourceFile[];
42
+ contracts: Compiled<Contract>[];
43
+ scripts: Compiled<Script>[];
44
+ readonly contractsRootPath: string;
45
+ readonly artifactsRootPath: string;
46
+ readonly nodeProvider: NodeProvider;
47
+ static currentProject: Project;
48
+ static readonly abstractContractMatcher: TypedMatcher<SourceType>;
49
+ static readonly contractMatcher: TypedMatcher<SourceType.Contract>;
50
+ static readonly interfaceMatcher: TypedMatcher<SourceType.Interface>;
51
+ static readonly scriptMatcher: TypedMatcher<SourceType.Script>;
52
+ static readonly matchers: TypedMatcher<SourceType>[];
53
+ private constructor();
54
+ private getContractPath;
55
+ private static checkCompilerWarnings;
56
+ static contract(path: string, compilerOptions?: Partial<CompilerOptions>): Contract;
57
+ static script(path: string, compilerOptions?: Partial<CompilerOptions>): Script;
58
+ private saveArtifactsToFile;
59
+ contractByCodeHash(codeHash: string): Contract;
60
+ private saveProjectArtifactToFile;
61
+ private static compile;
62
+ private static loadArtifacts;
63
+ private static loadSourceFile;
64
+ private static loadSourceFiles;
65
+ static build(contractsRootPath?: string, artifactsRootPath?: string): Promise<void>;
66
+ }
67
+ export declare abstract class Artifact {
68
+ readonly typeId: string;
69
+ readonly functions: FunctionSig[];
70
+ constructor(typeId: string, functions: FunctionSig[]);
32
71
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
72
+ publicFunctions(): string[];
73
+ usingPreapprovedAssetsFunctions(): string[];
74
+ usingAssetsInContractFunctions(): string[];
33
75
  }
34
- export declare class Contract extends Common {
76
+ export declare class Contract extends Artifact {
35
77
  readonly bytecode: string;
36
78
  readonly codeHash: string;
37
- readonly fieldsSig: node.FieldsSig;
38
- readonly eventsSig: node.EventSig[];
39
- constructor(sourceCodeSha256: string, bytecode: string, codeHash: string, fieldsSig: node.FieldsSig, eventsSig: node.EventSig[], functions: node.FunctionSig[]);
40
- static checkCodeType(fileName: string, contractStr: string): void;
41
- private static loadContractStr;
42
- static fromSource(provider: NodeProvider, path: string): Promise<Contract>;
43
- private static compile;
79
+ readonly fieldsSig: FieldsSig;
80
+ readonly eventsSig: EventSig[];
81
+ constructor(typeId: string, bytecode: string, codeHash: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
44
82
  static fromJson(artifact: any): Contract;
83
+ static fromCompileResult(typeId: string, result: CompileContractResult): Contract;
45
84
  static fromArtifactFile(path: string): Promise<Contract>;
46
- fetchState(provider: NodeProvider, address: string, group: number): Promise<ContractState>;
85
+ fetchState(address: string, group: number): Promise<ContractState>;
47
86
  toString(): string;
48
87
  toState(fields: Fields, asset: Asset, address?: string): ContractState;
49
88
  static randomAddress(): string;
50
89
  private _test;
51
- testPublicMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
52
- testPrivateMethod(provider: NodeProvider, funcName: string, params: TestContractParams): Promise<TestContractResult>;
90
+ testPublicMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
91
+ testPrivateMethod(funcName: string, params: TestContractParams): Promise<TestContractResult>;
53
92
  toApiFields(fields?: Fields): node.Val[];
54
93
  toApiArgs(funcName: string, args?: Arguments): node.Val[];
55
94
  getMethodIndex(funcName: string): number;
56
95
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
57
96
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
58
- static fromCodeHash(codeHash: string): Promise<Contract>;
59
- static getFieldsSig(state: node.ContractState): Promise<node.FieldsSig>;
60
97
  fromApiContractState(state: node.ContractState): Promise<ContractState>;
61
- static ContractCreatedEvent: node.EventSig;
62
- static ContractDestroyedEvent: node.EventSig;
98
+ static ContractCreatedEvent: EventSig;
99
+ static ContractDestroyedEvent: EventSig;
63
100
  static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
64
101
  fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
65
102
  paramsForDeployment(params: BuildDeployContractTx): Promise<SignDeployContractTxParams>;
66
103
  transactionForDeployment(signer: SignerWithNodeProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
67
104
  buildByteCodeToDeploy(initialFields: Fields): string;
68
105
  }
69
- export declare class Script extends Common {
106
+ export declare class Script extends Artifact {
70
107
  readonly bytecodeTemplate: string;
71
- readonly fieldsSig: node.FieldsSig;
72
- constructor(sourceCodeSha256: string, bytecodeTemplate: string, fieldsSig: node.FieldsSig, functions: node.FunctionSig[]);
73
- static checkCodeType(fileName: string, contractStr: string): void;
74
- private static loadContractStr;
75
- static fromSource(provider: NodeProvider, path: string): Promise<Script>;
76
- private static compile;
108
+ readonly fieldsSig: FieldsSig;
109
+ constructor(typeId: string, bytecodeTemplate: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
110
+ static fromCompileResult(typeId: string, result: CompileScriptResult): Script;
77
111
  static fromJson(artifact: any): Script;
78
112
  static fromArtifactFile(path: string): Promise<Script>;
79
113
  toString(): string;
@@ -107,7 +141,7 @@ export interface ContractState {
107
141
  initialStateHash?: string;
108
142
  codeHash: string;
109
143
  fields: Fields;
110
- fieldsSig: node.FieldsSig;
144
+ fieldsSig: FieldsSig;
111
145
  asset: Asset;
112
146
  }
113
147
  export interface TestContractParams {