@fuel-ts/account 0.0.0-rc-1976-20240405090158 → 0.0.0-rc-1976-20240405092005
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 +212 -38
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +540 -457
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +328 -240
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +212 -38
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +501 -424
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +298 -213
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
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 ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
33
33
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
34
|
-
import { bn as
|
34
|
+
import { bn as bn17 } 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 ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
75
|
+
import { BN, bn as bn15, 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 bn7 } from "@fuel-ts/math";
|
1159
1159
|
import {
|
1160
1160
|
PolicyType,
|
1161
1161
|
TransactionCoder,
|
@@ -1560,6 +1560,86 @@ 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
|
+
|
1563
1643
|
// src/providers/transaction-request/errors.ts
|
1564
1644
|
var ChangeOutputCollisionError = class extends Error {
|
1565
1645
|
name = "ChangeOutputCollisionError";
|
@@ -1625,10 +1705,10 @@ var BaseTransactionRequest = class {
|
|
1625
1705
|
witnesses,
|
1626
1706
|
baseAssetId
|
1627
1707
|
} = {}) {
|
1628
|
-
this.gasPrice =
|
1708
|
+
this.gasPrice = bn7(gasPrice);
|
1629
1709
|
this.maturity = maturity ?? 0;
|
1630
|
-
this.witnessLimit = witnessLimit ?
|
1631
|
-
this.maxFee = maxFee ?
|
1710
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1711
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1632
1712
|
this.inputs = inputs ?? [];
|
1633
1713
|
this.outputs = outputs ?? [];
|
1634
1714
|
this.witnesses = witnesses ?? [];
|
@@ -2057,13 +2137,13 @@ var BaseTransactionRequest = class {
|
|
2057
2137
|
assetId,
|
2058
2138
|
owner: resourcesOwner || Address.fromRandom(),
|
2059
2139
|
maturity: 0,
|
2060
|
-
blockCreated:
|
2061
|
-
txCreatedIdx:
|
2140
|
+
blockCreated: bn7(1),
|
2141
|
+
txCreatedIdx: bn7(1)
|
2062
2142
|
}
|
2063
2143
|
]);
|
2064
2144
|
}
|
2065
2145
|
};
|
2066
|
-
updateAssetInput(this.baseAssetId,
|
2146
|
+
updateAssetInput(this.baseAssetId, bn7(1e11));
|
2067
2147
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2068
2148
|
}
|
2069
2149
|
/**
|
@@ -2074,7 +2154,7 @@ var BaseTransactionRequest = class {
|
|
2074
2154
|
*/
|
2075
2155
|
getCoinOutputsQuantities() {
|
2076
2156
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2077
|
-
amount:
|
2157
|
+
amount: bn7(amount),
|
2078
2158
|
assetId: assetId.toString()
|
2079
2159
|
}));
|
2080
2160
|
return coinsQuantities;
|
@@ -2103,7 +2183,7 @@ var BaseTransactionRequest = class {
|
|
2103
2183
|
default:
|
2104
2184
|
return;
|
2105
2185
|
}
|
2106
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2186
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2107
2187
|
i.predicate = correspondingInput.predicate;
|
2108
2188
|
i.predicateData = correspondingInput.predicateData;
|
2109
2189
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2114,14 +2194,14 @@ var BaseTransactionRequest = class {
|
|
2114
2194
|
|
2115
2195
|
// src/providers/transaction-request/create-transaction-request.ts
|
2116
2196
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2117
|
-
import { bn as
|
2197
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2118
2198
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2119
2199
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2120
2200
|
|
2121
2201
|
// src/providers/transaction-request/hash-transaction.ts
|
2122
2202
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2123
2203
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2124
|
-
import { bn as
|
2204
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2125
2205
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2126
2206
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2127
2207
|
import { clone as clone2 } from "ramda";
|
@@ -2138,11 +2218,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2138
2218
|
blockHeight: 0,
|
2139
2219
|
txIndex: 0
|
2140
2220
|
};
|
2141
|
-
inputClone.predicateGasUsed =
|
2221
|
+
inputClone.predicateGasUsed = bn8(0);
|
2142
2222
|
return inputClone;
|
2143
2223
|
}
|
2144
2224
|
case InputType3.Message: {
|
2145
|
-
inputClone.predicateGasUsed =
|
2225
|
+
inputClone.predicateGasUsed = bn8(0);
|
2146
2226
|
return inputClone;
|
2147
2227
|
}
|
2148
2228
|
case InputType3.Contract: {
|
@@ -2169,12 +2249,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2169
2249
|
return outputClone;
|
2170
2250
|
}
|
2171
2251
|
case OutputType3.Change: {
|
2172
|
-
outputClone.amount =
|
2252
|
+
outputClone.amount = bn8(0);
|
2173
2253
|
return outputClone;
|
2174
2254
|
}
|
2175
2255
|
case OutputType3.Variable: {
|
2176
2256
|
outputClone.to = ZeroBytes325;
|
2177
|
-
outputClone.amount =
|
2257
|
+
outputClone.amount = bn8(0);
|
2178
2258
|
outputClone.assetId = ZeroBytes325;
|
2179
2259
|
return outputClone;
|
2180
2260
|
}
|
@@ -2298,7 +2378,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2298
2378
|
}
|
2299
2379
|
metadataGas(gasCosts) {
|
2300
2380
|
return calculateMetadataGasForTxCreate({
|
2301
|
-
contractBytesSize:
|
2381
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2302
2382
|
gasCosts,
|
2303
2383
|
stateRootSize: this.storageSlots.length,
|
2304
2384
|
txBytesSize: this.byteSize()
|
@@ -2310,7 +2390,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2310
2390
|
import { Interface } from "@fuel-ts/abi-coder";
|
2311
2391
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2312
2392
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2313
|
-
import { bn as
|
2393
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2314
2394
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2315
2395
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2316
2396
|
|
@@ -2364,7 +2444,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2364
2444
|
*/
|
2365
2445
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2366
2446
|
super(rest);
|
2367
|
-
this.gasLimit =
|
2447
|
+
this.gasLimit = bn10(gasLimit);
|
2368
2448
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2369
2449
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2370
2450
|
this.abis = rest.abis;
|
@@ -2512,7 +2592,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2512
2592
|
};
|
2513
2593
|
|
2514
2594
|
// src/providers/transaction-request/utils.ts
|
2515
|
-
import { ErrorCode as
|
2595
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2516
2596
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2517
2597
|
var transactionRequestify = (obj) => {
|
2518
2598
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2527,14 +2607,14 @@ var transactionRequestify = (obj) => {
|
|
2527
2607
|
return CreateTransactionRequest.from(obj);
|
2528
2608
|
}
|
2529
2609
|
default: {
|
2530
|
-
throw new
|
2610
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2531
2611
|
}
|
2532
2612
|
}
|
2533
2613
|
};
|
2534
2614
|
|
2535
2615
|
// src/providers/transaction-response/transaction-response.ts
|
2536
|
-
import { ErrorCode as
|
2537
|
-
import { bn as
|
2616
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2617
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2538
2618
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2539
2619
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2540
2620
|
|
@@ -2542,7 +2622,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2542
2622
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2543
2623
|
|
2544
2624
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2545
|
-
import { bn as
|
2625
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2546
2626
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2547
2627
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2548
2628
|
var calculateTransactionFee = (params) => {
|
@@ -2551,24 +2631,24 @@ var calculateTransactionFee = (params) => {
|
|
2551
2631
|
rawPayload,
|
2552
2632
|
consensusParameters: { gasCosts, feeParams }
|
2553
2633
|
} = params;
|
2554
|
-
const gasPerByte =
|
2555
|
-
const gasPriceFactor =
|
2634
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2635
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2556
2636
|
const transactionBytes = arrayify9(rawPayload);
|
2557
2637
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2558
2638
|
if (transaction.type === TransactionType6.Mint) {
|
2559
2639
|
return {
|
2560
|
-
fee:
|
2561
|
-
minFee:
|
2562
|
-
maxFee:
|
2563
|
-
feeFromGasUsed:
|
2640
|
+
fee: bn11(0),
|
2641
|
+
minFee: bn11(0),
|
2642
|
+
maxFee: bn11(0),
|
2643
|
+
feeFromGasUsed: bn11(0)
|
2564
2644
|
};
|
2565
2645
|
}
|
2566
2646
|
const { type, witnesses, inputs, policies } = transaction;
|
2567
|
-
let metadataGas =
|
2568
|
-
let gasLimit =
|
2647
|
+
let metadataGas = bn11(0);
|
2648
|
+
let gasLimit = bn11(0);
|
2569
2649
|
if (type === TransactionType6.Create) {
|
2570
2650
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2571
|
-
const contractBytesSize =
|
2651
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2572
2652
|
metadataGas = calculateMetadataGasForTxCreate({
|
2573
2653
|
contractBytesSize,
|
2574
2654
|
gasCosts,
|
@@ -2587,12 +2667,12 @@ var calculateTransactionFee = (params) => {
|
|
2587
2667
|
}
|
2588
2668
|
const minGas = getMinGas({
|
2589
2669
|
gasCosts,
|
2590
|
-
gasPerByte:
|
2670
|
+
gasPerByte: bn11(gasPerByte),
|
2591
2671
|
inputs,
|
2592
2672
|
metadataGas,
|
2593
2673
|
txBytesSize: transactionBytes.length
|
2594
2674
|
});
|
2595
|
-
const gasPrice =
|
2675
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2596
2676
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2597
2677
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2598
2678
|
const maxGas = getMaxGas({
|
@@ -2616,13 +2696,13 @@ var calculateTransactionFee = (params) => {
|
|
2616
2696
|
|
2617
2697
|
// src/providers/transaction-summary/operations.ts
|
2618
2698
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2619
|
-
import { ErrorCode as
|
2620
|
-
import { bn as
|
2621
|
-
import { ReceiptType as
|
2699
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2700
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2701
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2622
2702
|
|
2623
2703
|
// src/providers/transaction-summary/call.ts
|
2624
2704
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2625
|
-
import { bn as
|
2705
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2626
2706
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2627
2707
|
const abiInterface = new Interface2(abi);
|
2628
2708
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2631,7 +2711,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2631
2711
|
let encodedArgs;
|
2632
2712
|
if (functionFragment.isInputDataPointer) {
|
2633
2713
|
if (rawPayload) {
|
2634
|
-
const argsOffset =
|
2714
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2635
2715
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2636
2716
|
}
|
2637
2717
|
} else {
|
@@ -2665,7 +2745,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2665
2745
|
};
|
2666
2746
|
|
2667
2747
|
// src/providers/transaction-summary/input.ts
|
2668
|
-
import { ErrorCode as
|
2748
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2669
2749
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2670
2750
|
function getInputsByTypes(inputs, types) {
|
2671
2751
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2703,8 +2783,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2703
2783
|
return void 0;
|
2704
2784
|
}
|
2705
2785
|
if (contractInput.type !== InputType5.Contract) {
|
2706
|
-
throw new
|
2707
|
-
|
2786
|
+
throw new FuelError9(
|
2787
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2708
2788
|
`Contract input should be of type 'contract'.`
|
2709
2789
|
);
|
2710
2790
|
}
|
@@ -2792,8 +2872,8 @@ function getTransactionTypeName(transactionType) {
|
|
2792
2872
|
case TransactionType7.Script:
|
2793
2873
|
return "Script" /* Script */;
|
2794
2874
|
default:
|
2795
|
-
throw new
|
2796
|
-
|
2875
|
+
throw new FuelError10(
|
2876
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2797
2877
|
`Invalid transaction type: ${transactionType}.`
|
2798
2878
|
);
|
2799
2879
|
}
|
@@ -2815,10 +2895,10 @@ function hasSameAssetId(a) {
|
|
2815
2895
|
return (b) => a.assetId === b.assetId;
|
2816
2896
|
}
|
2817
2897
|
function getReceiptsCall(receipts) {
|
2818
|
-
return getReceiptsByType(receipts,
|
2898
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2819
2899
|
}
|
2820
2900
|
function getReceiptsMessageOut(receipts) {
|
2821
|
-
return getReceiptsByType(receipts,
|
2901
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2822
2902
|
}
|
2823
2903
|
var mergeAssets = (op1, op2) => {
|
2824
2904
|
const assets1 = op1.assetsSent || [];
|
@@ -2831,7 +2911,7 @@ var mergeAssets = (op1, op2) => {
|
|
2831
2911
|
if (!matchingAsset) {
|
2832
2912
|
return asset1;
|
2833
2913
|
}
|
2834
|
-
const mergedAmount =
|
2914
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2835
2915
|
return { ...asset1, amount: mergedAmount };
|
2836
2916
|
});
|
2837
2917
|
return mergedAssets.concat(filteredAssets);
|
@@ -2857,7 +2937,7 @@ function addOperation(operations, toAdd) {
|
|
2857
2937
|
return allOperations;
|
2858
2938
|
}
|
2859
2939
|
function getReceiptsTransferOut(receipts) {
|
2860
|
-
return getReceiptsByType(receipts,
|
2940
|
+
return getReceiptsByType(receipts, ReceiptType4.TransferOut);
|
2861
2941
|
}
|
2862
2942
|
function getWithdrawFromFuelOperations({
|
2863
2943
|
inputs,
|
@@ -3017,11 +3097,11 @@ function getTransferOperations({
|
|
3017
3097
|
});
|
3018
3098
|
const transferReceipts = getReceiptsByType(
|
3019
3099
|
receipts,
|
3020
|
-
|
3100
|
+
ReceiptType4.Transfer
|
3021
3101
|
);
|
3022
3102
|
const transferOutReceipts = getReceiptsByType(
|
3023
3103
|
receipts,
|
3024
|
-
|
3104
|
+
ReceiptType4.TransferOut
|
3025
3105
|
);
|
3026
3106
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3027
3107
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3106,17 +3186,17 @@ function getOperations({
|
|
3106
3186
|
}
|
3107
3187
|
|
3108
3188
|
// src/providers/transaction-summary/receipt.ts
|
3109
|
-
import { ReceiptType as
|
3189
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3110
3190
|
var processGqlReceipt = (gqlReceipt) => {
|
3111
3191
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3112
3192
|
switch (receipt.type) {
|
3113
|
-
case
|
3193
|
+
case ReceiptType5.ReturnData: {
|
3114
3194
|
return {
|
3115
3195
|
...receipt,
|
3116
3196
|
data: gqlReceipt.data || "0x"
|
3117
3197
|
};
|
3118
3198
|
}
|
3119
|
-
case
|
3199
|
+
case ReceiptType5.LogData: {
|
3120
3200
|
return {
|
3121
3201
|
...receipt,
|
3122
3202
|
data: gqlReceipt.data || "0x"
|
@@ -3129,7 +3209,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3129
3209
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3130
3210
|
const mintedAssets = [];
|
3131
3211
|
receipts.forEach((receipt) => {
|
3132
|
-
if (receipt.type ===
|
3212
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3133
3213
|
mintedAssets.push({
|
3134
3214
|
subId: receipt.subId,
|
3135
3215
|
contractId: receipt.contractId,
|
@@ -3143,7 +3223,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3143
3223
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3144
3224
|
const burnedAssets = [];
|
3145
3225
|
receipts.forEach((receipt) => {
|
3146
|
-
if (receipt.type ===
|
3226
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3147
3227
|
burnedAssets.push({
|
3148
3228
|
subId: receipt.subId,
|
3149
3229
|
contractId: receipt.contractId,
|
@@ -3156,7 +3236,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3156
3236
|
};
|
3157
3237
|
|
3158
3238
|
// src/providers/transaction-summary/status.ts
|
3159
|
-
import { ErrorCode as
|
3239
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3160
3240
|
var getTransactionStatusName = (gqlStatus) => {
|
3161
3241
|
switch (gqlStatus) {
|
3162
3242
|
case "FailureStatus":
|
@@ -3168,8 +3248,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3168
3248
|
case "SqueezedOutStatus":
|
3169
3249
|
return "squeezedout" /* squeezedout */;
|
3170
3250
|
default:
|
3171
|
-
throw new
|
3172
|
-
|
3251
|
+
throw new FuelError11(
|
3252
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3173
3253
|
`Invalid transaction status: ${gqlStatus}.`
|
3174
3254
|
);
|
3175
3255
|
}
|
@@ -3282,12 +3362,12 @@ function assembleTransactionSummary(params) {
|
|
3282
3362
|
|
3283
3363
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3284
3364
|
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3285
|
-
import { ReceiptType as
|
3365
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3286
3366
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3287
3367
|
return receipts.reduce((logs, receipt) => {
|
3288
|
-
if (receipt.type ===
|
3368
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3289
3369
|
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3290
|
-
const data = receipt.type ===
|
3370
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3291
3371
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3292
3372
|
logs.push(decodedLog);
|
3293
3373
|
}
|
@@ -3302,7 +3382,7 @@ var TransactionResponse = class {
|
|
3302
3382
|
/** Current provider */
|
3303
3383
|
provider;
|
3304
3384
|
/** Gas used on the transaction */
|
3305
|
-
gasUsed =
|
3385
|
+
gasUsed = bn14(0);
|
3306
3386
|
/** The graphql Transaction with receipts object. */
|
3307
3387
|
gqlTransaction;
|
3308
3388
|
abis;
|
@@ -3407,8 +3487,8 @@ var TransactionResponse = class {
|
|
3407
3487
|
});
|
3408
3488
|
for await (const { statusChange } of subscription) {
|
3409
3489
|
if (statusChange.type === "SqueezedOutStatus") {
|
3410
|
-
throw new
|
3411
|
-
|
3490
|
+
throw new FuelError12(
|
3491
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3412
3492
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3413
3493
|
);
|
3414
3494
|
}
|
@@ -3430,14 +3510,26 @@ var TransactionResponse = class {
|
|
3430
3510
|
gqlTransaction: this.gqlTransaction,
|
3431
3511
|
...transactionSummary
|
3432
3512
|
};
|
3513
|
+
let logs = [];
|
3433
3514
|
if (this.abis) {
|
3434
|
-
|
3515
|
+
logs = getDecodedLogs(
|
3435
3516
|
transactionSummary.receipts,
|
3436
3517
|
this.abis.main,
|
3437
3518
|
this.abis.otherContractsAbis
|
3438
3519
|
);
|
3439
3520
|
transactionResult.logs = logs;
|
3440
3521
|
}
|
3522
|
+
if (transactionResult.isStatusFailure) {
|
3523
|
+
const {
|
3524
|
+
receipts,
|
3525
|
+
gqlTransaction: { status }
|
3526
|
+
} = transactionResult;
|
3527
|
+
throw extractTxError({
|
3528
|
+
receipts,
|
3529
|
+
status,
|
3530
|
+
logs
|
3531
|
+
});
|
3532
|
+
}
|
3441
3533
|
return transactionResult;
|
3442
3534
|
}
|
3443
3535
|
/**
|
@@ -3446,14 +3538,7 @@ var TransactionResponse = class {
|
|
3446
3538
|
* @param contractsAbiMap - The contracts ABI map.
|
3447
3539
|
*/
|
3448
3540
|
async wait(contractsAbiMap) {
|
3449
|
-
|
3450
|
-
if (result.isStatusFailure) {
|
3451
|
-
throw new FuelError11(
|
3452
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3453
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3454
|
-
);
|
3455
|
-
}
|
3456
|
-
return result;
|
3541
|
+
return this.waitForResult(contractsAbiMap);
|
3457
3542
|
}
|
3458
3543
|
};
|
3459
3544
|
|
@@ -3515,30 +3600,30 @@ var processGqlChain = (chain) => {
|
|
3515
3600
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3516
3601
|
return {
|
3517
3602
|
name,
|
3518
|
-
baseChainHeight:
|
3603
|
+
baseChainHeight: bn15(daHeight),
|
3519
3604
|
consensusParameters: {
|
3520
|
-
contractMaxSize:
|
3521
|
-
maxInputs:
|
3522
|
-
maxOutputs:
|
3523
|
-
maxWitnesses:
|
3524
|
-
maxGasPerTx:
|
3525
|
-
maxScriptLength:
|
3526
|
-
maxScriptDataLength:
|
3527
|
-
maxStorageSlots:
|
3528
|
-
maxPredicateLength:
|
3529
|
-
maxPredicateDataLength:
|
3530
|
-
maxGasPerPredicate:
|
3531
|
-
gasPriceFactor:
|
3532
|
-
gasPerByte:
|
3533
|
-
maxMessageDataLength:
|
3534
|
-
chainId:
|
3605
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3606
|
+
maxInputs: bn15(txParams.maxInputs),
|
3607
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3608
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3609
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3610
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3611
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3612
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3613
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3614
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3615
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3616
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3617
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3618
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3619
|
+
chainId: bn15(consensusParameters.chainId),
|
3535
3620
|
baseAssetId: consensusParameters.baseAssetId,
|
3536
3621
|
gasCosts
|
3537
3622
|
},
|
3538
3623
|
gasCosts,
|
3539
3624
|
latestBlock: {
|
3540
3625
|
id: latestBlock.id,
|
3541
|
-
height:
|
3626
|
+
height: bn15(latestBlock.header.height),
|
3542
3627
|
time: latestBlock.header.time,
|
3543
3628
|
transactions: latestBlock.transactions.map((i) => ({
|
3544
3629
|
id: i.id
|
@@ -3608,8 +3693,8 @@ var _Provider = class {
|
|
3608
3693
|
getChain() {
|
3609
3694
|
const chain = _Provider.chainInfoCache[this.url];
|
3610
3695
|
if (!chain) {
|
3611
|
-
throw new
|
3612
|
-
|
3696
|
+
throw new FuelError13(
|
3697
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3613
3698
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3614
3699
|
);
|
3615
3700
|
}
|
@@ -3621,8 +3706,8 @@ var _Provider = class {
|
|
3621
3706
|
getNode() {
|
3622
3707
|
const node = _Provider.nodeInfoCache[this.url];
|
3623
3708
|
if (!node) {
|
3624
|
-
throw new
|
3625
|
-
|
3709
|
+
throw new FuelError13(
|
3710
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3626
3711
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3627
3712
|
);
|
3628
3713
|
}
|
@@ -3669,8 +3754,8 @@ var _Provider = class {
|
|
3669
3754
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3670
3755
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3671
3756
|
if (!isMajorSupported || !isMinorSupported) {
|
3672
|
-
throw new
|
3673
|
-
|
3757
|
+
throw new FuelError13(
|
3758
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3674
3759
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3675
3760
|
);
|
3676
3761
|
}
|
@@ -3733,7 +3818,7 @@ var _Provider = class {
|
|
3733
3818
|
*/
|
3734
3819
|
async getBlockNumber() {
|
3735
3820
|
const { chain } = await this.operations.getChain();
|
3736
|
-
return
|
3821
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3737
3822
|
}
|
3738
3823
|
/**
|
3739
3824
|
* Returns the chain information.
|
@@ -3743,9 +3828,9 @@ var _Provider = class {
|
|
3743
3828
|
async fetchNode() {
|
3744
3829
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3745
3830
|
const processedNodeInfo = {
|
3746
|
-
maxDepth:
|
3747
|
-
maxTx:
|
3748
|
-
minGasPrice:
|
3831
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3832
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3833
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3749
3834
|
nodeVersion: nodeInfo.nodeVersion,
|
3750
3835
|
utxoValidation: nodeInfo.utxoValidation,
|
3751
3836
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3811,8 +3896,8 @@ var _Provider = class {
|
|
3811
3896
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3812
3897
|
for await (const { submitAndAwait } of subscription) {
|
3813
3898
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3814
|
-
throw new
|
3815
|
-
|
3899
|
+
throw new FuelError13(
|
3900
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3816
3901
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3817
3902
|
);
|
3818
3903
|
}
|
@@ -3879,7 +3964,7 @@ var _Provider = class {
|
|
3879
3964
|
} = response;
|
3880
3965
|
if (inputs) {
|
3881
3966
|
inputs.forEach((input, index) => {
|
3882
|
-
if ("predicateGasUsed" in input &&
|
3967
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3883
3968
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3884
3969
|
}
|
3885
3970
|
});
|
@@ -3992,7 +4077,7 @@ var _Provider = class {
|
|
3992
4077
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3993
4078
|
if (estimatePredicates) {
|
3994
4079
|
if (isScriptTransaction) {
|
3995
|
-
txRequestClone.gasLimit =
|
4080
|
+
txRequestClone.gasLimit = bn15(0);
|
3996
4081
|
}
|
3997
4082
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3998
4083
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4008,8 +4093,8 @@ var _Provider = class {
|
|
4008
4093
|
let missingContractIds = [];
|
4009
4094
|
let outputVariables = 0;
|
4010
4095
|
if (isScriptTransaction && estimateTxDependencies) {
|
4011
|
-
txRequestClone.gasPrice =
|
4012
|
-
txRequestClone.gasLimit =
|
4096
|
+
txRequestClone.gasPrice = bn15(0);
|
4097
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4013
4098
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4014
4099
|
receipts = result.receipts;
|
4015
4100
|
outputVariables = result.outputVariables;
|
@@ -4071,11 +4156,11 @@ var _Provider = class {
|
|
4071
4156
|
return coins.map((coin) => ({
|
4072
4157
|
id: coin.utxoId,
|
4073
4158
|
assetId: coin.assetId,
|
4074
|
-
amount:
|
4159
|
+
amount: bn15(coin.amount),
|
4075
4160
|
owner: Address2.fromAddressOrString(coin.owner),
|
4076
|
-
maturity:
|
4077
|
-
blockCreated:
|
4078
|
-
txCreatedIdx:
|
4161
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4162
|
+
blockCreated: bn15(coin.blockCreated),
|
4163
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4079
4164
|
}));
|
4080
4165
|
}
|
4081
4166
|
/**
|
@@ -4112,9 +4197,9 @@ var _Provider = class {
|
|
4112
4197
|
switch (coin.__typename) {
|
4113
4198
|
case "MessageCoin":
|
4114
4199
|
return {
|
4115
|
-
amount:
|
4200
|
+
amount: bn15(coin.amount),
|
4116
4201
|
assetId: coin.assetId,
|
4117
|
-
daHeight:
|
4202
|
+
daHeight: bn15(coin.daHeight),
|
4118
4203
|
sender: Address2.fromAddressOrString(coin.sender),
|
4119
4204
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4120
4205
|
nonce: coin.nonce
|
@@ -4122,12 +4207,12 @@ var _Provider = class {
|
|
4122
4207
|
case "Coin":
|
4123
4208
|
return {
|
4124
4209
|
id: coin.utxoId,
|
4125
|
-
amount:
|
4210
|
+
amount: bn15(coin.amount),
|
4126
4211
|
assetId: coin.assetId,
|
4127
4212
|
owner: Address2.fromAddressOrString(coin.owner),
|
4128
|
-
maturity:
|
4129
|
-
blockCreated:
|
4130
|
-
txCreatedIdx:
|
4213
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4214
|
+
blockCreated: bn15(coin.blockCreated),
|
4215
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4131
4216
|
};
|
4132
4217
|
default:
|
4133
4218
|
return null;
|
@@ -4144,13 +4229,13 @@ var _Provider = class {
|
|
4144
4229
|
async getBlock(idOrHeight) {
|
4145
4230
|
let variables;
|
4146
4231
|
if (typeof idOrHeight === "number") {
|
4147
|
-
variables = { height:
|
4232
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4148
4233
|
} else if (idOrHeight === "latest") {
|
4149
4234
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4150
4235
|
} else if (idOrHeight.length === 66) {
|
4151
4236
|
variables = { blockId: idOrHeight };
|
4152
4237
|
} else {
|
4153
|
-
variables = { blockId:
|
4238
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4154
4239
|
}
|
4155
4240
|
const { block } = await this.operations.getBlock(variables);
|
4156
4241
|
if (!block) {
|
@@ -4158,7 +4243,7 @@ var _Provider = class {
|
|
4158
4243
|
}
|
4159
4244
|
return {
|
4160
4245
|
id: block.id,
|
4161
|
-
height:
|
4246
|
+
height: bn15(block.header.height),
|
4162
4247
|
time: block.header.time,
|
4163
4248
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4164
4249
|
};
|
@@ -4173,7 +4258,7 @@ var _Provider = class {
|
|
4173
4258
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4174
4259
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4175
4260
|
id: block.id,
|
4176
|
-
height:
|
4261
|
+
height: bn15(block.header.height),
|
4177
4262
|
time: block.header.time,
|
4178
4263
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4179
4264
|
}));
|
@@ -4188,7 +4273,7 @@ var _Provider = class {
|
|
4188
4273
|
async getBlockWithTransactions(idOrHeight) {
|
4189
4274
|
let variables;
|
4190
4275
|
if (typeof idOrHeight === "number") {
|
4191
|
-
variables = { blockHeight:
|
4276
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4192
4277
|
} else if (idOrHeight === "latest") {
|
4193
4278
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4194
4279
|
} else {
|
@@ -4200,7 +4285,7 @@ var _Provider = class {
|
|
4200
4285
|
}
|
4201
4286
|
return {
|
4202
4287
|
id: block.id,
|
4203
|
-
height:
|
4288
|
+
height: bn15(block.header.height, 10),
|
4204
4289
|
time: block.header.time,
|
4205
4290
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4206
4291
|
transactions: block.transactions.map(
|
@@ -4249,7 +4334,7 @@ var _Provider = class {
|
|
4249
4334
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4250
4335
|
asset: hexlify12(assetId)
|
4251
4336
|
});
|
4252
|
-
return
|
4337
|
+
return bn15(contractBalance.amount, 10);
|
4253
4338
|
}
|
4254
4339
|
/**
|
4255
4340
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4263,7 +4348,7 @@ var _Provider = class {
|
|
4263
4348
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4264
4349
|
assetId: hexlify12(assetId)
|
4265
4350
|
});
|
4266
|
-
return
|
4351
|
+
return bn15(balance.amount, 10);
|
4267
4352
|
}
|
4268
4353
|
/**
|
4269
4354
|
* Returns balances for the given owner.
|
@@ -4281,7 +4366,7 @@ var _Provider = class {
|
|
4281
4366
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4282
4367
|
return balances.map((balance) => ({
|
4283
4368
|
assetId: balance.assetId,
|
4284
|
-
amount:
|
4369
|
+
amount: bn15(balance.amount)
|
4285
4370
|
}));
|
4286
4371
|
}
|
4287
4372
|
/**
|
@@ -4303,15 +4388,15 @@ var _Provider = class {
|
|
4303
4388
|
sender: message.sender,
|
4304
4389
|
recipient: message.recipient,
|
4305
4390
|
nonce: message.nonce,
|
4306
|
-
amount:
|
4391
|
+
amount: bn15(message.amount),
|
4307
4392
|
data: message.data
|
4308
4393
|
}),
|
4309
4394
|
sender: Address2.fromAddressOrString(message.sender),
|
4310
4395
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4311
4396
|
nonce: message.nonce,
|
4312
|
-
amount:
|
4397
|
+
amount: bn15(message.amount),
|
4313
4398
|
data: InputMessageCoder.decodeData(message.data),
|
4314
|
-
daHeight:
|
4399
|
+
daHeight: bn15(message.daHeight)
|
4315
4400
|
}));
|
4316
4401
|
}
|
4317
4402
|
/**
|
@@ -4329,8 +4414,8 @@ var _Provider = class {
|
|
4329
4414
|
nonce
|
4330
4415
|
};
|
4331
4416
|
if (commitBlockId && commitBlockHeight) {
|
4332
|
-
throw new
|
4333
|
-
|
4417
|
+
throw new FuelError13(
|
4418
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4334
4419
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4335
4420
|
);
|
4336
4421
|
}
|
@@ -4364,41 +4449,41 @@ var _Provider = class {
|
|
4364
4449
|
} = result.messageProof;
|
4365
4450
|
return {
|
4366
4451
|
messageProof: {
|
4367
|
-
proofIndex:
|
4452
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4368
4453
|
proofSet: messageProof.proofSet
|
4369
4454
|
},
|
4370
4455
|
blockProof: {
|
4371
|
-
proofIndex:
|
4456
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4372
4457
|
proofSet: blockProof.proofSet
|
4373
4458
|
},
|
4374
4459
|
messageBlockHeader: {
|
4375
4460
|
id: messageBlockHeader.id,
|
4376
|
-
daHeight:
|
4377
|
-
transactionsCount:
|
4461
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4462
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4378
4463
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4379
|
-
height:
|
4464
|
+
height: bn15(messageBlockHeader.height),
|
4380
4465
|
prevRoot: messageBlockHeader.prevRoot,
|
4381
4466
|
time: messageBlockHeader.time,
|
4382
4467
|
applicationHash: messageBlockHeader.applicationHash,
|
4383
4468
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4384
|
-
messageReceiptCount:
|
4469
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4385
4470
|
},
|
4386
4471
|
commitBlockHeader: {
|
4387
4472
|
id: commitBlockHeader.id,
|
4388
|
-
daHeight:
|
4389
|
-
transactionsCount:
|
4473
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4474
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4390
4475
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4391
|
-
height:
|
4476
|
+
height: bn15(commitBlockHeader.height),
|
4392
4477
|
prevRoot: commitBlockHeader.prevRoot,
|
4393
4478
|
time: commitBlockHeader.time,
|
4394
4479
|
applicationHash: commitBlockHeader.applicationHash,
|
4395
4480
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4396
|
-
messageReceiptCount:
|
4481
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4397
4482
|
},
|
4398
4483
|
sender: Address2.fromAddressOrString(sender),
|
4399
4484
|
recipient: Address2.fromAddressOrString(recipient),
|
4400
4485
|
nonce,
|
4401
|
-
amount:
|
4486
|
+
amount: bn15(amount),
|
4402
4487
|
data
|
4403
4488
|
};
|
4404
4489
|
}
|
@@ -4421,10 +4506,10 @@ var _Provider = class {
|
|
4421
4506
|
*/
|
4422
4507
|
async produceBlocks(amount, startTime) {
|
4423
4508
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4424
|
-
blocksToProduce:
|
4509
|
+
blocksToProduce: bn15(amount).toString(10),
|
4425
4510
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4426
4511
|
});
|
4427
|
-
return
|
4512
|
+
return bn15(latestBlockHeight);
|
4428
4513
|
}
|
4429
4514
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4430
4515
|
async getTransactionResponse(transactionId) {
|
@@ -4447,8 +4532,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4447
4532
|
__publicField(Provider, "nodeInfoCache", {});
|
4448
4533
|
|
4449
4534
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4450
|
-
import { ErrorCode as
|
4451
|
-
import { bn as
|
4535
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4536
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4452
4537
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4453
4538
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4454
4539
|
async function getTransactionSummary(params) {
|
@@ -4457,8 +4542,8 @@ async function getTransactionSummary(params) {
|
|
4457
4542
|
transactionId: id
|
4458
4543
|
});
|
4459
4544
|
if (!gqlTransaction) {
|
4460
|
-
throw new
|
4461
|
-
|
4545
|
+
throw new FuelError14(
|
4546
|
+
ErrorCode14.TRANSACTION_NOT_FOUND,
|
4462
4547
|
`Transaction not found for given id: ${id}.`
|
4463
4548
|
);
|
4464
4549
|
}
|
@@ -4476,8 +4561,8 @@ async function getTransactionSummary(params) {
|
|
4476
4561
|
transaction: decodedTransaction,
|
4477
4562
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4478
4563
|
gqlTransactionStatus: gqlTransaction.status,
|
4479
|
-
gasPerByte:
|
4480
|
-
gasPriceFactor:
|
4564
|
+
gasPerByte: bn16(gasPerByte),
|
4565
|
+
gasPriceFactor: bn16(gasPriceFactor),
|
4481
4566
|
abiMap,
|
4482
4567
|
maxInputs,
|
4483
4568
|
gasCosts
|
@@ -4731,7 +4816,7 @@ var Account = class extends AbstractAccount {
|
|
4731
4816
|
*/
|
4732
4817
|
get provider() {
|
4733
4818
|
if (!this._provider) {
|
4734
|
-
throw new
|
4819
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4735
4820
|
}
|
4736
4821
|
return this._provider;
|
4737
4822
|
}
|
@@ -4783,8 +4868,8 @@ var Account = class extends AbstractAccount {
|
|
4783
4868
|
if (!hasNextPage) {
|
4784
4869
|
break;
|
4785
4870
|
}
|
4786
|
-
throw new
|
4787
|
-
|
4871
|
+
throw new FuelError15(
|
4872
|
+
ErrorCode15.NOT_SUPPORTED,
|
4788
4873
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4789
4874
|
);
|
4790
4875
|
}
|
@@ -4809,8 +4894,8 @@ var Account = class extends AbstractAccount {
|
|
4809
4894
|
if (!hasNextPage) {
|
4810
4895
|
break;
|
4811
4896
|
}
|
4812
|
-
throw new
|
4813
|
-
|
4897
|
+
throw new FuelError15(
|
4898
|
+
ErrorCode15.NOT_SUPPORTED,
|
4814
4899
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4815
4900
|
);
|
4816
4901
|
}
|
@@ -4846,8 +4931,8 @@ var Account = class extends AbstractAccount {
|
|
4846
4931
|
if (!hasNextPage) {
|
4847
4932
|
break;
|
4848
4933
|
}
|
4849
|
-
throw new
|
4850
|
-
|
4934
|
+
throw new FuelError15(
|
4935
|
+
ErrorCode15.NOT_SUPPORTED,
|
4851
4936
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4852
4937
|
);
|
4853
4938
|
}
|
@@ -4864,7 +4949,7 @@ var Account = class extends AbstractAccount {
|
|
4864
4949
|
async fund(request, coinQuantities, fee) {
|
4865
4950
|
const baseAssetId = this.provider.getBaseAssetId();
|
4866
4951
|
const updatedQuantities = addAmountToAsset({
|
4867
|
-
amount:
|
4952
|
+
amount: bn17(fee),
|
4868
4953
|
assetId: baseAssetId,
|
4869
4954
|
coinQuantities
|
4870
4955
|
});
|
@@ -4872,7 +4957,7 @@ var Account = class extends AbstractAccount {
|
|
4872
4957
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4873
4958
|
quantitiesDict[assetId] = {
|
4874
4959
|
required: amount,
|
4875
|
-
owned:
|
4960
|
+
owned: bn17(0)
|
4876
4961
|
};
|
4877
4962
|
});
|
4878
4963
|
const cachedUtxos = [];
|
@@ -4885,7 +4970,7 @@ var Account = class extends AbstractAccount {
|
|
4885
4970
|
if (isCoin2) {
|
4886
4971
|
const assetId = String(input.assetId);
|
4887
4972
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4888
|
-
const amount =
|
4973
|
+
const amount = bn17(input.amount);
|
4889
4974
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4890
4975
|
cachedUtxos.push(input.id);
|
4891
4976
|
}
|
@@ -4932,8 +5017,8 @@ var Account = class extends AbstractAccount {
|
|
4932
5017
|
estimateTxDependencies: true,
|
4933
5018
|
resourcesOwner: this
|
4934
5019
|
});
|
4935
|
-
request.gasPrice =
|
4936
|
-
request.gasLimit =
|
5020
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
5021
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4937
5022
|
this.validateGas({
|
4938
5023
|
gasUsed,
|
4939
5024
|
gasPrice: request.gasPrice,
|
@@ -4954,9 +5039,9 @@ var Account = class extends AbstractAccount {
|
|
4954
5039
|
* @returns A promise that resolves to the transaction response.
|
4955
5040
|
*/
|
4956
5041
|
async transfer(destination, amount, assetId, txParams = {}) {
|
4957
|
-
if (
|
4958
|
-
throw new
|
4959
|
-
|
5042
|
+
if (bn17(amount).lte(0)) {
|
5043
|
+
throw new FuelError15(
|
5044
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4960
5045
|
"Transfer amount must be a positive number."
|
4961
5046
|
);
|
4962
5047
|
}
|
@@ -4974,9 +5059,9 @@ var Account = class extends AbstractAccount {
|
|
4974
5059
|
* @returns A promise that resolves to the transaction response.
|
4975
5060
|
*/
|
4976
5061
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4977
|
-
if (
|
4978
|
-
throw new
|
4979
|
-
|
5062
|
+
if (bn17(amount).lte(0)) {
|
5063
|
+
throw new FuelError15(
|
5064
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4980
5065
|
"Transfer amount must be a positive number."
|
4981
5066
|
);
|
4982
5067
|
}
|
@@ -4986,7 +5071,7 @@ var Account = class extends AbstractAccount {
|
|
4986
5071
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4987
5072
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4988
5073
|
hexlifiedContractId: contractAddress.toB256(),
|
4989
|
-
amountToTransfer:
|
5074
|
+
amountToTransfer: bn17(amount),
|
4990
5075
|
assetId: assetIdToTransfer
|
4991
5076
|
});
|
4992
5077
|
const request = new ScriptTransactionRequest({
|
@@ -4997,9 +5082,9 @@ var Account = class extends AbstractAccount {
|
|
4997
5082
|
request.addContractInputAndOutput(contractAddress);
|
4998
5083
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4999
5084
|
request,
|
5000
|
-
[{ amount:
|
5085
|
+
[{ amount: bn17(amount), assetId: String(assetIdToTransfer) }]
|
5001
5086
|
);
|
5002
|
-
request.gasLimit =
|
5087
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5003
5088
|
this.validateGas({
|
5004
5089
|
gasUsed,
|
5005
5090
|
gasPrice: request.gasPrice,
|
@@ -5025,7 +5110,7 @@ var Account = class extends AbstractAccount {
|
|
5025
5110
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5026
5111
|
);
|
5027
5112
|
const amountDataArray = arrayify14(
|
5028
|
-
"0x".concat(
|
5113
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
5029
5114
|
);
|
5030
5115
|
const script = new Uint8Array([
|
5031
5116
|
...arrayify14(withdrawScript.bytes),
|
@@ -5034,12 +5119,12 @@ var Account = class extends AbstractAccount {
|
|
5034
5119
|
]);
|
5035
5120
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5036
5121
|
const request = new ScriptTransactionRequest(params);
|
5037
|
-
const forwardingQuantities = [{ amount:
|
5122
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: baseAssetId }];
|
5038
5123
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5039
5124
|
request,
|
5040
5125
|
forwardingQuantities
|
5041
5126
|
);
|
5042
|
-
request.gasLimit =
|
5127
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5043
5128
|
this.validateGas({
|
5044
5129
|
gasUsed,
|
5045
5130
|
gasPrice: request.gasPrice,
|
@@ -5051,7 +5136,7 @@ var Account = class extends AbstractAccount {
|
|
5051
5136
|
}
|
5052
5137
|
async signMessage(message) {
|
5053
5138
|
if (!this._connector) {
|
5054
|
-
throw new
|
5139
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5055
5140
|
}
|
5056
5141
|
return this._connector.signMessage(this.address.toString(), message);
|
5057
5142
|
}
|
@@ -5063,8 +5148,8 @@ var Account = class extends AbstractAccount {
|
|
5063
5148
|
*/
|
5064
5149
|
async signTransaction(transactionRequestLike) {
|
5065
5150
|
if (!this._connector) {
|
5066
|
-
throw new
|
5067
|
-
|
5151
|
+
throw new FuelError15(
|
5152
|
+
ErrorCode15.MISSING_CONNECTOR,
|
5068
5153
|
"A connector is required to sign transactions."
|
5069
5154
|
);
|
5070
5155
|
}
|
@@ -5111,14 +5196,14 @@ var Account = class extends AbstractAccount {
|
|
5111
5196
|
minGasPrice
|
5112
5197
|
}) {
|
5113
5198
|
if (minGasPrice.gt(gasPrice)) {
|
5114
|
-
throw new
|
5115
|
-
|
5199
|
+
throw new FuelError15(
|
5200
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5116
5201
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5117
5202
|
);
|
5118
5203
|
}
|
5119
5204
|
if (gasUsed.gt(gasLimit)) {
|
5120
|
-
throw new
|
5121
|
-
|
5205
|
+
throw new FuelError15(
|
5206
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5122
5207
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5123
5208
|
);
|
5124
5209
|
}
|
@@ -5249,7 +5334,7 @@ import {
|
|
5249
5334
|
decryptJsonWalletData,
|
5250
5335
|
encryptJsonWalletData
|
5251
5336
|
} from "@fuel-ts/crypto";
|
5252
|
-
import { ErrorCode as
|
5337
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
5253
5338
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5254
5339
|
import { v4 as uuidv4 } from "uuid";
|
5255
5340
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5327,8 +5412,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5327
5412
|
const macHashUint8Array = keccak256(data);
|
5328
5413
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5329
5414
|
if (mac !== macHash) {
|
5330
|
-
throw new
|
5331
|
-
|
5415
|
+
throw new FuelError16(
|
5416
|
+
ErrorCode16.INVALID_PASSWORD,
|
5332
5417
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5333
5418
|
);
|
5334
5419
|
}
|
@@ -5450,15 +5535,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5450
5535
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5451
5536
|
|
5452
5537
|
// src/hdwallet/hdwallet.ts
|
5453
|
-
import { ErrorCode as
|
5538
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5454
5539
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5455
|
-
import { bn as
|
5540
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5456
5541
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5457
5542
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5458
5543
|
|
5459
5544
|
// src/mnemonic/mnemonic.ts
|
5460
5545
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5461
|
-
import { ErrorCode as
|
5546
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5462
5547
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5463
5548
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5464
5549
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7522,7 +7607,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7522
7607
|
})(Language || {});
|
7523
7608
|
|
7524
7609
|
// src/mnemonic/utils.ts
|
7525
|
-
import { ErrorCode as
|
7610
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7526
7611
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7527
7612
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7528
7613
|
function toUtf8Bytes(stri) {
|
@@ -7539,8 +7624,8 @@ function toUtf8Bytes(stri) {
|
|
7539
7624
|
i += 1;
|
7540
7625
|
const c2 = str.charCodeAt(i);
|
7541
7626
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7542
|
-
throw new
|
7543
|
-
|
7627
|
+
throw new FuelError17(
|
7628
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7544
7629
|
"Invalid UTF-8 in the input string."
|
7545
7630
|
);
|
7546
7631
|
}
|
@@ -7603,8 +7688,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7603
7688
|
for (let i = 0; i < words.length; i += 1) {
|
7604
7689
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7605
7690
|
if (index === -1) {
|
7606
|
-
throw new
|
7607
|
-
|
7691
|
+
throw new FuelError17(
|
7692
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7608
7693
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7609
7694
|
);
|
7610
7695
|
}
|
@@ -7620,8 +7705,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7620
7705
|
const checksumMask = getUpperMask(checksumBits);
|
7621
7706
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7622
7707
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7623
|
-
throw new
|
7624
|
-
|
7708
|
+
throw new FuelError17(
|
7709
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7625
7710
|
"Checksum validation failed for the provided mnemonic."
|
7626
7711
|
);
|
7627
7712
|
}
|
@@ -7635,16 +7720,16 @@ var TestnetPRV = "0x04358394";
|
|
7635
7720
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7636
7721
|
function assertWordList(wordlist) {
|
7637
7722
|
if (wordlist.length !== 2048) {
|
7638
|
-
throw new
|
7639
|
-
|
7723
|
+
throw new FuelError18(
|
7724
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7640
7725
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7641
7726
|
);
|
7642
7727
|
}
|
7643
7728
|
}
|
7644
7729
|
function assertEntropy(entropy) {
|
7645
7730
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7646
|
-
throw new
|
7647
|
-
|
7731
|
+
throw new FuelError18(
|
7732
|
+
ErrorCode18.INVALID_ENTROPY,
|
7648
7733
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7649
7734
|
);
|
7650
7735
|
}
|
@@ -7654,7 +7739,7 @@ function assertMnemonic(words) {
|
|
7654
7739
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7655
7740
|
", "
|
7656
7741
|
)}] words, but got ${words.length}.`;
|
7657
|
-
throw new
|
7742
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7658
7743
|
}
|
7659
7744
|
}
|
7660
7745
|
var Mnemonic = class {
|
@@ -7772,8 +7857,8 @@ var Mnemonic = class {
|
|
7772
7857
|
static masterKeysFromSeed(seed) {
|
7773
7858
|
const seedArray = arrayify17(seed);
|
7774
7859
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7775
|
-
throw new
|
7776
|
-
|
7860
|
+
throw new FuelError18(
|
7861
|
+
ErrorCode18.INVALID_SEED,
|
7777
7862
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7778
7863
|
);
|
7779
7864
|
}
|
@@ -7850,7 +7935,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7850
7935
|
function parsePath(path, depth = 0) {
|
7851
7936
|
const components = path.split("/");
|
7852
7937
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7853
|
-
throw new
|
7938
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7854
7939
|
}
|
7855
7940
|
if (components[0] === "m") {
|
7856
7941
|
components.shift();
|
@@ -7879,8 +7964,8 @@ var HDWallet = class {
|
|
7879
7964
|
this.privateKey = hexlify17(config.privateKey);
|
7880
7965
|
} else {
|
7881
7966
|
if (!config.publicKey) {
|
7882
|
-
throw new
|
7883
|
-
|
7967
|
+
throw new FuelError19(
|
7968
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7884
7969
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7885
7970
|
);
|
7886
7971
|
}
|
@@ -7909,8 +7994,8 @@ var HDWallet = class {
|
|
7909
7994
|
const data = new Uint8Array(37);
|
7910
7995
|
if (index & HARDENED_INDEX) {
|
7911
7996
|
if (!privateKey) {
|
7912
|
-
throw new
|
7913
|
-
|
7997
|
+
throw new FuelError19(
|
7998
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7914
7999
|
"Cannot derive a hardened index without a private Key."
|
7915
8000
|
);
|
7916
8001
|
}
|
@@ -7924,7 +8009,7 @@ var HDWallet = class {
|
|
7924
8009
|
const IR = bytes.slice(32);
|
7925
8010
|
if (privateKey) {
|
7926
8011
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7927
|
-
const ki =
|
8012
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7928
8013
|
return new HDWallet({
|
7929
8014
|
privateKey: ki,
|
7930
8015
|
chainCode: IR,
|
@@ -7962,8 +8047,8 @@ var HDWallet = class {
|
|
7962
8047
|
*/
|
7963
8048
|
toExtendedKey(isPublic = false, testnet = false) {
|
7964
8049
|
if (this.depth >= 256) {
|
7965
|
-
throw new
|
7966
|
-
|
8050
|
+
throw new FuelError19(
|
8051
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7967
8052
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7968
8053
|
);
|
7969
8054
|
}
|
@@ -7994,10 +8079,10 @@ var HDWallet = class {
|
|
7994
8079
|
const bytes = arrayify18(decoded);
|
7995
8080
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7996
8081
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7997
|
-
throw new
|
8082
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7998
8083
|
}
|
7999
8084
|
if (!validChecksum) {
|
8000
|
-
throw new
|
8085
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8001
8086
|
}
|
8002
8087
|
const depth = bytes[4];
|
8003
8088
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -8005,14 +8090,14 @@ var HDWallet = class {
|
|
8005
8090
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
8006
8091
|
const key = bytes.slice(45, 78);
|
8007
8092
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8008
|
-
throw new
|
8009
|
-
|
8093
|
+
throw new FuelError19(
|
8094
|
+
ErrorCode19.HD_WALLET_ERROR,
|
8010
8095
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8011
8096
|
);
|
8012
8097
|
}
|
8013
8098
|
if (isPublicExtendedKey(bytes)) {
|
8014
8099
|
if (key[0] !== 3) {
|
8015
|
-
throw new
|
8100
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
8016
8101
|
}
|
8017
8102
|
return new HDWallet({
|
8018
8103
|
publicKey: key,
|
@@ -8023,7 +8108,7 @@ var HDWallet = class {
|
|
8023
8108
|
});
|
8024
8109
|
}
|
8025
8110
|
if (key[0] !== 0) {
|
8026
|
-
throw new
|
8111
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
8027
8112
|
}
|
8028
8113
|
return new HDWallet({
|
8029
8114
|
privateKey: key.slice(1),
|
@@ -8191,7 +8276,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8191
8276
|
// src/wallet-manager/wallet-manager.ts
|
8192
8277
|
import { Address as Address8 } from "@fuel-ts/address";
|
8193
8278
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8194
|
-
import { ErrorCode as
|
8279
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8195
8280
|
import { EventEmitter } from "events";
|
8196
8281
|
|
8197
8282
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8214,7 +8299,7 @@ var MemoryStorage = class {
|
|
8214
8299
|
|
8215
8300
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8216
8301
|
import { Address as Address6 } from "@fuel-ts/address";
|
8217
|
-
import { ErrorCode as
|
8302
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8218
8303
|
var _secret;
|
8219
8304
|
var MnemonicVault = class {
|
8220
8305
|
constructor(options) {
|
@@ -8270,8 +8355,8 @@ var MnemonicVault = class {
|
|
8270
8355
|
}
|
8271
8356
|
numberOfAccounts += 1;
|
8272
8357
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8273
|
-
throw new
|
8274
|
-
|
8358
|
+
throw new FuelError20(
|
8359
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8275
8360
|
`Account with address '${address}' not found in derived wallets.`
|
8276
8361
|
);
|
8277
8362
|
}
|
@@ -8285,7 +8370,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8285
8370
|
|
8286
8371
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8287
8372
|
import { Address as Address7 } from "@fuel-ts/address";
|
8288
|
-
import { ErrorCode as
|
8373
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8289
8374
|
var _privateKeys;
|
8290
8375
|
var PrivateKeyVault = class {
|
8291
8376
|
/**
|
@@ -8326,8 +8411,8 @@ var PrivateKeyVault = class {
|
|
8326
8411
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8327
8412
|
);
|
8328
8413
|
if (!privateKey) {
|
8329
|
-
throw new
|
8330
|
-
|
8414
|
+
throw new FuelError21(
|
8415
|
+
ErrorCode21.WALLET_MANAGER_ERROR,
|
8331
8416
|
`No private key found for address '${address}'.`
|
8332
8417
|
);
|
8333
8418
|
}
|
@@ -8351,7 +8436,7 @@ var ERROR_MESSAGES = {
|
|
8351
8436
|
};
|
8352
8437
|
function assert(condition, message) {
|
8353
8438
|
if (!condition) {
|
8354
|
-
throw new
|
8439
|
+
throw new FuelError22(ErrorCode22.WALLET_MANAGER_ERROR, message);
|
8355
8440
|
}
|
8356
8441
|
}
|
8357
8442
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8577,25 +8662,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8577
8662
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8578
8663
|
|
8579
8664
|
// src/wallet-manager/types.ts
|
8580
|
-
import { ErrorCode as
|
8665
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8581
8666
|
var Vault = class {
|
8582
8667
|
constructor(_options) {
|
8583
|
-
throw new
|
8668
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8584
8669
|
}
|
8585
8670
|
serialize() {
|
8586
|
-
throw new
|
8671
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8587
8672
|
}
|
8588
8673
|
getAccounts() {
|
8589
|
-
throw new
|
8674
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8590
8675
|
}
|
8591
8676
|
addAccount() {
|
8592
|
-
throw new
|
8677
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8593
8678
|
}
|
8594
8679
|
exportAccount(_address) {
|
8595
|
-
throw new
|
8680
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8596
8681
|
}
|
8597
8682
|
getWallet(_address) {
|
8598
|
-
throw new
|
8683
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8599
8684
|
}
|
8600
8685
|
};
|
8601
8686
|
__publicField(Vault, "type");
|
@@ -8611,7 +8696,7 @@ import {
|
|
8611
8696
|
SCRIPT_FIXED_SIZE
|
8612
8697
|
} from "@fuel-ts/abi-coder";
|
8613
8698
|
import { Address as Address9 } from "@fuel-ts/address";
|
8614
|
-
import { ErrorCode as
|
8699
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8615
8700
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8616
8701
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8617
8702
|
|
@@ -8740,8 +8825,8 @@ var Predicate = class extends Account {
|
|
8740
8825
|
if (jsonAbi) {
|
8741
8826
|
abiInterface = new Interface4(jsonAbi);
|
8742
8827
|
if (abiInterface.functions.main === void 0) {
|
8743
|
-
throw new
|
8744
|
-
|
8828
|
+
throw new FuelError24(
|
8829
|
+
ErrorCode24.ABI_MAIN_METHOD_MISSING,
|
8745
8830
|
'Cannot use ABI without "main" function.'
|
8746
8831
|
);
|
8747
8832
|
}
|
@@ -8786,8 +8871,8 @@ var Predicate = class extends Account {
|
|
8786
8871
|
mutatedBytes.set(encoded, offset);
|
8787
8872
|
});
|
8788
8873
|
} catch (err) {
|
8789
|
-
throw new
|
8790
|
-
|
8874
|
+
throw new FuelError24(
|
8875
|
+
ErrorCode24.INVALID_CONFIGURABLE_CONSTANTS,
|
8791
8876
|
`Error setting configurable constants: ${err.message}.`
|
8792
8877
|
);
|
8793
8878
|
}
|
@@ -8796,7 +8881,7 @@ var Predicate = class extends Account {
|
|
8796
8881
|
};
|
8797
8882
|
|
8798
8883
|
// src/connectors/fuel.ts
|
8799
|
-
import { ErrorCode as
|
8884
|
+
import { ErrorCode as ErrorCode25, FuelError as FuelError25 } from "@fuel-ts/errors";
|
8800
8885
|
|
8801
8886
|
// src/connectors/fuel-connector.ts
|
8802
8887
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9429,7 +9514,7 @@ var _Fuel = class extends FuelConnector {
|
|
9429
9514
|
const currentNetwork = await this.currentNetwork();
|
9430
9515
|
provider = await Provider.create(currentNetwork.url);
|
9431
9516
|
} else {
|
9432
|
-
throw new
|
9517
|
+
throw new FuelError25(ErrorCode25.INVALID_PROVIDER, "Provider is not valid.");
|
9433
9518
|
}
|
9434
9519
|
return provider;
|
9435
9520
|
}
|
@@ -9508,7 +9593,9 @@ export {
|
|
9508
9593
|
WalletUnlocked,
|
9509
9594
|
addAmountToAsset,
|
9510
9595
|
addOperation,
|
9596
|
+
assemblePanicError,
|
9511
9597
|
assembleReceiptByType,
|
9598
|
+
assembleRevertError,
|
9512
9599
|
assembleTransactionSummary,
|
9513
9600
|
assets,
|
9514
9601
|
buildBlockExplorerUrl,
|
@@ -9523,6 +9610,7 @@ export {
|
|
9523
9610
|
english,
|
9524
9611
|
extractBurnedAssetsFromReceipts,
|
9525
9612
|
extractMintedAssetsFromReceipts,
|
9613
|
+
extractTxError,
|
9526
9614
|
gasUsedByInputs,
|
9527
9615
|
getAssetEth,
|
9528
9616
|
getAssetFuel,
|