@fuel-ts/account 0.0.0-rc-1895-20240404023124 → 0.0.0-rc-1832-20240404064601
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/index.global.js +84 -177
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +468 -551
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -328
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +84 -177
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +434 -511
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +213 -298
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/providers/utils/extract-tx-error.d.ts +0 -36
- package/dist/providers/utils/extract-tx-error.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
@@ -30,9 +30,9 @@ 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
|
-
import { bn as
|
35
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
37
|
|
38
38
|
// src/providers/coin-quantity.ts
|
@@ -73,8 +73,8 @@ 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
|
77
|
-
import { BN, bn as
|
76
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
77
|
+
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
78
78
|
import {
|
79
79
|
InputType as InputType6,
|
80
80
|
TransactionType as TransactionType8,
|
@@ -1157,7 +1157,7 @@ var outputify = (value) => {
|
|
1157
1157
|
// src/providers/transaction-request/transaction-request.ts
|
1158
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
1159
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1160
|
-
import { bn as
|
1160
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1161
1161
|
import {
|
1162
1162
|
PolicyType,
|
1163
1163
|
TransactionCoder,
|
@@ -1562,86 +1562,6 @@ function sleep(time) {
|
|
1562
1562
|
});
|
1563
1563
|
}
|
1564
1564
|
|
1565
|
-
// src/providers/utils/extract-tx-error.ts
|
1566
|
-
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1567
|
-
import { bn as bn6 } from "@fuel-ts/math";
|
1568
|
-
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1569
|
-
import {
|
1570
|
-
FAILED_REQUIRE_SIGNAL,
|
1571
|
-
FAILED_ASSERT_EQ_SIGNAL,
|
1572
|
-
FAILED_ASSERT_NE_SIGNAL,
|
1573
|
-
FAILED_ASSERT_SIGNAL,
|
1574
|
-
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1575
|
-
PANIC_REASONS,
|
1576
|
-
PANIC_DOC_URL
|
1577
|
-
} from "@fuel-ts/transactions/configs";
|
1578
|
-
var assemblePanicError = (status) => {
|
1579
|
-
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1580
|
-
const reason = status.reason;
|
1581
|
-
if (PANIC_REASONS.includes(status.reason)) {
|
1582
|
-
errorMessage = `${errorMessage}
|
1583
|
-
|
1584
|
-
You can read more about this error at:
|
1585
|
-
|
1586
|
-
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1587
|
-
}
|
1588
|
-
return { errorMessage, reason };
|
1589
|
-
};
|
1590
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1591
|
-
var assembleRevertError = (receipts, logs) => {
|
1592
|
-
let errorMessage = "The transaction reverted with an unknown reason.";
|
1593
|
-
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1594
|
-
let reason = "";
|
1595
|
-
if (revertReceipt) {
|
1596
|
-
const reasonHex = bn6(revertReceipt.val).toHex();
|
1597
|
-
switch (reasonHex) {
|
1598
|
-
case FAILED_REQUIRE_SIGNAL: {
|
1599
|
-
reason = "require";
|
1600
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1601
|
-
break;
|
1602
|
-
}
|
1603
|
-
case FAILED_ASSERT_EQ_SIGNAL: {
|
1604
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1605
|
-
reason = "assert_eq";
|
1606
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1607
|
-
break;
|
1608
|
-
}
|
1609
|
-
case FAILED_ASSERT_NE_SIGNAL: {
|
1610
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1611
|
-
reason = "assert_ne";
|
1612
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1613
|
-
break;
|
1614
|
-
}
|
1615
|
-
case FAILED_ASSERT_SIGNAL:
|
1616
|
-
reason = "assert";
|
1617
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1618
|
-
break;
|
1619
|
-
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1620
|
-
reason = "MissingOutputChange";
|
1621
|
-
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1622
|
-
break;
|
1623
|
-
default:
|
1624
|
-
reason = "unknown";
|
1625
|
-
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1626
|
-
}
|
1627
|
-
}
|
1628
|
-
return { errorMessage, reason };
|
1629
|
-
};
|
1630
|
-
var extractTxError = (params) => {
|
1631
|
-
const { receipts, status, logs } = params;
|
1632
|
-
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1633
|
-
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1634
|
-
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1635
|
-
const metadata = {
|
1636
|
-
logs,
|
1637
|
-
receipts,
|
1638
|
-
panic: isPanic,
|
1639
|
-
revert: isRevert,
|
1640
|
-
reason
|
1641
|
-
};
|
1642
|
-
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1643
|
-
};
|
1644
|
-
|
1645
1565
|
// src/providers/transaction-request/errors.ts
|
1646
1566
|
var ChangeOutputCollisionError = class extends Error {
|
1647
1567
|
name = "ChangeOutputCollisionError";
|
@@ -1704,10 +1624,10 @@ var BaseTransactionRequest = class {
|
|
1704
1624
|
outputs,
|
1705
1625
|
witnesses
|
1706
1626
|
} = {}) {
|
1707
|
-
this.gasPrice =
|
1627
|
+
this.gasPrice = bn6(gasPrice);
|
1708
1628
|
this.maturity = maturity ?? 0;
|
1709
|
-
this.witnessLimit = witnessLimit ?
|
1710
|
-
this.maxFee = maxFee ?
|
1629
|
+
this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
|
1630
|
+
this.maxFee = maxFee ? bn6(maxFee) : void 0;
|
1711
1631
|
this.inputs = inputs ?? [];
|
1712
1632
|
this.outputs = outputs ?? [];
|
1713
1633
|
this.witnesses = witnesses ?? [];
|
@@ -2137,13 +2057,13 @@ var BaseTransactionRequest = class {
|
|
2137
2057
|
assetId,
|
2138
2058
|
owner: resourcesOwner || Address.fromRandom(),
|
2139
2059
|
maturity: 0,
|
2140
|
-
blockCreated:
|
2141
|
-
txCreatedIdx:
|
2060
|
+
blockCreated: bn6(1),
|
2061
|
+
txCreatedIdx: bn6(1)
|
2142
2062
|
}
|
2143
2063
|
]);
|
2144
2064
|
}
|
2145
2065
|
};
|
2146
|
-
updateAssetInput(BaseAssetId2,
|
2066
|
+
updateAssetInput(BaseAssetId2, bn6(1e11));
|
2147
2067
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2148
2068
|
}
|
2149
2069
|
/**
|
@@ -2154,7 +2074,7 @@ var BaseTransactionRequest = class {
|
|
2154
2074
|
*/
|
2155
2075
|
getCoinOutputsQuantities() {
|
2156
2076
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2157
|
-
amount:
|
2077
|
+
amount: bn6(amount),
|
2158
2078
|
assetId: assetId.toString()
|
2159
2079
|
}));
|
2160
2080
|
return coinsQuantities;
|
@@ -2183,7 +2103,7 @@ var BaseTransactionRequest = class {
|
|
2183
2103
|
default:
|
2184
2104
|
return;
|
2185
2105
|
}
|
2186
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2106
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn6(correspondingInput.predicateGasUsed).gt(0)) {
|
2187
2107
|
i.predicate = correspondingInput.predicate;
|
2188
2108
|
i.predicateData = correspondingInput.predicateData;
|
2189
2109
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2194,14 +2114,14 @@ var BaseTransactionRequest = class {
|
|
2194
2114
|
|
2195
2115
|
// src/providers/transaction-request/create-transaction-request.ts
|
2196
2116
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2197
|
-
import { bn as
|
2117
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2198
2118
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2199
2119
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2200
2120
|
|
2201
2121
|
// src/providers/transaction-request/hash-transaction.ts
|
2202
2122
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2203
2123
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2204
|
-
import { bn as
|
2124
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
2205
2125
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2206
2126
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2207
2127
|
import { clone as clone2 } from "ramda";
|
@@ -2218,11 +2138,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2218
2138
|
blockHeight: 0,
|
2219
2139
|
txIndex: 0
|
2220
2140
|
};
|
2221
|
-
inputClone.predicateGasUsed =
|
2141
|
+
inputClone.predicateGasUsed = bn7(0);
|
2222
2142
|
return inputClone;
|
2223
2143
|
}
|
2224
2144
|
case InputType3.Message: {
|
2225
|
-
inputClone.predicateGasUsed =
|
2145
|
+
inputClone.predicateGasUsed = bn7(0);
|
2226
2146
|
return inputClone;
|
2227
2147
|
}
|
2228
2148
|
case InputType3.Contract: {
|
@@ -2249,12 +2169,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2249
2169
|
return outputClone;
|
2250
2170
|
}
|
2251
2171
|
case OutputType3.Change: {
|
2252
|
-
outputClone.amount =
|
2172
|
+
outputClone.amount = bn7(0);
|
2253
2173
|
return outputClone;
|
2254
2174
|
}
|
2255
2175
|
case OutputType3.Variable: {
|
2256
2176
|
outputClone.to = ZeroBytes325;
|
2257
|
-
outputClone.amount =
|
2177
|
+
outputClone.amount = bn7(0);
|
2258
2178
|
outputClone.assetId = ZeroBytes325;
|
2259
2179
|
return outputClone;
|
2260
2180
|
}
|
@@ -2378,7 +2298,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2378
2298
|
}
|
2379
2299
|
metadataGas(gasCosts) {
|
2380
2300
|
return calculateMetadataGasForTxCreate({
|
2381
|
-
contractBytesSize:
|
2301
|
+
contractBytesSize: bn8(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2382
2302
|
gasCosts,
|
2383
2303
|
stateRootSize: this.storageSlots.length,
|
2384
2304
|
txBytesSize: this.byteSize()
|
@@ -2390,7 +2310,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2390
2310
|
import { Interface } from "@fuel-ts/abi-coder";
|
2391
2311
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2392
2312
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2393
|
-
import { bn as
|
2313
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2394
2314
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2395
2315
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2396
2316
|
|
@@ -2444,7 +2364,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2444
2364
|
*/
|
2445
2365
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2446
2366
|
super(rest);
|
2447
|
-
this.gasLimit =
|
2367
|
+
this.gasLimit = bn9(gasLimit);
|
2448
2368
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2449
2369
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2450
2370
|
this.abis = rest.abis;
|
@@ -2592,7 +2512,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2592
2512
|
};
|
2593
2513
|
|
2594
2514
|
// src/providers/transaction-request/utils.ts
|
2595
|
-
import { ErrorCode as
|
2515
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
2596
2516
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2597
2517
|
var transactionRequestify = (obj) => {
|
2598
2518
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2607,14 +2527,14 @@ var transactionRequestify = (obj) => {
|
|
2607
2527
|
return CreateTransactionRequest.from(obj);
|
2608
2528
|
}
|
2609
2529
|
default: {
|
2610
|
-
throw new
|
2530
|
+
throw new FuelError7(ErrorCode7.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2611
2531
|
}
|
2612
2532
|
}
|
2613
2533
|
};
|
2614
2534
|
|
2615
2535
|
// src/providers/transaction-response/transaction-response.ts
|
2616
|
-
import { ErrorCode as
|
2617
|
-
import { bn as
|
2536
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
2537
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2618
2538
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2619
2539
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2620
2540
|
|
@@ -2622,7 +2542,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2622
2542
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2623
2543
|
|
2624
2544
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2625
|
-
import { bn as
|
2545
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2626
2546
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2627
2547
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2628
2548
|
var calculateTransactionFee = (params) => {
|
@@ -2631,24 +2551,24 @@ var calculateTransactionFee = (params) => {
|
|
2631
2551
|
rawPayload,
|
2632
2552
|
consensusParameters: { gasCosts, feeParams }
|
2633
2553
|
} = params;
|
2634
|
-
const gasPerByte =
|
2635
|
-
const gasPriceFactor =
|
2554
|
+
const gasPerByte = bn10(feeParams.gasPerByte);
|
2555
|
+
const gasPriceFactor = bn10(feeParams.gasPriceFactor);
|
2636
2556
|
const transactionBytes = arrayify9(rawPayload);
|
2637
2557
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2638
2558
|
if (transaction.type === TransactionType6.Mint) {
|
2639
2559
|
return {
|
2640
|
-
fee:
|
2641
|
-
minFee:
|
2642
|
-
maxFee:
|
2643
|
-
feeFromGasUsed:
|
2560
|
+
fee: bn10(0),
|
2561
|
+
minFee: bn10(0),
|
2562
|
+
maxFee: bn10(0),
|
2563
|
+
feeFromGasUsed: bn10(0)
|
2644
2564
|
};
|
2645
2565
|
}
|
2646
2566
|
const { type, witnesses, inputs, policies } = transaction;
|
2647
|
-
let metadataGas =
|
2648
|
-
let gasLimit =
|
2567
|
+
let metadataGas = bn10(0);
|
2568
|
+
let gasLimit = bn10(0);
|
2649
2569
|
if (type === TransactionType6.Create) {
|
2650
2570
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2651
|
-
const contractBytesSize =
|
2571
|
+
const contractBytesSize = bn10(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2652
2572
|
metadataGas = calculateMetadataGasForTxCreate({
|
2653
2573
|
contractBytesSize,
|
2654
2574
|
gasCosts,
|
@@ -2667,12 +2587,12 @@ var calculateTransactionFee = (params) => {
|
|
2667
2587
|
}
|
2668
2588
|
const minGas = getMinGas({
|
2669
2589
|
gasCosts,
|
2670
|
-
gasPerByte:
|
2590
|
+
gasPerByte: bn10(gasPerByte),
|
2671
2591
|
inputs,
|
2672
2592
|
metadataGas,
|
2673
2593
|
txBytesSize: transactionBytes.length
|
2674
2594
|
});
|
2675
|
-
const gasPrice =
|
2595
|
+
const gasPrice = bn10(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2676
2596
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2677
2597
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2678
2598
|
const maxGas = getMaxGas({
|
@@ -2696,13 +2616,13 @@ var calculateTransactionFee = (params) => {
|
|
2696
2616
|
|
2697
2617
|
// src/providers/transaction-summary/operations.ts
|
2698
2618
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2699
|
-
import { ErrorCode as
|
2700
|
-
import { bn as
|
2701
|
-
import { ReceiptType as
|
2619
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2620
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2621
|
+
import { ReceiptType as ReceiptType3, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2702
2622
|
|
2703
2623
|
// src/providers/transaction-summary/call.ts
|
2704
2624
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2705
|
-
import { bn as
|
2625
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2706
2626
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2707
2627
|
const abiInterface = new Interface2(abi);
|
2708
2628
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2711,7 +2631,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2711
2631
|
let encodedArgs;
|
2712
2632
|
if (functionFragment.isInputDataPointer) {
|
2713
2633
|
if (rawPayload) {
|
2714
|
-
const argsOffset =
|
2634
|
+
const argsOffset = bn11(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2715
2635
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2716
2636
|
}
|
2717
2637
|
} else {
|
@@ -2745,7 +2665,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2745
2665
|
};
|
2746
2666
|
|
2747
2667
|
// src/providers/transaction-summary/input.ts
|
2748
|
-
import { ErrorCode as
|
2668
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2749
2669
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2750
2670
|
function getInputsByTypes(inputs, types) {
|
2751
2671
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2783,8 +2703,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2783
2703
|
return void 0;
|
2784
2704
|
}
|
2785
2705
|
if (contractInput.type !== InputType5.Contract) {
|
2786
|
-
throw new
|
2787
|
-
|
2706
|
+
throw new FuelError8(
|
2707
|
+
ErrorCode8.INVALID_TRANSACTION_INPUT,
|
2788
2708
|
`Contract input should be of type 'contract'.`
|
2789
2709
|
);
|
2790
2710
|
}
|
@@ -2872,8 +2792,8 @@ function getTransactionTypeName(transactionType) {
|
|
2872
2792
|
case TransactionType7.Script:
|
2873
2793
|
return "Script" /* Script */;
|
2874
2794
|
default:
|
2875
|
-
throw new
|
2876
|
-
|
2795
|
+
throw new FuelError9(
|
2796
|
+
ErrorCode9.INVALID_TRANSACTION_TYPE,
|
2877
2797
|
`Invalid transaction type: ${transactionType}.`
|
2878
2798
|
);
|
2879
2799
|
}
|
@@ -2895,10 +2815,10 @@ function hasSameAssetId(a) {
|
|
2895
2815
|
return (b) => a.assetId === b.assetId;
|
2896
2816
|
}
|
2897
2817
|
function getReceiptsCall(receipts) {
|
2898
|
-
return getReceiptsByType(receipts,
|
2818
|
+
return getReceiptsByType(receipts, ReceiptType3.Call);
|
2899
2819
|
}
|
2900
2820
|
function getReceiptsMessageOut(receipts) {
|
2901
|
-
return getReceiptsByType(receipts,
|
2821
|
+
return getReceiptsByType(receipts, ReceiptType3.MessageOut);
|
2902
2822
|
}
|
2903
2823
|
var mergeAssets = (op1, op2) => {
|
2904
2824
|
const assets1 = op1.assetsSent || [];
|
@@ -2911,7 +2831,7 @@ var mergeAssets = (op1, op2) => {
|
|
2911
2831
|
if (!matchingAsset) {
|
2912
2832
|
return asset1;
|
2913
2833
|
}
|
2914
|
-
const mergedAmount =
|
2834
|
+
const mergedAmount = bn12(asset1.amount).add(matchingAsset.amount);
|
2915
2835
|
return { ...asset1, amount: mergedAmount };
|
2916
2836
|
});
|
2917
2837
|
return mergedAssets.concat(filteredAssets);
|
@@ -2937,7 +2857,7 @@ function addOperation(operations, toAdd) {
|
|
2937
2857
|
return allOperations;
|
2938
2858
|
}
|
2939
2859
|
function getReceiptsTransferOut(receipts) {
|
2940
|
-
return getReceiptsByType(receipts,
|
2860
|
+
return getReceiptsByType(receipts, ReceiptType3.TransferOut);
|
2941
2861
|
}
|
2942
2862
|
function getWithdrawFromFuelOperations({
|
2943
2863
|
inputs,
|
@@ -3097,11 +3017,11 @@ function getTransferOperations({
|
|
3097
3017
|
});
|
3098
3018
|
const transferReceipts = getReceiptsByType(
|
3099
3019
|
receipts,
|
3100
|
-
|
3020
|
+
ReceiptType3.Transfer
|
3101
3021
|
);
|
3102
3022
|
const transferOutReceipts = getReceiptsByType(
|
3103
3023
|
receipts,
|
3104
|
-
|
3024
|
+
ReceiptType3.TransferOut
|
3105
3025
|
);
|
3106
3026
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3107
3027
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3186,17 +3106,17 @@ function getOperations({
|
|
3186
3106
|
}
|
3187
3107
|
|
3188
3108
|
// src/providers/transaction-summary/receipt.ts
|
3189
|
-
import { ReceiptType as
|
3109
|
+
import { ReceiptType as ReceiptType4 } from "@fuel-ts/transactions";
|
3190
3110
|
var processGqlReceipt = (gqlReceipt) => {
|
3191
3111
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3192
3112
|
switch (receipt.type) {
|
3193
|
-
case
|
3113
|
+
case ReceiptType4.ReturnData: {
|
3194
3114
|
return {
|
3195
3115
|
...receipt,
|
3196
3116
|
data: gqlReceipt.data || "0x"
|
3197
3117
|
};
|
3198
3118
|
}
|
3199
|
-
case
|
3119
|
+
case ReceiptType4.LogData: {
|
3200
3120
|
return {
|
3201
3121
|
...receipt,
|
3202
3122
|
data: gqlReceipt.data || "0x"
|
@@ -3209,7 +3129,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3209
3129
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3210
3130
|
const mintedAssets = [];
|
3211
3131
|
receipts.forEach((receipt) => {
|
3212
|
-
if (receipt.type ===
|
3132
|
+
if (receipt.type === ReceiptType4.Mint) {
|
3213
3133
|
mintedAssets.push({
|
3214
3134
|
subId: receipt.subId,
|
3215
3135
|
contractId: receipt.contractId,
|
@@ -3223,7 +3143,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3223
3143
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3224
3144
|
const burnedAssets = [];
|
3225
3145
|
receipts.forEach((receipt) => {
|
3226
|
-
if (receipt.type ===
|
3146
|
+
if (receipt.type === ReceiptType4.Burn) {
|
3227
3147
|
burnedAssets.push({
|
3228
3148
|
subId: receipt.subId,
|
3229
3149
|
contractId: receipt.contractId,
|
@@ -3236,7 +3156,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3236
3156
|
};
|
3237
3157
|
|
3238
3158
|
// src/providers/transaction-summary/status.ts
|
3239
|
-
import { ErrorCode as
|
3159
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
3240
3160
|
var getTransactionStatusName = (gqlStatus) => {
|
3241
3161
|
switch (gqlStatus) {
|
3242
3162
|
case "FailureStatus":
|
@@ -3248,8 +3168,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3248
3168
|
case "SqueezedOutStatus":
|
3249
3169
|
return "squeezedout" /* squeezedout */;
|
3250
3170
|
default:
|
3251
|
-
throw new
|
3252
|
-
|
3171
|
+
throw new FuelError10(
|
3172
|
+
ErrorCode10.INVALID_TRANSACTION_STATUS,
|
3253
3173
|
`Invalid transaction status: ${gqlStatus}.`
|
3254
3174
|
);
|
3255
3175
|
}
|
@@ -3362,12 +3282,12 @@ function assembleTransactionSummary(params) {
|
|
3362
3282
|
|
3363
3283
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3364
3284
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3365
|
-
import { ReceiptType as
|
3285
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3366
3286
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3367
3287
|
return receipts.reduce((logs, receipt) => {
|
3368
|
-
if (receipt.type ===
|
3288
|
+
if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
|
3369
3289
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3370
|
-
const data = receipt.type ===
|
3290
|
+
const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3371
3291
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3372
3292
|
logs.push(decodedLog);
|
3373
3293
|
}
|
@@ -3382,7 +3302,7 @@ var TransactionResponse = class {
|
|
3382
3302
|
/** Current provider */
|
3383
3303
|
provider;
|
3384
3304
|
/** Gas used on the transaction */
|
3385
|
-
gasUsed =
|
3305
|
+
gasUsed = bn13(0);
|
3386
3306
|
/** The graphql Transaction with receipts object. */
|
3387
3307
|
gqlTransaction;
|
3388
3308
|
abis;
|
@@ -3487,8 +3407,8 @@ var TransactionResponse = class {
|
|
3487
3407
|
});
|
3488
3408
|
for await (const { statusChange } of subscription) {
|
3489
3409
|
if (statusChange.type === "SqueezedOutStatus") {
|
3490
|
-
throw new
|
3491
|
-
|
3410
|
+
throw new FuelError11(
|
3411
|
+
ErrorCode11.TRANSACTION_SQUEEZED_OUT,
|
3492
3412
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3493
3413
|
);
|
3494
3414
|
}
|
@@ -3510,26 +3430,14 @@ var TransactionResponse = class {
|
|
3510
3430
|
gqlTransaction: this.gqlTransaction,
|
3511
3431
|
...transactionSummary
|
3512
3432
|
};
|
3513
|
-
let logs = [];
|
3514
3433
|
if (this.abis) {
|
3515
|
-
logs = getDecodedLogs(
|
3434
|
+
const logs = getDecodedLogs(
|
3516
3435
|
transactionSummary.receipts,
|
3517
3436
|
this.abis.main,
|
3518
3437
|
this.abis.otherContractsAbis
|
3519
3438
|
);
|
3520
3439
|
transactionResult.logs = logs;
|
3521
3440
|
}
|
3522
|
-
if (transactionResult.isStatusFailure) {
|
3523
|
-
const {
|
3524
|
-
receipts,
|
3525
|
-
gqlTransaction: { status }
|
3526
|
-
} = transactionResult;
|
3527
|
-
throw extractTxError({
|
3528
|
-
receipts,
|
3529
|
-
status,
|
3530
|
-
logs
|
3531
|
-
});
|
3532
|
-
}
|
3533
3441
|
return transactionResult;
|
3534
3442
|
}
|
3535
3443
|
/**
|
@@ -3538,7 +3446,14 @@ var TransactionResponse = class {
|
|
3538
3446
|
* @param contractsAbiMap - The contracts ABI map.
|
3539
3447
|
*/
|
3540
3448
|
async wait(contractsAbiMap) {
|
3541
|
-
|
3449
|
+
const result = await this.waitForResult(contractsAbiMap);
|
3450
|
+
if (result.isStatusFailure) {
|
3451
|
+
throw new FuelError11(
|
3452
|
+
ErrorCode11.TRANSACTION_FAILED,
|
3453
|
+
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3454
|
+
);
|
3455
|
+
}
|
3456
|
+
return result;
|
3542
3457
|
}
|
3543
3458
|
};
|
3544
3459
|
|
@@ -3600,29 +3515,29 @@ var processGqlChain = (chain) => {
|
|
3600
3515
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3601
3516
|
return {
|
3602
3517
|
name,
|
3603
|
-
baseChainHeight:
|
3518
|
+
baseChainHeight: bn14(daHeight),
|
3604
3519
|
consensusParameters: {
|
3605
|
-
contractMaxSize:
|
3606
|
-
maxInputs:
|
3607
|
-
maxOutputs:
|
3608
|
-
maxWitnesses:
|
3609
|
-
maxGasPerTx:
|
3610
|
-
maxScriptLength:
|
3611
|
-
maxScriptDataLength:
|
3612
|
-
maxStorageSlots:
|
3613
|
-
maxPredicateLength:
|
3614
|
-
maxPredicateDataLength:
|
3615
|
-
maxGasPerPredicate:
|
3616
|
-
gasPriceFactor:
|
3617
|
-
gasPerByte:
|
3618
|
-
maxMessageDataLength:
|
3619
|
-
chainId:
|
3520
|
+
contractMaxSize: bn14(contractParams.contractMaxSize),
|
3521
|
+
maxInputs: bn14(txParams.maxInputs),
|
3522
|
+
maxOutputs: bn14(txParams.maxOutputs),
|
3523
|
+
maxWitnesses: bn14(txParams.maxWitnesses),
|
3524
|
+
maxGasPerTx: bn14(txParams.maxGasPerTx),
|
3525
|
+
maxScriptLength: bn14(scriptParams.maxScriptLength),
|
3526
|
+
maxScriptDataLength: bn14(scriptParams.maxScriptDataLength),
|
3527
|
+
maxStorageSlots: bn14(contractParams.maxStorageSlots),
|
3528
|
+
maxPredicateLength: bn14(predicateParams.maxPredicateLength),
|
3529
|
+
maxPredicateDataLength: bn14(predicateParams.maxPredicateDataLength),
|
3530
|
+
maxGasPerPredicate: bn14(predicateParams.maxGasPerPredicate),
|
3531
|
+
gasPriceFactor: bn14(feeParams.gasPriceFactor),
|
3532
|
+
gasPerByte: bn14(feeParams.gasPerByte),
|
3533
|
+
maxMessageDataLength: bn14(predicateParams.maxMessageDataLength),
|
3534
|
+
chainId: bn14(consensusParameters.chainId),
|
3620
3535
|
gasCosts
|
3621
3536
|
},
|
3622
3537
|
gasCosts,
|
3623
3538
|
latestBlock: {
|
3624
3539
|
id: latestBlock.id,
|
3625
|
-
height:
|
3540
|
+
height: bn14(latestBlock.header.height),
|
3626
3541
|
time: latestBlock.header.time,
|
3627
3542
|
transactions: latestBlock.transactions.map((i) => ({
|
3628
3543
|
id: i.id
|
@@ -3692,8 +3607,8 @@ var _Provider = class {
|
|
3692
3607
|
getChain() {
|
3693
3608
|
const chain = _Provider.chainInfoCache[this.url];
|
3694
3609
|
if (!chain) {
|
3695
|
-
throw new
|
3696
|
-
|
3610
|
+
throw new FuelError12(
|
3611
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3697
3612
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3698
3613
|
);
|
3699
3614
|
}
|
@@ -3705,8 +3620,8 @@ var _Provider = class {
|
|
3705
3620
|
getNode() {
|
3706
3621
|
const node = _Provider.nodeInfoCache[this.url];
|
3707
3622
|
if (!node) {
|
3708
|
-
throw new
|
3709
|
-
|
3623
|
+
throw new FuelError12(
|
3624
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3710
3625
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3711
3626
|
);
|
3712
3627
|
}
|
@@ -3753,8 +3668,8 @@ var _Provider = class {
|
|
3753
3668
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3754
3669
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3755
3670
|
if (!isMajorSupported || !isMinorSupported) {
|
3756
|
-
throw new
|
3757
|
-
|
3671
|
+
throw new FuelError12(
|
3672
|
+
FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3758
3673
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3759
3674
|
);
|
3760
3675
|
}
|
@@ -3817,7 +3732,7 @@ var _Provider = class {
|
|
3817
3732
|
*/
|
3818
3733
|
async getBlockNumber() {
|
3819
3734
|
const { chain } = await this.operations.getChain();
|
3820
|
-
return
|
3735
|
+
return bn14(chain.latestBlock.header.height, 10);
|
3821
3736
|
}
|
3822
3737
|
/**
|
3823
3738
|
* Returns the chain information.
|
@@ -3827,9 +3742,9 @@ var _Provider = class {
|
|
3827
3742
|
async fetchNode() {
|
3828
3743
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3829
3744
|
const processedNodeInfo = {
|
3830
|
-
maxDepth:
|
3831
|
-
maxTx:
|
3832
|
-
minGasPrice:
|
3745
|
+
maxDepth: bn14(nodeInfo.maxDepth),
|
3746
|
+
maxTx: bn14(nodeInfo.maxTx),
|
3747
|
+
minGasPrice: bn14(nodeInfo.minGasPrice),
|
3833
3748
|
nodeVersion: nodeInfo.nodeVersion,
|
3834
3749
|
utxoValidation: nodeInfo.utxoValidation,
|
3835
3750
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3884,8 +3799,8 @@ var _Provider = class {
|
|
3884
3799
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3885
3800
|
for await (const { submitAndAwait } of subscription) {
|
3886
3801
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3887
|
-
throw new
|
3888
|
-
|
3802
|
+
throw new FuelError12(
|
3803
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3889
3804
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3890
3805
|
);
|
3891
3806
|
}
|
@@ -3952,7 +3867,7 @@ var _Provider = class {
|
|
3952
3867
|
} = response;
|
3953
3868
|
if (inputs) {
|
3954
3869
|
inputs.forEach((input, index) => {
|
3955
|
-
if ("predicateGasUsed" in input &&
|
3870
|
+
if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
|
3956
3871
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3957
3872
|
}
|
3958
3873
|
});
|
@@ -4065,7 +3980,7 @@ var _Provider = class {
|
|
4065
3980
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4066
3981
|
if (estimatePredicates) {
|
4067
3982
|
if (isScriptTransaction) {
|
4068
|
-
txRequestClone.gasLimit =
|
3983
|
+
txRequestClone.gasLimit = bn14(0);
|
4069
3984
|
}
|
4070
3985
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4071
3986
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4081,8 +3996,8 @@ var _Provider = class {
|
|
4081
3996
|
let missingContractIds = [];
|
4082
3997
|
let outputVariables = 0;
|
4083
3998
|
if (isScriptTransaction && estimateTxDependencies) {
|
4084
|
-
txRequestClone.gasPrice =
|
4085
|
-
txRequestClone.gasLimit =
|
3999
|
+
txRequestClone.gasPrice = bn14(0);
|
4000
|
+
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4086
4001
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4087
4002
|
receipts = result.receipts;
|
4088
4003
|
outputVariables = result.outputVariables;
|
@@ -4144,11 +4059,11 @@ var _Provider = class {
|
|
4144
4059
|
return coins.map((coin) => ({
|
4145
4060
|
id: coin.utxoId,
|
4146
4061
|
assetId: coin.assetId,
|
4147
|
-
amount:
|
4062
|
+
amount: bn14(coin.amount),
|
4148
4063
|
owner: Address2.fromAddressOrString(coin.owner),
|
4149
|
-
maturity:
|
4150
|
-
blockCreated:
|
4151
|
-
txCreatedIdx:
|
4064
|
+
maturity: bn14(coin.maturity).toNumber(),
|
4065
|
+
blockCreated: bn14(coin.blockCreated),
|
4066
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4152
4067
|
}));
|
4153
4068
|
}
|
4154
4069
|
/**
|
@@ -4185,9 +4100,9 @@ var _Provider = class {
|
|
4185
4100
|
switch (coin.__typename) {
|
4186
4101
|
case "MessageCoin":
|
4187
4102
|
return {
|
4188
|
-
amount:
|
4103
|
+
amount: bn14(coin.amount),
|
4189
4104
|
assetId: coin.assetId,
|
4190
|
-
daHeight:
|
4105
|
+
daHeight: bn14(coin.daHeight),
|
4191
4106
|
sender: Address2.fromAddressOrString(coin.sender),
|
4192
4107
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4193
4108
|
nonce: coin.nonce
|
@@ -4195,12 +4110,12 @@ var _Provider = class {
|
|
4195
4110
|
case "Coin":
|
4196
4111
|
return {
|
4197
4112
|
id: coin.utxoId,
|
4198
|
-
amount:
|
4113
|
+
amount: bn14(coin.amount),
|
4199
4114
|
assetId: coin.assetId,
|
4200
4115
|
owner: Address2.fromAddressOrString(coin.owner),
|
4201
|
-
maturity:
|
4202
|
-
blockCreated:
|
4203
|
-
txCreatedIdx:
|
4116
|
+
maturity: bn14(coin.maturity).toNumber(),
|
4117
|
+
blockCreated: bn14(coin.blockCreated),
|
4118
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4204
4119
|
};
|
4205
4120
|
default:
|
4206
4121
|
return null;
|
@@ -4217,13 +4132,13 @@ var _Provider = class {
|
|
4217
4132
|
async getBlock(idOrHeight) {
|
4218
4133
|
let variables;
|
4219
4134
|
if (typeof idOrHeight === "number") {
|
4220
|
-
variables = { height:
|
4135
|
+
variables = { height: bn14(idOrHeight).toString(10) };
|
4221
4136
|
} else if (idOrHeight === "latest") {
|
4222
4137
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4223
4138
|
} else if (idOrHeight.length === 66) {
|
4224
4139
|
variables = { blockId: idOrHeight };
|
4225
4140
|
} else {
|
4226
|
-
variables = { blockId:
|
4141
|
+
variables = { blockId: bn14(idOrHeight).toString(10) };
|
4227
4142
|
}
|
4228
4143
|
const { block } = await this.operations.getBlock(variables);
|
4229
4144
|
if (!block) {
|
@@ -4231,7 +4146,7 @@ var _Provider = class {
|
|
4231
4146
|
}
|
4232
4147
|
return {
|
4233
4148
|
id: block.id,
|
4234
|
-
height:
|
4149
|
+
height: bn14(block.header.height),
|
4235
4150
|
time: block.header.time,
|
4236
4151
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4237
4152
|
};
|
@@ -4246,7 +4161,7 @@ var _Provider = class {
|
|
4246
4161
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4247
4162
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4248
4163
|
id: block.id,
|
4249
|
-
height:
|
4164
|
+
height: bn14(block.header.height),
|
4250
4165
|
time: block.header.time,
|
4251
4166
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4252
4167
|
}));
|
@@ -4261,7 +4176,7 @@ var _Provider = class {
|
|
4261
4176
|
async getBlockWithTransactions(idOrHeight) {
|
4262
4177
|
let variables;
|
4263
4178
|
if (typeof idOrHeight === "number") {
|
4264
|
-
variables = { blockHeight:
|
4179
|
+
variables = { blockHeight: bn14(idOrHeight).toString(10) };
|
4265
4180
|
} else if (idOrHeight === "latest") {
|
4266
4181
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4267
4182
|
} else {
|
@@ -4273,7 +4188,7 @@ var _Provider = class {
|
|
4273
4188
|
}
|
4274
4189
|
return {
|
4275
4190
|
id: block.id,
|
4276
|
-
height:
|
4191
|
+
height: bn14(block.header.height, 10),
|
4277
4192
|
time: block.header.time,
|
4278
4193
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4279
4194
|
transactions: block.transactions.map(
|
@@ -4322,7 +4237,7 @@ var _Provider = class {
|
|
4322
4237
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4323
4238
|
asset: hexlify12(assetId)
|
4324
4239
|
});
|
4325
|
-
return
|
4240
|
+
return bn14(contractBalance.amount, 10);
|
4326
4241
|
}
|
4327
4242
|
/**
|
4328
4243
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4336,7 +4251,7 @@ var _Provider = class {
|
|
4336
4251
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4337
4252
|
assetId: hexlify12(assetId)
|
4338
4253
|
});
|
4339
|
-
return
|
4254
|
+
return bn14(balance.amount, 10);
|
4340
4255
|
}
|
4341
4256
|
/**
|
4342
4257
|
* Returns balances for the given owner.
|
@@ -4354,7 +4269,7 @@ var _Provider = class {
|
|
4354
4269
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4355
4270
|
return balances.map((balance) => ({
|
4356
4271
|
assetId: balance.assetId,
|
4357
|
-
amount:
|
4272
|
+
amount: bn14(balance.amount)
|
4358
4273
|
}));
|
4359
4274
|
}
|
4360
4275
|
/**
|
@@ -4376,15 +4291,15 @@ var _Provider = class {
|
|
4376
4291
|
sender: message.sender,
|
4377
4292
|
recipient: message.recipient,
|
4378
4293
|
nonce: message.nonce,
|
4379
|
-
amount:
|
4294
|
+
amount: bn14(message.amount),
|
4380
4295
|
data: message.data
|
4381
4296
|
}),
|
4382
4297
|
sender: Address2.fromAddressOrString(message.sender),
|
4383
4298
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4384
4299
|
nonce: message.nonce,
|
4385
|
-
amount:
|
4300
|
+
amount: bn14(message.amount),
|
4386
4301
|
data: InputMessageCoder.decodeData(message.data),
|
4387
|
-
daHeight:
|
4302
|
+
daHeight: bn14(message.daHeight)
|
4388
4303
|
}));
|
4389
4304
|
}
|
4390
4305
|
/**
|
@@ -4402,8 +4317,8 @@ var _Provider = class {
|
|
4402
4317
|
nonce
|
4403
4318
|
};
|
4404
4319
|
if (commitBlockId && commitBlockHeight) {
|
4405
|
-
throw new
|
4406
|
-
|
4320
|
+
throw new FuelError12(
|
4321
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4407
4322
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4408
4323
|
);
|
4409
4324
|
}
|
@@ -4437,41 +4352,41 @@ var _Provider = class {
|
|
4437
4352
|
} = result.messageProof;
|
4438
4353
|
return {
|
4439
4354
|
messageProof: {
|
4440
|
-
proofIndex:
|
4355
|
+
proofIndex: bn14(messageProof.proofIndex),
|
4441
4356
|
proofSet: messageProof.proofSet
|
4442
4357
|
},
|
4443
4358
|
blockProof: {
|
4444
|
-
proofIndex:
|
4359
|
+
proofIndex: bn14(blockProof.proofIndex),
|
4445
4360
|
proofSet: blockProof.proofSet
|
4446
4361
|
},
|
4447
4362
|
messageBlockHeader: {
|
4448
4363
|
id: messageBlockHeader.id,
|
4449
|
-
daHeight:
|
4450
|
-
transactionsCount:
|
4364
|
+
daHeight: bn14(messageBlockHeader.daHeight),
|
4365
|
+
transactionsCount: bn14(messageBlockHeader.transactionsCount),
|
4451
4366
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4452
|
-
height:
|
4367
|
+
height: bn14(messageBlockHeader.height),
|
4453
4368
|
prevRoot: messageBlockHeader.prevRoot,
|
4454
4369
|
time: messageBlockHeader.time,
|
4455
4370
|
applicationHash: messageBlockHeader.applicationHash,
|
4456
4371
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4457
|
-
messageReceiptCount:
|
4372
|
+
messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
|
4458
4373
|
},
|
4459
4374
|
commitBlockHeader: {
|
4460
4375
|
id: commitBlockHeader.id,
|
4461
|
-
daHeight:
|
4462
|
-
transactionsCount:
|
4376
|
+
daHeight: bn14(commitBlockHeader.daHeight),
|
4377
|
+
transactionsCount: bn14(commitBlockHeader.transactionsCount),
|
4463
4378
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4464
|
-
height:
|
4379
|
+
height: bn14(commitBlockHeader.height),
|
4465
4380
|
prevRoot: commitBlockHeader.prevRoot,
|
4466
4381
|
time: commitBlockHeader.time,
|
4467
4382
|
applicationHash: commitBlockHeader.applicationHash,
|
4468
4383
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4469
|
-
messageReceiptCount:
|
4384
|
+
messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
|
4470
4385
|
},
|
4471
4386
|
sender: Address2.fromAddressOrString(sender),
|
4472
4387
|
recipient: Address2.fromAddressOrString(recipient),
|
4473
4388
|
nonce,
|
4474
|
-
amount:
|
4389
|
+
amount: bn14(amount),
|
4475
4390
|
data
|
4476
4391
|
};
|
4477
4392
|
}
|
@@ -4494,10 +4409,10 @@ var _Provider = class {
|
|
4494
4409
|
*/
|
4495
4410
|
async produceBlocks(amount, startTime) {
|
4496
4411
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4497
|
-
blocksToProduce:
|
4412
|
+
blocksToProduce: bn14(amount).toString(10),
|
4498
4413
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4499
4414
|
});
|
4500
|
-
return
|
4415
|
+
return bn14(latestBlockHeight);
|
4501
4416
|
}
|
4502
4417
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4503
4418
|
async getTransactionResponse(transactionId) {
|
@@ -4520,8 +4435,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4520
4435
|
__publicField(Provider, "nodeInfoCache", {});
|
4521
4436
|
|
4522
4437
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4523
|
-
import { ErrorCode as
|
4524
|
-
import { bn as
|
4438
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4439
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
4525
4440
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4526
4441
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4527
4442
|
async function getTransactionSummary(params) {
|
@@ -4530,8 +4445,8 @@ async function getTransactionSummary(params) {
|
|
4530
4445
|
transactionId: id
|
4531
4446
|
});
|
4532
4447
|
if (!gqlTransaction) {
|
4533
|
-
throw new
|
4534
|
-
|
4448
|
+
throw new FuelError13(
|
4449
|
+
ErrorCode13.TRANSACTION_NOT_FOUND,
|
4535
4450
|
`Transaction not found for given id: ${id}.`
|
4536
4451
|
);
|
4537
4452
|
}
|
@@ -4549,8 +4464,8 @@ async function getTransactionSummary(params) {
|
|
4549
4464
|
transaction: decodedTransaction,
|
4550
4465
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4551
4466
|
gqlTransactionStatus: gqlTransaction.status,
|
4552
|
-
gasPerByte:
|
4553
|
-
gasPriceFactor:
|
4467
|
+
gasPerByte: bn15(gasPerByte),
|
4468
|
+
gasPriceFactor: bn15(gasPriceFactor),
|
4554
4469
|
abiMap,
|
4555
4470
|
maxInputs,
|
4556
4471
|
gasCosts
|
@@ -4804,7 +4719,7 @@ var Account = class extends AbstractAccount {
|
|
4804
4719
|
*/
|
4805
4720
|
get provider() {
|
4806
4721
|
if (!this._provider) {
|
4807
|
-
throw new
|
4722
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4808
4723
|
}
|
4809
4724
|
return this._provider;
|
4810
4725
|
}
|
@@ -4856,8 +4771,8 @@ var Account = class extends AbstractAccount {
|
|
4856
4771
|
if (!hasNextPage) {
|
4857
4772
|
break;
|
4858
4773
|
}
|
4859
|
-
throw new
|
4860
|
-
|
4774
|
+
throw new FuelError14(
|
4775
|
+
ErrorCode14.NOT_SUPPORTED,
|
4861
4776
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4862
4777
|
);
|
4863
4778
|
}
|
@@ -4882,8 +4797,8 @@ var Account = class extends AbstractAccount {
|
|
4882
4797
|
if (!hasNextPage) {
|
4883
4798
|
break;
|
4884
4799
|
}
|
4885
|
-
throw new
|
4886
|
-
|
4800
|
+
throw new FuelError14(
|
4801
|
+
ErrorCode14.NOT_SUPPORTED,
|
4887
4802
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4888
4803
|
);
|
4889
4804
|
}
|
@@ -4918,8 +4833,8 @@ var Account = class extends AbstractAccount {
|
|
4918
4833
|
if (!hasNextPage) {
|
4919
4834
|
break;
|
4920
4835
|
}
|
4921
|
-
throw new
|
4922
|
-
|
4836
|
+
throw new FuelError14(
|
4837
|
+
ErrorCode14.NOT_SUPPORTED,
|
4923
4838
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4924
4839
|
);
|
4925
4840
|
}
|
@@ -4935,7 +4850,7 @@ var Account = class extends AbstractAccount {
|
|
4935
4850
|
*/
|
4936
4851
|
async fund(request, coinQuantities, fee) {
|
4937
4852
|
const updatedQuantities = addAmountToAsset({
|
4938
|
-
amount:
|
4853
|
+
amount: bn16(fee),
|
4939
4854
|
assetId: BaseAssetId3,
|
4940
4855
|
coinQuantities
|
4941
4856
|
});
|
@@ -4943,7 +4858,7 @@ var Account = class extends AbstractAccount {
|
|
4943
4858
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4944
4859
|
quantitiesDict[assetId] = {
|
4945
4860
|
required: amount,
|
4946
|
-
owned:
|
4861
|
+
owned: bn16(0)
|
4947
4862
|
};
|
4948
4863
|
});
|
4949
4864
|
const cachedUtxos = [];
|
@@ -4956,7 +4871,7 @@ var Account = class extends AbstractAccount {
|
|
4956
4871
|
if (isCoin2) {
|
4957
4872
|
const assetId = String(input.assetId);
|
4958
4873
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4959
|
-
const amount =
|
4874
|
+
const amount = bn16(input.amount);
|
4960
4875
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4961
4876
|
cachedUtxos.push(input.id);
|
4962
4877
|
}
|
@@ -5002,8 +4917,8 @@ var Account = class extends AbstractAccount {
|
|
5002
4917
|
estimateTxDependencies: true,
|
5003
4918
|
resourcesOwner: this
|
5004
4919
|
});
|
5005
|
-
request.gasPrice =
|
5006
|
-
request.gasLimit =
|
4920
|
+
request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
|
4921
|
+
request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
|
5007
4922
|
this.validateGas({
|
5008
4923
|
gasUsed,
|
5009
4924
|
gasPrice: request.gasPrice,
|
@@ -5024,9 +4939,9 @@ var Account = class extends AbstractAccount {
|
|
5024
4939
|
* @returns A promise that resolves to the transaction response.
|
5025
4940
|
*/
|
5026
4941
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
5027
|
-
if (
|
5028
|
-
throw new
|
5029
|
-
|
4942
|
+
if (bn16(amount).lte(0)) {
|
4943
|
+
throw new FuelError14(
|
4944
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
5030
4945
|
"Transfer amount must be a positive number."
|
5031
4946
|
);
|
5032
4947
|
}
|
@@ -5043,9 +4958,9 @@ var Account = class extends AbstractAccount {
|
|
5043
4958
|
* @returns A promise that resolves to the transaction response.
|
5044
4959
|
*/
|
5045
4960
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
5046
|
-
if (
|
5047
|
-
throw new
|
5048
|
-
|
4961
|
+
if (bn16(amount).lte(0)) {
|
4962
|
+
throw new FuelError14(
|
4963
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
5049
4964
|
"Transfer amount must be a positive number."
|
5050
4965
|
);
|
5051
4966
|
}
|
@@ -5054,7 +4969,7 @@ var Account = class extends AbstractAccount {
|
|
5054
4969
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5055
4970
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5056
4971
|
hexlifiedContractId: contractAddress.toB256(),
|
5057
|
-
amountToTransfer:
|
4972
|
+
amountToTransfer: bn16(amount),
|
5058
4973
|
assetId
|
5059
4974
|
});
|
5060
4975
|
const request = new ScriptTransactionRequest({
|
@@ -5065,9 +4980,9 @@ var Account = class extends AbstractAccount {
|
|
5065
4980
|
request.addContractInputAndOutput(contractAddress);
|
5066
4981
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5067
4982
|
request,
|
5068
|
-
[{ amount:
|
4983
|
+
[{ amount: bn16(amount), assetId: String(assetId) }]
|
5069
4984
|
);
|
5070
|
-
request.gasLimit =
|
4985
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
5071
4986
|
this.validateGas({
|
5072
4987
|
gasUsed,
|
5073
4988
|
gasPrice: request.gasPrice,
|
@@ -5092,7 +5007,7 @@ var Account = class extends AbstractAccount {
|
|
5092
5007
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5093
5008
|
);
|
5094
5009
|
const amountDataArray = arrayify14(
|
5095
|
-
"0x".concat(
|
5010
|
+
"0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
|
5096
5011
|
);
|
5097
5012
|
const script = new Uint8Array([
|
5098
5013
|
...arrayify14(withdrawScript.bytes),
|
@@ -5101,12 +5016,12 @@ var Account = class extends AbstractAccount {
|
|
5101
5016
|
]);
|
5102
5017
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5103
5018
|
const request = new ScriptTransactionRequest(params);
|
5104
|
-
const forwardingQuantities = [{ amount:
|
5019
|
+
const forwardingQuantities = [{ amount: bn16(amount), assetId: BaseAssetId3 }];
|
5105
5020
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5106
5021
|
request,
|
5107
5022
|
forwardingQuantities
|
5108
5023
|
);
|
5109
|
-
request.gasLimit =
|
5024
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
5110
5025
|
this.validateGas({
|
5111
5026
|
gasUsed,
|
5112
5027
|
gasPrice: request.gasPrice,
|
@@ -5118,7 +5033,7 @@ var Account = class extends AbstractAccount {
|
|
5118
5033
|
}
|
5119
5034
|
async signMessage(message) {
|
5120
5035
|
if (!this._connector) {
|
5121
|
-
throw new
|
5036
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5122
5037
|
}
|
5123
5038
|
return this._connector.signMessage(this.address.toString(), message);
|
5124
5039
|
}
|
@@ -5130,8 +5045,8 @@ var Account = class extends AbstractAccount {
|
|
5130
5045
|
*/
|
5131
5046
|
async signTransaction(transactionRequestLike) {
|
5132
5047
|
if (!this._connector) {
|
5133
|
-
throw new
|
5134
|
-
|
5048
|
+
throw new FuelError14(
|
5049
|
+
ErrorCode14.MISSING_CONNECTOR,
|
5135
5050
|
"A connector is required to sign transactions."
|
5136
5051
|
);
|
5137
5052
|
}
|
@@ -5178,14 +5093,14 @@ var Account = class extends AbstractAccount {
|
|
5178
5093
|
minGasPrice
|
5179
5094
|
}) {
|
5180
5095
|
if (minGasPrice.gt(gasPrice)) {
|
5181
|
-
throw new
|
5182
|
-
|
5096
|
+
throw new FuelError14(
|
5097
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5183
5098
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5184
5099
|
);
|
5185
5100
|
}
|
5186
5101
|
if (gasUsed.gt(gasLimit)) {
|
5187
|
-
throw new
|
5188
|
-
|
5102
|
+
throw new FuelError14(
|
5103
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
5189
5104
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5190
5105
|
);
|
5191
5106
|
}
|
@@ -5316,7 +5231,7 @@ import {
|
|
5316
5231
|
decryptJsonWalletData,
|
5317
5232
|
encryptJsonWalletData
|
5318
5233
|
} from "@fuel-ts/crypto";
|
5319
|
-
import { ErrorCode as
|
5234
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5320
5235
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5321
5236
|
import { v4 as uuidv4 } from "uuid";
|
5322
5237
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5394,8 +5309,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5394
5309
|
const macHashUint8Array = keccak256(data);
|
5395
5310
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5396
5311
|
if (mac !== macHash) {
|
5397
|
-
throw new
|
5398
|
-
|
5312
|
+
throw new FuelError15(
|
5313
|
+
ErrorCode15.INVALID_PASSWORD,
|
5399
5314
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5400
5315
|
);
|
5401
5316
|
}
|
@@ -5517,15 +5432,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5517
5432
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5518
5433
|
|
5519
5434
|
// src/hdwallet/hdwallet.ts
|
5520
|
-
import { ErrorCode as
|
5435
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5521
5436
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5522
|
-
import { bn as
|
5437
|
+
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5523
5438
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5524
5439
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5525
5440
|
|
5526
5441
|
// src/mnemonic/mnemonic.ts
|
5527
5442
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5528
|
-
import { ErrorCode as
|
5443
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5529
5444
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5530
5445
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5531
5446
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7589,7 +7504,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7589
7504
|
})(Language || {});
|
7590
7505
|
|
7591
7506
|
// src/mnemonic/utils.ts
|
7592
|
-
import { ErrorCode as
|
7507
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7593
7508
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7594
7509
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7595
7510
|
function toUtf8Bytes(stri) {
|
@@ -7606,8 +7521,8 @@ function toUtf8Bytes(stri) {
|
|
7606
7521
|
i += 1;
|
7607
7522
|
const c2 = str.charCodeAt(i);
|
7608
7523
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7609
|
-
throw new
|
7610
|
-
|
7524
|
+
throw new FuelError16(
|
7525
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7611
7526
|
"Invalid UTF-8 in the input string."
|
7612
7527
|
);
|
7613
7528
|
}
|
@@ -7670,8 +7585,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7670
7585
|
for (let i = 0; i < words.length; i += 1) {
|
7671
7586
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7672
7587
|
if (index === -1) {
|
7673
|
-
throw new
|
7674
|
-
|
7588
|
+
throw new FuelError16(
|
7589
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7675
7590
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7676
7591
|
);
|
7677
7592
|
}
|
@@ -7687,8 +7602,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7687
7602
|
const checksumMask = getUpperMask(checksumBits);
|
7688
7603
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7689
7604
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7690
|
-
throw new
|
7691
|
-
|
7605
|
+
throw new FuelError16(
|
7606
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7692
7607
|
"Checksum validation failed for the provided mnemonic."
|
7693
7608
|
);
|
7694
7609
|
}
|
@@ -7702,16 +7617,16 @@ var TestnetPRV = "0x04358394";
|
|
7702
7617
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7703
7618
|
function assertWordList(wordlist) {
|
7704
7619
|
if (wordlist.length !== 2048) {
|
7705
|
-
throw new
|
7706
|
-
|
7620
|
+
throw new FuelError17(
|
7621
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7707
7622
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7708
7623
|
);
|
7709
7624
|
}
|
7710
7625
|
}
|
7711
7626
|
function assertEntropy(entropy) {
|
7712
7627
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7713
|
-
throw new
|
7714
|
-
|
7628
|
+
throw new FuelError17(
|
7629
|
+
ErrorCode17.INVALID_ENTROPY,
|
7715
7630
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7716
7631
|
);
|
7717
7632
|
}
|
@@ -7721,7 +7636,7 @@ function assertMnemonic(words) {
|
|
7721
7636
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7722
7637
|
", "
|
7723
7638
|
)}] words, but got ${words.length}.`;
|
7724
|
-
throw new
|
7639
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7725
7640
|
}
|
7726
7641
|
}
|
7727
7642
|
var Mnemonic = class {
|
@@ -7839,8 +7754,8 @@ var Mnemonic = class {
|
|
7839
7754
|
static masterKeysFromSeed(seed) {
|
7840
7755
|
const seedArray = arrayify17(seed);
|
7841
7756
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7842
|
-
throw new
|
7843
|
-
|
7757
|
+
throw new FuelError17(
|
7758
|
+
ErrorCode17.INVALID_SEED,
|
7844
7759
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7845
7760
|
);
|
7846
7761
|
}
|
@@ -7917,7 +7832,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7917
7832
|
function parsePath(path, depth = 0) {
|
7918
7833
|
const components = path.split("/");
|
7919
7834
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7920
|
-
throw new
|
7835
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7921
7836
|
}
|
7922
7837
|
if (components[0] === "m") {
|
7923
7838
|
components.shift();
|
@@ -7946,8 +7861,8 @@ var HDWallet = class {
|
|
7946
7861
|
this.privateKey = hexlify17(config.privateKey);
|
7947
7862
|
} else {
|
7948
7863
|
if (!config.publicKey) {
|
7949
|
-
throw new
|
7950
|
-
|
7864
|
+
throw new FuelError18(
|
7865
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7951
7866
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7952
7867
|
);
|
7953
7868
|
}
|
@@ -7976,8 +7891,8 @@ var HDWallet = class {
|
|
7976
7891
|
const data = new Uint8Array(37);
|
7977
7892
|
if (index & HARDENED_INDEX) {
|
7978
7893
|
if (!privateKey) {
|
7979
|
-
throw new
|
7980
|
-
|
7894
|
+
throw new FuelError18(
|
7895
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7981
7896
|
"Cannot derive a hardened index without a private Key."
|
7982
7897
|
);
|
7983
7898
|
}
|
@@ -7991,7 +7906,7 @@ var HDWallet = class {
|
|
7991
7906
|
const IR = bytes.slice(32);
|
7992
7907
|
if (privateKey) {
|
7993
7908
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7994
|
-
const ki =
|
7909
|
+
const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
|
7995
7910
|
return new HDWallet({
|
7996
7911
|
privateKey: ki,
|
7997
7912
|
chainCode: IR,
|
@@ -8029,8 +7944,8 @@ var HDWallet = class {
|
|
8029
7944
|
*/
|
8030
7945
|
toExtendedKey(isPublic = false, testnet = false) {
|
8031
7946
|
if (this.depth >= 256) {
|
8032
|
-
throw new
|
8033
|
-
|
7947
|
+
throw new FuelError18(
|
7948
|
+
ErrorCode18.HD_WALLET_ERROR,
|
8034
7949
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8035
7950
|
);
|
8036
7951
|
}
|
@@ -8061,10 +7976,10 @@ var HDWallet = class {
|
|
8061
7976
|
const bytes = arrayify18(decoded);
|
8062
7977
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8063
7978
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8064
|
-
throw new
|
7979
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8065
7980
|
}
|
8066
7981
|
if (!validChecksum) {
|
8067
|
-
throw new
|
7982
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8068
7983
|
}
|
8069
7984
|
const depth = bytes[4];
|
8070
7985
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -8072,14 +7987,14 @@ var HDWallet = class {
|
|
8072
7987
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
8073
7988
|
const key = bytes.slice(45, 78);
|
8074
7989
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8075
|
-
throw new
|
8076
|
-
|
7990
|
+
throw new FuelError18(
|
7991
|
+
ErrorCode18.HD_WALLET_ERROR,
|
8077
7992
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8078
7993
|
);
|
8079
7994
|
}
|
8080
7995
|
if (isPublicExtendedKey(bytes)) {
|
8081
7996
|
if (key[0] !== 3) {
|
8082
|
-
throw new
|
7997
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
8083
7998
|
}
|
8084
7999
|
return new HDWallet({
|
8085
8000
|
publicKey: key,
|
@@ -8090,7 +8005,7 @@ var HDWallet = class {
|
|
8090
8005
|
});
|
8091
8006
|
}
|
8092
8007
|
if (key[0] !== 0) {
|
8093
|
-
throw new
|
8008
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
8094
8009
|
}
|
8095
8010
|
return new HDWallet({
|
8096
8011
|
privateKey: key.slice(1),
|
@@ -8258,7 +8173,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8258
8173
|
// src/wallet-manager/wallet-manager.ts
|
8259
8174
|
import { Address as Address8 } from "@fuel-ts/address";
|
8260
8175
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8261
|
-
import { ErrorCode as
|
8176
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8262
8177
|
import { EventEmitter } from "events";
|
8263
8178
|
|
8264
8179
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8281,7 +8196,7 @@ var MemoryStorage = class {
|
|
8281
8196
|
|
8282
8197
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8283
8198
|
import { Address as Address6 } from "@fuel-ts/address";
|
8284
|
-
import { ErrorCode as
|
8199
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
8285
8200
|
var _secret;
|
8286
8201
|
var MnemonicVault = class {
|
8287
8202
|
constructor(options) {
|
@@ -8337,8 +8252,8 @@ var MnemonicVault = class {
|
|
8337
8252
|
}
|
8338
8253
|
numberOfAccounts += 1;
|
8339
8254
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8340
|
-
throw new
|
8341
|
-
|
8255
|
+
throw new FuelError19(
|
8256
|
+
ErrorCode19.WALLET_MANAGER_ERROR,
|
8342
8257
|
`Account with address '${address}' not found in derived wallets.`
|
8343
8258
|
);
|
8344
8259
|
}
|
@@ -8352,7 +8267,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8352
8267
|
|
8353
8268
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8354
8269
|
import { Address as Address7 } from "@fuel-ts/address";
|
8355
|
-
import { ErrorCode as
|
8270
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8356
8271
|
var _privateKeys;
|
8357
8272
|
var PrivateKeyVault = class {
|
8358
8273
|
/**
|
@@ -8393,8 +8308,8 @@ var PrivateKeyVault = class {
|
|
8393
8308
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8394
8309
|
);
|
8395
8310
|
if (!privateKey) {
|
8396
|
-
throw new
|
8397
|
-
|
8311
|
+
throw new FuelError20(
|
8312
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8398
8313
|
`No private key found for address '${address}'.`
|
8399
8314
|
);
|
8400
8315
|
}
|
@@ -8418,7 +8333,7 @@ var ERROR_MESSAGES = {
|
|
8418
8333
|
};
|
8419
8334
|
function assert(condition, message) {
|
8420
8335
|
if (!condition) {
|
8421
|
-
throw new
|
8336
|
+
throw new FuelError21(ErrorCode21.WALLET_MANAGER_ERROR, message);
|
8422
8337
|
}
|
8423
8338
|
}
|
8424
8339
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8644,25 +8559,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8644
8559
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8645
8560
|
|
8646
8561
|
// src/wallet-manager/types.ts
|
8647
|
-
import { ErrorCode as
|
8562
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8648
8563
|
var Vault = class {
|
8649
8564
|
constructor(_options) {
|
8650
|
-
throw new
|
8565
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8651
8566
|
}
|
8652
8567
|
serialize() {
|
8653
|
-
throw new
|
8568
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8654
8569
|
}
|
8655
8570
|
getAccounts() {
|
8656
|
-
throw new
|
8571
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8657
8572
|
}
|
8658
8573
|
addAccount() {
|
8659
|
-
throw new
|
8574
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8660
8575
|
}
|
8661
8576
|
exportAccount(_address) {
|
8662
|
-
throw new
|
8577
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8663
8578
|
}
|
8664
8579
|
getWallet(_address) {
|
8665
|
-
throw new
|
8580
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8666
8581
|
}
|
8667
8582
|
};
|
8668
8583
|
__publicField(Vault, "type");
|
@@ -8679,7 +8594,7 @@ import {
|
|
8679
8594
|
} from "@fuel-ts/abi-coder";
|
8680
8595
|
import { Address as Address9 } from "@fuel-ts/address";
|
8681
8596
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8682
|
-
import { ErrorCode as
|
8597
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8683
8598
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8684
8599
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8685
8600
|
|
@@ -8807,8 +8722,8 @@ var Predicate = class extends Account {
|
|
8807
8722
|
if (jsonAbi) {
|
8808
8723
|
abiInterface = new Interface4(jsonAbi);
|
8809
8724
|
if (abiInterface.functions.main === void 0) {
|
8810
|
-
throw new
|
8811
|
-
|
8725
|
+
throw new FuelError23(
|
8726
|
+
ErrorCode23.ABI_MAIN_METHOD_MISSING,
|
8812
8727
|
'Cannot use ABI without "main" function.'
|
8813
8728
|
);
|
8814
8729
|
}
|
@@ -8853,8 +8768,8 @@ var Predicate = class extends Account {
|
|
8853
8768
|
mutatedBytes.set(encoded, offset);
|
8854
8769
|
});
|
8855
8770
|
} catch (err) {
|
8856
|
-
throw new
|
8857
|
-
|
8771
|
+
throw new FuelError23(
|
8772
|
+
ErrorCode23.INVALID_CONFIGURABLE_CONSTANTS,
|
8858
8773
|
`Error setting configurable constants: ${err.message}.`
|
8859
8774
|
);
|
8860
8775
|
}
|
@@ -8863,7 +8778,7 @@ var Predicate = class extends Account {
|
|
8863
8778
|
};
|
8864
8779
|
|
8865
8780
|
// src/connectors/fuel.ts
|
8866
|
-
import { ErrorCode as
|
8781
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8867
8782
|
|
8868
8783
|
// src/connectors/fuel-connector.ts
|
8869
8784
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9496,7 +9411,7 @@ var _Fuel = class extends FuelConnector {
|
|
9496
9411
|
const currentNetwork = await this.currentNetwork();
|
9497
9412
|
provider = await Provider.create(currentNetwork.url);
|
9498
9413
|
} else {
|
9499
|
-
throw new
|
9414
|
+
throw new FuelError24(ErrorCode24.INVALID_PROVIDER, "Provider is not valid.");
|
9500
9415
|
}
|
9501
9416
|
return provider;
|
9502
9417
|
}
|
@@ -9575,9 +9490,7 @@ export {
|
|
9575
9490
|
WalletUnlocked,
|
9576
9491
|
addAmountToAsset,
|
9577
9492
|
addOperation,
|
9578
|
-
assemblePanicError,
|
9579
9493
|
assembleReceiptByType,
|
9580
|
-
assembleRevertError,
|
9581
9494
|
assembleTransactionSummary,
|
9582
9495
|
assets,
|
9583
9496
|
buildBlockExplorerUrl,
|
@@ -9592,7 +9505,6 @@ export {
|
|
9592
9505
|
english,
|
9593
9506
|
extractBurnedAssetsFromReceipts,
|
9594
9507
|
extractMintedAssetsFromReceipts,
|
9595
|
-
extractTxError,
|
9596
9508
|
gasUsedByInputs,
|
9597
9509
|
getAssetEth,
|
9598
9510
|
getAssetFuel,
|