@fuel-ts/account 0.0.0-rc-1976-20240404171500 → 0.0.0-rc-1976-20240405090158
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 +38 -212
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +457 -540
- 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 +38 -212
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +424 -501
- 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
@@ -29,9 +29,9 @@ var __privateMethod = (obj, member, method) => {
|
|
29
29
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
|
-
import { ErrorCode as
|
32
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
33
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
|
-
import { bn as
|
34
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
35
35
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
36
36
|
|
37
37
|
// src/providers/coin-quantity.ts
|
@@ -71,8 +71,8 @@ var addAmountToAsset = (params) => {
|
|
71
71
|
|
72
72
|
// src/providers/provider.ts
|
73
73
|
import { Address as Address2 } from "@fuel-ts/address";
|
74
|
-
import { ErrorCode as
|
75
|
-
import { BN, bn as
|
74
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
75
|
+
import { BN, bn as bn14, max } from "@fuel-ts/math";
|
76
76
|
import {
|
77
77
|
InputType as InputType6,
|
78
78
|
TransactionType as TransactionType8,
|
@@ -1155,7 +1155,7 @@ var outputify = (value) => {
|
|
1155
1155
|
// src/providers/transaction-request/transaction-request.ts
|
1156
1156
|
import { Address, addressify } from "@fuel-ts/address";
|
1157
1157
|
import { ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1158
|
-
import { bn as
|
1158
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1159
1159
|
import {
|
1160
1160
|
PolicyType,
|
1161
1161
|
TransactionCoder,
|
@@ -1560,86 +1560,6 @@ function sleep(time) {
|
|
1560
1560
|
});
|
1561
1561
|
}
|
1562
1562
|
|
1563
|
-
// src/providers/utils/extract-tx-error.ts
|
1564
|
-
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1565
|
-
import { bn as bn6 } from "@fuel-ts/math";
|
1566
|
-
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1567
|
-
import {
|
1568
|
-
FAILED_REQUIRE_SIGNAL,
|
1569
|
-
FAILED_ASSERT_EQ_SIGNAL,
|
1570
|
-
FAILED_ASSERT_NE_SIGNAL,
|
1571
|
-
FAILED_ASSERT_SIGNAL,
|
1572
|
-
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1573
|
-
PANIC_REASONS,
|
1574
|
-
PANIC_DOC_URL
|
1575
|
-
} from "@fuel-ts/transactions/configs";
|
1576
|
-
var assemblePanicError = (status) => {
|
1577
|
-
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1578
|
-
const reason = status.reason;
|
1579
|
-
if (PANIC_REASONS.includes(status.reason)) {
|
1580
|
-
errorMessage = `${errorMessage}
|
1581
|
-
|
1582
|
-
You can read more about this error at:
|
1583
|
-
|
1584
|
-
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1585
|
-
}
|
1586
|
-
return { errorMessage, reason };
|
1587
|
-
};
|
1588
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1589
|
-
var assembleRevertError = (receipts, logs) => {
|
1590
|
-
let errorMessage = "The transaction reverted with an unknown reason.";
|
1591
|
-
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1592
|
-
let reason = "";
|
1593
|
-
if (revertReceipt) {
|
1594
|
-
const reasonHex = bn6(revertReceipt.val).toHex();
|
1595
|
-
switch (reasonHex) {
|
1596
|
-
case FAILED_REQUIRE_SIGNAL: {
|
1597
|
-
reason = "require";
|
1598
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1599
|
-
break;
|
1600
|
-
}
|
1601
|
-
case FAILED_ASSERT_EQ_SIGNAL: {
|
1602
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1603
|
-
reason = "assert_eq";
|
1604
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1605
|
-
break;
|
1606
|
-
}
|
1607
|
-
case FAILED_ASSERT_NE_SIGNAL: {
|
1608
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1609
|
-
reason = "assert_ne";
|
1610
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1611
|
-
break;
|
1612
|
-
}
|
1613
|
-
case FAILED_ASSERT_SIGNAL:
|
1614
|
-
reason = "assert";
|
1615
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1616
|
-
break;
|
1617
|
-
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1618
|
-
reason = "MissingOutputChange";
|
1619
|
-
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1620
|
-
break;
|
1621
|
-
default:
|
1622
|
-
reason = "unknown";
|
1623
|
-
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1624
|
-
}
|
1625
|
-
}
|
1626
|
-
return { errorMessage, reason };
|
1627
|
-
};
|
1628
|
-
var extractTxError = (params) => {
|
1629
|
-
const { receipts, status, logs } = params;
|
1630
|
-
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1631
|
-
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1632
|
-
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1633
|
-
const metadata = {
|
1634
|
-
logs,
|
1635
|
-
receipts,
|
1636
|
-
panic: isPanic,
|
1637
|
-
revert: isRevert,
|
1638
|
-
reason
|
1639
|
-
};
|
1640
|
-
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1641
|
-
};
|
1642
|
-
|
1643
1563
|
// src/providers/transaction-request/errors.ts
|
1644
1564
|
var ChangeOutputCollisionError = class extends Error {
|
1645
1565
|
name = "ChangeOutputCollisionError";
|
@@ -1705,10 +1625,10 @@ var BaseTransactionRequest = class {
|
|
1705
1625
|
witnesses,
|
1706
1626
|
baseAssetId
|
1707
1627
|
} = {}) {
|
1708
|
-
this.gasPrice =
|
1628
|
+
this.gasPrice = bn6(gasPrice);
|
1709
1629
|
this.maturity = maturity ?? 0;
|
1710
|
-
this.witnessLimit = witnessLimit ?
|
1711
|
-
this.maxFee = maxFee ?
|
1630
|
+
this.witnessLimit = witnessLimit ? bn6(witnessLimit) : void 0;
|
1631
|
+
this.maxFee = maxFee ? bn6(maxFee) : void 0;
|
1712
1632
|
this.inputs = inputs ?? [];
|
1713
1633
|
this.outputs = outputs ?? [];
|
1714
1634
|
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(this.baseAssetId,
|
2066
|
+
updateAssetInput(this.baseAssetId, 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,30 +3515,30 @@ 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
|
baseAssetId: consensusParameters.baseAssetId,
|
3621
3536
|
gasCosts
|
3622
3537
|
},
|
3623
3538
|
gasCosts,
|
3624
3539
|
latestBlock: {
|
3625
3540
|
id: latestBlock.id,
|
3626
|
-
height:
|
3541
|
+
height: bn14(latestBlock.header.height),
|
3627
3542
|
time: latestBlock.header.time,
|
3628
3543
|
transactions: latestBlock.transactions.map((i) => ({
|
3629
3544
|
id: i.id
|
@@ -3693,8 +3608,8 @@ var _Provider = class {
|
|
3693
3608
|
getChain() {
|
3694
3609
|
const chain = _Provider.chainInfoCache[this.url];
|
3695
3610
|
if (!chain) {
|
3696
|
-
throw new
|
3697
|
-
|
3611
|
+
throw new FuelError12(
|
3612
|
+
ErrorCode12.CHAIN_INFO_CACHE_EMPTY,
|
3698
3613
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3699
3614
|
);
|
3700
3615
|
}
|
@@ -3706,8 +3621,8 @@ var _Provider = class {
|
|
3706
3621
|
getNode() {
|
3707
3622
|
const node = _Provider.nodeInfoCache[this.url];
|
3708
3623
|
if (!node) {
|
3709
|
-
throw new
|
3710
|
-
|
3624
|
+
throw new FuelError12(
|
3625
|
+
ErrorCode12.NODE_INFO_CACHE_EMPTY,
|
3711
3626
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3712
3627
|
);
|
3713
3628
|
}
|
@@ -3754,8 +3669,8 @@ var _Provider = class {
|
|
3754
3669
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3755
3670
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3756
3671
|
if (!isMajorSupported || !isMinorSupported) {
|
3757
|
-
throw new
|
3758
|
-
|
3672
|
+
throw new FuelError12(
|
3673
|
+
FuelError12.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3759
3674
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3760
3675
|
);
|
3761
3676
|
}
|
@@ -3818,7 +3733,7 @@ var _Provider = class {
|
|
3818
3733
|
*/
|
3819
3734
|
async getBlockNumber() {
|
3820
3735
|
const { chain } = await this.operations.getChain();
|
3821
|
-
return
|
3736
|
+
return bn14(chain.latestBlock.header.height, 10);
|
3822
3737
|
}
|
3823
3738
|
/**
|
3824
3739
|
* Returns the chain information.
|
@@ -3828,9 +3743,9 @@ var _Provider = class {
|
|
3828
3743
|
async fetchNode() {
|
3829
3744
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3830
3745
|
const processedNodeInfo = {
|
3831
|
-
maxDepth:
|
3832
|
-
maxTx:
|
3833
|
-
minGasPrice:
|
3746
|
+
maxDepth: bn14(nodeInfo.maxDepth),
|
3747
|
+
maxTx: bn14(nodeInfo.maxTx),
|
3748
|
+
minGasPrice: bn14(nodeInfo.minGasPrice),
|
3834
3749
|
nodeVersion: nodeInfo.nodeVersion,
|
3835
3750
|
utxoValidation: nodeInfo.utxoValidation,
|
3836
3751
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3896,8 +3811,8 @@ var _Provider = class {
|
|
3896
3811
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3897
3812
|
for await (const { submitAndAwait } of subscription) {
|
3898
3813
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3899
|
-
throw new
|
3900
|
-
|
3814
|
+
throw new FuelError12(
|
3815
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3901
3816
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3902
3817
|
);
|
3903
3818
|
}
|
@@ -3964,7 +3879,7 @@ var _Provider = class {
|
|
3964
3879
|
} = response;
|
3965
3880
|
if (inputs) {
|
3966
3881
|
inputs.forEach((input, index) => {
|
3967
|
-
if ("predicateGasUsed" in input &&
|
3882
|
+
if ("predicateGasUsed" in input && bn14(input.predicateGasUsed).gt(0)) {
|
3968
3883
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3969
3884
|
}
|
3970
3885
|
});
|
@@ -4077,7 +3992,7 @@ var _Provider = class {
|
|
4077
3992
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4078
3993
|
if (estimatePredicates) {
|
4079
3994
|
if (isScriptTransaction) {
|
4080
|
-
txRequestClone.gasLimit =
|
3995
|
+
txRequestClone.gasLimit = bn14(0);
|
4081
3996
|
}
|
4082
3997
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4083
3998
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4093,8 +4008,8 @@ var _Provider = class {
|
|
4093
4008
|
let missingContractIds = [];
|
4094
4009
|
let outputVariables = 0;
|
4095
4010
|
if (isScriptTransaction && estimateTxDependencies) {
|
4096
|
-
txRequestClone.gasPrice =
|
4097
|
-
txRequestClone.gasLimit =
|
4011
|
+
txRequestClone.gasPrice = bn14(0);
|
4012
|
+
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4098
4013
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4099
4014
|
receipts = result.receipts;
|
4100
4015
|
outputVariables = result.outputVariables;
|
@@ -4156,11 +4071,11 @@ var _Provider = class {
|
|
4156
4071
|
return coins.map((coin) => ({
|
4157
4072
|
id: coin.utxoId,
|
4158
4073
|
assetId: coin.assetId,
|
4159
|
-
amount:
|
4074
|
+
amount: bn14(coin.amount),
|
4160
4075
|
owner: Address2.fromAddressOrString(coin.owner),
|
4161
|
-
maturity:
|
4162
|
-
blockCreated:
|
4163
|
-
txCreatedIdx:
|
4076
|
+
maturity: bn14(coin.maturity).toNumber(),
|
4077
|
+
blockCreated: bn14(coin.blockCreated),
|
4078
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4164
4079
|
}));
|
4165
4080
|
}
|
4166
4081
|
/**
|
@@ -4197,9 +4112,9 @@ var _Provider = class {
|
|
4197
4112
|
switch (coin.__typename) {
|
4198
4113
|
case "MessageCoin":
|
4199
4114
|
return {
|
4200
|
-
amount:
|
4115
|
+
amount: bn14(coin.amount),
|
4201
4116
|
assetId: coin.assetId,
|
4202
|
-
daHeight:
|
4117
|
+
daHeight: bn14(coin.daHeight),
|
4203
4118
|
sender: Address2.fromAddressOrString(coin.sender),
|
4204
4119
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4205
4120
|
nonce: coin.nonce
|
@@ -4207,12 +4122,12 @@ var _Provider = class {
|
|
4207
4122
|
case "Coin":
|
4208
4123
|
return {
|
4209
4124
|
id: coin.utxoId,
|
4210
|
-
amount:
|
4125
|
+
amount: bn14(coin.amount),
|
4211
4126
|
assetId: coin.assetId,
|
4212
4127
|
owner: Address2.fromAddressOrString(coin.owner),
|
4213
|
-
maturity:
|
4214
|
-
blockCreated:
|
4215
|
-
txCreatedIdx:
|
4128
|
+
maturity: bn14(coin.maturity).toNumber(),
|
4129
|
+
blockCreated: bn14(coin.blockCreated),
|
4130
|
+
txCreatedIdx: bn14(coin.txCreatedIdx)
|
4216
4131
|
};
|
4217
4132
|
default:
|
4218
4133
|
return null;
|
@@ -4229,13 +4144,13 @@ var _Provider = class {
|
|
4229
4144
|
async getBlock(idOrHeight) {
|
4230
4145
|
let variables;
|
4231
4146
|
if (typeof idOrHeight === "number") {
|
4232
|
-
variables = { height:
|
4147
|
+
variables = { height: bn14(idOrHeight).toString(10) };
|
4233
4148
|
} else if (idOrHeight === "latest") {
|
4234
4149
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4235
4150
|
} else if (idOrHeight.length === 66) {
|
4236
4151
|
variables = { blockId: idOrHeight };
|
4237
4152
|
} else {
|
4238
|
-
variables = { blockId:
|
4153
|
+
variables = { blockId: bn14(idOrHeight).toString(10) };
|
4239
4154
|
}
|
4240
4155
|
const { block } = await this.operations.getBlock(variables);
|
4241
4156
|
if (!block) {
|
@@ -4243,7 +4158,7 @@ var _Provider = class {
|
|
4243
4158
|
}
|
4244
4159
|
return {
|
4245
4160
|
id: block.id,
|
4246
|
-
height:
|
4161
|
+
height: bn14(block.header.height),
|
4247
4162
|
time: block.header.time,
|
4248
4163
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4249
4164
|
};
|
@@ -4258,7 +4173,7 @@ var _Provider = class {
|
|
4258
4173
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4259
4174
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4260
4175
|
id: block.id,
|
4261
|
-
height:
|
4176
|
+
height: bn14(block.header.height),
|
4262
4177
|
time: block.header.time,
|
4263
4178
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4264
4179
|
}));
|
@@ -4273,7 +4188,7 @@ var _Provider = class {
|
|
4273
4188
|
async getBlockWithTransactions(idOrHeight) {
|
4274
4189
|
let variables;
|
4275
4190
|
if (typeof idOrHeight === "number") {
|
4276
|
-
variables = { blockHeight:
|
4191
|
+
variables = { blockHeight: bn14(idOrHeight).toString(10) };
|
4277
4192
|
} else if (idOrHeight === "latest") {
|
4278
4193
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4279
4194
|
} else {
|
@@ -4285,7 +4200,7 @@ var _Provider = class {
|
|
4285
4200
|
}
|
4286
4201
|
return {
|
4287
4202
|
id: block.id,
|
4288
|
-
height:
|
4203
|
+
height: bn14(block.header.height, 10),
|
4289
4204
|
time: block.header.time,
|
4290
4205
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4291
4206
|
transactions: block.transactions.map(
|
@@ -4334,7 +4249,7 @@ var _Provider = class {
|
|
4334
4249
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4335
4250
|
asset: hexlify12(assetId)
|
4336
4251
|
});
|
4337
|
-
return
|
4252
|
+
return bn14(contractBalance.amount, 10);
|
4338
4253
|
}
|
4339
4254
|
/**
|
4340
4255
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4348,7 +4263,7 @@ var _Provider = class {
|
|
4348
4263
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4349
4264
|
assetId: hexlify12(assetId)
|
4350
4265
|
});
|
4351
|
-
return
|
4266
|
+
return bn14(balance.amount, 10);
|
4352
4267
|
}
|
4353
4268
|
/**
|
4354
4269
|
* Returns balances for the given owner.
|
@@ -4366,7 +4281,7 @@ var _Provider = class {
|
|
4366
4281
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4367
4282
|
return balances.map((balance) => ({
|
4368
4283
|
assetId: balance.assetId,
|
4369
|
-
amount:
|
4284
|
+
amount: bn14(balance.amount)
|
4370
4285
|
}));
|
4371
4286
|
}
|
4372
4287
|
/**
|
@@ -4388,15 +4303,15 @@ var _Provider = class {
|
|
4388
4303
|
sender: message.sender,
|
4389
4304
|
recipient: message.recipient,
|
4390
4305
|
nonce: message.nonce,
|
4391
|
-
amount:
|
4306
|
+
amount: bn14(message.amount),
|
4392
4307
|
data: message.data
|
4393
4308
|
}),
|
4394
4309
|
sender: Address2.fromAddressOrString(message.sender),
|
4395
4310
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4396
4311
|
nonce: message.nonce,
|
4397
|
-
amount:
|
4312
|
+
amount: bn14(message.amount),
|
4398
4313
|
data: InputMessageCoder.decodeData(message.data),
|
4399
|
-
daHeight:
|
4314
|
+
daHeight: bn14(message.daHeight)
|
4400
4315
|
}));
|
4401
4316
|
}
|
4402
4317
|
/**
|
@@ -4414,8 +4329,8 @@ var _Provider = class {
|
|
4414
4329
|
nonce
|
4415
4330
|
};
|
4416
4331
|
if (commitBlockId && commitBlockHeight) {
|
4417
|
-
throw new
|
4418
|
-
|
4332
|
+
throw new FuelError12(
|
4333
|
+
ErrorCode12.INVALID_INPUT_PARAMETERS,
|
4419
4334
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4420
4335
|
);
|
4421
4336
|
}
|
@@ -4449,41 +4364,41 @@ var _Provider = class {
|
|
4449
4364
|
} = result.messageProof;
|
4450
4365
|
return {
|
4451
4366
|
messageProof: {
|
4452
|
-
proofIndex:
|
4367
|
+
proofIndex: bn14(messageProof.proofIndex),
|
4453
4368
|
proofSet: messageProof.proofSet
|
4454
4369
|
},
|
4455
4370
|
blockProof: {
|
4456
|
-
proofIndex:
|
4371
|
+
proofIndex: bn14(blockProof.proofIndex),
|
4457
4372
|
proofSet: blockProof.proofSet
|
4458
4373
|
},
|
4459
4374
|
messageBlockHeader: {
|
4460
4375
|
id: messageBlockHeader.id,
|
4461
|
-
daHeight:
|
4462
|
-
transactionsCount:
|
4376
|
+
daHeight: bn14(messageBlockHeader.daHeight),
|
4377
|
+
transactionsCount: bn14(messageBlockHeader.transactionsCount),
|
4463
4378
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4464
|
-
height:
|
4379
|
+
height: bn14(messageBlockHeader.height),
|
4465
4380
|
prevRoot: messageBlockHeader.prevRoot,
|
4466
4381
|
time: messageBlockHeader.time,
|
4467
4382
|
applicationHash: messageBlockHeader.applicationHash,
|
4468
4383
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4469
|
-
messageReceiptCount:
|
4384
|
+
messageReceiptCount: bn14(messageBlockHeader.messageReceiptCount)
|
4470
4385
|
},
|
4471
4386
|
commitBlockHeader: {
|
4472
4387
|
id: commitBlockHeader.id,
|
4473
|
-
daHeight:
|
4474
|
-
transactionsCount:
|
4388
|
+
daHeight: bn14(commitBlockHeader.daHeight),
|
4389
|
+
transactionsCount: bn14(commitBlockHeader.transactionsCount),
|
4475
4390
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4476
|
-
height:
|
4391
|
+
height: bn14(commitBlockHeader.height),
|
4477
4392
|
prevRoot: commitBlockHeader.prevRoot,
|
4478
4393
|
time: commitBlockHeader.time,
|
4479
4394
|
applicationHash: commitBlockHeader.applicationHash,
|
4480
4395
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4481
|
-
messageReceiptCount:
|
4396
|
+
messageReceiptCount: bn14(commitBlockHeader.messageReceiptCount)
|
4482
4397
|
},
|
4483
4398
|
sender: Address2.fromAddressOrString(sender),
|
4484
4399
|
recipient: Address2.fromAddressOrString(recipient),
|
4485
4400
|
nonce,
|
4486
|
-
amount:
|
4401
|
+
amount: bn14(amount),
|
4487
4402
|
data
|
4488
4403
|
};
|
4489
4404
|
}
|
@@ -4506,10 +4421,10 @@ var _Provider = class {
|
|
4506
4421
|
*/
|
4507
4422
|
async produceBlocks(amount, startTime) {
|
4508
4423
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4509
|
-
blocksToProduce:
|
4424
|
+
blocksToProduce: bn14(amount).toString(10),
|
4510
4425
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4511
4426
|
});
|
4512
|
-
return
|
4427
|
+
return bn14(latestBlockHeight);
|
4513
4428
|
}
|
4514
4429
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4515
4430
|
async getTransactionResponse(transactionId) {
|
@@ -4532,8 +4447,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4532
4447
|
__publicField(Provider, "nodeInfoCache", {});
|
4533
4448
|
|
4534
4449
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4535
|
-
import { ErrorCode as
|
4536
|
-
import { bn as
|
4450
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
4451
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
4537
4452
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4538
4453
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4539
4454
|
async function getTransactionSummary(params) {
|
@@ -4542,8 +4457,8 @@ async function getTransactionSummary(params) {
|
|
4542
4457
|
transactionId: id
|
4543
4458
|
});
|
4544
4459
|
if (!gqlTransaction) {
|
4545
|
-
throw new
|
4546
|
-
|
4460
|
+
throw new FuelError13(
|
4461
|
+
ErrorCode13.TRANSACTION_NOT_FOUND,
|
4547
4462
|
`Transaction not found for given id: ${id}.`
|
4548
4463
|
);
|
4549
4464
|
}
|
@@ -4561,8 +4476,8 @@ async function getTransactionSummary(params) {
|
|
4561
4476
|
transaction: decodedTransaction,
|
4562
4477
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4563
4478
|
gqlTransactionStatus: gqlTransaction.status,
|
4564
|
-
gasPerByte:
|
4565
|
-
gasPriceFactor:
|
4479
|
+
gasPerByte: bn15(gasPerByte),
|
4480
|
+
gasPriceFactor: bn15(gasPriceFactor),
|
4566
4481
|
abiMap,
|
4567
4482
|
maxInputs,
|
4568
4483
|
gasCosts
|
@@ -4816,7 +4731,7 @@ var Account = class extends AbstractAccount {
|
|
4816
4731
|
*/
|
4817
4732
|
get provider() {
|
4818
4733
|
if (!this._provider) {
|
4819
|
-
throw new
|
4734
|
+
throw new FuelError14(ErrorCode14.MISSING_PROVIDER, "Provider not set");
|
4820
4735
|
}
|
4821
4736
|
return this._provider;
|
4822
4737
|
}
|
@@ -4868,8 +4783,8 @@ var Account = class extends AbstractAccount {
|
|
4868
4783
|
if (!hasNextPage) {
|
4869
4784
|
break;
|
4870
4785
|
}
|
4871
|
-
throw new
|
4872
|
-
|
4786
|
+
throw new FuelError14(
|
4787
|
+
ErrorCode14.NOT_SUPPORTED,
|
4873
4788
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4874
4789
|
);
|
4875
4790
|
}
|
@@ -4894,8 +4809,8 @@ var Account = class extends AbstractAccount {
|
|
4894
4809
|
if (!hasNextPage) {
|
4895
4810
|
break;
|
4896
4811
|
}
|
4897
|
-
throw new
|
4898
|
-
|
4812
|
+
throw new FuelError14(
|
4813
|
+
ErrorCode14.NOT_SUPPORTED,
|
4899
4814
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4900
4815
|
);
|
4901
4816
|
}
|
@@ -4931,8 +4846,8 @@ var Account = class extends AbstractAccount {
|
|
4931
4846
|
if (!hasNextPage) {
|
4932
4847
|
break;
|
4933
4848
|
}
|
4934
|
-
throw new
|
4935
|
-
|
4849
|
+
throw new FuelError14(
|
4850
|
+
ErrorCode14.NOT_SUPPORTED,
|
4936
4851
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4937
4852
|
);
|
4938
4853
|
}
|
@@ -4949,7 +4864,7 @@ var Account = class extends AbstractAccount {
|
|
4949
4864
|
async fund(request, coinQuantities, fee) {
|
4950
4865
|
const baseAssetId = this.provider.getBaseAssetId();
|
4951
4866
|
const updatedQuantities = addAmountToAsset({
|
4952
|
-
amount:
|
4867
|
+
amount: bn16(fee),
|
4953
4868
|
assetId: baseAssetId,
|
4954
4869
|
coinQuantities
|
4955
4870
|
});
|
@@ -4957,7 +4872,7 @@ var Account = class extends AbstractAccount {
|
|
4957
4872
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4958
4873
|
quantitiesDict[assetId] = {
|
4959
4874
|
required: amount,
|
4960
|
-
owned:
|
4875
|
+
owned: bn16(0)
|
4961
4876
|
};
|
4962
4877
|
});
|
4963
4878
|
const cachedUtxos = [];
|
@@ -4970,7 +4885,7 @@ var Account = class extends AbstractAccount {
|
|
4970
4885
|
if (isCoin2) {
|
4971
4886
|
const assetId = String(input.assetId);
|
4972
4887
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4973
|
-
const amount =
|
4888
|
+
const amount = bn16(input.amount);
|
4974
4889
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4975
4890
|
cachedUtxos.push(input.id);
|
4976
4891
|
}
|
@@ -5017,8 +4932,8 @@ var Account = class extends AbstractAccount {
|
|
5017
4932
|
estimateTxDependencies: true,
|
5018
4933
|
resourcesOwner: this
|
5019
4934
|
});
|
5020
|
-
request.gasPrice =
|
5021
|
-
request.gasLimit =
|
4935
|
+
request.gasPrice = bn16(txParams.gasPrice ?? minGasPrice);
|
4936
|
+
request.gasLimit = bn16(txParams.gasLimit ?? gasUsed);
|
5022
4937
|
this.validateGas({
|
5023
4938
|
gasUsed,
|
5024
4939
|
gasPrice: request.gasPrice,
|
@@ -5039,9 +4954,9 @@ var Account = class extends AbstractAccount {
|
|
5039
4954
|
* @returns A promise that resolves to the transaction response.
|
5040
4955
|
*/
|
5041
4956
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5042
|
-
if (
|
5043
|
-
throw new
|
5044
|
-
|
4957
|
+
if (bn16(amount).lte(0)) {
|
4958
|
+
throw new FuelError14(
|
4959
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
5045
4960
|
"Transfer amount must be a positive number."
|
5046
4961
|
);
|
5047
4962
|
}
|
@@ -5059,9 +4974,9 @@ var Account = class extends AbstractAccount {
|
|
5059
4974
|
* @returns A promise that resolves to the transaction response.
|
5060
4975
|
*/
|
5061
4976
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5062
|
-
if (
|
5063
|
-
throw new
|
5064
|
-
|
4977
|
+
if (bn16(amount).lte(0)) {
|
4978
|
+
throw new FuelError14(
|
4979
|
+
ErrorCode14.INVALID_TRANSFER_AMOUNT,
|
5065
4980
|
"Transfer amount must be a positive number."
|
5066
4981
|
);
|
5067
4982
|
}
|
@@ -5071,7 +4986,7 @@ var Account = class extends AbstractAccount {
|
|
5071
4986
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5072
4987
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5073
4988
|
hexlifiedContractId: contractAddress.toB256(),
|
5074
|
-
amountToTransfer:
|
4989
|
+
amountToTransfer: bn16(amount),
|
5075
4990
|
assetId: assetIdToTransfer
|
5076
4991
|
});
|
5077
4992
|
const request = new ScriptTransactionRequest({
|
@@ -5082,9 +4997,9 @@ var Account = class extends AbstractAccount {
|
|
5082
4997
|
request.addContractInputAndOutput(contractAddress);
|
5083
4998
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5084
4999
|
request,
|
5085
|
-
[{ amount:
|
5000
|
+
[{ amount: bn16(amount), assetId: String(assetIdToTransfer) }]
|
5086
5001
|
);
|
5087
|
-
request.gasLimit =
|
5002
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
5088
5003
|
this.validateGas({
|
5089
5004
|
gasUsed,
|
5090
5005
|
gasPrice: request.gasPrice,
|
@@ -5110,7 +5025,7 @@ var Account = class extends AbstractAccount {
|
|
5110
5025
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5111
5026
|
);
|
5112
5027
|
const amountDataArray = arrayify14(
|
5113
|
-
"0x".concat(
|
5028
|
+
"0x".concat(bn16(amount).toHex().substring(2).padStart(16, "0"))
|
5114
5029
|
);
|
5115
5030
|
const script = new Uint8Array([
|
5116
5031
|
...arrayify14(withdrawScript.bytes),
|
@@ -5119,12 +5034,12 @@ var Account = class extends AbstractAccount {
|
|
5119
5034
|
]);
|
5120
5035
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5121
5036
|
const request = new ScriptTransactionRequest(params);
|
5122
|
-
const forwardingQuantities = [{ amount:
|
5037
|
+
const forwardingQuantities = [{ amount: bn16(amount), assetId: baseAssetId }];
|
5123
5038
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5124
5039
|
request,
|
5125
5040
|
forwardingQuantities
|
5126
5041
|
);
|
5127
|
-
request.gasLimit =
|
5042
|
+
request.gasLimit = bn16(params.gasLimit ?? gasUsed);
|
5128
5043
|
this.validateGas({
|
5129
5044
|
gasUsed,
|
5130
5045
|
gasPrice: request.gasPrice,
|
@@ -5136,7 +5051,7 @@ var Account = class extends AbstractAccount {
|
|
5136
5051
|
}
|
5137
5052
|
async signMessage(message) {
|
5138
5053
|
if (!this._connector) {
|
5139
|
-
throw new
|
5054
|
+
throw new FuelError14(ErrorCode14.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5140
5055
|
}
|
5141
5056
|
return this._connector.signMessage(this.address.toString(), message);
|
5142
5057
|
}
|
@@ -5148,8 +5063,8 @@ var Account = class extends AbstractAccount {
|
|
5148
5063
|
*/
|
5149
5064
|
async signTransaction(transactionRequestLike) {
|
5150
5065
|
if (!this._connector) {
|
5151
|
-
throw new
|
5152
|
-
|
5066
|
+
throw new FuelError14(
|
5067
|
+
ErrorCode14.MISSING_CONNECTOR,
|
5153
5068
|
"A connector is required to sign transactions."
|
5154
5069
|
);
|
5155
5070
|
}
|
@@ -5196,14 +5111,14 @@ var Account = class extends AbstractAccount {
|
|
5196
5111
|
minGasPrice
|
5197
5112
|
}) {
|
5198
5113
|
if (minGasPrice.gt(gasPrice)) {
|
5199
|
-
throw new
|
5200
|
-
|
5114
|
+
throw new FuelError14(
|
5115
|
+
ErrorCode14.GAS_PRICE_TOO_LOW,
|
5201
5116
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5202
5117
|
);
|
5203
5118
|
}
|
5204
5119
|
if (gasUsed.gt(gasLimit)) {
|
5205
|
-
throw new
|
5206
|
-
|
5120
|
+
throw new FuelError14(
|
5121
|
+
ErrorCode14.GAS_LIMIT_TOO_LOW,
|
5207
5122
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5208
5123
|
);
|
5209
5124
|
}
|
@@ -5334,7 +5249,7 @@ import {
|
|
5334
5249
|
decryptJsonWalletData,
|
5335
5250
|
encryptJsonWalletData
|
5336
5251
|
} from "@fuel-ts/crypto";
|
5337
|
-
import { ErrorCode as
|
5252
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
5338
5253
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5339
5254
|
import { v4 as uuidv4 } from "uuid";
|
5340
5255
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5412,8 +5327,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5412
5327
|
const macHashUint8Array = keccak256(data);
|
5413
5328
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5414
5329
|
if (mac !== macHash) {
|
5415
|
-
throw new
|
5416
|
-
|
5330
|
+
throw new FuelError15(
|
5331
|
+
ErrorCode15.INVALID_PASSWORD,
|
5417
5332
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5418
5333
|
);
|
5419
5334
|
}
|
@@ -5535,15 +5450,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5535
5450
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5536
5451
|
|
5537
5452
|
// src/hdwallet/hdwallet.ts
|
5538
|
-
import { ErrorCode as
|
5453
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5539
5454
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5540
|
-
import { bn as
|
5455
|
+
import { bn as bn17, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5541
5456
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5542
5457
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5543
5458
|
|
5544
5459
|
// src/mnemonic/mnemonic.ts
|
5545
5460
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5546
|
-
import { ErrorCode as
|
5461
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
5547
5462
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5548
5463
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5549
5464
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7607,7 +7522,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7607
7522
|
})(Language || {});
|
7608
7523
|
|
7609
7524
|
// src/mnemonic/utils.ts
|
7610
|
-
import { ErrorCode as
|
7525
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
7611
7526
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7612
7527
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7613
7528
|
function toUtf8Bytes(stri) {
|
@@ -7624,8 +7539,8 @@ function toUtf8Bytes(stri) {
|
|
7624
7539
|
i += 1;
|
7625
7540
|
const c2 = str.charCodeAt(i);
|
7626
7541
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7627
|
-
throw new
|
7628
|
-
|
7542
|
+
throw new FuelError16(
|
7543
|
+
ErrorCode16.INVALID_INPUT_PARAMETERS,
|
7629
7544
|
"Invalid UTF-8 in the input string."
|
7630
7545
|
);
|
7631
7546
|
}
|
@@ -7688,8 +7603,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7688
7603
|
for (let i = 0; i < words.length; i += 1) {
|
7689
7604
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7690
7605
|
if (index === -1) {
|
7691
|
-
throw new
|
7692
|
-
|
7606
|
+
throw new FuelError16(
|
7607
|
+
ErrorCode16.INVALID_MNEMONIC,
|
7693
7608
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7694
7609
|
);
|
7695
7610
|
}
|
@@ -7705,8 +7620,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7705
7620
|
const checksumMask = getUpperMask(checksumBits);
|
7706
7621
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7707
7622
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7708
|
-
throw new
|
7709
|
-
|
7623
|
+
throw new FuelError16(
|
7624
|
+
ErrorCode16.INVALID_CHECKSUM,
|
7710
7625
|
"Checksum validation failed for the provided mnemonic."
|
7711
7626
|
);
|
7712
7627
|
}
|
@@ -7720,16 +7635,16 @@ var TestnetPRV = "0x04358394";
|
|
7720
7635
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7721
7636
|
function assertWordList(wordlist) {
|
7722
7637
|
if (wordlist.length !== 2048) {
|
7723
|
-
throw new
|
7724
|
-
|
7638
|
+
throw new FuelError17(
|
7639
|
+
ErrorCode17.INVALID_WORD_LIST,
|
7725
7640
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7726
7641
|
);
|
7727
7642
|
}
|
7728
7643
|
}
|
7729
7644
|
function assertEntropy(entropy) {
|
7730
7645
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7731
|
-
throw new
|
7732
|
-
|
7646
|
+
throw new FuelError17(
|
7647
|
+
ErrorCode17.INVALID_ENTROPY,
|
7733
7648
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7734
7649
|
);
|
7735
7650
|
}
|
@@ -7739,7 +7654,7 @@ function assertMnemonic(words) {
|
|
7739
7654
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7740
7655
|
", "
|
7741
7656
|
)}] words, but got ${words.length}.`;
|
7742
|
-
throw new
|
7657
|
+
throw new FuelError17(ErrorCode17.INVALID_MNEMONIC, errorMsg);
|
7743
7658
|
}
|
7744
7659
|
}
|
7745
7660
|
var Mnemonic = class {
|
@@ -7857,8 +7772,8 @@ var Mnemonic = class {
|
|
7857
7772
|
static masterKeysFromSeed(seed) {
|
7858
7773
|
const seedArray = arrayify17(seed);
|
7859
7774
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7860
|
-
throw new
|
7861
|
-
|
7775
|
+
throw new FuelError17(
|
7776
|
+
ErrorCode17.INVALID_SEED,
|
7862
7777
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7863
7778
|
);
|
7864
7779
|
}
|
@@ -7935,7 +7850,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7935
7850
|
function parsePath(path, depth = 0) {
|
7936
7851
|
const components = path.split("/");
|
7937
7852
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7938
|
-
throw new
|
7853
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7939
7854
|
}
|
7940
7855
|
if (components[0] === "m") {
|
7941
7856
|
components.shift();
|
@@ -7964,8 +7879,8 @@ var HDWallet = class {
|
|
7964
7879
|
this.privateKey = hexlify17(config.privateKey);
|
7965
7880
|
} else {
|
7966
7881
|
if (!config.publicKey) {
|
7967
|
-
throw new
|
7968
|
-
|
7882
|
+
throw new FuelError18(
|
7883
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7969
7884
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7970
7885
|
);
|
7971
7886
|
}
|
@@ -7994,8 +7909,8 @@ var HDWallet = class {
|
|
7994
7909
|
const data = new Uint8Array(37);
|
7995
7910
|
if (index & HARDENED_INDEX) {
|
7996
7911
|
if (!privateKey) {
|
7997
|
-
throw new
|
7998
|
-
|
7912
|
+
throw new FuelError18(
|
7913
|
+
ErrorCode18.HD_WALLET_ERROR,
|
7999
7914
|
"Cannot derive a hardened index without a private Key."
|
8000
7915
|
);
|
8001
7916
|
}
|
@@ -8009,7 +7924,7 @@ var HDWallet = class {
|
|
8009
7924
|
const IR = bytes.slice(32);
|
8010
7925
|
if (privateKey) {
|
8011
7926
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8012
|
-
const ki =
|
7927
|
+
const ki = bn17(IL).add(privateKey).mod(N).toBytes(32);
|
8013
7928
|
return new HDWallet({
|
8014
7929
|
privateKey: ki,
|
8015
7930
|
chainCode: IR,
|
@@ -8047,8 +7962,8 @@ var HDWallet = class {
|
|
8047
7962
|
*/
|
8048
7963
|
toExtendedKey(isPublic = false, testnet = false) {
|
8049
7964
|
if (this.depth >= 256) {
|
8050
|
-
throw new
|
8051
|
-
|
7965
|
+
throw new FuelError18(
|
7966
|
+
ErrorCode18.HD_WALLET_ERROR,
|
8052
7967
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8053
7968
|
);
|
8054
7969
|
}
|
@@ -8079,10 +7994,10 @@ var HDWallet = class {
|
|
8079
7994
|
const bytes = arrayify18(decoded);
|
8080
7995
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8081
7996
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8082
|
-
throw new
|
7997
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8083
7998
|
}
|
8084
7999
|
if (!validChecksum) {
|
8085
|
-
throw new
|
8000
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8086
8001
|
}
|
8087
8002
|
const depth = bytes[4];
|
8088
8003
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -8090,14 +8005,14 @@ var HDWallet = class {
|
|
8090
8005
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
8091
8006
|
const key = bytes.slice(45, 78);
|
8092
8007
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8093
|
-
throw new
|
8094
|
-
|
8008
|
+
throw new FuelError18(
|
8009
|
+
ErrorCode18.HD_WALLET_ERROR,
|
8095
8010
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8096
8011
|
);
|
8097
8012
|
}
|
8098
8013
|
if (isPublicExtendedKey(bytes)) {
|
8099
8014
|
if (key[0] !== 3) {
|
8100
|
-
throw new
|
8015
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid public extended key.");
|
8101
8016
|
}
|
8102
8017
|
return new HDWallet({
|
8103
8018
|
publicKey: key,
|
@@ -8108,7 +8023,7 @@ var HDWallet = class {
|
|
8108
8023
|
});
|
8109
8024
|
}
|
8110
8025
|
if (key[0] !== 0) {
|
8111
|
-
throw new
|
8026
|
+
throw new FuelError18(ErrorCode18.HD_WALLET_ERROR, "Invalid private extended key.");
|
8112
8027
|
}
|
8113
8028
|
return new HDWallet({
|
8114
8029
|
privateKey: key.slice(1),
|
@@ -8276,7 +8191,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8276
8191
|
// src/wallet-manager/wallet-manager.ts
|
8277
8192
|
import { Address as Address8 } from "@fuel-ts/address";
|
8278
8193
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8279
|
-
import { ErrorCode as
|
8194
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8280
8195
|
import { EventEmitter } from "events";
|
8281
8196
|
|
8282
8197
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8299,7 +8214,7 @@ var MemoryStorage = class {
|
|
8299
8214
|
|
8300
8215
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8301
8216
|
import { Address as Address6 } from "@fuel-ts/address";
|
8302
|
-
import { ErrorCode as
|
8217
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
8303
8218
|
var _secret;
|
8304
8219
|
var MnemonicVault = class {
|
8305
8220
|
constructor(options) {
|
@@ -8355,8 +8270,8 @@ var MnemonicVault = class {
|
|
8355
8270
|
}
|
8356
8271
|
numberOfAccounts += 1;
|
8357
8272
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8358
|
-
throw new
|
8359
|
-
|
8273
|
+
throw new FuelError19(
|
8274
|
+
ErrorCode19.WALLET_MANAGER_ERROR,
|
8360
8275
|
`Account with address '${address}' not found in derived wallets.`
|
8361
8276
|
);
|
8362
8277
|
}
|
@@ -8370,7 +8285,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8370
8285
|
|
8371
8286
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8372
8287
|
import { Address as Address7 } from "@fuel-ts/address";
|
8373
|
-
import { ErrorCode as
|
8288
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8374
8289
|
var _privateKeys;
|
8375
8290
|
var PrivateKeyVault = class {
|
8376
8291
|
/**
|
@@ -8411,8 +8326,8 @@ var PrivateKeyVault = class {
|
|
8411
8326
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8412
8327
|
);
|
8413
8328
|
if (!privateKey) {
|
8414
|
-
throw new
|
8415
|
-
|
8329
|
+
throw new FuelError20(
|
8330
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8416
8331
|
`No private key found for address '${address}'.`
|
8417
8332
|
);
|
8418
8333
|
}
|
@@ -8436,7 +8351,7 @@ var ERROR_MESSAGES = {
|
|
8436
8351
|
};
|
8437
8352
|
function assert(condition, message) {
|
8438
8353
|
if (!condition) {
|
8439
|
-
throw new
|
8354
|
+
throw new FuelError21(ErrorCode21.WALLET_MANAGER_ERROR, message);
|
8440
8355
|
}
|
8441
8356
|
}
|
8442
8357
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8662,25 +8577,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8662
8577
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8663
8578
|
|
8664
8579
|
// src/wallet-manager/types.ts
|
8665
|
-
import { ErrorCode as
|
8580
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8666
8581
|
var Vault = class {
|
8667
8582
|
constructor(_options) {
|
8668
|
-
throw new
|
8583
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8669
8584
|
}
|
8670
8585
|
serialize() {
|
8671
|
-
throw new
|
8586
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8672
8587
|
}
|
8673
8588
|
getAccounts() {
|
8674
|
-
throw new
|
8589
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8675
8590
|
}
|
8676
8591
|
addAccount() {
|
8677
|
-
throw new
|
8592
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8678
8593
|
}
|
8679
8594
|
exportAccount(_address) {
|
8680
|
-
throw new
|
8595
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8681
8596
|
}
|
8682
8597
|
getWallet(_address) {
|
8683
|
-
throw new
|
8598
|
+
throw new FuelError22(ErrorCode22.NOT_IMPLEMENTED, "Not implemented.");
|
8684
8599
|
}
|
8685
8600
|
};
|
8686
8601
|
__publicField(Vault, "type");
|
@@ -8696,7 +8611,7 @@ import {
|
|
8696
8611
|
SCRIPT_FIXED_SIZE
|
8697
8612
|
} from "@fuel-ts/abi-coder";
|
8698
8613
|
import { Address as Address9 } from "@fuel-ts/address";
|
8699
|
-
import { ErrorCode as
|
8614
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8700
8615
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8701
8616
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8702
8617
|
|
@@ -8825,8 +8740,8 @@ var Predicate = class extends Account {
|
|
8825
8740
|
if (jsonAbi) {
|
8826
8741
|
abiInterface = new Interface4(jsonAbi);
|
8827
8742
|
if (abiInterface.functions.main === void 0) {
|
8828
|
-
throw new
|
8829
|
-
|
8743
|
+
throw new FuelError23(
|
8744
|
+
ErrorCode23.ABI_MAIN_METHOD_MISSING,
|
8830
8745
|
'Cannot use ABI without "main" function.'
|
8831
8746
|
);
|
8832
8747
|
}
|
@@ -8871,8 +8786,8 @@ var Predicate = class extends Account {
|
|
8871
8786
|
mutatedBytes.set(encoded, offset);
|
8872
8787
|
});
|
8873
8788
|
} catch (err) {
|
8874
|
-
throw new
|
8875
|
-
|
8789
|
+
throw new FuelError23(
|
8790
|
+
ErrorCode23.INVALID_CONFIGURABLE_CONSTANTS,
|
8876
8791
|
`Error setting configurable constants: ${err.message}.`
|
8877
8792
|
);
|
8878
8793
|
}
|
@@ -8881,7 +8796,7 @@ var Predicate = class extends Account {
|
|
8881
8796
|
};
|
8882
8797
|
|
8883
8798
|
// src/connectors/fuel.ts
|
8884
|
-
import { ErrorCode as
|
8799
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8885
8800
|
|
8886
8801
|
// src/connectors/fuel-connector.ts
|
8887
8802
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9514,7 +9429,7 @@ var _Fuel = class extends FuelConnector {
|
|
9514
9429
|
const currentNetwork = await this.currentNetwork();
|
9515
9430
|
provider = await Provider.create(currentNetwork.url);
|
9516
9431
|
} else {
|
9517
|
-
throw new
|
9432
|
+
throw new FuelError24(ErrorCode24.INVALID_PROVIDER, "Provider is not valid.");
|
9518
9433
|
}
|
9519
9434
|
return provider;
|
9520
9435
|
}
|
@@ -9593,9 +9508,7 @@ export {
|
|
9593
9508
|
WalletUnlocked,
|
9594
9509
|
addAmountToAsset,
|
9595
9510
|
addOperation,
|
9596
|
-
assemblePanicError,
|
9597
9511
|
assembleReceiptByType,
|
9598
|
-
assembleRevertError,
|
9599
9512
|
assembleTransactionSummary,
|
9600
9513
|
assets,
|
9601
9514
|
buildBlockExplorerUrl,
|
@@ -9610,7 +9523,6 @@ export {
|
|
9610
9523
|
english,
|
9611
9524
|
extractBurnedAssetsFromReceipts,
|
9612
9525
|
extractMintedAssetsFromReceipts,
|
9613
|
-
extractTxError,
|
9614
9526
|
gasUsedByInputs,
|
9615
9527
|
getAssetEth,
|
9616
9528
|
getAssetFuel,
|