@fuel-ts/account 0.76.0 → 0.77.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.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/account.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +840 -1334
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +85 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -115
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +16 -15
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +9 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/assets/index.d.ts +1 -0
- package/dist/providers/assets/index.d.ts.map +1 -1
- package/dist/providers/assets/types.d.ts +5 -5
- package/dist/providers/assets/types.d.ts.map +1 -1
- package/dist/providers/assets/utils/network.d.ts +4 -4
- package/dist/providers/assets/utils/network.d.ts.map +1 -1
- package/dist/providers/assets/utils/resolveIconPaths.d.ts +1 -1
- package/dist/providers/fuel-graphql-subscriber.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +23 -14
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/hash-transaction.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/test-utils.global.js +817 -1308
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +64 -26
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +105 -75
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -30,7 +30,7 @@ var __privateMethod = (obj, member, method) => {
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
|
-
import { ErrorCode as
|
33
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
35
|
import { bn as bn16 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
@@ -73,7 +73,7 @@ var addAmountToAsset = (params) => {
|
|
73
73
|
|
74
74
|
// src/providers/provider.ts
|
75
75
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
|
-
import { ErrorCode as
|
76
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
77
77
|
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
78
78
|
import {
|
79
79
|
InputType as InputType6,
|
@@ -149,6 +149,9 @@ var TransactionStatusFragmentFragmentDoc = gql`
|
|
149
149
|
time
|
150
150
|
reason
|
151
151
|
}
|
152
|
+
... on SqueezedOutStatus {
|
153
|
+
reason
|
154
|
+
}
|
152
155
|
}
|
153
156
|
`;
|
154
157
|
var TransactionFragmentFragmentDoc = gql`
|
@@ -891,7 +894,7 @@ function getSdk(requester) {
|
|
891
894
|
}
|
892
895
|
|
893
896
|
// src/providers/fuel-graphql-subscriber.ts
|
894
|
-
import { FuelError } from "@fuel-ts/errors";
|
897
|
+
import { ErrorCode, FuelError } from "@fuel-ts/errors";
|
895
898
|
import { print } from "graphql";
|
896
899
|
var _FuelGraphqlSubscriber = class {
|
897
900
|
constructor(options) {
|
@@ -926,7 +929,16 @@ var _FuelGraphqlSubscriber = class {
|
|
926
929
|
if (!text.startsWith("data:")) {
|
927
930
|
continue;
|
928
931
|
}
|
929
|
-
|
932
|
+
let data;
|
933
|
+
let errors;
|
934
|
+
try {
|
935
|
+
({ data, errors } = JSON.parse(text.replace(/^data:/, "")));
|
936
|
+
} catch (e) {
|
937
|
+
throw new FuelError(
|
938
|
+
ErrorCode.STREAM_PARSING_ERROR,
|
939
|
+
`Error while parsing stream data response: ${text}`
|
940
|
+
);
|
941
|
+
}
|
930
942
|
if (Array.isArray(errors)) {
|
931
943
|
throw new FuelError(
|
932
944
|
FuelError.CODES.INVALID_REQUEST,
|
@@ -952,7 +964,7 @@ var FuelGraphqlSubscriber = _FuelGraphqlSubscriber;
|
|
952
964
|
__publicField(FuelGraphqlSubscriber, "textDecoder", new TextDecoder());
|
953
965
|
|
954
966
|
// src/providers/memory-cache.ts
|
955
|
-
import { ErrorCode, FuelError as FuelError2 } from "@fuel-ts/errors";
|
967
|
+
import { ErrorCode as ErrorCode2, FuelError as FuelError2 } from "@fuel-ts/errors";
|
956
968
|
import { hexlify as hexlify2 } from "@fuel-ts/utils";
|
957
969
|
var cache = {};
|
958
970
|
var DEFAULT_TTL_IN_MS = 30 * 1e3;
|
@@ -962,7 +974,7 @@ var MemoryCache = class {
|
|
962
974
|
this.ttl = ttlInMs;
|
963
975
|
if (typeof ttlInMs !== "number" || this.ttl <= 0) {
|
964
976
|
throw new FuelError2(
|
965
|
-
|
977
|
+
ErrorCode2.INVALID_TTL,
|
966
978
|
`Invalid TTL: ${this.ttl}. Use a value greater than zero.`
|
967
979
|
);
|
968
980
|
}
|
@@ -1012,7 +1024,7 @@ var MemoryCache = class {
|
|
1012
1024
|
|
1013
1025
|
// src/providers/transaction-request/input.ts
|
1014
1026
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1015
|
-
import { ErrorCode as
|
1027
|
+
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1016
1028
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
1017
1029
|
import { InputType } from "@fuel-ts/transactions";
|
1018
1030
|
import { arrayify, hexlify as hexlify3 } from "@fuel-ts/utils";
|
@@ -1078,7 +1090,7 @@ var inputify = (value) => {
|
|
1078
1090
|
}
|
1079
1091
|
default: {
|
1080
1092
|
throw new FuelError3(
|
1081
|
-
|
1093
|
+
ErrorCode3.INVALID_TRANSACTION_INPUT,
|
1082
1094
|
`Invalid transaction input type: ${type}.`
|
1083
1095
|
);
|
1084
1096
|
}
|
@@ -1087,7 +1099,7 @@ var inputify = (value) => {
|
|
1087
1099
|
|
1088
1100
|
// src/providers/transaction-request/output.ts
|
1089
1101
|
import { ZeroBytes32 as ZeroBytes322 } from "@fuel-ts/address/configs";
|
1090
|
-
import { ErrorCode as
|
1102
|
+
import { ErrorCode as ErrorCode4, FuelError as FuelError4 } from "@fuel-ts/errors";
|
1091
1103
|
import { bn as bn3 } from "@fuel-ts/math";
|
1092
1104
|
import { OutputType } from "@fuel-ts/transactions";
|
1093
1105
|
import { hexlify as hexlify4 } from "@fuel-ts/utils";
|
@@ -1135,7 +1147,7 @@ var outputify = (value) => {
|
|
1135
1147
|
}
|
1136
1148
|
default: {
|
1137
1149
|
throw new FuelError4(
|
1138
|
-
|
1150
|
+
ErrorCode4.INVALID_TRANSACTION_INPUT,
|
1139
1151
|
`Invalid transaction output type: ${type}.`
|
1140
1152
|
);
|
1141
1153
|
}
|
@@ -1163,7 +1175,7 @@ var isMessage = (resource) => "recipient" in resource;
|
|
1163
1175
|
|
1164
1176
|
// src/providers/utils/receipts.ts
|
1165
1177
|
import { ZeroBytes32 as ZeroBytes323 } from "@fuel-ts/address/configs";
|
1166
|
-
import { ErrorCode as
|
1178
|
+
import { ErrorCode as ErrorCode5, FuelError as FuelError5 } from "@fuel-ts/errors";
|
1167
1179
|
import { bn as bn4 } from "@fuel-ts/math";
|
1168
1180
|
import {
|
1169
1181
|
ReceiptBurnCoder,
|
@@ -1368,12 +1380,12 @@ function assembleReceiptByType(receipt) {
|
|
1368
1380
|
return burnReceipt;
|
1369
1381
|
}
|
1370
1382
|
default:
|
1371
|
-
throw new FuelError5(
|
1383
|
+
throw new FuelError5(ErrorCode5.INVALID_RECEIPT_TYPE, `Invalid receipt type: ${receiptType}.`);
|
1372
1384
|
}
|
1373
1385
|
}
|
1374
1386
|
|
1375
1387
|
// src/providers/utils/block-explorer.ts
|
1376
|
-
import { ErrorCode as
|
1388
|
+
import { ErrorCode as ErrorCode6, FuelError as FuelError6 } from "@fuel-ts/errors";
|
1377
1389
|
var DEFAULT_BLOCK_EXPLORER_URL = "https://fuellabs.github.io/block-explorer-v2";
|
1378
1390
|
var getPathFromInput = (key, value) => {
|
1379
1391
|
const pathMap = {
|
@@ -1408,14 +1420,14 @@ var buildBlockExplorerUrl = (options = {}) => {
|
|
1408
1420
|
const hasAnyDefinedValues = definedValues.length > 0;
|
1409
1421
|
if (definedValues.length > 1) {
|
1410
1422
|
throw new FuelError6(
|
1411
|
-
|
1423
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1412
1424
|
`Only one of the following can be passed in to buildBlockExplorerUrl: ${customInputParams.map((param) => param.key).join(", ")}.`
|
1413
1425
|
);
|
1414
1426
|
}
|
1415
1427
|
if (path && definedValues.length > 0) {
|
1416
1428
|
const inputKeys = customInputParams.map(({ key }) => key).join(", ");
|
1417
1429
|
throw new FuelError6(
|
1418
|
-
|
1430
|
+
ErrorCode6.ERROR_BUILDING_BLOCK_EXPLORER_URL,
|
1419
1431
|
`You cannot pass in a path to 'buildBlockExplorerUrl' along with any of the following: ${inputKeys}.`
|
1420
1432
|
);
|
1421
1433
|
}
|
@@ -1803,7 +1815,7 @@ var BaseTransactionRequest = class {
|
|
1803
1815
|
txPointer: "0x00000000000000000000000000000000",
|
1804
1816
|
witnessIndex,
|
1805
1817
|
predicate: predicate?.bytes,
|
1806
|
-
predicateData: predicate?.
|
1818
|
+
predicateData: predicate?.predicateDataBytes
|
1807
1819
|
};
|
1808
1820
|
this.pushInput(input);
|
1809
1821
|
this.addChangeOutput(owner, assetId);
|
@@ -1836,7 +1848,7 @@ var BaseTransactionRequest = class {
|
|
1836
1848
|
amount,
|
1837
1849
|
witnessIndex,
|
1838
1850
|
predicate: predicate?.bytes,
|
1839
|
-
predicateData: predicate?.
|
1851
|
+
predicateData: predicate?.predicateDataBytes
|
1840
1852
|
};
|
1841
1853
|
this.pushInput(input);
|
1842
1854
|
this.addChangeOutput(recipient, assetId);
|
@@ -2079,11 +2091,10 @@ import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
|
2079
2091
|
|
2080
2092
|
// src/providers/transaction-request/hash-transaction.ts
|
2081
2093
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2082
|
-
import { uint64ToBytesBE } from "@fuel-ts/hasher";
|
2094
|
+
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2083
2095
|
import { bn as bn7 } from "@fuel-ts/math";
|
2084
2096
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2085
2097
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2086
|
-
import { sha256 } from "ethers";
|
2087
2098
|
import { clone as clone2 } from "ramda";
|
2088
2099
|
function hashTransaction(transactionRequest, chainId) {
|
2089
2100
|
const transaction = transactionRequest.toTransaction();
|
@@ -2470,7 +2481,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2470
2481
|
};
|
2471
2482
|
|
2472
2483
|
// src/providers/transaction-request/utils.ts
|
2473
|
-
import { ErrorCode as
|
2484
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2474
2485
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2475
2486
|
var transactionRequestify = (obj) => {
|
2476
2487
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2485,13 +2496,13 @@ var transactionRequestify = (obj) => {
|
|
2485
2496
|
return CreateTransactionRequest.from(obj);
|
2486
2497
|
}
|
2487
2498
|
default: {
|
2488
|
-
throw new FuelError7(
|
2499
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2489
2500
|
}
|
2490
2501
|
}
|
2491
2502
|
};
|
2492
2503
|
|
2493
2504
|
// src/providers/transaction-response/transaction-response.ts
|
2494
|
-
import { ErrorCode as
|
2505
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2495
2506
|
import { bn as bn13 } from "@fuel-ts/math";
|
2496
2507
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2497
2508
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
@@ -2574,7 +2585,7 @@ var calculateTransactionFee = (params) => {
|
|
2574
2585
|
|
2575
2586
|
// src/providers/transaction-summary/operations.ts
|
2576
2587
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2577
|
-
import { ErrorCode as
|
2588
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2578
2589
|
import { bn as bn12 } from "@fuel-ts/math";
|
2579
2590
|
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2580
2591
|
|
@@ -2623,7 +2634,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2623
2634
|
};
|
2624
2635
|
|
2625
2636
|
// src/providers/transaction-summary/input.ts
|
2626
|
-
import { ErrorCode as
|
2637
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2627
2638
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2628
2639
|
function getInputsByTypes(inputs, types) {
|
2629
2640
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2662,7 +2673,7 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2662
2673
|
}
|
2663
2674
|
if (contractInput.type !== InputType5.Contract) {
|
2664
2675
|
throw new FuelError8(
|
2665
|
-
|
2676
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2666
2677
|
`Contract input should be of type 'contract'.`
|
2667
2678
|
);
|
2668
2679
|
}
|
@@ -2751,7 +2762,7 @@ function getTransactionTypeName(transactionType) {
|
|
2751
2762
|
return "Script" /* Script */;
|
2752
2763
|
default:
|
2753
2764
|
throw new FuelError9(
|
2754
|
-
|
2765
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2755
2766
|
`Invalid transaction type: ${transactionType}.`
|
2756
2767
|
);
|
2757
2768
|
}
|
@@ -3114,7 +3125,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3114
3125
|
};
|
3115
3126
|
|
3116
3127
|
// src/providers/transaction-summary/status.ts
|
3117
|
-
import { ErrorCode as
|
3128
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3118
3129
|
var getTransactionStatusName = (gqlStatus) => {
|
3119
3130
|
switch (gqlStatus) {
|
3120
3131
|
case "FailureStatus":
|
@@ -3127,7 +3138,7 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3127
3138
|
return "squeezedout" /* squeezedout */;
|
3128
3139
|
default:
|
3129
3140
|
throw new FuelError10(
|
3130
|
-
|
3141
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3131
3142
|
`Invalid transaction status: ${gqlStatus}.`
|
3132
3143
|
);
|
3133
3144
|
}
|
@@ -3347,6 +3358,12 @@ var TransactionResponse = class {
|
|
3347
3358
|
transactionId: this.id
|
3348
3359
|
});
|
3349
3360
|
for await (const { statusChange } of subscription) {
|
3361
|
+
if (statusChange.type === "SqueezedOutStatus") {
|
3362
|
+
throw new FuelError11(
|
3363
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3364
|
+
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3365
|
+
);
|
3366
|
+
}
|
3350
3367
|
if (statusChange.type !== "SubmittedStatus") {
|
3351
3368
|
break;
|
3352
3369
|
}
|
@@ -3376,7 +3393,7 @@ var TransactionResponse = class {
|
|
3376
3393
|
const result = await this.waitForResult(contractsAbiMap);
|
3377
3394
|
if (result.isStatusFailure) {
|
3378
3395
|
throw new FuelError11(
|
3379
|
-
|
3396
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3380
3397
|
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3381
3398
|
);
|
3382
3399
|
}
|
@@ -3524,14 +3541,15 @@ var _Provider = class {
|
|
3524
3541
|
}
|
3525
3542
|
static getFetchFn(options) {
|
3526
3543
|
const { retryOptions, timeout } = options;
|
3527
|
-
return autoRetryFetch((...args) => {
|
3528
|
-
if (options.fetch) {
|
3529
|
-
return options.fetch(...args);
|
3530
|
-
}
|
3544
|
+
return autoRetryFetch(async (...args) => {
|
3531
3545
|
const url = args[0];
|
3532
3546
|
const request = args[1];
|
3533
3547
|
const signal = timeout ? AbortSignal.timeout(timeout) : void 0;
|
3534
|
-
|
3548
|
+
let fullRequest = { ...request, signal };
|
3549
|
+
if (options.requestMiddleware) {
|
3550
|
+
fullRequest = await options.requestMiddleware(fullRequest);
|
3551
|
+
}
|
3552
|
+
return options.fetch ? options.fetch(url, fullRequest, options) : fetch(url, fullRequest);
|
3535
3553
|
}, retryOptions);
|
3536
3554
|
}
|
3537
3555
|
/**
|
@@ -3551,7 +3569,7 @@ var _Provider = class {
|
|
3551
3569
|
const chain = _Provider.chainInfoCache[this.url];
|
3552
3570
|
if (!chain) {
|
3553
3571
|
throw new FuelError12(
|
3554
|
-
|
3572
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3555
3573
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3556
3574
|
);
|
3557
3575
|
}
|
@@ -3564,7 +3582,7 @@ var _Provider = class {
|
|
3564
3582
|
const node = _Provider.nodeInfoCache[this.url];
|
3565
3583
|
if (!node) {
|
3566
3584
|
throw new FuelError12(
|
3567
|
-
|
3585
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3568
3586
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3569
3587
|
);
|
3570
3588
|
}
|
@@ -3737,6 +3755,12 @@ var _Provider = class {
|
|
3737
3755
|
if (awaitExecution) {
|
3738
3756
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3739
3757
|
for await (const { submitAndAwait } of subscription) {
|
3758
|
+
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3759
|
+
throw new FuelError12(
|
3760
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3761
|
+
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3762
|
+
);
|
3763
|
+
}
|
3740
3764
|
if (submitAndAwait.type !== "SubmittedStatus") {
|
3741
3765
|
break;
|
3742
3766
|
}
|
@@ -4247,7 +4271,7 @@ var _Provider = class {
|
|
4247
4271
|
};
|
4248
4272
|
if (commitBlockId && commitBlockHeight) {
|
4249
4273
|
throw new FuelError12(
|
4250
|
-
|
4274
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4251
4275
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4252
4276
|
);
|
4253
4277
|
}
|
@@ -4364,7 +4388,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4364
4388
|
__publicField(Provider, "nodeInfoCache", {});
|
4365
4389
|
|
4366
4390
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4367
|
-
import { ErrorCode as
|
4391
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4368
4392
|
import { bn as bn15 } from "@fuel-ts/math";
|
4369
4393
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4370
4394
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
@@ -4375,7 +4399,7 @@ async function getTransactionSummary(params) {
|
|
4375
4399
|
});
|
4376
4400
|
if (!gqlTransaction) {
|
4377
4401
|
throw new FuelError13(
|
4378
|
-
|
4402
|
+
ErrorCode13.TRANSACTION_NOT_FOUND,
|
4379
4403
|
`Transaction not found for given id: ${id}.`
|
4380
4404
|
);
|
4381
4405
|
}
|
@@ -4648,7 +4672,7 @@ var Account = class extends AbstractAccount {
|
|
4648
4672
|
*/
|
4649
4673
|
get provider() {
|
4650
4674
|
if (!this._provider) {
|
4651
|
-
throw new FuelError14(
|
4675
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4652
4676
|
}
|
4653
4677
|
return this._provider;
|
4654
4678
|
}
|
@@ -4701,7 +4725,7 @@ var Account = class extends AbstractAccount {
|
|
4701
4725
|
break;
|
4702
4726
|
}
|
4703
4727
|
throw new FuelError14(
|
4704
|
-
|
4728
|
+
ErrorCode14.NOT_SUPPORTED,
|
4705
4729
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4706
4730
|
);
|
4707
4731
|
}
|
@@ -4727,7 +4751,7 @@ var Account = class extends AbstractAccount {
|
|
4727
4751
|
break;
|
4728
4752
|
}
|
4729
4753
|
throw new FuelError14(
|
4730
|
-
|
4754
|
+
ErrorCode14.NOT_SUPPORTED,
|
4731
4755
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4732
4756
|
);
|
4733
4757
|
}
|
@@ -4763,7 +4787,7 @@ var Account = class extends AbstractAccount {
|
|
4763
4787
|
break;
|
4764
4788
|
}
|
4765
4789
|
throw new FuelError14(
|
4766
|
-
|
4790
|
+
ErrorCode14.NOT_SUPPORTED,
|
4767
4791
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4768
4792
|
);
|
4769
4793
|
}
|
@@ -4868,6 +4892,12 @@ var Account = class extends AbstractAccount {
|
|
4868
4892
|
* @returns A promise that resolves to the transaction response.
|
4869
4893
|
*/
|
4870
4894
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4895
|
+
if (bn16(amount).lte(0)) {
|
4896
|
+
throw new FuelError14(
|
4897
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4898
|
+
"Transfer amount must be a positive number."
|
4899
|
+
);
|
4900
|
+
}
|
4871
4901
|
const request = await this.createTransfer(destination, amount, assetId, txParams);
|
4872
4902
|
return this.sendTransaction(request, { estimateTxDependencies: false });
|
4873
4903
|
}
|
@@ -4881,6 +4911,12 @@ var Account = class extends AbstractAccount {
|
|
4881
4911
|
* @returns A promise that resolves to the transaction response.
|
4882
4912
|
*/
|
4883
4913
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4914
|
+
if (bn16(amount).lte(0)) {
|
4915
|
+
throw new FuelError14(
|
4916
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
4917
|
+
"Transfer amount must be a positive number."
|
4918
|
+
);
|
4919
|
+
}
|
4884
4920
|
const contractAddress = Address3.fromAddressOrString(contractId);
|
4885
4921
|
const { minGasPrice } = this.provider.getGasConfig();
|
4886
4922
|
const params = { gasPrice: minGasPrice, ...txParams };
|
@@ -4950,7 +4986,7 @@ var Account = class extends AbstractAccount {
|
|
4950
4986
|
}
|
4951
4987
|
async signMessage(message) {
|
4952
4988
|
if (!this._connector) {
|
4953
|
-
throw new FuelError14(
|
4989
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4954
4990
|
}
|
4955
4991
|
return this._connector.signMessage(this.address.toString(), message);
|
4956
4992
|
}
|
@@ -4996,13 +5032,13 @@ var Account = class extends AbstractAccount {
|
|
4996
5032
|
}) {
|
4997
5033
|
if (minGasPrice.gt(gasPrice)) {
|
4998
5034
|
throw new FuelError14(
|
4999
|
-
|
5035
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5000
5036
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5001
5037
|
);
|
5002
5038
|
}
|
5003
5039
|
if (gasUsed.gt(gasLimit)) {
|
5004
5040
|
throw new FuelError14(
|
5005
|
-
|
5041
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
5006
5042
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5007
5043
|
);
|
5008
5044
|
}
|
@@ -5133,7 +5169,7 @@ import {
|
|
5133
5169
|
decryptJsonWalletData,
|
5134
5170
|
encryptJsonWalletData
|
5135
5171
|
} from "@fuel-ts/crypto";
|
5136
|
-
import { ErrorCode as
|
5172
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5137
5173
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5138
5174
|
import { v4 as uuidv4 } from "uuid";
|
5139
5175
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5212,7 +5248,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5212
5248
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5213
5249
|
if (mac !== macHash) {
|
5214
5250
|
throw new FuelError15(
|
5215
|
-
|
5251
|
+
ErrorCode15.INVALID_PASSWORD,
|
5216
5252
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5217
5253
|
);
|
5218
5254
|
}
|
@@ -5334,24 +5370,18 @@ var BaseWalletUnlocked = class extends Account {
|
|
5334
5370
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5335
5371
|
|
5336
5372
|
// src/hdwallet/hdwallet.ts
|
5337
|
-
import { ErrorCode as
|
5373
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5374
|
+
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5338
5375
|
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5339
5376
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5340
|
-
import {
|
5341
|
-
toBeHex,
|
5342
|
-
dataSlice as dataSlice2,
|
5343
|
-
encodeBase58 as encodeBase582,
|
5344
|
-
decodeBase58,
|
5345
|
-
sha256 as sha2564,
|
5346
|
-
computeHmac as computeHmac2,
|
5347
|
-
ripemd160
|
5348
|
-
} from "ethers";
|
5377
|
+
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5349
5378
|
|
5350
5379
|
// src/mnemonic/mnemonic.ts
|
5351
5380
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5352
|
-
import { ErrorCode as
|
5381
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5382
|
+
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5353
5383
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5354
|
-
import { dataSlice, pbkdf2,
|
5384
|
+
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5355
5385
|
|
5356
5386
|
// src/wordlists/words/english.ts
|
5357
5387
|
var english = [
|
@@ -7412,9 +7442,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7412
7442
|
})(Language || {});
|
7413
7443
|
|
7414
7444
|
// src/mnemonic/utils.ts
|
7415
|
-
import { ErrorCode as
|
7445
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7446
|
+
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7416
7447
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7417
|
-
import { sha256 as sha2562 } from "ethers";
|
7418
7448
|
function toUtf8Bytes(stri) {
|
7419
7449
|
const str = stri.normalize("NFKD");
|
7420
7450
|
const result = [];
|
@@ -7430,7 +7460,7 @@ function toUtf8Bytes(stri) {
|
|
7430
7460
|
const c2 = str.charCodeAt(i);
|
7431
7461
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7432
7462
|
throw new FuelError16(
|
7433
|
-
|
7463
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7434
7464
|
"Invalid UTF-8 in the input string."
|
7435
7465
|
);
|
7436
7466
|
}
|
@@ -7494,7 +7524,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7494
7524
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7495
7525
|
if (index === -1) {
|
7496
7526
|
throw new FuelError16(
|
7497
|
-
|
7527
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7498
7528
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7499
7529
|
);
|
7500
7530
|
}
|
@@ -7511,7 +7541,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7511
7541
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7512
7542
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7513
7543
|
throw new FuelError16(
|
7514
|
-
|
7544
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7515
7545
|
"Checksum validation failed for the provided mnemonic."
|
7516
7546
|
);
|
7517
7547
|
}
|
@@ -7526,7 +7556,7 @@ var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
|
7526
7556
|
function assertWordList(wordlist) {
|
7527
7557
|
if (wordlist.length !== 2048) {
|
7528
7558
|
throw new FuelError17(
|
7529
|
-
|
7559
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7530
7560
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7531
7561
|
);
|
7532
7562
|
}
|
@@ -7534,7 +7564,7 @@ function assertWordList(wordlist) {
|
|
7534
7564
|
function assertEntropy(entropy) {
|
7535
7565
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7536
7566
|
throw new FuelError17(
|
7537
|
-
|
7567
|
+
ErrorCode17.INVALID_ENTROPY,
|
7538
7568
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7539
7569
|
);
|
7540
7570
|
}
|
@@ -7544,7 +7574,7 @@ function assertMnemonic(words) {
|
|
7544
7574
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7545
7575
|
", "
|
7546
7576
|
)}] words, but got ${words.length}.`;
|
7547
|
-
throw new FuelError17(
|
7577
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7548
7578
|
}
|
7549
7579
|
}
|
7550
7580
|
var Mnemonic = class {
|
@@ -7663,7 +7693,7 @@ var Mnemonic = class {
|
|
7663
7693
|
const seedArray = arrayify17(seed);
|
7664
7694
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7665
7695
|
throw new FuelError17(
|
7666
|
-
|
7696
|
+
ErrorCode17.INVALID_SEED,
|
7667
7697
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7668
7698
|
);
|
7669
7699
|
}
|
@@ -7740,7 +7770,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7740
7770
|
function parsePath(path, depth = 0) {
|
7741
7771
|
const components = path.split("/");
|
7742
7772
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7743
|
-
throw new FuelError18(
|
7773
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7744
7774
|
}
|
7745
7775
|
if (components[0] === "m") {
|
7746
7776
|
components.shift();
|
@@ -7770,7 +7800,7 @@ var HDWallet = class {
|
|
7770
7800
|
} else {
|
7771
7801
|
if (!config.publicKey) {
|
7772
7802
|
throw new FuelError18(
|
7773
|
-
|
7803
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7774
7804
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7775
7805
|
);
|
7776
7806
|
}
|
@@ -7800,7 +7830,7 @@ var HDWallet = class {
|
|
7800
7830
|
if (index & HARDENED_INDEX) {
|
7801
7831
|
if (!privateKey) {
|
7802
7832
|
throw new FuelError18(
|
7803
|
-
|
7833
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7804
7834
|
"Cannot derive a hardened index without a private Key."
|
7805
7835
|
);
|
7806
7836
|
}
|
@@ -7853,7 +7883,7 @@ var HDWallet = class {
|
|
7853
7883
|
toExtendedKey(isPublic = false, testnet = false) {
|
7854
7884
|
if (this.depth >= 256) {
|
7855
7885
|
throw new FuelError18(
|
7856
|
-
|
7886
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7857
7887
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7858
7888
|
);
|
7859
7889
|
}
|
@@ -7884,10 +7914,10 @@ var HDWallet = class {
|
|
7884
7914
|
const bytes = arrayify18(decoded);
|
7885
7915
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7886
7916
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7887
|
-
throw new FuelError18(
|
7917
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7888
7918
|
}
|
7889
7919
|
if (!validChecksum) {
|
7890
|
-
throw new FuelError18(
|
7920
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7891
7921
|
}
|
7892
7922
|
const depth = bytes[4];
|
7893
7923
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7896,13 +7926,13 @@ var HDWallet = class {
|
|
7896
7926
|
const key = bytes.slice(45, 78);
|
7897
7927
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7898
7928
|
throw new FuelError18(
|
7899
|
-
|
7929
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7900
7930
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7901
7931
|
);
|
7902
7932
|
}
|
7903
7933
|
if (isPublicExtendedKey(bytes)) {
|
7904
7934
|
if (key[0] !== 3) {
|
7905
|
-
throw new FuelError18(
|
7935
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
7906
7936
|
}
|
7907
7937
|
return new HDWallet({
|
7908
7938
|
publicKey: key,
|
@@ -7913,7 +7943,7 @@ var HDWallet = class {
|
|
7913
7943
|
});
|
7914
7944
|
}
|
7915
7945
|
if (key[0] !== 0) {
|
7916
|
-
throw new FuelError18(
|
7946
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
7917
7947
|
}
|
7918
7948
|
return new HDWallet({
|
7919
7949
|
privateKey: key.slice(1),
|
@@ -8081,7 +8111,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8081
8111
|
// src/wallet-manager/wallet-manager.ts
|
8082
8112
|
import { Address as Address8 } from "@fuel-ts/address";
|
8083
8113
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8084
|
-
import { ErrorCode as
|
8114
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8085
8115
|
import { EventEmitter } from "events";
|
8086
8116
|
|
8087
8117
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8104,7 +8134,7 @@ var MemoryStorage = class {
|
|
8104
8134
|
|
8105
8135
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8106
8136
|
import { Address as Address6 } from "@fuel-ts/address";
|
8107
|
-
import { ErrorCode as
|
8137
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
8108
8138
|
var _secret;
|
8109
8139
|
var MnemonicVault = class {
|
8110
8140
|
constructor(options) {
|
@@ -8161,7 +8191,7 @@ var MnemonicVault = class {
|
|
8161
8191
|
numberOfAccounts += 1;
|
8162
8192
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8163
8193
|
throw new FuelError19(
|
8164
|
-
|
8194
|
+
ErrorCode19.WALLET_MANAGER_ERROR,
|
8165
8195
|
`Account with address '${address}' not found in derived wallets.`
|
8166
8196
|
);
|
8167
8197
|
}
|
@@ -8175,7 +8205,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8175
8205
|
|
8176
8206
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8177
8207
|
import { Address as Address7 } from "@fuel-ts/address";
|
8178
|
-
import { ErrorCode as
|
8208
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8179
8209
|
var _privateKeys;
|
8180
8210
|
var PrivateKeyVault = class {
|
8181
8211
|
/**
|
@@ -8217,7 +8247,7 @@ var PrivateKeyVault = class {
|
|
8217
8247
|
);
|
8218
8248
|
if (!privateKey) {
|
8219
8249
|
throw new FuelError20(
|
8220
|
-
|
8250
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8221
8251
|
`No private key found for address '${address}'.`
|
8222
8252
|
);
|
8223
8253
|
}
|
@@ -8241,7 +8271,7 @@ var ERROR_MESSAGES = {
|
|
8241
8271
|
};
|
8242
8272
|
function assert(condition, message) {
|
8243
8273
|
if (!condition) {
|
8244
|
-
throw new FuelError21(
|
8274
|
+
throw new FuelError21(ErrorCode21.WALLET_MANAGER_ERROR, message);
|
8245
8275
|
}
|
8246
8276
|
}
|
8247
8277
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8467,25 +8497,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8467
8497
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8468
8498
|
|
8469
8499
|
// src/wallet-manager/types.ts
|
8470
|
-
import { ErrorCode as
|
8500
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8471
8501
|
var Vault = class {
|
8472
8502
|
constructor(_options) {
|
8473
|
-
throw new FuelError22(
|
8503
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8474
8504
|
}
|
8475
8505
|
serialize() {
|
8476
|
-
throw new FuelError22(
|
8506
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8477
8507
|
}
|
8478
8508
|
getAccounts() {
|
8479
|
-
throw new FuelError22(
|
8509
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8480
8510
|
}
|
8481
8511
|
addAccount() {
|
8482
|
-
throw new FuelError22(
|
8512
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8483
8513
|
}
|
8484
8514
|
exportAccount(_address) {
|
8485
|
-
throw new FuelError22(
|
8515
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8486
8516
|
}
|
8487
8517
|
getWallet(_address) {
|
8488
|
-
throw new FuelError22(
|
8518
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8489
8519
|
}
|
8490
8520
|
};
|
8491
8521
|
__publicField(Vault, "type");
|
@@ -8502,7 +8532,7 @@ import {
|
|
8502
8532
|
} from "@fuel-ts/abi-coder";
|
8503
8533
|
import { Address as Address9 } from "@fuel-ts/address";
|
8504
8534
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8505
|
-
import { ErrorCode as
|
8535
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8506
8536
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8507
8537
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8508
8538
|
|
@@ -8522,27 +8552,37 @@ var getPredicateRoot = (bytecode) => {
|
|
8522
8552
|
// src/predicate/predicate.ts
|
8523
8553
|
var Predicate = class extends Account {
|
8524
8554
|
bytes;
|
8525
|
-
|
8526
|
-
|
8555
|
+
predicateDataBytes = Uint8Array.from([]);
|
8556
|
+
predicateData = [];
|
8527
8557
|
interface;
|
8528
8558
|
/**
|
8529
8559
|
* Creates an instance of the Predicate class.
|
8530
8560
|
*
|
8531
|
-
* @param
|
8561
|
+
* @param bytecode - The bytecode of the predicate.
|
8562
|
+
* @param abi - The JSON ABI of the predicate.
|
8532
8563
|
* @param provider - The provider used to interact with the blockchain.
|
8533
|
-
* @param
|
8564
|
+
* @param inputData - The predicate input data (optional).
|
8534
8565
|
* @param configurableConstants - Optional configurable constants for the predicate.
|
8535
8566
|
*/
|
8536
|
-
constructor(
|
8567
|
+
constructor({
|
8568
|
+
bytecode,
|
8569
|
+
abi,
|
8570
|
+
provider,
|
8571
|
+
inputData,
|
8572
|
+
configurableConstants
|
8573
|
+
}) {
|
8537
8574
|
const { predicateBytes, predicateInterface } = Predicate.processPredicateData(
|
8538
|
-
|
8539
|
-
|
8575
|
+
bytecode,
|
8576
|
+
abi,
|
8540
8577
|
configurableConstants
|
8541
8578
|
);
|
8542
8579
|
const address = Address9.fromB256(getPredicateRoot(predicateBytes));
|
8543
8580
|
super(address, provider);
|
8544
8581
|
this.bytes = predicateBytes;
|
8545
8582
|
this.interface = predicateInterface;
|
8583
|
+
if (inputData !== void 0 && inputData.length > 0) {
|
8584
|
+
this.predicateData = inputData;
|
8585
|
+
}
|
8546
8586
|
}
|
8547
8587
|
/**
|
8548
8588
|
* Populates the transaction data with predicate data.
|
@@ -8594,18 +8634,8 @@ var Predicate = class extends Account {
|
|
8594
8634
|
const transactionRequest = this.populateTransactionPredicateData(transactionRequestLike);
|
8595
8635
|
return super.simulateTransaction(transactionRequest);
|
8596
8636
|
}
|
8597
|
-
/**
|
8598
|
-
* Sets data for the predicate.
|
8599
|
-
*
|
8600
|
-
* @param args - Arguments for the predicate function.
|
8601
|
-
* @returns The Predicate instance with updated predicate data.
|
8602
|
-
*/
|
8603
|
-
setData(...args) {
|
8604
|
-
this.predicateArgs = args;
|
8605
|
-
return this;
|
8606
|
-
}
|
8607
8637
|
getPredicateData(policiesLength) {
|
8608
|
-
if (!this.
|
8638
|
+
if (!this.predicateData.length) {
|
8609
8639
|
return new Uint8Array();
|
8610
8640
|
}
|
8611
8641
|
const mainFn = this.interface?.functions.main;
|
@@ -8614,7 +8644,7 @@ var Predicate = class extends Account {
|
|
8614
8644
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8615
8645
|
});
|
8616
8646
|
const OFFSET = VM_TX_MEMORY + SCRIPT_FIXED_SIZE + INPUT_COIN_FIXED_SIZE + WORD_SIZE + paddedCode.byteLength + policiesLength * WORD_SIZE;
|
8617
|
-
return mainFn?.encodeArguments(this.
|
8647
|
+
return mainFn?.encodeArguments(this.predicateData, OFFSET) || new Uint8Array();
|
8618
8648
|
}
|
8619
8649
|
/**
|
8620
8650
|
* Processes the predicate data and returns the altered bytecode and interface.
|
@@ -8631,7 +8661,7 @@ var Predicate = class extends Account {
|
|
8631
8661
|
abiInterface = new Interface3(jsonAbi);
|
8632
8662
|
if (abiInterface.functions.main === void 0) {
|
8633
8663
|
throw new FuelError23(
|
8634
|
-
|
8664
|
+
ErrorCode23.ABI_MAIN_METHOD_MISSING,
|
8635
8665
|
'Cannot use ABI without "main" function.'
|
8636
8666
|
);
|
8637
8667
|
}
|
@@ -8677,7 +8707,7 @@ var Predicate = class extends Account {
|
|
8677
8707
|
});
|
8678
8708
|
} catch (err) {
|
8679
8709
|
throw new FuelError23(
|
8680
|
-
|
8710
|
+
ErrorCode23.INVALID_CONFIGURABLE_CONSTANTS,
|
8681
8711
|
`Error setting configurable constants: ${err.message}.`
|
8682
8712
|
);
|
8683
8713
|
}
|
@@ -8686,7 +8716,7 @@ var Predicate = class extends Account {
|
|
8686
8716
|
};
|
8687
8717
|
|
8688
8718
|
// src/connectors/fuel.ts
|
8689
|
-
import { ErrorCode as
|
8719
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8690
8720
|
|
8691
8721
|
// src/connectors/fuel-connector.ts
|
8692
8722
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9307,7 +9337,7 @@ var _Fuel = class extends FuelConnector {
|
|
9307
9337
|
const currentNetwork = await this.currentNetwork();
|
9308
9338
|
provider = await Provider.create(currentNetwork.url);
|
9309
9339
|
} else {
|
9310
|
-
throw new FuelError24(
|
9340
|
+
throw new FuelError24(ErrorCode24.INVALID_PROVIDER, "Provider is not valid.");
|
9311
9341
|
}
|
9312
9342
|
return provider;
|
9313
9343
|
}
|