@alephium/web3 1.2.4 → 1.4.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.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/address/address.js +6 -0
- package/dist/src/api/api-alephium.d.ts +17 -7
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/contract/contract.d.ts +2 -1
- package/dist/src/contract/contract.js +37 -22
- package/package.json +2 -2
- package/src/address/address.ts +7 -1
- package/src/api/api-alephium.ts +19 -7
- package/src/contract/contract.ts +49 -33
|
@@ -214,6 +214,12 @@ function subContractId(parentContractId, pathInHex, group) {
|
|
|
214
214
|
if (group < 0 || group >= constants_1.TOTAL_NUMBER_OF_GROUPS) {
|
|
215
215
|
throw new Error(`Invalid group ${group}`);
|
|
216
216
|
}
|
|
217
|
+
if (!(0, utils_1.isHexString)(parentContractId)) {
|
|
218
|
+
throw new Error(`Invalid parent contract ID: ${parentContractId}, expected hex string`);
|
|
219
|
+
}
|
|
220
|
+
if (!(0, utils_1.isHexString)(pathInHex)) {
|
|
221
|
+
throw new Error(`Invalid path: ${pathInHex}, expected hex string`);
|
|
222
|
+
}
|
|
217
223
|
const data = (0, utils_1.concatBytes)([(0, utils_1.hexToBinUnsafe)(parentContractId), (0, utils_1.hexToBinUnsafe)(pathInHex)]);
|
|
218
224
|
const bytes = new Uint8Array([
|
|
219
225
|
...blakejs_1.default.blake2b(blakejs_1.default.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
|
|
@@ -10,7 +10,6 @@ export interface AddressBalance {
|
|
|
10
10
|
lockedBalance: string;
|
|
11
11
|
/** @format x.x ALPH */
|
|
12
12
|
lockedBalanceHint: string;
|
|
13
|
-
warning?: string;
|
|
14
13
|
}
|
|
15
14
|
/** AddressInfo */
|
|
16
15
|
export interface AddressInfo {
|
|
@@ -75,7 +74,6 @@ export interface Balance {
|
|
|
75
74
|
lockedTokenBalances?: Token[];
|
|
76
75
|
/** @format int32 */
|
|
77
76
|
utxoNum: number;
|
|
78
|
-
warning?: string;
|
|
79
77
|
}
|
|
80
78
|
/** Balances */
|
|
81
79
|
export interface Balances {
|
|
@@ -451,6 +449,9 @@ export interface CompileProjectResult {
|
|
|
451
449
|
contracts: CompileContractResult[];
|
|
452
450
|
scripts: CompileScriptResult[];
|
|
453
451
|
structs?: StructSig[];
|
|
452
|
+
constants?: Constant[];
|
|
453
|
+
enums?: Enum[];
|
|
454
|
+
warnings?: string[];
|
|
454
455
|
}
|
|
455
456
|
/** CompileScriptResult */
|
|
456
457
|
export interface CompileScriptResult {
|
|
@@ -470,6 +471,7 @@ export interface CompilerOptions {
|
|
|
470
471
|
ignoreUnusedPrivateFunctionsWarnings?: boolean;
|
|
471
472
|
ignoreUpdateFieldsCheckWarnings?: boolean;
|
|
472
473
|
ignoreCheckExternalCallerWarnings?: boolean;
|
|
474
|
+
ignoreUnusedFunctionReturnWarnings?: boolean;
|
|
473
475
|
}
|
|
474
476
|
/** Confirmed */
|
|
475
477
|
export interface Confirmed {
|
|
@@ -566,6 +568,11 @@ export interface ContractState {
|
|
|
566
568
|
mutFields: Val[];
|
|
567
569
|
asset: AssetState;
|
|
568
570
|
}
|
|
571
|
+
/** CurrentDifficulty */
|
|
572
|
+
export interface CurrentDifficulty {
|
|
573
|
+
/** @format bigint */
|
|
574
|
+
difficulty: string;
|
|
575
|
+
}
|
|
569
576
|
/** DebugMessage */
|
|
570
577
|
export interface DebugMessage {
|
|
571
578
|
/** @format address */
|
|
@@ -659,6 +666,10 @@ export interface Group {
|
|
|
659
666
|
/** @format int32 */
|
|
660
667
|
group: number;
|
|
661
668
|
}
|
|
669
|
+
/** HashRateResponse */
|
|
670
|
+
export interface HashRateResponse {
|
|
671
|
+
hashrate: string;
|
|
672
|
+
}
|
|
662
673
|
/** HashesAtHeight */
|
|
663
674
|
export interface HashesAtHeight {
|
|
664
675
|
headers: string[];
|
|
@@ -1003,7 +1014,6 @@ export interface UTXO {
|
|
|
1003
1014
|
/** UTXOs */
|
|
1004
1015
|
export interface UTXOs {
|
|
1005
1016
|
utxos: UTXO[];
|
|
1006
|
-
warning?: string;
|
|
1007
1017
|
}
|
|
1008
1018
|
/** Unauthorized */
|
|
1009
1019
|
export interface Unauthorized {
|
|
@@ -1179,7 +1189,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
1179
1189
|
}
|
|
1180
1190
|
/**
|
|
1181
1191
|
* @title Alephium API
|
|
1182
|
-
* @version 3.
|
|
1192
|
+
* @version 3.5.0
|
|
1183
1193
|
* @baseUrl ../
|
|
1184
1194
|
*/
|
|
1185
1195
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -1469,7 +1479,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1469
1479
|
* @min 0
|
|
1470
1480
|
*/
|
|
1471
1481
|
toTs?: number;
|
|
1472
|
-
}, params?: RequestParams) => Promise<
|
|
1482
|
+
}, params?: RequestParams) => Promise<HashRateResponse>;
|
|
1473
1483
|
/**
|
|
1474
1484
|
* No description
|
|
1475
1485
|
*
|
|
@@ -1484,7 +1494,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1484
1494
|
* @min 1
|
|
1485
1495
|
*/
|
|
1486
1496
|
timespan?: number;
|
|
1487
|
-
}, params?: RequestParams) => Promise<
|
|
1497
|
+
}, params?: RequestParams) => Promise<HashRateResponse>;
|
|
1488
1498
|
/**
|
|
1489
1499
|
* No description
|
|
1490
1500
|
*
|
|
@@ -1493,7 +1503,7 @@ export declare class Api<SecurityDataType extends unknown> extends HttpClient<Se
|
|
|
1493
1503
|
* @summary Get the average difficulty of the latest blocks from all shards
|
|
1494
1504
|
* @request GET:/infos/current-difficulty
|
|
1495
1505
|
*/
|
|
1496
|
-
getInfosCurrentDifficulty: (params?: RequestParams) => Promise<
|
|
1506
|
+
getInfosCurrentDifficulty: (params?: RequestParams) => Promise<CurrentDifficulty>;
|
|
1497
1507
|
};
|
|
1498
1508
|
blockflow: {
|
|
1499
1509
|
/**
|
|
@@ -182,6 +182,7 @@ export declare abstract class ContractFactory<I extends ContractInstance, F exte
|
|
|
182
182
|
constructor(contract: Contract);
|
|
183
183
|
abstract at(address: string): I;
|
|
184
184
|
deploy(signer: SignerProvider, deployParams: DeployContractParams<F>): Promise<DeployContractResult<I>>;
|
|
185
|
+
deployTemplate(signer: SignerProvider): Promise<DeployContractResult<I>>;
|
|
185
186
|
stateForTest(initFields: F, asset?: Asset, address?: string): ContractState<F>;
|
|
186
187
|
}
|
|
187
188
|
export declare class ExecutableScript<P extends Fields = Fields, R extends Val | null = null> {
|
|
@@ -288,7 +289,7 @@ export declare function subscribeContractEvent<F extends Fields, M extends Contr
|
|
|
288
289
|
export declare function subscribeContractEvents(contract: Contract, instance: ContractInstance, options: EventSubscribeOptions<ContractEvent<any>>, fromCount?: number): EventSubscription;
|
|
289
290
|
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
291
|
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,
|
|
292
|
+
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
293
|
export declare function getContractEventsCurrentCount(contractAddress: Address): Promise<number>;
|
|
293
294
|
export declare const getContractIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
294
295
|
export declare const getTokenIdFromUnsignedTx: (nodeProvider: NodeProvider, unsignedTx: string) => Promise<HexString>;
|
|
@@ -60,7 +60,8 @@ exports.DEFAULT_NODE_COMPILER_OPTIONS = {
|
|
|
60
60
|
ignoreUnusedFieldsWarnings: false,
|
|
61
61
|
ignoreUnusedPrivateFunctionsWarnings: false,
|
|
62
62
|
ignoreUpdateFieldsCheckWarnings: false,
|
|
63
|
-
ignoreCheckExternalCallerWarnings: false
|
|
63
|
+
ignoreCheckExternalCallerWarnings: false,
|
|
64
|
+
ignoreUnusedFunctionReturnWarnings: false
|
|
64
65
|
};
|
|
65
66
|
exports.DEFAULT_COMPILER_OPTIONS = { errorOnWarnings: true, ...exports.DEFAULT_NODE_COMPILER_OPTIONS };
|
|
66
67
|
class Struct {
|
|
@@ -627,6 +628,11 @@ class ContractFactory {
|
|
|
627
628
|
contractInstance: this.at(result.contractAddress)
|
|
628
629
|
};
|
|
629
630
|
}
|
|
631
|
+
async deployTemplate(signer) {
|
|
632
|
+
return this.deploy(signer, {
|
|
633
|
+
initialFields: this.contract.getInitialFieldsWithDefaultValues()
|
|
634
|
+
});
|
|
635
|
+
}
|
|
630
636
|
// This is used for testing contract functions
|
|
631
637
|
stateForTest(initFields, asset, address) {
|
|
632
638
|
const newAsset = {
|
|
@@ -1068,8 +1074,8 @@ exports.callMethod = callMethod;
|
|
|
1068
1074
|
async function signExecuteMethod(contract, instance, methodName, params) {
|
|
1069
1075
|
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1070
1076
|
const functionSig = contract.contract.functions[methodIndex];
|
|
1071
|
-
const
|
|
1072
|
-
const bytecodeTemplate = getBytecodeTemplate(methodIndex,
|
|
1077
|
+
const methodUsePreapprovedAssets = contract.contract.decodedMethods[methodIndex].usePreapprovedAssets;
|
|
1078
|
+
const bytecodeTemplate = getBytecodeTemplate(methodIndex, methodUsePreapprovedAssets, functionSig, contract.contract.structs, params.attoAlphAmount, params.tokens);
|
|
1073
1079
|
const fieldsSig = toFieldsSig(contract.contract.name, functionSig);
|
|
1074
1080
|
const bytecode = ralph.buildScriptByteCode(bytecodeTemplate, { __contract__: instance.contractId, ...params.args }, fieldsSig, contract.contract.structs);
|
|
1075
1081
|
const signer = params.signer;
|
|
@@ -1086,16 +1092,17 @@ async function signExecuteMethod(contract, instance, methodName, params) {
|
|
|
1086
1092
|
return await signer.signAndSubmitExecuteScriptTx(signerParams);
|
|
1087
1093
|
}
|
|
1088
1094
|
exports.signExecuteMethod = signExecuteMethod;
|
|
1089
|
-
function getBytecodeTemplate(methodIndex,
|
|
1095
|
+
function getBytecodeTemplate(methodIndex, methodUsePreapprovedAssets, functionSig, structs, attoAlphAmount, tokens) {
|
|
1090
1096
|
// For the default TxScript main function
|
|
1091
1097
|
const numberOfMethods = '01';
|
|
1092
1098
|
const isPublic = '01';
|
|
1093
|
-
const
|
|
1099
|
+
const scriptUseApprovedAssets = attoAlphAmount !== undefined || tokens !== undefined;
|
|
1100
|
+
const modifier = scriptUseApprovedAssets ? '03' : '00';
|
|
1094
1101
|
const argsLength = '00';
|
|
1095
1102
|
const returnsLength = '00';
|
|
1096
1103
|
const [templateVarStoreLocalInstrs, templateVarsLength] = getTemplateVarStoreLocalInstrs(functionSig, structs);
|
|
1097
|
-
const approveAlphInstrs = getApproveAlphInstrs(
|
|
1098
|
-
const approveTokensInstrs = getApproveTokensInstrs(
|
|
1104
|
+
const approveAlphInstrs = getApproveAlphInstrs(methodUsePreapprovedAssets ? attoAlphAmount : undefined);
|
|
1105
|
+
const approveTokensInstrs = getApproveTokensInstrs(methodUsePreapprovedAssets ? tokens : undefined);
|
|
1099
1106
|
const callerInstrs = getCallAddressInstrs(approveAlphInstrs.length / 2 + approveTokensInstrs.length / 3);
|
|
1100
1107
|
// First template var is the contract
|
|
1101
1108
|
const functionArgsNum = encodeU256Const(BigInt(templateVarsLength - 1));
|
|
@@ -1241,23 +1248,31 @@ function toFieldsSig(contractName, functionSig) {
|
|
|
1241
1248
|
isMutable: [false].concat(functionSig.paramIsMutable)
|
|
1242
1249
|
};
|
|
1243
1250
|
}
|
|
1244
|
-
async function multicallMethods(contract, instance,
|
|
1245
|
-
const callEntries = Object.entries(calls);
|
|
1246
|
-
const callsParams = callEntries.map((
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
+
async function multicallMethods(contract, instance, callss, getContractByCodeHash) {
|
|
1252
|
+
const callEntries = callss.map((calls) => Object.entries(calls));
|
|
1253
|
+
const callsParams = callEntries.map((entries) => {
|
|
1254
|
+
return entries.map((entry) => {
|
|
1255
|
+
const [methodName, params] = entry;
|
|
1256
|
+
const methodIndex = contract.contract.getMethodIndex(methodName);
|
|
1257
|
+
const txId = params?.txId ?? randomTxId();
|
|
1258
|
+
return contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
|
|
1259
|
+
});
|
|
1251
1260
|
});
|
|
1252
|
-
const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams });
|
|
1253
|
-
|
|
1254
|
-
callsParams.
|
|
1255
|
-
const
|
|
1256
|
-
const
|
|
1257
|
-
|
|
1258
|
-
|
|
1261
|
+
const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsMulticallContract({ calls: callsParams.flat() });
|
|
1262
|
+
let callResultIndex = 0;
|
|
1263
|
+
const results = callsParams.map((calls, index0) => {
|
|
1264
|
+
const callsResult = {};
|
|
1265
|
+
const entries = callEntries[`${index0}`];
|
|
1266
|
+
calls.forEach((call, index1) => {
|
|
1267
|
+
const methodIndex = call.methodIndex;
|
|
1268
|
+
const callResult = result.results[`${callResultIndex}`];
|
|
1269
|
+
const methodName = entries[`${index1}`][`0`];
|
|
1270
|
+
callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(callResult, call.txId, methodIndex, getContractByCodeHash);
|
|
1271
|
+
callResultIndex += 1;
|
|
1272
|
+
});
|
|
1273
|
+
return callsResult;
|
|
1259
1274
|
});
|
|
1260
|
-
return
|
|
1275
|
+
return results.length === 1 ? results[0] : results;
|
|
1261
1276
|
}
|
|
1262
1277
|
exports.multicallMethods = multicallMethods;
|
|
1263
1278
|
async function getContractEventsCurrentCount(contractAddress) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.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.
|
|
36
|
+
"alephium_version": "3.5.0",
|
|
37
37
|
"explorer_backend_version": "2.0.0"
|
|
38
38
|
},
|
|
39
39
|
"type": "commonjs",
|
package/src/address/address.ts
CHANGED
|
@@ -22,7 +22,7 @@ import { TOTAL_NUMBER_OF_GROUPS } from '../constants'
|
|
|
22
22
|
import blake from 'blakejs'
|
|
23
23
|
import bs58 from '../utils/bs58'
|
|
24
24
|
import djb2 from '../utils/djb2'
|
|
25
|
-
import { binToHex, concatBytes, hexToBinUnsafe } from '../utils'
|
|
25
|
+
import { binToHex, concatBytes, hexToBinUnsafe, isHexString } from '../utils'
|
|
26
26
|
import { KeyType } from '../signer'
|
|
27
27
|
import { MultiSig, lockupScriptCodec } from '../codec/lockup-script-codec'
|
|
28
28
|
import { compactSignedIntCodec } from '../codec'
|
|
@@ -211,6 +211,12 @@ export function subContractId(parentContractId: string, pathInHex: string, group
|
|
|
211
211
|
if (group < 0 || group >= TOTAL_NUMBER_OF_GROUPS) {
|
|
212
212
|
throw new Error(`Invalid group ${group}`)
|
|
213
213
|
}
|
|
214
|
+
if (!isHexString(parentContractId)) {
|
|
215
|
+
throw new Error(`Invalid parent contract ID: ${parentContractId}, expected hex string`)
|
|
216
|
+
}
|
|
217
|
+
if (!isHexString(pathInHex)) {
|
|
218
|
+
throw new Error(`Invalid path: ${pathInHex}, expected hex string`)
|
|
219
|
+
}
|
|
214
220
|
const data = concatBytes([hexToBinUnsafe(parentContractId), hexToBinUnsafe(pathInHex)])
|
|
215
221
|
const bytes = new Uint8Array([
|
|
216
222
|
...blake.blake2b(blake.blake2b(data, undefined, 32), undefined, 32).slice(0, -1),
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -21,7 +21,6 @@ export interface AddressBalance {
|
|
|
21
21
|
lockedBalance: string
|
|
22
22
|
/** @format x.x ALPH */
|
|
23
23
|
lockedBalanceHint: string
|
|
24
|
-
warning?: string
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/** AddressInfo */
|
|
@@ -93,7 +92,6 @@ export interface Balance {
|
|
|
93
92
|
lockedTokenBalances?: Token[]
|
|
94
93
|
/** @format int32 */
|
|
95
94
|
utxoNum: number
|
|
96
|
-
warning?: string
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
/** Balances */
|
|
@@ -503,6 +501,9 @@ export interface CompileProjectResult {
|
|
|
503
501
|
contracts: CompileContractResult[]
|
|
504
502
|
scripts: CompileScriptResult[]
|
|
505
503
|
structs?: StructSig[]
|
|
504
|
+
constants?: Constant[]
|
|
505
|
+
enums?: Enum[]
|
|
506
|
+
warnings?: string[]
|
|
506
507
|
}
|
|
507
508
|
|
|
508
509
|
/** CompileScriptResult */
|
|
@@ -524,6 +525,7 @@ export interface CompilerOptions {
|
|
|
524
525
|
ignoreUnusedPrivateFunctionsWarnings?: boolean
|
|
525
526
|
ignoreUpdateFieldsCheckWarnings?: boolean
|
|
526
527
|
ignoreCheckExternalCallerWarnings?: boolean
|
|
528
|
+
ignoreUnusedFunctionReturnWarnings?: boolean
|
|
527
529
|
}
|
|
528
530
|
|
|
529
531
|
/** Confirmed */
|
|
@@ -632,6 +634,12 @@ export interface ContractState {
|
|
|
632
634
|
asset: AssetState
|
|
633
635
|
}
|
|
634
636
|
|
|
637
|
+
/** CurrentDifficulty */
|
|
638
|
+
export interface CurrentDifficulty {
|
|
639
|
+
/** @format bigint */
|
|
640
|
+
difficulty: string
|
|
641
|
+
}
|
|
642
|
+
|
|
635
643
|
/** DebugMessage */
|
|
636
644
|
export interface DebugMessage {
|
|
637
645
|
/** @format address */
|
|
@@ -738,6 +746,11 @@ export interface Group {
|
|
|
738
746
|
group: number
|
|
739
747
|
}
|
|
740
748
|
|
|
749
|
+
/** HashRateResponse */
|
|
750
|
+
export interface HashRateResponse {
|
|
751
|
+
hashrate: string
|
|
752
|
+
}
|
|
753
|
+
|
|
741
754
|
/** HashesAtHeight */
|
|
742
755
|
export interface HashesAtHeight {
|
|
743
756
|
headers: string[]
|
|
@@ -1132,7 +1145,6 @@ export interface UTXO {
|
|
|
1132
1145
|
/** UTXOs */
|
|
1133
1146
|
export interface UTXOs {
|
|
1134
1147
|
utxos: UTXO[]
|
|
1135
|
-
warning?: string
|
|
1136
1148
|
}
|
|
1137
1149
|
|
|
1138
1150
|
/** Unauthorized */
|
|
@@ -1481,7 +1493,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1481
1493
|
|
|
1482
1494
|
/**
|
|
1483
1495
|
* @title Alephium API
|
|
1484
|
-
* @version 3.
|
|
1496
|
+
* @version 3.5.0
|
|
1485
1497
|
* @baseUrl ../
|
|
1486
1498
|
*/
|
|
1487
1499
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -2019,7 +2031,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2019
2031
|
},
|
|
2020
2032
|
params: RequestParams = {}
|
|
2021
2033
|
) =>
|
|
2022
|
-
this.request<
|
|
2034
|
+
this.request<HashRateResponse, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2023
2035
|
path: `/infos/history-hashrate`,
|
|
2024
2036
|
method: 'GET',
|
|
2025
2037
|
query: query,
|
|
@@ -2045,7 +2057,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2045
2057
|
},
|
|
2046
2058
|
params: RequestParams = {}
|
|
2047
2059
|
) =>
|
|
2048
|
-
this.request<
|
|
2060
|
+
this.request<HashRateResponse, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2049
2061
|
path: `/infos/current-hashrate`,
|
|
2050
2062
|
method: 'GET',
|
|
2051
2063
|
query: query,
|
|
@@ -2062,7 +2074,7 @@ export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDa
|
|
|
2062
2074
|
* @request GET:/infos/current-difficulty
|
|
2063
2075
|
*/
|
|
2064
2076
|
getInfosCurrentDifficulty: (params: RequestParams = {}) =>
|
|
2065
|
-
this.request<
|
|
2077
|
+
this.request<CurrentDifficulty, BadRequest | Unauthorized | NotFound | InternalServerError | ServiceUnavailable>({
|
|
2066
2078
|
path: `/infos/current-difficulty`,
|
|
2067
2079
|
method: 'GET',
|
|
2068
2080
|
format: 'json',
|
package/src/contract/contract.ts
CHANGED
|
@@ -112,7 +112,8 @@ export const DEFAULT_NODE_COMPILER_OPTIONS: node.CompilerOptions = {
|
|
|
112
112
|
ignoreUnusedFieldsWarnings: false,
|
|
113
113
|
ignoreUnusedPrivateFunctionsWarnings: false,
|
|
114
114
|
ignoreUpdateFieldsCheckWarnings: false,
|
|
115
|
-
ignoreCheckExternalCallerWarnings: false
|
|
115
|
+
ignoreCheckExternalCallerWarnings: false,
|
|
116
|
+
ignoreUnusedFunctionReturnWarnings: false
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
export const DEFAULT_COMPILER_OPTIONS: CompilerOptions = { errorOnWarnings: true, ...DEFAULT_NODE_COMPILER_OPTIONS }
|
|
@@ -1010,6 +1011,12 @@ export abstract class ContractFactory<I extends ContractInstance, F extends Fiel
|
|
|
1010
1011
|
}
|
|
1011
1012
|
}
|
|
1012
1013
|
|
|
1014
|
+
async deployTemplate(signer: SignerProvider): Promise<DeployContractResult<I>> {
|
|
1015
|
+
return this.deploy(signer, {
|
|
1016
|
+
initialFields: this.contract.getInitialFieldsWithDefaultValues() as F
|
|
1017
|
+
})
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1013
1020
|
// This is used for testing contract functions
|
|
1014
1021
|
stateForTest(initFields: F, asset?: Asset, address?: string): ContractState<F> {
|
|
1015
1022
|
const newAsset = {
|
|
@@ -1681,10 +1688,10 @@ export async function signExecuteMethod<I extends ContractInstance, F extends Fi
|
|
|
1681
1688
|
): Promise<SignExecuteScriptTxResult> {
|
|
1682
1689
|
const methodIndex = contract.contract.getMethodIndex(methodName)
|
|
1683
1690
|
const functionSig = contract.contract.functions[methodIndex]
|
|
1684
|
-
const
|
|
1691
|
+
const methodUsePreapprovedAssets = contract.contract.decodedMethods[methodIndex].usePreapprovedAssets
|
|
1685
1692
|
const bytecodeTemplate = getBytecodeTemplate(
|
|
1686
1693
|
methodIndex,
|
|
1687
|
-
|
|
1694
|
+
methodUsePreapprovedAssets,
|
|
1688
1695
|
functionSig,
|
|
1689
1696
|
contract.contract.structs,
|
|
1690
1697
|
params.attoAlphAmount,
|
|
@@ -1716,7 +1723,7 @@ export async function signExecuteMethod<I extends ContractInstance, F extends Fi
|
|
|
1716
1723
|
|
|
1717
1724
|
function getBytecodeTemplate(
|
|
1718
1725
|
methodIndex: number,
|
|
1719
|
-
|
|
1726
|
+
methodUsePreapprovedAssets: boolean,
|
|
1720
1727
|
functionSig: FunctionSig,
|
|
1721
1728
|
structs: Struct[],
|
|
1722
1729
|
attoAlphAmount?: Number256,
|
|
@@ -1725,14 +1732,15 @@ function getBytecodeTemplate(
|
|
|
1725
1732
|
// For the default TxScript main function
|
|
1726
1733
|
const numberOfMethods = '01'
|
|
1727
1734
|
const isPublic = '01'
|
|
1728
|
-
const
|
|
1735
|
+
const scriptUseApprovedAssets = attoAlphAmount !== undefined || tokens !== undefined
|
|
1736
|
+
const modifier = scriptUseApprovedAssets ? '03' : '00'
|
|
1729
1737
|
const argsLength = '00'
|
|
1730
1738
|
const returnsLength = '00'
|
|
1731
1739
|
|
|
1732
1740
|
const [templateVarStoreLocalInstrs, templateVarsLength] = getTemplateVarStoreLocalInstrs(functionSig, structs)
|
|
1733
1741
|
|
|
1734
|
-
const approveAlphInstrs: string[] = getApproveAlphInstrs(
|
|
1735
|
-
const approveTokensInstrs: string[] = getApproveTokensInstrs(
|
|
1742
|
+
const approveAlphInstrs: string[] = getApproveAlphInstrs(methodUsePreapprovedAssets ? attoAlphAmount : undefined)
|
|
1743
|
+
const approveTokensInstrs: string[] = getApproveTokensInstrs(methodUsePreapprovedAssets ? tokens : undefined)
|
|
1736
1744
|
const callerInstrs: string[] = getCallAddressInstrs(approveAlphInstrs.length / 2 + approveTokensInstrs.length / 3)
|
|
1737
1745
|
|
|
1738
1746
|
// First template var is the contract
|
|
@@ -1921,35 +1929,43 @@ function toFieldsSig(contractName: string, functionSig: FunctionSig): FieldsSig
|
|
|
1921
1929
|
export async function multicallMethods<I extends ContractInstance, F extends Fields>(
|
|
1922
1930
|
contract: ContractFactory<I, F>,
|
|
1923
1931
|
instance: ContractInstance,
|
|
1924
|
-
|
|
1932
|
+
callss: Record<string, Optional<CallContractParams<any>, 'args'>>[],
|
|
1925
1933
|
getContractByCodeHash: (codeHash: string) => Contract
|
|
1926
|
-
): Promise<Record<string, CallContractResult<any>>> {
|
|
1927
|
-
const callEntries = Object.entries(calls)
|
|
1928
|
-
const callsParams = callEntries.map((
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1934
|
+
): Promise<Record<string, CallContractResult<any>>[] | Record<string, CallContractResult<any>>> {
|
|
1935
|
+
const callEntries = callss.map((calls) => Object.entries(calls))
|
|
1936
|
+
const callsParams = callEntries.map((entries) => {
|
|
1937
|
+
return entries.map((entry) => {
|
|
1938
|
+
const [methodName, params] = entry
|
|
1939
|
+
const methodIndex = contract.contract.getMethodIndex(methodName)
|
|
1940
|
+
const txId = params?.txId ?? randomTxId()
|
|
1941
|
+
return contract.contract.toApiCallContract(
|
|
1942
|
+
{ ...params, txId: txId, args: params.args === undefined ? {} : params.args },
|
|
1943
|
+
instance.groupIndex,
|
|
1944
|
+
instance.address,
|
|
1945
|
+
methodIndex
|
|
1946
|
+
)
|
|
1947
|
+
})
|
|
1938
1948
|
})
|
|
1939
|
-
const result = await getCurrentNodeProvider().contracts.postContractsMulticallContract({ calls: callsParams })
|
|
1940
|
-
|
|
1941
|
-
callsParams.
|
|
1942
|
-
const
|
|
1943
|
-
const
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
callResult
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1949
|
+
const result = await getCurrentNodeProvider().contracts.postContractsMulticallContract({ calls: callsParams.flat() })
|
|
1950
|
+
let callResultIndex = 0
|
|
1951
|
+
const results = callsParams.map((calls, index0) => {
|
|
1952
|
+
const callsResult: Record<string, CallContractResult<any>> = {}
|
|
1953
|
+
const entries = callEntries[`${index0}`]
|
|
1954
|
+
calls.forEach((call, index1) => {
|
|
1955
|
+
const methodIndex = call.methodIndex
|
|
1956
|
+
const callResult = result.results[`${callResultIndex}`]
|
|
1957
|
+
const methodName = entries[`${index1}`][`0`]
|
|
1958
|
+
callsResult[`${methodName}`] = contract.contract.fromApiCallContractResult(
|
|
1959
|
+
callResult,
|
|
1960
|
+
call.txId!,
|
|
1961
|
+
methodIndex,
|
|
1962
|
+
getContractByCodeHash
|
|
1963
|
+
) as CallContractResult<any>
|
|
1964
|
+
callResultIndex += 1
|
|
1965
|
+
})
|
|
1966
|
+
return callsResult
|
|
1951
1967
|
})
|
|
1952
|
-
return
|
|
1968
|
+
return results.length === 1 ? results[0] : results
|
|
1953
1969
|
}
|
|
1954
1970
|
|
|
1955
1971
|
export async function getContractEventsCurrentCount(contractAddress: Address): Promise<number> {
|