@alephium/web3 1.2.3 → 1.3.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.
@@ -451,6 +451,9 @@ export interface CompileProjectResult {
451
451
  contracts: CompileContractResult[];
452
452
  scripts: CompileScriptResult[];
453
453
  structs?: StructSig[];
454
+ constants?: Constant[];
455
+ enums?: Enum[];
456
+ warnings?: string[];
454
457
  }
455
458
  /** CompileScriptResult */
456
459
  export interface CompileScriptResult {
@@ -566,6 +569,11 @@ export interface ContractState {
566
569
  mutFields: Val[];
567
570
  asset: AssetState;
568
571
  }
572
+ /** CurrentDifficulty */
573
+ export interface CurrentDifficulty {
574
+ /** @format bigint */
575
+ difficulty: string;
576
+ }
569
577
  /** DebugMessage */
570
578
  export interface DebugMessage {
571
579
  /** @format address */
@@ -659,6 +667,10 @@ export interface Group {
659
667
  /** @format int32 */
660
668
  group: number;
661
669
  }
670
+ /** HashRateResponse */
671
+ export interface HashRateResponse {
672
+ hashrate: string;
673
+ }
662
674
  /** HashesAtHeight */
663
675
  export interface HashesAtHeight {
664
676
  headers: string[];
@@ -1179,7 +1191,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
1179
1191
  }
1180
1192
  /**
1181
1193
  * @title Alephium API
1182
- * @version 3.3.0
1194
+ * @version 3.4.0
1183
1195
  * @baseUrl ../
1184
1196
  */
1185
1197
  export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -1469,7 +1481,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1469
1481
  * @min 0
1470
1482
  */
1471
1483
  toTs?: number;
1472
- }, params?: RequestParams) => Promise<string>;
1484
+ }, params?: RequestParams) => Promise<HashRateResponse>;
1473
1485
  /**
1474
1486
  * No description
1475
1487
  *
@@ -1484,7 +1496,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1484
1496
  * @min 1
1485
1497
  */
1486
1498
  timespan?: number;
1487
- }, params?: RequestParams) => Promise<string>;
1499
+ }, params?: RequestParams) => Promise<HashRateResponse>;
1488
1500
  /**
1489
1501
  * No description
1490
1502
  *
@@ -1493,7 +1505,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
1493
1505
  * @summary Get the average difficulty of the latest blocks from all shards
1494
1506
  * @request GET:/infos/current-difficulty
1495
1507
  */
1496
- getInfosCurrentDifficulty: (params?: RequestParams) => Promise<string>;
1508
+ getInfosCurrentDifficulty: (params?: RequestParams) => Promise<CurrentDifficulty>;
1497
1509
  };
1498
1510
  blockflow: {
1499
1511
  /**
@@ -151,7 +151,7 @@ class HttpClient {
151
151
  exports.HttpClient = HttpClient;
152
152
  /**
153
153
  * @title Alephium API
154
- * @version 3.3.0
154
+ * @version 3.4.0
155
155
  * @baseUrl ../
156
156
  */
157
157
  class Api extends HttpClient {
@@ -288,7 +288,7 @@ export declare function subscribeContractEvent<F extends Fields, M extends Contr
288
288
  export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
289
289
  export declare function callMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<CallContractParams<A>, 'args'>, getContractByCodeHash: (codeHash: string) => Contract): Promise<CallContractResult<R>>;
290
290
  export declare function signExecuteMethod<I extends ContractInstance, F extends Fields, A extends Arguments, R>(contract: ContractFactory<I, F>, instance: ContractInstance, methodName: string, params: Optional<SignExecuteContractMethodParams<A>, 'args'>): Promise<SignExecuteScriptTxResult>;
291
- export declare function multicallMethods<I extends ContractInstance, F extends Fields>(contract: ContractFactory<I, F>, instance: ContractInstance, calls: Record<string, Optional<CallContractParams<any>, 'args'>>, getContractByCodeHash: (codeHash: string) => Contract): Promise<Record<string, CallContractResult<any>>>;
291
+ export declare function multicallMethods<I extends ContractInstance, F extends Fields>(contract: ContractFactory<I, F>, instance: ContractInstance, callss: Record<string, Optional<CallContractParams<any>, 'args'>>[], getContractByCodeHash: (codeHash: string) => Contract): Promise<Record<string, CallContractResult<any>>[] | Record<string, CallContractResult<any>>>;
292
292
  export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
293
293
  export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
294
294
  export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
@@ -1241,23 +1241,31 @@ function toFieldsSig(contractName, functionSig) {
1241
1241
  isMutable: [false].concat(functionSig.paramIsMutable)
1242
1242
  };
1243
1243
  }
