@alephium/web3 0.29.1 → 0.29.3
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/api/api-alephium.d.ts +2 -1
- package/dist/src/api/api-alephium.js +1 -1
- package/dist/src/contract/contract.d.ts +4 -2
- package/dist/src/contract/contract.js +15 -5
- package/dist/src/utils/utils.d.ts +1 -0
- package/dist/src/utils/utils.js +5 -1
- package/package.json +2 -2
- package/src/api/api-alephium.ts +2 -1
- package/src/contract/contract.ts +20 -7
- package/src/utils/utils.ts +4 -0
|
@@ -338,6 +338,7 @@ export interface CallContractSucceeded {
|
|
|
338
338
|
txInputs: string[];
|
|
339
339
|
txOutputs: Output[];
|
|
340
340
|
events: ContractEventByTxId[];
|
|
341
|
+
debugMessages: DebugMessage[];
|
|
341
342
|
type: string;
|
|
342
343
|
}
|
|
343
344
|
export interface ChainInfo {
|
|
@@ -982,7 +983,7 @@ export declare class HttpClient<SecurityDataType = unknown> {
|
|
|
982
983
|
}
|
|
983
984
|
/**
|
|
984
985
|
* @title Alephium API
|
|
985
|
-
* @version 2.8.
|
|
986
|
+
* @version 2.8.2
|
|
986
987
|
* @baseUrl ../
|
|
987
988
|
*/
|
|
988
989
|
export declare class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
|
@@ -99,10 +99,11 @@ export declare abstract class Artifact {
|
|
|
99
99
|
readonly name: string;
|
|
100
100
|
readonly functions: FunctionSig[];
|
|
101
101
|
constructor(version: string, name: string, functions: FunctionSig[]);
|
|
102
|
-
abstract buildByteCodeToDeploy(initialFields
|
|
102
|
+
abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
|
|
103
103
|
publicFunctions(): string[];
|
|
104
104
|
usingPreapprovedAssetsFunctions(): string[];
|
|
105
105
|
usingAssetsInContractFunctions(): string[];
|
|
106
|
+
isDevnet(signer: SignerProvider): Promise<boolean>;
|
|
106
107
|
}
|
|
107
108
|
export declare class Contract extends Artifact {
|
|
108
109
|
readonly bytecode: string;
|
|
@@ -138,7 +139,7 @@ export declare class Contract extends Artifact {
|
|
|
138
139
|
static fromApiEvent(event: node.ContractEventByTxId, codeHash: string | undefined, txId: string, getContractByCodeHash?: (codeHash: string) => Contract): ContractEvent;
|
|
139
140
|
fromApiTestContractResult(methodName: string, result: node.TestContractResult, txId: string): TestContractResult<unknown>;
|
|
140
141
|
txParamsForDeployment<P extends Fields>(signer: SignerProvider, params: DeployContractParams<P>): Promise<SignDeployContractTxParams>;
|
|
141
|
-
buildByteCodeToDeploy(initialFields: Fields): string;
|
|
142
|
+
buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string;
|
|
142
143
|
static fromApiEvents(events: node.ContractEventByTxId[], addressToCodeHash: Map<string, string>, txId: string, getContractByCodeHash?: (codeHash: string) => Contract): ContractEvent[];
|
|
143
144
|
toApiCallContract<T extends Arguments>(params: CallContractParams<T>, groupIndex: number, contractAddress: string, methodIndex: number): node.CallContract;
|
|
144
145
|
fromApiCallContractResult(result: node.CallContractResult, txId: string, methodIndex: number, getContractByCodeHash?: (codeHash: string) => Contract): CallContractResult<unknown>;
|
|
@@ -272,6 +273,7 @@ export interface CallContractResult<R> {
|
|
|
272
273
|
txInputs: string[];
|
|
273
274
|
txOutputs: Output[];
|
|
274
275
|
events: ContractEvent[];
|
|
276
|
+
debugMessages: DebugMessage[];
|
|
275
277
|
}
|
|
276
278
|
export declare const CreateContractEventAddress: string;
|
|
277
279
|
export declare const DestroyContractEventAddress: string;
|
|
@@ -494,6 +494,13 @@ class Artifact {
|
|
|
494
494
|
usingAssetsInContractFunctions() {
|
|
495
495
|
return this.functions.filter((func) => func.useAssetsInContract).map((func) => func.name);
|
|
496
496
|
}
|
|
497
|
+
async isDevnet(signer) {
|
|
498
|
+
if (!signer.nodeProvider) {
|
|
499
|
+
return false;
|
|
500
|
+
}
|
|
501
|
+
const chainParams = await signer.nodeProvider.infos.getInfosChainParams();
|
|
502
|
+
return (0, utils_1.isDevnet)(chainParams.networkId);
|
|
503
|
+
}
|
|
497
504
|
}
|
|
498
505
|
exports.Artifact = Artifact;
|
|
499
506
|
class Contract extends Artifact {
|
|
@@ -587,7 +594,7 @@ class Contract extends Artifact {
|
|
|
587
594
|
printDebugMessages(funcName, messages) {
|
|
588
595
|
if (messages.length != 0) {
|
|
589
596
|
console.log(`Testing ${this.name}.${funcName}:`);
|
|
590
|
-
messages.forEach((m) => console.log(
|
|
597
|
+
messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`));
|
|
591
598
|
}
|
|
592
599
|
}
|
|
593
600
|
toApiFields(fields) {
|
|
@@ -701,8 +708,9 @@ class Contract extends Artifact {
|
|
|
701
708
|
};
|
|
702
709
|
}
|
|
703
710
|
async txParamsForDeployment(signer, params) {
|
|
711
|
+
const isDevnet = await this.isDevnet(signer);
|
|
704
712
|
const initialFields = params.initialFields ?? {};
|
|
705
|
-
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields));
|
|
713
|
+
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet);
|
|
706
714
|
const selectedAccount = await signer.getSelectedAccount();
|
|
707
715
|
const signerParams = {
|
|
708
716
|
signerAddress: selectedAccount.address,
|
|
@@ -716,9 +724,9 @@ class Contract extends Artifact {
|
|
|
716
724
|
};
|
|
717
725
|
return signerParams;
|
|
718
726
|
}
|
|
719
|
-
buildByteCodeToDeploy(initialFields) {
|
|
727
|
+
buildByteCodeToDeploy(initialFields, isDevnet) {
|
|
720
728
|
try {
|
|
721
|
-
return ralph.buildContractByteCode(this.bytecode, initialFields, this.fieldsSig);
|
|
729
|
+
return ralph.buildContractByteCode(isDevnet ? this.bytecodeDebug : this.bytecode, initialFields, this.fieldsSig);
|
|
722
730
|
}
|
|
723
731
|
catch (error) {
|
|
724
732
|
throw new Error(`Failed to build bytecode for contract ${this.name}, error: ${error}`);
|
|
@@ -760,7 +768,8 @@ class Contract extends Artifact {
|
|
|
760
768
|
contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
|
|
761
769
|
txInputs: callResult.txInputs,
|
|
762
770
|
txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
|
|
763
|
-
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash)
|
|
771
|
+
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash),
|
|
772
|
+
debugMessages: callResult.debugMessages
|
|
764
773
|
};
|
|
765
774
|
}
|
|
766
775
|
}
|
|
@@ -1154,6 +1163,7 @@ async function callMethod(contract, instance, methodName, params, getContractByC
|
|
|
1154
1163
|
const callParams = contract.contract.toApiCallContract({ ...params, txId: txId, args: params.args === undefined ? {} : params.args }, instance.groupIndex, instance.address, methodIndex);
|
|
1155
1164
|
const result = await (0, global_1.getCurrentNodeProvider)().contracts.postContractsCallContract(callParams);
|
|
1156
1165
|
const callResult = contract.contract.fromApiCallContractResult(result, txId, methodIndex, getContractByCodeHash);
|
|
1166
|
+
contract.contract.printDebugMessages(methodName, callResult.debugMessages);
|
|
1157
1167
|
return callResult;
|
|
1158
1168
|
}
|
|
1159
1169
|
exports.callMethod = callMethod;
|
|
@@ -39,6 +39,7 @@ export declare function blockChainIndex(blockHash: HexString): {
|
|
|
39
39
|
export declare function stringToHex(str: string): string;
|
|
40
40
|
export declare function hexToString(str: string): string;
|
|
41
41
|
export declare function sleep(ms: number): Promise<void>;
|
|
42
|
+
export declare function isDevnet(networkId?: number): boolean;
|
|
42
43
|
type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
|
|
43
44
|
export type Eq<X, Y> = _Eq<{
|
|
44
45
|
[P in keyof X]: X[P];
|
package/dist/src/utils/utils.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.assertType = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.AddressType = exports.toNonNegativeBigInt = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
|
|
23
|
+
exports.assertType = exports.isDevnet = exports.sleep = exports.hexToString = exports.stringToHex = exports.blockChainIndex = exports.subContractId = exports.contractIdFromTx = exports.addressFromTokenId = exports.addressFromContractId = exports.addressFromScript = exports.addressFromPublicKey = exports.publicKeyFromPrivateKey = exports.groupOfPrivateKey = exports.binToHex = exports.hexToBinUnsafe = exports.tokenIdFromAddress = exports.contractIdFromAddress = exports.groupOfAddress = exports.AddressType = exports.toNonNegativeBigInt = exports.isHexString = exports.xorByte = exports.signatureDecode = exports.encodeHexSignature = exports.encodeSignature = exports.networkIds = void 0;
|
|
24
24
|
const elliptic_1 = require("elliptic");
|
|
25
25
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
26
26
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -257,6 +257,10 @@ function sleep(ms) {
|
|
|
257
257
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
258
258
|
}
|
|
259
259
|
exports.sleep = sleep;
|
|
260
|
+
function isDevnet(networkId) {
|
|
261
|
+
return networkId !== 0 && networkId !== 1;
|
|
262
|
+
}
|
|
263
|
+
exports.isDevnet = isDevnet;
|
|
260
264
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|
|
261
265
|
function assertType() { }
|
|
262
266
|
exports.assertType = assertType;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alephium/web3",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.3",
|
|
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.8.
|
|
30
|
+
"alephium_version": "2.8.2",
|
|
31
31
|
"explorer_backend_version": "1.16.1"
|
|
32
32
|
},
|
|
33
33
|
"type": "commonjs",
|
package/src/api/api-alephium.ts
CHANGED
|
@@ -383,6 +383,7 @@ export interface CallContractSucceeded {
|
|
|
383
383
|
txInputs: string[]
|
|
384
384
|
txOutputs: Output[]
|
|
385
385
|
events: ContractEventByTxId[]
|
|
386
|
+
debugMessages: DebugMessage[]
|
|
386
387
|
type: string
|
|
387
388
|
}
|
|
388
389
|
|
|
@@ -1277,7 +1278,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
1277
1278
|
|
|
1278
1279
|
/**
|
|
1279
1280
|
* @title Alephium API
|
|
1280
|
-
* @version 2.8.
|
|
1281
|
+
* @version 2.8.2
|
|
1281
1282
|
* @baseUrl ../
|
|
1282
1283
|
*/
|
|
1283
1284
|
export class Api<SecurityDataType extends unknown> extends HttpClient<SecurityDataType> {
|
package/src/contract/contract.ts
CHANGED
|
@@ -55,7 +55,8 @@ import {
|
|
|
55
55
|
groupOfAddress,
|
|
56
56
|
addressFromContractId,
|
|
57
57
|
WebCrypto,
|
|
58
|
-
hexToBinUnsafe
|
|
58
|
+
hexToBinUnsafe,
|
|
59
|
+
isDevnet
|
|
59
60
|
} from '../utils'
|
|
60
61
|
import { getCurrentNodeProvider } from '../global'
|
|
61
62
|
import * as path from 'path'
|
|
@@ -715,7 +716,7 @@ export abstract class Artifact {
|
|
|
715
716
|
this.functions = functions
|
|
716
717
|
}
|
|
717
718
|
|
|
718
|
-
abstract buildByteCodeToDeploy(initialFields
|
|
719
|
+
abstract buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string
|
|
719
720
|
|
|
720
721
|
publicFunctions(): string[] {
|
|
721
722
|
return this.functions.filter((func) => func.isPublic).map((func) => func.name)
|
|
@@ -728,6 +729,14 @@ export abstract class Artifact {
|
|
|
728
729
|
usingAssetsInContractFunctions(): string[] {
|
|
729
730
|
return this.functions.filter((func) => func.useAssetsInContract).map((func) => func.name)
|
|
730
731
|
}
|
|
732
|
+
|
|
733
|
+
async isDevnet(signer: SignerProvider): Promise<boolean> {
|
|
734
|
+
if (!signer.nodeProvider) {
|
|
735
|
+
return false
|
|
736
|
+
}
|
|
737
|
+
const chainParams = await signer.nodeProvider.infos.getInfosChainParams()
|
|
738
|
+
return isDevnet(chainParams.networkId)
|
|
739
|
+
}
|
|
731
740
|
}
|
|
732
741
|
|
|
733
742
|
export class Contract extends Artifact {
|
|
@@ -884,7 +893,7 @@ export class Contract extends Artifact {
|
|
|
884
893
|
printDebugMessages(funcName: string, messages: DebugMessage[]) {
|
|
885
894
|
if (messages.length != 0) {
|
|
886
895
|
console.log(`Testing ${this.name}.${funcName}:`)
|
|
887
|
-
messages.forEach((m) => console.log(
|
|
896
|
+
messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`))
|
|
888
897
|
}
|
|
889
898
|
}
|
|
890
899
|
|
|
@@ -1039,8 +1048,9 @@ export class Contract extends Artifact {
|
|
|
1039
1048
|
signer: SignerProvider,
|
|
1040
1049
|
params: DeployContractParams<P>
|
|
1041
1050
|
): Promise<SignDeployContractTxParams> {
|
|
1051
|
+
const isDevnet = await this.isDevnet(signer)
|
|
1042
1052
|
const initialFields: Fields = params.initialFields ?? {}
|
|
1043
|
-
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields))
|
|
1053
|
+
const bytecode = this.buildByteCodeToDeploy(addStdIdToFields(this, initialFields), isDevnet)
|
|
1044
1054
|
const selectedAccount = await signer.getSelectedAccount()
|
|
1045
1055
|
const signerParams: SignDeployContractTxParams = {
|
|
1046
1056
|
signerAddress: selectedAccount.address,
|
|
@@ -1055,9 +1065,9 @@ export class Contract extends Artifact {
|
|
|
1055
1065
|
return signerParams
|
|
1056
1066
|
}
|
|
1057
1067
|
|
|
1058
|
-
buildByteCodeToDeploy(initialFields: Fields): string {
|
|
1068
|
+
buildByteCodeToDeploy(initialFields: Fields, isDevnet: boolean): string {
|
|
1059
1069
|
try {
|
|
1060
|
-
return ralph.buildContractByteCode(this.bytecode, initialFields, this.fieldsSig)
|
|
1070
|
+
return ralph.buildContractByteCode(isDevnet ? this.bytecodeDebug : this.bytecode, initialFields, this.fieldsSig)
|
|
1061
1071
|
} catch (error) {
|
|
1062
1072
|
throw new Error(`Failed to build bytecode for contract ${this.name}, error: ${error}`)
|
|
1063
1073
|
}
|
|
@@ -1116,7 +1126,8 @@ export class Contract extends Artifact {
|
|
|
1116
1126
|
contracts: callResult.contracts.map((state) => Contract.fromApiContractState(state, getContractByCodeHash)),
|
|
1117
1127
|
txInputs: callResult.txInputs,
|
|
1118
1128
|
txOutputs: callResult.txOutputs.map((output) => fromApiOutput(output)),
|
|
1119
|
-
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash)
|
|
1129
|
+
events: Contract.fromApiEvents(callResult.events, addressToCodeHash, txId, getContractByCodeHash),
|
|
1130
|
+
debugMessages: callResult.debugMessages
|
|
1120
1131
|
}
|
|
1121
1132
|
}
|
|
1122
1133
|
}
|
|
@@ -1503,6 +1514,7 @@ export interface CallContractResult<R> {
|
|
|
1503
1514
|
txInputs: string[]
|
|
1504
1515
|
txOutputs: Output[]
|
|
1505
1516
|
events: ContractEvent[]
|
|
1517
|
+
debugMessages: DebugMessage[]
|
|
1506
1518
|
}
|
|
1507
1519
|
|
|
1508
1520
|
function specialContractAddress(n: number): string {
|
|
@@ -1767,6 +1779,7 @@ export async function callMethod<I extends ContractInstance, F extends Fields, A
|
|
|
1767
1779
|
)
|
|
1768
1780
|
const result = await getCurrentNodeProvider().contracts.postContractsCallContract(callParams)
|
|
1769
1781
|
const callResult = contract.contract.fromApiCallContractResult(result, txId, methodIndex, getContractByCodeHash)
|
|
1782
|
+
contract.contract.printDebugMessages(methodName, callResult.debugMessages)
|
|
1770
1783
|
return callResult as CallContractResult<R>
|
|
1771
1784
|
}
|
|
1772
1785
|
|
package/src/utils/utils.ts
CHANGED
|
@@ -265,6 +265,10 @@ export function sleep(ms: number): Promise<void> {
|
|
|
265
265
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
export function isDevnet(networkId?: number): boolean {
|
|
269
|
+
return networkId !== 0 && networkId !== 1
|
|
270
|
+
}
|
|
271
|
+
|
|
268
272
|
type _Eq<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false
|
|
269
273
|
export type Eq<X, Y> = _Eq<{ [P in keyof X]: X[P] }, { [P in keyof Y]: Y[P] }>
|
|
270
274
|
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
|