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

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.
@@ -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;
@@ -116,13 +116,13 @@ export declare class Contract extends Artifact {
116
116
  getMethodIndex(funcName: string): number;
117
117
  toApiContractStates(states?: ContractState[]): node.ContractState[] | undefined;
118
118
  toTestContract(funcName: string, params: TestContractParams): node.TestContract;
119
- fromApiContractState(state: node.ContractState): Promise<ContractState>;
119
+ fromApiContractState(state: node.ContractState): ContractState;
120
120
  static ContractCreatedEvent: EventSig;
121
121
  static ContractDestroyedEvent: EventSig;
122
- static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): Promise<ContractEventByTxId>;
123
- fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult>;
122
+ static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): ContractEventByTxId;
123
+ fromTestContractResult(methodIndex: number, result: node.TestContractResult): TestContractResult;
124
124
  txParamsForDeployment(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxParams>;
125
- deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<DeployContractTransaction>;
125
+ deploy(signer: SignerProvider, params: Omit<BuildDeployContractTx, 'signerAddress'>): Promise<SignDeployContractTxResult>;
126
126
  buildByteCodeToDeploy(initialFields: Fields): string;
127
127
  }
128
128
  export declare class Script extends Artifact {
@@ -135,7 +135,7 @@ export declare class Script extends Artifact {
135
135
  static fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script>;
136
136
  toString(): string;
137
137
  txParamsForExecution(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxParams>;
138
- execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<BuildScriptTxResult>;
138
+ execute(signer: SignerProvider, params: Omit<BuildExecuteScriptTx, 'signerAddress'>): Promise<SignExecuteScriptTxResult>;
139
139
  buildByteCodeToDeploy(initialFields: Fields): string;
140
140
  }
141
141
  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);
@@ -526,7 +526,7 @@ class Contract extends Artifact {
526
526
  inputAssets: toApiInputAssets(params.inputAssets)
527
527
  };
528
528
  }
529
- async fromApiContractState(state) {
529
+ fromApiContractState(state) {
530
530
  const contract = Project.currentProject.contractByCodeHash(state.codeHash);
531
531
  return {
532
532
  address: state.address,
@@ -539,7 +539,7 @@ class Contract extends Artifact {
539
539
  asset: fromApiAsset(state.asset)
540
540
  };
541
541
  }
542
- static async fromApiEvent(event, codeHash) {
542
+ static fromApiEvent(event, codeHash) {
543
543
  let eventSig;
544
544
  if (event.eventIndex == -1) {
545
545
  eventSig = this.ContractCreatedEvent;
@@ -558,7 +558,7 @@ class Contract extends Artifact {
558
558
  fields: fromApiEventFields(event.fields, eventSig)
559
559
  };
560
560
  }
561
- async fromTestContractResult(methodIndex, result) {
561
+ fromTestContractResult(methodIndex, result) {
562
562
  const addressToCodeHash = new Map();
563
563
  addressToCodeHash.set(result.address, result.codeHash);
564
564
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash));
@@ -567,9 +567,9 @@ class Contract extends Artifact {
567
567
  contractAddress: result.address,
568
568
  returns: (0, api_1.fromApiArray)(result.returns, this.functions[`${methodIndex}`].returnTypes),
569
569
  gasUsed: result.gasUsed,
570
- contracts: await Promise.all(result.contracts.map((contract) => this.fromApiContractState(contract))),
570
+ contracts: result.contracts.map((contract) => this.fromApiContractState(contract)),
571
571
  txOutputs: result.txOutputs.map(fromApiOutput),
572
- events: await Promise.all(result.events.map((event) => {
572
+ events: result.events.map((event) => {
573
573
  const contractAddress = event.contractAddress;
574
574
  const codeHash = addressToCodeHash.get(contractAddress);
575
575
  if (typeof codeHash !== 'undefined' || event.eventIndex < 0) {
@@ -578,7 +578,7 @@ class Contract extends Artifact {
578
578
  else {
579
579
  throw Error(`Cannot find codeHash for the contract address: ${contractAddress}`);
580
580
  }
581
- })),
581
+ }),
582
582
  debugMessages: result.debugMessages
583
583
  };
584
584
  }
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.37",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -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)
@@ -732,7 +738,7 @@ export class Contract extends Artifact {
732
738
  }
733
739
  }
734
740
 
735
- async fromApiContractState(state: node.ContractState): Promise<ContractState> {
741
+ fromApiContractState(state: node.ContractState): ContractState {
736
742
  const contract = Project.currentProject.contractByCodeHash(state.codeHash)
737
743
  return {
738
744
  address: state.address,
@@ -758,10 +764,7 @@ export class Contract extends Artifact {
758
764
  fieldTypes: ['Address']
759
765
  }
760
766
 
761
- static async fromApiEvent(
762
- event: node.ContractEventByTxId,
763
- codeHash: string | undefined
764
- ): Promise<ContractEventByTxId> {
767
+ static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined): ContractEventByTxId {
765
768
  let eventSig: EventSig
766
769
 
767
770
  if (event.eventIndex == -1) {
@@ -781,7 +784,7 @@ export class Contract extends Artifact {
781
784
  }
782
785
  }
783
786
 
784
- async fromTestContractResult(methodIndex: number, result: node.TestContractResult): Promise<TestContractResult> {
787
+ fromTestContractResult(methodIndex: number, result: node.TestContractResult): TestContractResult {
785
788
  const addressToCodeHash = new Map<string, string>()
786
789
  addressToCodeHash.set(result.address, result.codeHash)
787
790
  result.contracts.forEach((contract) => addressToCodeHash.set(contract.address, contract.codeHash))
@@ -790,19 +793,17 @@ export class Contract extends Artifact {
790
793
  contractAddress: result.address,
791
794
  returns: fromApiArray(result.returns, this.functions[`${methodIndex}`].returnTypes),
792
795
  gasUsed: result.gasUsed,
793
- contracts: await Promise.all(result.contracts.map((contract) => this.fromApiContractState(contract))),
796
+ contracts: result.contracts.map((contract) => this.fromApiContractState(contract)),
794
797
  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
- ),
798
+ events: result.events.map((event) => {
799
+ const contractAddress = event.contractAddress
800
+ const codeHash = addressToCodeHash.get(contractAddress)
801
+ if (typeof codeHash !== 'undefined' || event.eventIndex < 0) {
802
+ return Contract.fromApiEvent(event, codeHash)
803
+ } else {
804
+ throw Error(`Cannot find codeHash for the contract address: ${contractAddress}`)
805
+ }
806
+ }),
806
807
  debugMessages: result.debugMessages
807
808
  }
808
809
  }
@@ -827,7 +828,7 @@ export class Contract extends Artifact {
827
828
  async deploy(
828
829
  signer: SignerProvider,
829
830
  params: Omit<BuildDeployContractTx, 'signerAddress'>
830
- ): Promise<DeployContractTransaction> {
831
+ ): Promise<SignDeployContractTxResult> {
831
832
  const signerParams = await this.txParamsForDeployment(signer, params)
832
833
  return signer.signAndSubmitDeployContractTx(signerParams)
833
834
  }
@@ -912,7 +913,7 @@ export class Script extends Artifact {
912
913
  async execute(
913
914
  signer: SignerProvider,
914
915
  params: Omit<BuildExecuteScriptTx, 'signerAddress'>
915
- ): Promise<BuildScriptTxResult> {
916
+ ): Promise<SignExecuteScriptTxResult> {
916
917
  const signerParams = await this.txParamsForExecution(signer, params)
917
918
  return await signer.signAndSubmitExecuteScriptTx(signerParams)
918
919
  }