@alephium/web3 0.12.0-test.2 → 0.12.0

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.
@@ -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.1
941
+ * @version 2.3.2
928
942
  * @baseUrl ../
929
943
  */
930
944
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 2.3.1
154
+ * @version 2.3.2
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -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
- return path.join(artifactsRootDir, externalPath) + '.json';
99
+ fullPath = path.join(artifactsRootDir, externalPath);
99
100
  }
100
- return path.join(artifactsRootDir, this.contractRelativePath) + '.json';
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 sourceStr = sourceInfos.map((f) => f.sourceCode).join('\n');
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, index) => {
296
- const sourceInfo = sourceInfos[`${index}`];
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, index) => {
301
- const sourceInfo = sourceInfos[index + contracts.size];
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.0-test.2",
3
+ "version": "0.12.0",
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.1",
30
+ "alephium_version": "2.3.2",
31
31
  "explorer_backend_version": "1.13.5"
32
32
  },
33
33
  "type": "commonjs",
@@ -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.1
1231
+ * @version 2.3.2
1215
1232
  * @baseUrl ../
1216
1233
  */
1217
1234
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -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
- return path.join(artifactsRootDir, externalPath) + '.json'
132
+ fullPath = path.join(artifactsRootDir, externalPath)
133
+ } else {
134
+ fullPath = path.join(artifactsRootDir, this.contractRelativePath)
130
135
  }
131
- return path.join(artifactsRootDir, this.contractRelativePath) + '.json'
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 sourceStr = sourceInfos.map((f) => f.sourceCode).join('\n')
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, index) => {
429
- const sourceInfo = sourceInfos[`${index}`]
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, index) => {
434
- const sourceInfo = sourceInfos[index + contracts.size]
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