1244
- async function multicallMethods(contract, instance, calls, getContractByCodeHash) {
1245
- const callEntries = Object.entries(calls);
1246
- const callsParams = callEntries.map((entry) => {
1247
- const [methodName, params] = entry;
1248
- const methodIndex = contract.contract.getMethodIndex(methodName);
1249
- const txId = params?.txId ?? randomTxId();
1250
- return contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
1244
+ async function multicallMethods(contract, instance, callss, getContractByCodeHash) {
1245
+ const callEntries = callss.map((calls) => Object.entries(calls));
1246
+ const callsParams = callEntries.map((entries) => {
1247
+ return entries.map((entry) => {
1248
+ const [methodName, params] = entry;
1249
+ const methodIndex = contract.contract.getMethodIndex(methodName);
1250
+ const txId = params?.txId ?? randomTxId();
1251
+ return contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
1252
+ });
1251
1253
  });
1252
- const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams });
1253
- const callsResult = {};
1254
- callsParams.forEach((call, index) => {
1255
- const methodIndex = call.methodIndex;
1256
- const callResult = result.results[`${methodIndex}`];
1257
- const methodName = callEntries[`${index}`][`0`];
1258
- callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(callResult, call.txId, methodIndex, getContractByCodeHash);
1254
+ const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams.flat() });
1255
+ let callResultIndex = 0;
1256
+ const results = callsParams.map((calls, index0) => {
1257
+ const callsResult = {};
1258
+ const entries = callEntries[`${index0}`];
1259
+ calls.forEach((call, index1) => {
1260
+ const methodIndex = call.methodIndex;
1261
+ const callResult = result.results[`${callResultIndex}`];
1262
+ const methodName = entries[`${index1}`][`0`];
1263
+ callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(callResult, call.txId, methodIndex, getContractByCodeHash);
1264
+ callResultIndex += 1;
1265
+ });
1266
+ return callsResult;
1259
1267
  });
1260
- return callsResult;
1268
+ return results.length === 1 ? results[0] : results;
1261
1269
  }
1262
1270
  exports.multicallMethods = multicallMethods;
1263
1271
  async function getContractEventsCurrentCount(contractAddress) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "1.2.3",
3
+ "version": "1.3.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",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "author": "Alephium dev <dev@alephium.org>",
35
35
  "config": {
36
- "alephium_version": "3.3.0",
36
+ "alephium_version": "3.4.0",
37
37
  "explorer_backend_version": "2.0.0"
38
38
  },
39
39
  "type": "commonjs",
@@ -503,6 +503,9 @@ export interface CompileProjectResult {
503
503
  contracts: CompileContractResult[]
504
504
  scripts: CompileScriptResult[]
505
505
  structs?: StructSig[]
506
+ constants?: Constant[]
507
+ enums?: Enum[]
508
+ warnings?: string[]
506
509
  }
507
510
 
508
511
  /** CompileScriptResult */
@@ -632,6 +635,12 @@ export interface ContractState {
632
635
  asset: AssetState
633
636
  }
634
637
 
638
+ /** CurrentDifficulty */
639
+ export interface CurrentDifficulty {
640
+ /** @format bigint */
641
+ difficulty: string
642
+ }
643
+
635
644
  /** DebugMessage */
636
645
  export interface DebugMessage {
637
646
  /** @format address */
@@ -738,6 +747,11 @@ export interface Group {
738
747
  group: number
739
748
  }
740
749
 
750
+ /** HashRateResponse */
751
+ export interface HashRateResponse {
752
+ hashrate: string
753
+ }
754
+
741
755
  /** HashesAtHeight */
742
756
  export interface HashesAtHeight {
743
757
  headers: string[]
@@ -1481,7 +1495,7 @@ export class HttpClient<SecurityDataType = unknown> {
1481
1495
 
1482
1496
  /**
1483
1497
  * @title Alephium API
1484
- * @version 3.3.0
1498
+ * @version 3.4.0
1485
1499
  * @baseUrl ../
1486
1500
  */
1487
1501
  export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
@@ -2019,7 +2033,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2019
2033
  },
2020
2034
  params: RequestParams = {}
2021
2035
  ) =>
2022
- this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2036
+ this.request<HashRateResponse, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2023
2037
  path: `/infos/history-hashrate`,
2024
2038
  method: 'GET',
2025
2039
  query: query,
@@ -2045,7 +2059,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2045
2059
  },
2046
2060
  params: RequestParams = {}
2047
2061
  ) =>
