@alephium/web3 0.2.0-rc.36 → 0.2.0-rc.38

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.
@@ -315,6 +315,7 @@ export interface ChangeActiveAddress {
315
315
  address: string;
316
316
  }
317
317
  export interface CompileContractResult {
318
+ version: string;
318
319
  name: string;
319
320
  bytecode: string;
320
321
  bytecodeDebugPatch: string;
@@ -332,6 +333,7 @@ export interface CompileProjectResult {
332
333
  scripts: CompileScriptResult[];
333
334
  }
334
335
  export interface CompileScriptResult {
336
+ version: string;
335
337
  name: string;
336
338
  bytecodeTemplate: string;
337
339
  bytecodeDebugPatch: string;
@@ -1364,6 +1366,18 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1364
1366
  * @request POST:/transactions/decode-unsigned-tx
1365
1367
  */
1366
1368
  postTransactionsDecodeUnsignedTx: (data: DecodeUnsignedTx, params?: RequestParams) => Promise<DecodeUnsignedTxResult>;
1369
+ /**
1370
+ * No description
1371
+ *
1372
+ * @tags Transactions
1373
+ * @name GetTransactionsDetailsTxid
1374
+ * @summary Get transaction details
1375
+ * @request GET:/transactions/details/{txId}
1376
+ */
1377
+ getTransactionsDetailsTxid: (txId: string, query?: {
1378
+ fromGroup?: number;
1379
+ toGroup?: number;
1380
+ }, params?: RequestParams) => Promise<Transaction>;
1367
1381
  /**
1368
1382
  * No description
1369
1383
  *
@@ -856,6 +856,21 @@ class Api extends HttpClient {
856
856
  format: 'json',
857
857
  ...params
858
858
  }).then(utils_1.convertHttpResponse),
859
+ /**
860
+ * No description
861
+ *
862
+ * @tags Transactions
863
+ * @name GetTransactionsDetailsTxid
864
+ * @summary Get transaction details
865
+ * @request GET:/transactions/details/{txId}
866
+ */
867
+ getTransactionsDetailsTxid: (txId, query, params = {}) => this.request({
868
+ path: `/transactions/details/${txId}`,
869
+ method: 'GET',
870
+ query: query,
871
+ format: 'json',
872
+ ...params
873
+ }).then(utils_1.convertHttpResponse),
859
874
  /**
860
875
  * No description
861
876
  *
@@ -85,16 +85,16 @@ class NodeProvider {
85
85
  else {
86
86
  nodeApi = param0;
87
87
  }
88
- this.wallets = nodeApi.wallets;
89
- this.infos = nodeApi.infos;
90
- this.blockflow = nodeApi.blockflow;
91
- this.addresses = nodeApi.addresses;
92
- this.transactions = nodeApi.transactions;
93
- this.contracts = nodeApi.contracts;
94
- this.multisig = nodeApi.multisig;
95
- this.utils = nodeApi.utils;
96
- this.miners = nodeApi.miners;
97
- this.events = nodeApi.events;
88
+ this.wallets = { ...nodeApi.wallets };
89
+ this.infos = { ...nodeApi.infos };
90
+ this.blockflow = { ...nodeApi.blockflow };
91
+ this.addresses = { ...nodeApi.addresses };
92
+ this.transactions = { ...nodeApi.transactions };
93
+ this.contracts = { ...nodeApi.contracts };
94
+ this.multisig = { ...nodeApi.multisig };
95
+ this.utils = { ...nodeApi.utils };
96
+ this.miners = { ...nodeApi.miners };
97
+ this.events = { ...nodeApi.events };
98
98
  }
99
99
  // This can prevent the proxied node provider from being modified
100
100
  static Proxy(nodeProvider) {
@@ -140,16 +140,16 @@ class ExplorerProvider {
140
140
  else {
141
141
  explorerApi = param0;
142
142
  }
143
- this.blocks = explorerApi.blocks;
144
- this.transactions = explorerApi.transactions;
145
- this.transactionByOutputRefKey = explorerApi.transactionByOutputRefKey;
146
- this.addresses = explorerApi.addresses;
147
- this.addressesActive = explorerApi.addressesActive;
148
- this.infos = explorerApi.infos;
149
- this.unconfirmedTransactions = explorerApi.unconfirmedTransactions;
150
- this.tokens = explorerApi.tokens;
151
- this.charts = explorerApi.charts;
152
- this.utils = explorerApi.utils;
143
+ this.blocks = { ...explorerApi.blocks };
144
+ this.transactions = { ...explorerApi.transactions };
145
+ this.transactionByOutputRefKey = { ...explorerApi.transactionByOutputRefKey };
146
+ this.addresses = { ...explorerApi.addresses };
147
+ this.addressesActive = { ...explorerApi.addressesActive };
148
+ this.infos = { ...explorerApi.infos };
149
+ this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions };
150
+ this.tokens = { ...explorerApi.tokens };
151
+ this.charts = { ...explorerApi.charts };
152
+ this.utils = { ...explorerApi.utils };
153
153
  }
154
154
  // This can prevent the proxied explorer provider from being modified
155
155
  static Proxy(explorerProvider) {
@@ -1,5 +1,5 @@
1
1
  import { NamedVals, node, Number256, Token, Val } from '../api';
2
- import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider } from '../signer';
2
+ import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider, SignExecuteScriptTxResult, SignDeployContractTxResult } from '../signer';
3
3
  export declare type FieldsSig = node.FieldsSig;
4
4
  export declare type EventSig = node.EventSig;
5
5
  export declare type FunctionSig = node.FunctionSig;
@@ -83,9 +83,10 @@ export declare class Project {
83
83
  static build(compilerOptionsPartial?: Partial<CompilerOptions>, contractsRootDir?: string, artifactsRootDir?: string): Promise<void>;
84
84
  }
85
85
  export declare abstract class Artifact {
86
+ readonly version: string;
86
87
  readonly name: string;
87
88
  readonly functions: FunctionSig[];
88
- constructor(name: string, functions: FunctionSig[]);
89
+ constructor(version: string, name: string, functions: FunctionSig[]);
89
90
  abstract buildByteCodeToDeploy(initialFields?: Fields): string;
90
91
  publicFunctions(): string[];
91
92
  usingPreapprovedAssetsFunctions(): string[];
@@ -99,7 +100,7 @@ export declare class Contract extends Artifact {
99
100
  readonly eventsSig: EventSig[];
100
101
  readonly bytecodeDebug: string;
101
102
  readonly codeHashDebug: string;
102
- constructor(name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
103
+ constructor(version: string, name: string, bytecode: string, bytecodeDebugPatch: string, codeHash: string, codeHashDebug: string, fieldsSig: FieldsSig, eventsSig: EventSig[], functions: FunctionSig[]);
103
104
  static fromJson(artifact: any, bytecodeDebugPatch?: string, codeHashDebug?: string): Contract;
104
105
  static fromCompileResult(result: node.CompileContractResult): Contract;
105
106
  static fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract>;
@@ -116,26 +117,26 @@ export declare class Contract extends Artifact {
116
117
  getMethodIndex(funcName: string): number;
117
118
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
118
119
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
119
- fromApiContractState(state: node.ContractState): Promise<ContractState>;
120
+ fromApiContractState(state: node.ContractState): ContractState;
120
121
  static ContractCreatedEvent: EventSig;
121
122
  static ContractDestroyedEvent: EventSig;
122
- static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
123
- fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
123
+ static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): ContractEventByTxId;
124
+ fromTestContractResult(methodIndex: number, result: node.TestContractResult): TestContractResult;
124
125
  txParamsForDeployment(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxParams>;
125
- deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
126
+ deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxResult>;
126
127
  buildByteCodeToDeploy(initialFields: Fields): string;
127
128
  }
128
129
  export declare class Script extends Artifact {
129
130
  readonly bytecodeTemplate: string;
130
131
  readonly bytecodeDebugPatch: string;
131
132
  readonly fieldsSig: FieldsSig;
132
- constructor(name: string, bytecodeTemplate: string, bytecodeDebugPatch: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
133
+ constructor(version: string, name: string, bytecodeTemplate: string, bytecodeDebugPatch: string, fieldsSig: FieldsSig, functions: FunctionSig[]);
133
134
  static fromCompileResult(result: node.CompileScriptResult): Script;
134
135
  static fromJson(artifact: any, bytecodeDebugPatch?: string): Script;
135
136
  static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
136
137
  toString(): string;
137
138
  txParamsForExecution(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxParams>;
138
- execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
139
+ execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxResult>;
139
140
  buildByteCodeToDeploy(initialFields: Fields): string;
140
141
  }
141
142
  export interface Asset {
@@ -241,7 +241,7 @@ class Project {
241
241
  return fs_2.promises.writeFile(artifactDir, compiled.artifact.toString());
242
242
  };
243
243
  for (const contract of this.contracts) {
244
- await saveToFile(contract);
244
+ saveToFile(contract);
245
245
  }
246
246
  for (const script of this.scripts) {
247
247
  await saveToFile(script);
@@ -375,7 +375,8 @@ Project.matchers = [
375
375
  Project.DEFAULT_CONTRACTS_DIR = 'contracts';
376
376
  Project.DEFAULT_ARTIFACTS_DIR = 'artifacts';
377
377
  class Artifact {
378
- constructor(name, functions) {
378
+ constructor(version, name, functions) {
379
+ this.version = version;
379
380
  this.name = name;
380
381
  this.functions = functions;
381
382
  }
@@ -391,8 +392,8 @@ class Artifact {
391
392
  }
392
393
  exports.Artifact = Artifact;
393
394
  class Contract extends Artifact {
394
- constructor(name, bytecode, bytecodeDebugPatch, codeHash, codeHashDebug, fieldsSig, eventsSig, functions) {
395
- super(name, functions);
395
+ constructor(version, name, bytecode, bytecodeDebugPatch, codeHash, codeHashDebug, fieldsSig, eventsSig, functions) {
396
+ super(version, name, functions);
396
397
  this.bytecode = bytecode;
397
398
  this.bytecodeDebugPatch = bytecodeDebugPatch;
398
399
  this.codeHash = codeHash;
@@ -403,7 +404,8 @@ class Contract extends Artifact {
403
404
  }
404
405
  // TODO: safely parse json
405
406
  static fromJson(artifact, bytecodeDebugPatch = '', codeHashDebug = '') {
406
- if (artifact.name == null ||
407
+ if (artifact.version == null ||
408
+ artifact.name == null ||
407
409
  artifact.bytecode == null ||
408
410
  artifact.codeHash == null ||
409
411
  artifact.fieldsSig == null ||
@@ -411,11 +413,11 @@ class Contract extends Artifact {
411
413
  artifact.functions == null) {
412
414
  throw Error('The artifact JSON for contract is incomplete');
413
415
  }
414
- const contract = new Contract(artifact.name, artifact.bytecode, bytecodeDebugPatch, artifact.codeHash, codeHashDebug ? codeHashDebug : artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions);
416
+ const contract = new Contract(artifact.version, artifact.name, artifact.bytecode, bytecodeDebugPatch, artifact.codeHash, codeHashDebug ? codeHashDebug : artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions);
415
417
  return contract;
416
418
  }
417
419
  static fromCompileResult(result) {
418
- return new Contract(result.name, result.bytecode, result.bytecodeDebugPatch, result.codeHash, result.codeHashDebug, result.fields, result.events, result.functions);
420
+ return new Contract(result.version, result.name, result.bytecode, result.bytecodeDebugPatch, result.codeHash, result.codeHashDebug, result.fields, result.events, result.functions);
419
421
  }
420
422
  // support both 'code.ral' and 'code.ral.json'
421
423
  static async fromArtifactFile(path, bytecodeDebugPatch, codeHashDebug) {
@@ -431,6 +433,7 @@ class Contract extends Artifact {
431
433
  }
432
434
  toString() {
433
435
  const object = {
436
+ version: this.version,
434
437
  name: this.name,
435
438
  bytecode: this.bytecode,
436
439
  codeHash: this.codeHash,
@@ -526,7 +529,7 @@ class Contract extends Artifact {
526
529
  inputAssets: toApiInputAssets(params.inputAssets)
527
530
  };
528
531
  }
529
- async fromApiContractState(state) {
532
+ fromApiContractState(state) {
530
533
  const contract = Project.currentProject.contractByCodeHash(state.codeHash);
531
534
  return {
532
535
  address: state.address,
@@ -539,7 +542,7 @@ class Contract extends Artifact {
539
542
  asset: fromApiAsset(state.asset)
540
543
  };
541
544
  }
542
- static async fromApiEvent(event, codeHash) {
545
+ static fromApiEvent(event, codeHash) {
543
546
  let eventSig;
544
547
  if (event.eventIndex == -1) {
545
548
  eventSig = this.ContractCreatedEvent;
@@ -558,7 +561,7 @@ class Contract extends Artifact {
558
561
  fields: fromApiEventFields(event.fields, eventSig)
559
562
  };
560
563
  }
561
- async fromTestContractResult(methodIndex, result) {
564
+ fromTestContractResult(methodIndex, result) {
562
565
  const addressToCodeHash = new Map();
563
566
  addressToCodeHash.set(result.address, result.codeHash);
564
567
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
@@ -567,9 +570,9 @@ class Contract extends Artifact {
567
570
  contractAddress: result.address,
568
571
  returns: (0, api_1.fromApiArray)(result.returns, this.functions[`${methodIndex}`].returnTypes),
569
572
  gasUsed: result.gasUsed,
570
- contracts: await Promise.all(result.contracts.map((contract) => this.fromApiContractState(contract))),
573
+ contracts: result.contracts.map((contract) => this.fromApiContractState(contract)),
571
574
  txOutputs: result.txOutputs.map(fromApiOutput),
572
- events: await Promise.all(result.events.map((event) => {
575
+ events: result.events.map((event) => {
573
576
  const contractAddress = event.contractAddress;
574
577
  const codeHash = addressToCodeHash.get(contractAddress);
575
578
  if (typeof codeHash !== 'undefined' || event.eventIndex < 0) {
@@ -578,7 +581,7 @@ class Contract extends Artifact {
578
581
  else {
579
582
  throw Error(`Cannot find codeHash for the contract address: ${contractAddress}`);
580
583
  }
581
- })),
584
+ }),
582
585
  debugMessages: result.debugMessages
583
586
  };
584
587
  }
@@ -615,24 +618,25 @@ Contract.ContractDestroyedEvent = {
615
618
  fieldTypes: ['Address']
616
619
  };
617
620
  class Script extends Artifact {
618
- constructor(name, bytecodeTemplate, bytecodeDebugPatch, fieldsSig, functions) {
619
- super(name, functions);
621
+ constructor(version, name, bytecodeTemplate, bytecodeDebugPatch, fieldsSig, functions) {
622
+ super(version, name, functions);
620
623
  this.bytecodeTemplate = bytecodeTemplate;
621
624
  this.bytecodeDebugPatch = bytecodeDebugPatch;
622
625
  this.fieldsSig = fieldsSig;
623
626
  }
624
627
  static fromCompileResult(result) {
625
- return new Script(result.name, result.bytecodeTemplate, result.bytecodeDebugPatch, result.fields, result.functions);
628
+ return new Script(result.version, result.name, result.bytecodeTemplate, result.bytecodeDebugPatch, result.fields, result.functions);
626
629
  }
627
630
  // TODO: safely parse json
628
631
  static fromJson(artifact, bytecodeDebugPatch = '') {
629
- if (artifact.name == null ||
632
+ if (artifact.version == null ||
633
+ artifact.name == null ||
630
634
  artifact.bytecodeTemplate == null ||
631
635
  artifact.fieldsSig == null ||
632
636
  artifact.functions == null) {
633
637
  throw Error('The artifact JSON for script is incomplete');
634
638
  }
635
- return new Script(artifact.name, artifact.bytecodeTemplate, bytecodeDebugPatch, artifact.fieldsSig, artifact.functions);
639
+ return new Script(artifact.version, artifact.name, artifact.bytecodeTemplate, bytecodeDebugPatch, artifact.fieldsSig, artifact.functions);
636
640
  }
637
641
  static async fromArtifactFile(path, bytecodeDebugPatch) {
638
642
  const content = await fs_2.promises.readFile(path);
@@ -641,6 +645,7 @@ class Script extends Artifact {
641
645
  }
642
646
  toString() {
643
647
  const object = {
648
+ version: this.version,
644
649
  name: this.name,
645
650
  bytecodeTemplate: this.bytecodeTemplate,
646
651
  fieldsSig: this.fieldsSig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.0-rc.36",
3
+ "version": "0.2.0-rc.38",
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-rc12",
30
+ "alephium_version": "1.5.0-rc13",
31
31
  "explorer_backend_version": "1.9.0-rc2"
32
32
  },
33
33
  "scripts": {
@@ -80,7 +80,7 @@
80
80
  "ts-jest": "^28.0.2",
81
81
  "ts-node": "^10.7.0",
82
82
  "tslib": "^2.3.1",
83
- "typescript": "4.7.4",
83
+ "typescript": "^4.7.4",
84
84
  "webpack": "^5.72.0",
85
85
  "webpack-cli": "^4.9.2"
86
86
  },
@@ -435,6 +435,7 @@ export interface ChangeActiveAddress {
435
435
  }
436
436
 
437
437
  export interface CompileContractResult {
438
+ version: string
438
439
  name: string
439
440
  bytecode: string
440
441
  bytecodeDebugPatch: string
@@ -456,6 +457,7 @@ export interface CompileProjectResult {
456
457
  }
457
458
 
458
459
  export interface CompileScriptResult {
460
+ version: string
459
461
  name: string
460
462
  bytecodeTemplate: string
461
463
  bytecodeDebugPatch: string
@@ -2166,6 +2168,27 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2166
2168
  ...params
2167
2169
  }).then(convertHttpResponse),
2168
2170
 
2171
+ /**
2172
+ * No description
2173
+ *
2174
+ * @tags Transactions
2175
+ * @name GetTransactionsDetailsTxid
2176
+ * @summary Get transaction details
2177
+ * @request GET:/transactions/details/{txId}
2178
+ */
2179
+ getTransactionsDetailsTxid: (
2180
+ txId: string,
2181
+ query?: { fromGroup?: number; toGroup?: number },
2182
+ params: RequestParams = {}
2183
+ ) =>
2184
+ this.request<Transaction, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2185
+ path: `/transactions/details/${txId}`,
2186
+ method: 'GET',
2187
+ query: query,
2188
+ format: 'json',
2189
+ ...params
2190
+ }).then(convertHttpResponse),
2191
+
2169
2192
  /**
2170
2193
  * No description
2171
2194
  *
package/src/api/index.ts CHANGED
@@ -78,16 +78,16 @@ export class NodeProvider {
78
78
  nodeApi = param0 as NodeProvider
79
79
  }
80
80
 
81
- this.wallets = nodeApi.wallets
82
- this.infos = nodeApi.infos
83
- this.blockflow = nodeApi.blockflow
84
- this.addresses = nodeApi.addresses
85
- this.transactions = nodeApi.transactions
86
- this.contracts = nodeApi.contracts
87
- this.multisig = nodeApi.multisig
88
- this.utils = nodeApi.utils
89
- this.miners = nodeApi.miners
90
- this.events = nodeApi.events
81
+ this.wallets = { ...nodeApi.wallets }
82
+ this.infos = { ...nodeApi.infos }
83
+ this.blockflow = { ...nodeApi.blockflow }
84
+ this.addresses = { ...nodeApi.addresses }
85
+ this.transactions = { ...nodeApi.transactions }
86
+ this.contracts = { ...nodeApi.contracts }
87
+ this.multisig = { ...nodeApi.multisig }
88
+ this.utils = { ...nodeApi.utils }
89
+ this.miners = { ...nodeApi.miners }
90
+ this.events = { ...nodeApi.events }
91
91
  }
92
92
 
93
93
  request = (args: ApiRequestArguments): Promise<any> => {
@@ -140,16 +140,16 @@ export class ExplorerProvider {
140
140
  explorerApi = param0 as ExplorerProvider
141
141
  }
142
142
 
143
- this.blocks = explorerApi.blocks
144
- this.transactions = explorerApi.transactions
145
- this.transactionByOutputRefKey = explorerApi.transactionByOutputRefKey
146
- this.addresses = explorerApi.addresses
147
- this.addressesActive = explorerApi.addressesActive
148
- this.infos = explorerApi.infos
149
- this.unconfirmedTransactions = explorerApi.unconfirmedTransactions
150
- this.tokens = explorerApi.tokens
151
- this.charts = explorerApi.charts
152
- this.utils = explorerApi.utils
143
+ this.blocks = { ...explorerApi.blocks }
144
+ this.transactions = { ...explorerApi.transactions }
145
+ this.transactionByOutputRefKey = { ...explorerApi.transactionByOutputRefKey }
146
+ this.addresses = { ...explorerApi.addresses }
147
+ this.addressesActive = { ...explorerApi.addressesActive }
148
+ this.infos = { ...explorerApi.infos }
149
+ this.unconfirmedTransactions = { ...explorerApi.unconfirmedTransactions }
150
+ this.tokens = { ...explorerApi.tokens }
151
+ this.charts = { ...explorerApi.charts }
152
+ this.utils = { ...explorerApi.utils }
153
153
  }
154
154
 
155
155
  request = (args: ApiRequestArguments): Promise<any> => {
@@ -35,7 +35,13 @@ import {
35
35
  fromApiTokens,
36
36
  fromApiVals
37
37
  } from '../api'
38
- import { SignDeployContractTxParams, SignExecuteScriptTxParams, SignerProvider } from '../signer'
38
+ import {
39
+ SignDeployContractTxParams,
40
+ SignExecuteScriptTxParams,
41
+ SignerProvider,
42
+ SignExecuteScriptTxResult,
43
+ SignDeployContractTxResult
44
+ } from '../signer'
39
45
  import * as ralph from './ralph'
40
46
  import { bs58, binToHex, contractIdFromAddress, assertType, Eq } from '../utils'
41
47
  import { getCurrentNodeProvider } from '../global'
@@ -320,7 +326,7 @@ export class Project {
320
326
  return fsPromises.writeFile(artifactDir, compiled.artifact.toString())
321
327
  }
322
328
  for (const contract of this.contracts) {
323
- await saveToFile(contract)
329
+ saveToFile(contract)
324
330
  }
325
331
  for (const script of this.scripts) {
326
332
  await saveToFile(script)
@@ -503,10 +509,12 @@ export class Project {
503
509
  }
504
510
 
505
511
  export abstract class Artifact {
512
+ readonly version: string
506
513
  readonly name: string
507
514
  readonly functions: FunctionSig[]
508
515
 
509
- constructor(name: string, functions: FunctionSig[]) {
516
+ constructor(version: string, name: string, functions: FunctionSig[]) {
517
+ this.version = version
510
518
  this.name = name
511
519
  this.functions = functions
512
520
  }
@@ -537,6 +545,7 @@ export class Contract extends Artifact {
537
545
  readonly codeHashDebug: string
538
546
 
539
547
  constructor(
548
+ version: string,
540
549
  name: string,
541
550
  bytecode: string,
542
551
  bytecodeDebugPatch: string,
@@ -546,7 +555,7 @@ export class Contract extends Artifact {
546
555
  eventsSig: EventSig[],
547
556
  functions: FunctionSig[]
548
557
  ) {
549
- super(name, functions)
558
+ super(version, name, functions)
550
559
  this.bytecode = bytecode
551
560
  this.bytecodeDebugPatch = bytecodeDebugPatch
552
561
  this.codeHash = codeHash
@@ -560,6 +569,7 @@ export class Contract extends Artifact {
560
569
  // TODO: safely parse json
561
570
  static fromJson(artifact: any, bytecodeDebugPatch = '', codeHashDebug = ''): Contract {
562
571
  if (
572
+ artifact.version == null ||
563
573
  artifact.name == null ||
564
574
  artifact.bytecode == null ||
565
575
  artifact.codeHash == null ||
@@ -570,6 +580,7 @@ export class Contract extends Artifact {
570
580
  throw Error('The artifact JSON for contract is incomplete')
571
581
  }
572
582
  const contract = new Contract(
583
+ artifact.version,
573
584
  artifact.name,
574
585
  artifact.bytecode,
575
586
  bytecodeDebugPatch,
@@ -584,6 +595,7 @@ export class Contract extends Artifact {
584
595
 
585
596
  static fromCompileResult(result: node.CompileContractResult): Contract {
586
597
  return new Contract(
598
+ result.version,
587
599
  result.name,
588
600
  result.bytecode,
589
601
  result.bytecodeDebugPatch,
@@ -611,6 +623,7 @@ export class Contract extends Artifact {
611
623
 
612
624
  override toString(): string {
613
625
  const object = {
626
+ version: this.version,
614
627
  name: this.name,
615
628
  bytecode: this.bytecode,
616
629
  codeHash: this.codeHash,
@@ -732,7 +745,7 @@ export class Contract extends Artifact {
732
745
  }
733
746
  }
734
747
 
735
- async fromApiContractState(state: node.ContractState): Promise<ContractState> {
748
+ fromApiContractState(state: node.ContractState): ContractState {
736
749
  const contract = Project.currentProject.contractByCodeHash(state.codeHash)
737
750
  return {
738
751
  address: state.address,
@@ -758,10 +771,7 @@ export class Contract extends Artifact {
758
771
  fieldTypes: ['Address']
759
772
  }
760
773
 
761
- static async fromApiEvent(
762
- event: node.ContractEventByTxId,
763
- codeHash: string | undefined
764
- ): Promise<ContractEventByTxId> {
774
+ static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): ContractEventByTxId {
765
775
  let eventSig: EventSig
766
776
 
767
777
  if (event.eventIndex == -1) {
@@ -781,7 +791,7 @@ export class Contract extends Artifact {
781
791
  }
782
792
  }
783
793
 
784
- async fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult> {
794
+ fromTestContractResult(methodIndex: number, result: node.TestContractResult): TestContractResult {
785
795
  const addressToCodeHash = new Map<string, string>()
786
796
  addressToCodeHash.set(result.address, result.codeHash)
787
797
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
@@ -790,19 +800,17 @@ export class Contract extends Artifact {
790
800
  contractAddress: result.address,
791
801
  returns: fromApiArray(result.returns, this.functions[`${methodIndex}`].returnTypes),
792
802
  gasUsed: result.gasUsed,
793
- contracts: await Promise.all(result.contracts.map((contract) => this.fromApiContractState(contract))),
803
+ contracts: result.contracts.map((contract) => this.fromApiContractState(contract)),
794
804
  txOutputs: result.txOutputs.map(fromApiOutput),
795
- events: await Promise.all(
796
- result.events.map((event) => {
797
- const contractAddress = event.contractAddress
798
- const codeHash = addressToCodeHash.get(contractAddress)
799
- if (typeof codeHash !== 'undefined' || event.eventIndex < 0) {
800
- return Contract.fromApiEvent(event, codeHash)
801
- } else {
802
- throw Error(`Cannot find codeHash for the contract address: ${contractAddress}`)
803
- }
804
- })
805
- ),
805
+ events: result.events.map((event) => {
806
+ const contractAddress = event.contractAddress
807
+ const codeHash = addressToCodeHash.get(contractAddress)
808
+ if (typeof codeHash !== 'undefined' || event.eventIndex < 0) {
809
+ return Contract.fromApiEvent(event, codeHash)
810
+ } else {
811
+ throw Error(`Cannot find codeHash for the contract address: ${contractAddress}`)
812
+ }
813
+ }),
806
814
  debugMessages: result.debugMessages
807
815
  }
808
816
  }
@@ -827,7 +835,7 @@ export class Contract extends Artifact {
827
835
  async deploy(
828
836
  signer: SignerProvider,
829
837
  params: Omit<BuildDeployContractTx, 'signerAddress'>
830
- ): Promise<DeployContractTransaction> {
838
+ ): Promise<SignDeployContractTxResult> {
831
839
  const signerParams = await this.txParamsForDeployment(signer, params)
832
840
  return signer.signAndSubmitDeployContractTx(signerParams)
833
841
  }
@@ -843,25 +851,34 @@ export class Script extends Artifact {
843
851
  readonly fieldsSig: FieldsSig
844
852
 
845
853
  constructor(
854
+ version: string,
846
855
  name: string,
847
856
  bytecodeTemplate: string,
848
857
  bytecodeDebugPatch: string,
849
858
  fieldsSig: FieldsSig,
850
859
  functions: FunctionSig[]
851
860
  ) {
852
- super(name, functions)
861
+ super(version, name, functions)
853
862
  this.bytecodeTemplate = bytecodeTemplate
854
863
  this.bytecodeDebugPatch = bytecodeDebugPatch
855
864
  this.fieldsSig = fieldsSig
856
865
  }
857
866
 
858
867
  static fromCompileResult(result: node.CompileScriptResult): Script {
859
- return new Script(result.name, result.bytecodeTemplate, result.bytecodeDebugPatch, result.fields, result.functions)
868
+ return new Script(
869
+ result.version,
870
+ result.name,
871
+ result.bytecodeTemplate,
872
+ result.bytecodeDebugPatch,
873
+ result.fields,
874
+ result.functions
875
+ )
860
876
  }
861
877
 
862
878
  // TODO: safely parse json
863
879
  static fromJson(artifact: any, bytecodeDebugPatch = ''): Script {
864
880
  if (
881
+ artifact.version == null ||
865
882
  artifact.name == null ||
866
883
  artifact.bytecodeTemplate == null ||
867
884
  artifact.fieldsSig == null ||
@@ -870,6 +887,7 @@ export class Script extends Artifact {
870
887
  throw Error('The artifact JSON for script is incomplete')
871
888
  }
872
889
  return new Script(
890
+ artifact.version,
873
891
  artifact.name,
874
892
  artifact.bytecodeTemplate,
875
893
  bytecodeDebugPatch,
@@ -886,6 +904,7 @@ export class Script extends Artifact {
886
904
 
887
905
  override toString(): string {
888
906
  const object = {
907
+ version: this.version,
889
908
  name: this.name,
890
909
  bytecodeTemplate: this.bytecodeTemplate,
891
910
  fieldsSig: this.fieldsSig,
@@ -912,7 +931,7 @@ export class Script extends Artifact {
912
931
  async execute(
913
932
  signer: SignerProvider,
914
933
  params: Omit<BuildExecuteScriptTx, 'signerAddress'>
915
- ): Promise<BuildScriptTxResult> {
934
+ ): Promise<SignExecuteScriptTxResult> {
916
935
  const signerParams = await this.txParamsForExecution(signer, params)
917
936
  return await signer.signAndSubmitExecuteScriptTx(signerParams)
918
937
  }