2048
- this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2062
+ this.request<HashRateResponse, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2049
2063
  path: `/infos/current-hashrate`,
2050
2064
  method: 'GET',
2051
2065
  query: query,
@@ -2062,7 +2076,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
2062
2076
  * @request GET:/infos/current-difficulty
2063
2077
  */
2064
2078
  getInfosCurrentDifficulty: (params: RequestParams = {}) =>
2065
- this.request<string, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2079
+ this.request<CurrentDifficulty, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
2066
2080
  path: `/infos/current-difficulty`,
2067
2081
  method: 'GET',
2068
2082
  format: 'json',
@@ -1921,35 +1921,43 @@ function toFieldsSig(contractName: string, functionSig: FunctionSig): FieldsSig
1921
1921
  export async function multicallMethods<I extends ContractInstance, F extends Fields>(
1922
1922
  contract: ContractFactory<I, F>,
1923
1923
  instance: ContractInstance,
1924
- calls: Record<string, Optional<CallContractParams<any>, 'args'>>,
1924
+ callss: Record<string, Optional<CallContractParams<any>, 'args'>>[],
1925
1925
  getContractByCodeHash: (codeHash: string) => Contract
1926
- ): Promise<Record<string, CallContractResult<any>>> {
1927
- const callEntries = Object.entries(calls)
1928
- const callsParams = callEntries.map((entry) => {
1929
- const [methodName, params] = entry
1930
- const methodIndex = contract.contract.getMethodIndex(methodName)
1931
- const txId = params?.txId ?? randomTxId()
1932
- return contract.contract.toApiCallContract(
1933
- { ...params, txId: txId, args: params.args === undefined ? {} : params.args },
1934
- instance.groupIndex,
1935
- instance.address,
1936
- methodIndex
1937
- )
1926
+ ): Promise<Record<string, CallContractResult<any>>[] | Record<string, CallContractResult<any>>> {
1927
+ const callEntries = callss.map((calls) => Object.entries(calls))
1928
+ const callsParams = callEntries.map((entries) => {
1929
+ return entries.map((entry) => {
1930
+ const [methodName, params] = entry
1931
+ const methodIndex = contract.contract.getMethodIndex(methodName)
1932
+ const txId = params?.txId ?? randomTxId()
1933
+ return contract.contract.toApiCallContract(
1934
+ { ...params, txId: txId, args: params.args === undefined ? {} : params.args },
1935
+ instance.groupIndex,
1936
+ instance.address,
1937
+ methodIndex
1938
+ )
1939
+ })
1938
1940
  })
1939
- const result = await getCurrentNodeProvider().contracts.postContractsMulticallContract({ calls: callsParams })
1940
- const callsResult: Record<string, CallContractResult<any>> = {}
1941
- callsParams.forEach((call, index) => {
1942
- const methodIndex = call.methodIndex
1943
- const callResult = result.results[`${methodIndex}`]
1944
- const methodName = callEntries[`${index}`][`0`]
1945
- callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(
1946
- callResult,
1947
- call.txId!,
1948
- methodIndex,
1949
- getContractByCodeHash
1950
- ) as CallContractResult<any>
1941
+ const result = await getCurrentNodeProvider().contracts.postContractsMulticallContract({ calls: callsParams.flat() })
1942
+ let callResultIndex = 0
1943
+ const results = callsParams.map((calls, index0) => {
1944
+ const callsResult: Record<string, CallContractResult<any>> = {}
1945
+ const entries = callEntries[`${index0}`]
1946
+ calls.forEach((call, index1) => {
1947
+ const methodIndex = call.methodIndex
1948
+ const callResult = result.results[`${callResultIndex}`]
1949
+ const methodName = entries[`${index1}`][`0`]
1950
+ callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(
1951
+ callResult,
1952
+ call.txId!,
1953
+ methodIndex,
1954
+ getContractByCodeHash
1955
+ ) as CallContractResult<any>
1956
+ callResultIndex += 1
1957
+ })
1958
+ return callsResult
1951
1959
  })
1952
- return callsResult
1960
+ return results.length === 1 ? results[0] : results
1953
1961
  }
1954
1962
 
1955
1963
  export async function getContractEventsCurrentCount(contractAddress: Address): Promise<number> {