@fuel-ts/account 0.0.0-rc-1936-20240326112905 → 0.0.0-rc-1895-20240327220629
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 +167 -22
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +581 -479
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +359 -252
- package/dist/index.mjs.map +1 -1
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +3 -0
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +5 -0
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-response/getDecodedLogs.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +5 -2
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +14 -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 +167 -9
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +541 -434
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +329 -214
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/index.mjs
CHANGED
@@ -30,9 +30,9 @@ var __privateMethod = (obj, member, method) => {
|
|
30
30
|
// src/account.ts
|
31
31
|
import { Address as Address3 } from "@fuel-ts/address";
|
32
32
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
33
|
-
import { ErrorCode as
|
33
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
34
34
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
35
|
-
import { bn as
|
35
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
36
36
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
37
37
|
|
38
38
|
// src/providers/coin-quantity.ts
|
@@ -73,8 +73,8 @@ var addAmountToAsset = (params) => {
|
|
73
73
|
|
74
74
|
// src/providers/provider.ts
|
75
75
|
import { Address as Address2 } from "@fuel-ts/address";
|
76
|
-
import { ErrorCode as
|
77
|
-
import { BN, bn as
|
76
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
77
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
78
78
|
import {
|
79
79
|
InputType as InputType6,
|
80
80
|
TransactionType as TransactionType8,
|
@@ -1157,7 +1157,7 @@ var outputify = (value) => {
|
|
1157
1157
|
// src/providers/transaction-request/transaction-request.ts
|
1158
1158
|
import { Address, addressify } from "@fuel-ts/address";
|
1159
1159
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1160
|
-
import { bn as
|
1160
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1161
1161
|
import {
|
1162
1162
|
PolicyType,
|
1163
1163
|
TransactionCoder,
|
@@ -1562,6 +1562,76 @@ function sleep(time) {
|
|
1562
1562
|
});
|
1563
1563
|
}
|
1564
1564
|
|
1565
|
+
// src/providers/utils/extract-tx-error.ts
|
1566
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1567
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1568
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1569
|
+
import {
|
1570
|
+
FAILED_REQUIRE_SIGNAL,
|
1571
|
+
FAILED_ASSERT_EQ_SIGNAL,
|
1572
|
+
FAILED_ASSERT_NE_SIGNAL,
|
1573
|
+
FAILED_ASSERT_SIGNAL,
|
1574
|
+
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1575
|
+
PANIC_REASONS,
|
1576
|
+
PANIC_DOC_URL
|
1577
|
+
} from "@fuel-ts/transactions/configs";
|
1578
|
+
var assemblePanicError = (status) => {
|
1579
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1580
|
+
if (PANIC_REASONS.includes(status.reason)) {
|
1581
|
+
errorMessage = `${errorMessage}
|
1582
|
+
|
1583
|
+
You can read more about this error at:
|
1584
|
+
|
1585
|
+
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1586
|
+
}
|
1587
|
+
return errorMessage;
|
1588
|
+
};
|
1589
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1590
|
+
var assembleRevertError = (receipts, logs) => {
|
1591
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1592
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1593
|
+
if (revertReceipt) {
|
1594
|
+
const reasonHex = bn6(revertReceipt.val).toHex();
|
1595
|
+
switch (reasonHex) {
|
1596
|
+
case FAILED_REQUIRE_SIGNAL: {
|
1597
|
+
errorMessage = `The transaction reverted because of a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1598
|
+
break;
|
1599
|
+
}
|
1600
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
1601
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1602
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1603
|
+
break;
|
1604
|
+
}
|
1605
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
1606
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1607
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1608
|
+
break;
|
1609
|
+
}
|
1610
|
+
case FAILED_ASSERT_SIGNAL:
|
1611
|
+
errorMessage = `The transaction reverted because of an "assert" statement failed to evaluate to true.`;
|
1612
|
+
break;
|
1613
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1614
|
+
errorMessage = `The transaction reverted because missing "OutputChange"(s).`;
|
1615
|
+
break;
|
1616
|
+
default:
|
1617
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1618
|
+
}
|
1619
|
+
}
|
1620
|
+
return errorMessage;
|
1621
|
+
};
|
1622
|
+
var extractTxError = (params) => {
|
1623
|
+
const { receipts, status, logs } = params;
|
1624
|
+
const wasPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1625
|
+
let err = status?.type === "FailureStatus" && wasPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1626
|
+
err += `
|
1627
|
+
|
1628
|
+
logs: ${JSON.stringify(logs, null, 2)}`;
|
1629
|
+
err += `
|
1630
|
+
|
1631
|
+
receipts: ${JSON.stringify(receipts, null, 2)}`;
|
1632
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, err);
|
1633
|
+
};
|
1634
|
+
|
1565
1635
|
// src/providers/transaction-request/errors.ts
|
1566
1636
|
var ChangeOutputCollisionError = class extends Error {
|
1567
1637
|
name = "ChangeOutputCollisionError";
|
@@ -1624,10 +1694,10 @@ var BaseTransactionRequest = class {
|
|
1624
1694
|
outputs,
|
1625
1695
|
witnesses
|
1626
1696
|
} = {}) {
|
1627
|
-
this.gasPrice =
|
1697
|
+
this.gasPrice = bn7(gasPrice);
|
1628
1698
|
this.maturity = maturity ?? 0;
|
1629
|
-
this.witnessLimit = witnessLimit ?
|
1630
|
-
this.maxFee = maxFee ?
|
1699
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1700
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1631
1701
|
this.inputs = inputs ?? [];
|
1632
1702
|
this.outputs = outputs ?? [];
|
1633
1703
|
this.witnesses = witnesses ?? [];
|
@@ -2057,13 +2127,13 @@ var BaseTransactionRequest = class {
|
|
2057
2127
|
assetId,
|
2058
2128
|
owner: resourcesOwner || Address.fromRandom(),
|
2059
2129
|
maturity: 0,
|
2060
|
-
blockCreated:
|
2061
|
-
txCreatedIdx:
|
2130
|
+
blockCreated: bn7(1),
|
2131
|
+
txCreatedIdx: bn7(1)
|
2062
2132
|
}
|
2063
2133
|
]);
|
2064
2134
|
}
|
2065
2135
|
};
|
2066
|
-
updateAssetInput(BaseAssetId2,
|
2136
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
2067
2137
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2068
2138
|
}
|
2069
2139
|
/**
|
@@ -2074,7 +2144,7 @@ var BaseTransactionRequest = class {
|
|
2074
2144
|
*/
|
2075
2145
|
getCoinOutputsQuantities() {
|
2076
2146
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2077
|
-
amount:
|
2147
|
+
amount: bn7(amount),
|
2078
2148
|
assetId: assetId.toString()
|
2079
2149
|
}));
|
2080
2150
|
return coinsQuantities;
|
@@ -2103,7 +2173,7 @@ var BaseTransactionRequest = class {
|
|
2103
2173
|
default:
|
2104
2174
|
return;
|
2105
2175
|
}
|
2106
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2176
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2107
2177
|
i.predicate = correspondingInput.predicate;
|
2108
2178
|
i.predicateData = correspondingInput.predicateData;
|
2109
2179
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2114,14 +2184,14 @@ var BaseTransactionRequest = class {
|
|
2114
2184
|
|
2115
2185
|
// src/providers/transaction-request/create-transaction-request.ts
|
2116
2186
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2117
|
-
import { bn as
|
2187
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2118
2188
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2119
2189
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2120
2190
|
|
2121
2191
|
// src/providers/transaction-request/hash-transaction.ts
|
2122
2192
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2123
2193
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2124
|
-
import { bn as
|
2194
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2125
2195
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2126
2196
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2127
2197
|
import { clone as clone2 } from "ramda";
|
@@ -2138,11 +2208,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2138
2208
|
blockHeight: 0,
|
2139
2209
|
txIndex: 0
|
2140
2210
|
};
|
2141
|
-
inputClone.predicateGasUsed =
|
2211
|
+
inputClone.predicateGasUsed = bn8(0);
|
2142
2212
|
return inputClone;
|
2143
2213
|
}
|
2144
2214
|
case InputType3.Message: {
|
2145
|
-
inputClone.predicateGasUsed =
|
2215
|
+
inputClone.predicateGasUsed = bn8(0);
|
2146
2216
|
return inputClone;
|
2147
2217
|
}
|
2148
2218
|
case InputType3.Contract: {
|
@@ -2169,12 +2239,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2169
2239
|
return outputClone;
|
2170
2240
|
}
|
2171
2241
|
case OutputType3.Change: {
|
2172
|
-
outputClone.amount =
|
2242
|
+
outputClone.amount = bn8(0);
|
2173
2243
|
return outputClone;
|
2174
2244
|
}
|
2175
2245
|
case OutputType3.Variable: {
|
2176
2246
|
outputClone.to = ZeroBytes325;
|
2177
|
-
outputClone.amount =
|
2247
|
+
outputClone.amount = bn8(0);
|
2178
2248
|
outputClone.assetId = ZeroBytes325;
|
2179
2249
|
return outputClone;
|
2180
2250
|
}
|
@@ -2298,7 +2368,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2298
2368
|
}
|
2299
2369
|
metadataGas(gasCosts) {
|
2300
2370
|
return calculateMetadataGasForTxCreate({
|
2301
|
-
contractBytesSize:
|
2371
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2302
2372
|
gasCosts,
|
2303
2373
|
stateRootSize: this.storageSlots.length,
|
2304
2374
|
txBytesSize: this.byteSize()
|
@@ -2310,7 +2380,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2310
2380
|
import { Interface } from "@fuel-ts/abi-coder";
|
2311
2381
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2312
2382
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2313
|
-
import { bn as
|
2383
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2314
2384
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2315
2385
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2316
2386
|
|
@@ -2356,6 +2426,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2356
2426
|
script;
|
2357
2427
|
/** Script input data (parameters) */
|
2358
2428
|
scriptData;
|
2429
|
+
abis;
|
2359
2430
|
/**
|
2360
2431
|
* Constructor for `ScriptTransactionRequest`.
|
2361
2432
|
*
|
@@ -2363,9 +2434,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2363
2434
|
*/
|
2364
2435
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2365
2436
|
super(rest);
|
2366
|
-
this.gasLimit =
|
2437
|
+
this.gasLimit = bn10(gasLimit);
|
2367
2438
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2368
2439
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2440
|
+
this.abis = rest.abis;
|
2369
2441
|
}
|
2370
2442
|
/**
|
2371
2443
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2510,7 +2582,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2510
2582
|
};
|
2511
2583
|
|
2512
2584
|
// src/providers/transaction-request/utils.ts
|
2513
|
-
import { ErrorCode as
|
2585
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2514
2586
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2515
2587
|
var transactionRequestify = (obj) => {
|
2516
2588
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2525,14 +2597,14 @@ var transactionRequestify = (obj) => {
|
|
2525
2597
|
return CreateTransactionRequest.from(obj);
|
2526
2598
|
}
|
2527
2599
|
default: {
|
2528
|
-
throw new
|
2600
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2529
2601
|
}
|
2530
2602
|
}
|
2531
2603
|
};
|
2532
2604
|
|
2533
2605
|
// src/providers/transaction-response/transaction-response.ts
|
2534
|
-
import { ErrorCode as
|
2535
|
-
import { bn as
|
2606
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2607
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2536
2608
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2537
2609
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2538
2610
|
|
@@ -2540,7 +2612,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2540
2612
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2541
2613
|
|
2542
2614
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2543
|
-
import { bn as
|
2615
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2544
2616
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2545
2617
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2546
2618
|
var calculateTransactionFee = (params) => {
|
@@ -2549,24 +2621,24 @@ var calculateTransactionFee = (params) => {
|
|
2549
2621
|
rawPayload,
|
2550
2622
|
consensusParameters: { gasCosts, feeParams }
|
2551
2623
|
} = params;
|
2552
|
-
const gasPerByte =
|
2553
|
-
const gasPriceFactor =
|
2624
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2625
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2554
2626
|
const transactionBytes = arrayify9(rawPayload);
|
2555
2627
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2556
2628
|
if (transaction.type === TransactionType6.Mint) {
|
2557
2629
|
return {
|
2558
|
-
fee:
|
2559
|
-
minFee:
|
2560
|
-
maxFee:
|
2561
|
-
feeFromGasUsed:
|
2630
|
+
fee: bn11(0),
|
2631
|
+
minFee: bn11(0),
|
2632
|
+
maxFee: bn11(0),
|
2633
|
+
feeFromGasUsed: bn11(0)
|
2562
2634
|
};
|
2563
2635
|
}
|
2564
2636
|
const { type, witnesses, inputs, policies } = transaction;
|
2565
|
-
let metadataGas =
|
2566
|
-
let gasLimit =
|
2637
|
+
let metadataGas = bn11(0);
|
2638
|
+
let gasLimit = bn11(0);
|
2567
2639
|
if (type === TransactionType6.Create) {
|
2568
2640
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2569
|
-
const contractBytesSize =
|
2641
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2570
2642
|
metadataGas = calculateMetadataGasForTxCreate({
|
2571
2643
|
contractBytesSize,
|
2572
2644
|
gasCosts,
|
@@ -2585,12 +2657,12 @@ var calculateTransactionFee = (params) => {
|
|
2585
2657
|
}
|
2586
2658
|
const minGas = getMinGas({
|
2587
2659
|
gasCosts,
|
2588
|
-
gasPerByte:
|
2660
|
+
gasPerByte: bn11(gasPerByte),
|
2589
2661
|
inputs,
|
2590
2662
|
metadataGas,
|
2591
2663
|
txBytesSize: transactionBytes.length
|
2592
2664
|
});
|
2593
|
-
const gasPrice =
|
2665
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2594
2666
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2595
2667
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2596
2668
|
const maxGas = getMaxGas({
|
@@ -2614,13 +2686,13 @@ var calculateTransactionFee = (params) => {
|
|
2614
2686
|
|
2615
2687
|
// src/providers/transaction-summary/operations.ts
|
2616
2688
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2617
|
-
import { ErrorCode as
|
2618
|
-
import { bn as
|
2619
|
-
import { ReceiptType as
|
2689
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2690
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2691
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2620
2692
|
|
2621
2693
|
// src/providers/transaction-summary/call.ts
|
2622
2694
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2623
|
-
import { bn as
|
2695
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2624
2696
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2625
2697
|
const abiInterface = new Interface2(abi);
|
2626
2698
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2629,7 +2701,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2629
2701
|
let encodedArgs;
|
2630
2702
|
if (functionFragment.isInputDataPointer) {
|
2631
2703
|
if (rawPayload) {
|
2632
|
-
const argsOffset =
|
2704
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2633
2705
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2634
2706
|
}
|
2635
2707
|
} else {
|
@@ -2663,7 +2735,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2663
2735
|
};
|
2664
2736
|
|
2665
2737
|
// src/providers/transaction-summary/input.ts
|
2666
|
-
import { ErrorCode as
|
2738
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2667
2739
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2668
2740
|
function getInputsByTypes(inputs, types) {
|
2669
2741
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2701,8 +2773,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2701
2773
|
return void 0;
|
2702
2774
|
}
|
2703
2775
|
if (contractInput.type !== InputType5.Contract) {
|
2704
|
-
throw new
|
2705
|
-
|
2776
|
+
throw new FuelError9(
|
2777
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2706
2778
|
`Contract input should be of type 'contract'.`
|
2707
2779
|
);
|
2708
2780
|
}
|
@@ -2790,8 +2862,8 @@ function getTransactionTypeName(transactionType) {
|
|
2790
2862
|
case TransactionType7.Script:
|
2791
2863
|
return "Script" /* Script */;
|
2792
2864
|
default:
|
2793
|
-
throw new
|
2794
|
-
|
2865
|
+
throw new FuelError10(
|
2866
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2795
2867
|
`Invalid transaction type: ${transactionType}.`
|
2796
2868
|
);
|
2797
2869
|
}
|
@@ -2813,10 +2885,10 @@ function hasSameAssetId(a) {
|
|
2813
2885
|
return (b) => a.assetId === b.assetId;
|
2814
2886
|
}
|
2815
2887
|
function getReceiptsCall(receipts) {
|
2816
|
-
return getReceiptsByType(receipts,
|
2888
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2817
2889
|
}
|
2818
2890
|
function getReceiptsMessageOut(receipts) {
|
2819
|
-
return getReceiptsByType(receipts,
|
2891
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2820
2892
|
}
|
2821
2893
|
var mergeAssets = (op1, op2) => {
|
2822
2894
|
const assets1 = op1.assetsSent || [];
|
@@ -2829,7 +2901,7 @@ var mergeAssets = (op1, op2) => {
|
|
2829
2901
|
if (!matchingAsset) {
|
2830
2902
|
return asset1;
|
2831
2903
|
}
|
2832
|
-
const mergedAmount =
|
2904
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2833
2905
|
return { ...asset1, amount: mergedAmount };
|
2834
2906
|
});
|
2835
2907
|
return mergedAssets.concat(filteredAssets);
|
@@ -2855,7 +2927,7 @@ function addOperation(operations, toAdd) {
|
|
2855
2927
|
return allOperations;
|
2856
2928
|
}
|
2857
2929
|
function getReceiptsTransferOut(receipts) {
|
2858
|
-
return getReceiptsByType(receipts,
|
2930
|
+
return getReceiptsByType(receipts, ReceiptType4.TransferOut);
|
2859
2931
|
}
|
2860
2932
|
function getWithdrawFromFuelOperations({
|
2861
2933
|
inputs,
|
@@ -3015,11 +3087,11 @@ function getTransferOperations({
|
|
3015
3087
|
});
|
3016
3088
|
const transferReceipts = getReceiptsByType(
|
3017
3089
|
receipts,
|
3018
|
-
|
3090
|
+
ReceiptType4.Transfer
|
3019
3091
|
);
|
3020
3092
|
const transferOutReceipts = getReceiptsByType(
|
3021
3093
|
receipts,
|
3022
|
-
|
3094
|
+
ReceiptType4.TransferOut
|
3023
3095
|
);
|
3024
3096
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3025
3097
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3104,17 +3176,17 @@ function getOperations({
|
|
3104
3176
|
}
|
3105
3177
|
|
3106
3178
|
// src/providers/transaction-summary/receipt.ts
|
3107
|
-
import { ReceiptType as
|
3179
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3108
3180
|
var processGqlReceipt = (gqlReceipt) => {
|
3109
3181
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3110
3182
|
switch (receipt.type) {
|
3111
|
-
case
|
3183
|
+
case ReceiptType5.ReturnData: {
|
3112
3184
|
return {
|
3113
3185
|
...receipt,
|
3114
3186
|
data: gqlReceipt.data || "0x"
|
3115
3187
|
};
|
3116
3188
|
}
|
3117
|
-
case
|
3189
|
+
case ReceiptType5.LogData: {
|
3118
3190
|
return {
|
3119
3191
|
...receipt,
|
3120
3192
|
data: gqlReceipt.data || "0x"
|
@@ -3127,7 +3199,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3127
3199
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3128
3200
|
const mintedAssets = [];
|
3129
3201
|
receipts.forEach((receipt) => {
|
3130
|
-
if (receipt.type ===
|
3202
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3131
3203
|
mintedAssets.push({
|
3132
3204
|
subId: receipt.subId,
|
3133
3205
|
contractId: receipt.contractId,
|
@@ -3141,7 +3213,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3141
3213
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3142
3214
|
const burnedAssets = [];
|
3143
3215
|
receipts.forEach((receipt) => {
|
3144
|
-
if (receipt.type ===
|
3216
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3145
3217
|
burnedAssets.push({
|
3146
3218
|
subId: receipt.subId,
|
3147
3219
|
contractId: receipt.contractId,
|
@@ -3154,7 +3226,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3154
3226
|
};
|
3155
3227
|
|
3156
3228
|
// src/providers/transaction-summary/status.ts
|
3157
|
-
import { ErrorCode as
|
3229
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3158
3230
|
var getTransactionStatusName = (gqlStatus) => {
|
3159
3231
|
switch (gqlStatus) {
|
3160
3232
|
case "FailureStatus":
|
@@ -3166,8 +3238,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3166
3238
|
case "SqueezedOutStatus":
|
3167
3239
|
return "squeezedout" /* squeezedout */;
|
3168
3240
|
default:
|
3169
|
-
throw new
|
3170
|
-
|
3241
|
+
throw new FuelError11(
|
3242
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3171
3243
|
`Invalid transaction status: ${gqlStatus}.`
|
3172
3244
|
);
|
3173
3245
|
}
|
@@ -3278,6 +3350,21 @@ function assembleTransactionSummary(params) {
|
|
3278
3350
|
return transactionSummary;
|
3279
3351
|
}
|
3280
3352
|
|
3353
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
3354
|
+
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3355
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3356
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3357
|
+
return receipts.reduce((logs, receipt) => {
|
3358
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3359
|
+
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3360
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3361
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3362
|
+
logs.push(decodedLog);
|
3363
|
+
}
|
3364
|
+
return logs;
|
3365
|
+
}, []);
|
3366
|
+
}
|
3367
|
+
|
3281
3368
|
// src/providers/transaction-response/transaction-response.ts
|
3282
3369
|
var TransactionResponse = class {
|
3283
3370
|
/** Transaction ID */
|
@@ -3285,18 +3372,20 @@ var TransactionResponse = class {
|
|
3285
3372
|
/** Current provider */
|
3286
3373
|
provider;
|
3287
3374
|
/** Gas used on the transaction */
|
3288
|
-
gasUsed =
|
3375
|
+
gasUsed = bn14(0);
|
3289
3376
|
/** The graphql Transaction with receipts object. */
|
3290
3377
|
gqlTransaction;
|
3378
|
+
abis;
|
3291
3379
|
/**
|
3292
3380
|
* Constructor for `TransactionResponse`.
|
3293
3381
|
*
|
3294
3382
|
* @param id - The transaction ID.
|
3295
3383
|
* @param provider - The provider.
|
3296
3384
|
*/
|
3297
|
-
constructor(id, provider) {
|
3385
|
+
constructor(id, provider, abis) {
|
3298
3386
|
this.id = id;
|
3299
3387
|
this.provider = provider;
|
3388
|
+
this.abis = abis;
|
3300
3389
|
}
|
3301
3390
|
/**
|
3302
3391
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -3306,8 +3395,8 @@ var TransactionResponse = class {
|
|
3306
3395
|
* @param id - The transaction ID.
|
3307
3396
|
* @param provider - The provider.
|
3308
3397
|
*/
|
3309
|
-
static async create(id, provider) {
|
3310
|
-
const response = new TransactionResponse(id, provider);
|
3398
|
+
static async create(id, provider, abis) {
|
3399
|
+
const response = new TransactionResponse(id, provider, abis);
|
3311
3400
|
await response.fetch();
|
3312
3401
|
return response;
|
3313
3402
|
}
|
@@ -3388,8 +3477,8 @@ var TransactionResponse = class {
|
|
3388
3477
|
});
|
3389
3478
|
for await (const { statusChange } of subscription) {
|
3390
3479
|
if (statusChange.type === "SqueezedOutStatus") {
|
3391
|
-
throw new
|
3392
|
-
|
3480
|
+
throw new FuelError12(
|
3481
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3393
3482
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3394
3483
|
);
|
3395
3484
|
}
|
@@ -3411,6 +3500,26 @@ var TransactionResponse = class {
|
|
3411
3500
|
gqlTransaction: this.gqlTransaction,
|
3412
3501
|
...transactionSummary
|
3413
3502
|
};
|
3503
|
+
let logs = [];
|
3504
|
+
if (this.abis) {
|
3505
|
+
logs = getDecodedLogs(
|
3506
|
+
transactionSummary.receipts,
|
3507
|
+
this.abis.main,
|
3508
|
+
this.abis.otherContractsAbis
|
3509
|
+
);
|
3510
|
+
transactionResult.logs = logs;
|
3511
|
+
}
|
3512
|
+
if (transactionResult.isStatusFailure) {
|
3513
|
+
const {
|
3514
|
+
receipts,
|
3515
|
+
gqlTransaction: { status }
|
3516
|
+
} = transactionResult;
|
3517
|
+
throw extractTxError({
|
3518
|
+
receipts,
|
3519
|
+
status,
|
3520
|
+
logs
|
3521
|
+
});
|
3522
|
+
}
|
3414
3523
|
return transactionResult;
|
3415
3524
|
}
|
3416
3525
|
/**
|
@@ -3421,30 +3530,21 @@ var TransactionResponse = class {
|
|
3421
3530
|
async wait(contractsAbiMap) {
|
3422
3531
|
const result = await this.waitForResult(contractsAbiMap);
|
3423
3532
|
if (result.isStatusFailure) {
|
3424
|
-
|
3425
|
-
|
3426
|
-
|
3427
|
-
|
3533
|
+
const {
|
3534
|
+
receipts,
|
3535
|
+
logs = [],
|
3536
|
+
gqlTransaction: { status }
|
3537
|
+
} = result;
|
3538
|
+
throw extractTxError({
|
3539
|
+
receipts,
|
3540
|
+
logs,
|
3541
|
+
status
|
3542
|
+
});
|
3428
3543
|
}
|
3429
3544
|
return result;
|
3430
3545
|
}
|
3431
3546
|
};
|
3432
3547
|
|
3433
|
-
// src/providers/transaction-response/getDecodedLogs.ts
|
3434
|
-
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3435
|
-
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3436
|
-
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3437
|
-
return receipts.reduce((logs, receipt) => {
|
3438
|
-
if (receipt.type === ReceiptType5.LogData || receipt.type === ReceiptType5.Log) {
|
3439
|
-
const interfaceToUse = externalAbis[receipt.id] ? new Interface3(externalAbis[receipt.id]) : new Interface3(mainAbi);
|
3440
|
-
const data = receipt.type === ReceiptType5.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3441
|
-
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3442
|
-
logs.push(decodedLog);
|
3443
|
-
}
|
3444
|
-
return logs;
|
3445
|
-
}, []);
|
3446
|
-
}
|
3447
|
-
|
3448
3548
|
// src/providers/utils/auto-retry-fetch.ts
|
3449
3549
|
function getWaitDelay(options, retryAttemptNum) {
|
3450
3550
|
const duration = options.baseDelay ?? 150;
|
@@ -3503,29 +3603,29 @@ var processGqlChain = (chain) => {
|
|
3503
3603
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3504
3604
|
return {
|
3505
3605
|
name,
|
3506
|
-
baseChainHeight:
|
3606
|
+
baseChainHeight: bn15(daHeight),
|
3507
3607
|
consensusParameters: {
|
3508
|
-
contractMaxSize:
|
3509
|
-
maxInputs:
|
3510
|
-
maxOutputs:
|
3511
|
-
maxWitnesses:
|
3512
|
-
maxGasPerTx:
|
3513
|
-
maxScriptLength:
|
3514
|
-
maxScriptDataLength:
|
3515
|
-
maxStorageSlots:
|
3516
|
-
maxPredicateLength:
|
3517
|
-
maxPredicateDataLength:
|
3518
|
-
maxGasPerPredicate:
|
3519
|
-
gasPriceFactor:
|
3520
|
-
gasPerByte:
|
3521
|
-
maxMessageDataLength:
|
3522
|
-
chainId:
|
3608
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3609
|
+
maxInputs: bn15(txParams.maxInputs),
|
3610
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3611
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3612
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3613
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3614
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3615
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3616
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3617
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3618
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3619
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3620
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3621
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3622
|
+
chainId: bn15(consensusParameters.chainId),
|
3523
3623
|
gasCosts
|
3524
3624
|
},
|
3525
3625
|
gasCosts,
|
3526
3626
|
latestBlock: {
|
3527
3627
|
id: latestBlock.id,
|
3528
|
-
height:
|
3628
|
+
height: bn15(latestBlock.header.height),
|
3529
3629
|
time: latestBlock.header.time,
|
3530
3630
|
transactions: latestBlock.transactions.map((i) => ({
|
3531
3631
|
id: i.id
|
@@ -3595,8 +3695,8 @@ var _Provider = class {
|
|
3595
3695
|
getChain() {
|
3596
3696
|
const chain = _Provider.chainInfoCache[this.url];
|
3597
3697
|
if (!chain) {
|
3598
|
-
throw new
|
3599
|
-
|
3698
|
+
throw new FuelError13(
|
3699
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3600
3700
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3601
3701
|
);
|
3602
3702
|
}
|
@@ -3608,8 +3708,8 @@ var _Provider = class {
|
|
3608
3708
|
getNode() {
|
3609
3709
|
const node = _Provider.nodeInfoCache[this.url];
|
3610
3710
|
if (!node) {
|
3611
|
-
throw new
|
3612
|
-
|
3711
|
+
throw new FuelError13(
|
3712
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3613
3713
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3614
3714
|
);
|
3615
3715
|
}
|
@@ -3656,8 +3756,8 @@ var _Provider = class {
|
|
3656
3756
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3657
3757
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3658
3758
|
if (!isMajorSupported || !isMinorSupported) {
|
3659
|
-
throw new
|
3660
|
-
|
3759
|
+
throw new FuelError13(
|
3760
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3661
3761
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3662
3762
|
);
|
3663
3763
|
}
|
@@ -3720,7 +3820,7 @@ var _Provider = class {
|
|
3720
3820
|
*/
|
3721
3821
|
async getBlockNumber() {
|
3722
3822
|
const { chain } = await this.operations.getChain();
|
3723
|
-
return
|
3823
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3724
3824
|
}
|
3725
3825
|
/**
|
3726
3826
|
* Returns the chain information.
|
@@ -3730,9 +3830,9 @@ var _Provider = class {
|
|
3730
3830
|
async fetchNode() {
|
3731
3831
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3732
3832
|
const processedNodeInfo = {
|
3733
|
-
maxDepth:
|
3734
|
-
maxTx:
|
3735
|
-
minGasPrice:
|
3833
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3834
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3835
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3736
3836
|
nodeVersion: nodeInfo.nodeVersion,
|
3737
3837
|
utxoValidation: nodeInfo.utxoValidation,
|
3738
3838
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3779,12 +3879,16 @@ var _Provider = class {
|
|
3779
3879
|
await this.estimateTxDependencies(transactionRequest);
|
3780
3880
|
}
|
3781
3881
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3882
|
+
let abis;
|
3883
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3884
|
+
abis = transactionRequest.abis;
|
3885
|
+
}
|
3782
3886
|
if (awaitExecution) {
|
3783
3887
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3784
3888
|
for await (const { submitAndAwait } of subscription) {
|
3785
3889
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3786
|
-
throw new
|
3787
|
-
|
3890
|
+
throw new FuelError13(
|
3891
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3788
3892
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3789
3893
|
);
|
3790
3894
|
}
|
@@ -3793,14 +3897,14 @@ var _Provider = class {
|
|
3793
3897
|
}
|
3794
3898
|
}
|
3795
3899
|
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
3796
|
-
const response = new TransactionResponse(transactionId2, this);
|
3900
|
+
const response = new TransactionResponse(transactionId2, this, abis);
|
3797
3901
|
await response.fetch();
|
3798
3902
|
return response;
|
3799
3903
|
}
|
3800
3904
|
const {
|
3801
3905
|
submit: { id: transactionId }
|
3802
3906
|
} = await this.operations.submit({ encodedTransaction });
|
3803
|
-
return new TransactionResponse(transactionId, this);
|
3907
|
+
return new TransactionResponse(transactionId, this, abis);
|
3804
3908
|
}
|
3805
3909
|
/**
|
3806
3910
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -3851,7 +3955,7 @@ var _Provider = class {
|
|
3851
3955
|
} = response;
|
3852
3956
|
if (inputs) {
|
3853
3957
|
inputs.forEach((input, index) => {
|
3854
|
-
if ("predicateGasUsed" in input &&
|
3958
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3855
3959
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3856
3960
|
}
|
3857
3961
|
});
|
@@ -3964,7 +4068,7 @@ var _Provider = class {
|
|
3964
4068
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3965
4069
|
if (estimatePredicates) {
|
3966
4070
|
if (isScriptTransaction) {
|
3967
|
-
txRequestClone.gasLimit =
|
4071
|
+
txRequestClone.gasLimit = bn15(0);
|
3968
4072
|
}
|
3969
4073
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3970
4074
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3980,8 +4084,8 @@ var _Provider = class {
|
|
3980
4084
|
let missingContractIds = [];
|
3981
4085
|
let outputVariables = 0;
|
3982
4086
|
if (isScriptTransaction && estimateTxDependencies) {
|
3983
|
-
txRequestClone.gasPrice =
|
3984
|
-
txRequestClone.gasLimit =
|
4087
|
+
txRequestClone.gasPrice = bn15(0);
|
4088
|
+
txRequestClone.gasLimit = bn15(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3985
4089
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3986
4090
|
receipts = result.receipts;
|
3987
4091
|
outputVariables = result.outputVariables;
|
@@ -4043,11 +4147,11 @@ var _Provider = class {
|
|
4043
4147
|
return coins.map((coin) => ({
|
4044
4148
|
id: coin.utxoId,
|
4045
4149
|
assetId: coin.assetId,
|
4046
|
-
amount:
|
4150
|
+
amount: bn15(coin.amount),
|
4047
4151
|
owner: Address2.fromAddressOrString(coin.owner),
|
4048
|
-
maturity:
|
4049
|
-
blockCreated:
|
4050
|
-
txCreatedIdx:
|
4152
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4153
|
+
blockCreated: bn15(coin.blockCreated),
|
4154
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4051
4155
|
}));
|
4052
4156
|
}
|
4053
4157
|
/**
|
@@ -4084,9 +4188,9 @@ var _Provider = class {
|
|
4084
4188
|
switch (coin.__typename) {
|
4085
4189
|
case "MessageCoin":
|
4086
4190
|
return {
|
4087
|
-
amount:
|
4191
|
+
amount: bn15(coin.amount),
|
4088
4192
|
assetId: coin.assetId,
|
4089
|
-
daHeight:
|
4193
|
+
daHeight: bn15(coin.daHeight),
|
4090
4194
|
sender: Address2.fromAddressOrString(coin.sender),
|
4091
4195
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4092
4196
|
nonce: coin.nonce
|
@@ -4094,12 +4198,12 @@ var _Provider = class {
|
|
4094
4198
|
case "Coin":
|
4095
4199
|
return {
|
4096
4200
|
id: coin.utxoId,
|
4097
|
-
amount:
|
4201
|
+
amount: bn15(coin.amount),
|
4098
4202
|
assetId: coin.assetId,
|
4099
4203
|
owner: Address2.fromAddressOrString(coin.owner),
|
4100
|
-
maturity:
|
4101
|
-
blockCreated:
|
4102
|
-
txCreatedIdx:
|
4204
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4205
|
+
blockCreated: bn15(coin.blockCreated),
|
4206
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
4103
4207
|
};
|
4104
4208
|
default:
|
4105
4209
|
return null;
|
@@ -4116,13 +4220,13 @@ var _Provider = class {
|
|
4116
4220
|
async getBlock(idOrHeight) {
|
4117
4221
|
let variables;
|
4118
4222
|
if (typeof idOrHeight === "number") {
|
4119
|
-
variables = { height:
|
4223
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
4120
4224
|
} else if (idOrHeight === "latest") {
|
4121
4225
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4122
4226
|
} else if (idOrHeight.length === 66) {
|
4123
4227
|
variables = { blockId: idOrHeight };
|
4124
4228
|
} else {
|
4125
|
-
variables = { blockId:
|
4229
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
4126
4230
|
}
|
4127
4231
|
const { block } = await this.operations.getBlock(variables);
|
4128
4232
|
if (!block) {
|
@@ -4130,7 +4234,7 @@ var _Provider = class {
|
|
4130
4234
|
}
|
4131
4235
|
return {
|
4132
4236
|
id: block.id,
|
4133
|
-
height:
|
4237
|
+
height: bn15(block.header.height),
|
4134
4238
|
time: block.header.time,
|
4135
4239
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4136
4240
|
};
|
@@ -4145,7 +4249,7 @@ var _Provider = class {
|
|
4145
4249
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4146
4250
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4147
4251
|
id: block.id,
|
4148
|
-
height:
|
4252
|
+
height: bn15(block.header.height),
|
4149
4253
|
time: block.header.time,
|
4150
4254
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4151
4255
|
}));
|
@@ -4160,7 +4264,7 @@ var _Provider = class {
|
|
4160
4264
|
async getBlockWithTransactions(idOrHeight) {
|
4161
4265
|
let variables;
|
4162
4266
|
if (typeof idOrHeight === "number") {
|
4163
|
-
variables = { blockHeight:
|
4267
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4164
4268
|
} else if (idOrHeight === "latest") {
|
4165
4269
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4166
4270
|
} else {
|
@@ -4172,7 +4276,7 @@ var _Provider = class {
|
|
4172
4276
|
}
|
4173
4277
|
return {
|
4174
4278
|
id: block.id,
|
4175
|
-
height:
|
4279
|
+
height: bn15(block.header.height, 10),
|
4176
4280
|
time: block.header.time,
|
4177
4281
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4178
4282
|
transactions: block.transactions.map(
|
@@ -4221,7 +4325,7 @@ var _Provider = class {
|
|
4221
4325
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4222
4326
|
asset: hexlify12(assetId)
|
4223
4327
|
});
|
4224
|
-
return
|
4328
|
+
return bn15(contractBalance.amount, 10);
|
4225
4329
|
}
|
4226
4330
|
/**
|
4227
4331
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4235,7 +4339,7 @@ var _Provider = class {
|
|
4235
4339
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4236
4340
|
assetId: hexlify12(assetId)
|
4237
4341
|
});
|
4238
|
-
return
|
4342
|
+
return bn15(balance.amount, 10);
|
4239
4343
|
}
|
4240
4344
|
/**
|
4241
4345
|
* Returns balances for the given owner.
|
@@ -4253,7 +4357,7 @@ var _Provider = class {
|
|
4253
4357
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4254
4358
|
return balances.map((balance) => ({
|
4255
4359
|
assetId: balance.assetId,
|
4256
|
-
amount:
|
4360
|
+
amount: bn15(balance.amount)
|
4257
4361
|
}));
|
4258
4362
|
}
|
4259
4363
|
/**
|
@@ -4275,15 +4379,15 @@ var _Provider = class {
|
|
4275
4379
|
sender: message.sender,
|
4276
4380
|
recipient: message.recipient,
|
4277
4381
|
nonce: message.nonce,
|
4278
|
-
amount:
|
4382
|
+
amount: bn15(message.amount),
|
4279
4383
|
data: message.data
|
4280
4384
|
}),
|
4281
4385
|
sender: Address2.fromAddressOrString(message.sender),
|
4282
4386
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4283
4387
|
nonce: message.nonce,
|
4284
|
-
amount:
|
4388
|
+
amount: bn15(message.amount),
|
4285
4389
|
data: InputMessageCoder.decodeData(message.data),
|
4286
|
-
daHeight:
|
4390
|
+
daHeight: bn15(message.daHeight)
|
4287
4391
|
}));
|
4288
4392
|
}
|
4289
4393
|
/**
|
@@ -4301,8 +4405,8 @@ var _Provider = class {
|
|
4301
4405
|
nonce
|
4302
4406
|
};
|
4303
4407
|
if (commitBlockId && commitBlockHeight) {
|
4304
|
-
throw new
|
4305
|
-
|
4408
|
+
throw new FuelError13(
|
4409
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4306
4410
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4307
4411
|
);
|
4308
4412
|
}
|
@@ -4336,41 +4440,41 @@ var _Provider = class {
|
|
4336
4440
|
} = result.messageProof;
|
4337
4441
|
return {
|
4338
4442
|
messageProof: {
|
4339
|
-
proofIndex:
|
4443
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4340
4444
|
proofSet: messageProof.proofSet
|
4341
4445
|
},
|
4342
4446
|
blockProof: {
|
4343
|
-
proofIndex:
|
4447
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4344
4448
|
proofSet: blockProof.proofSet
|
4345
4449
|
},
|
4346
4450
|
messageBlockHeader: {
|
4347
4451
|
id: messageBlockHeader.id,
|
4348
|
-
daHeight:
|
4349
|
-
transactionsCount:
|
4452
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4453
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4350
4454
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4351
|
-
height:
|
4455
|
+
height: bn15(messageBlockHeader.height),
|
4352
4456
|
prevRoot: messageBlockHeader.prevRoot,
|
4353
4457
|
time: messageBlockHeader.time,
|
4354
4458
|
applicationHash: messageBlockHeader.applicationHash,
|
4355
4459
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4356
|
-
messageReceiptCount:
|
4460
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4357
4461
|
},
|
4358
4462
|
commitBlockHeader: {
|
4359
4463
|
id: commitBlockHeader.id,
|
4360
|
-
daHeight:
|
4361
|
-
transactionsCount:
|
4464
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4465
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4362
4466
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4363
|
-
height:
|
4467
|
+
height: bn15(commitBlockHeader.height),
|
4364
4468
|
prevRoot: commitBlockHeader.prevRoot,
|
4365
4469
|
time: commitBlockHeader.time,
|
4366
4470
|
applicationHash: commitBlockHeader.applicationHash,
|
4367
4471
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4368
|
-
messageReceiptCount:
|
4472
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4369
4473
|
},
|
4370
4474
|
sender: Address2.fromAddressOrString(sender),
|
4371
4475
|
recipient: Address2.fromAddressOrString(recipient),
|
4372
4476
|
nonce,
|
4373
|
-
amount:
|
4477
|
+
amount: bn15(amount),
|
4374
4478
|
data
|
4375
4479
|
};
|
4376
4480
|
}
|
@@ -4393,10 +4497,10 @@ var _Provider = class {
|
|
4393
4497
|
*/
|
4394
4498
|
async produceBlocks(amount, startTime) {
|
4395
4499
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4396
|
-
blocksToProduce:
|
4500
|
+
blocksToProduce: bn15(amount).toString(10),
|
4397
4501
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4398
4502
|
});
|
4399
|
-
return
|
4503
|
+
return bn15(latestBlockHeight);
|
4400
4504
|
}
|
4401
4505
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4402
4506
|
async getTransactionResponse(transactionId) {
|
@@ -4419,8 +4523,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4419
4523
|
__publicField(Provider, "nodeInfoCache", {});
|
4420
4524
|
|
4421
4525
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4422
|
-
import { ErrorCode as
|
4423
|
-
import { bn as
|
4526
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4527
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4424
4528
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4425
4529
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4426
4530
|
async function getTransactionSummary(params) {
|
@@ -4429,8 +4533,8 @@ async function getTransactionSummary(params) {
|
|
4429
4533
|
transactionId: id
|
4430
4534
|
});
|
4431
4535
|
if (!gqlTransaction) {
|
4432
|
-
throw new
|
4433
|
-
|
4536
|
+
throw new FuelError14(
|
4537
|
+
ErrorCode14.TRANSACTION_NOT_FOUND,
|
4434
4538
|
`Transaction not found for given id: ${id}.`
|
4435
4539
|
);
|
4436
4540
|
}
|
@@ -4448,8 +4552,8 @@ async function getTransactionSummary(params) {
|
|
4448
4552
|
transaction: decodedTransaction,
|
4449
4553
|
transactionBytes: arrayify12(gqlTransaction.rawPayload),
|
4450
4554
|
gqlTransactionStatus: gqlTransaction.status,
|
4451
|
-
gasPerByte:
|
4452
|
-
gasPriceFactor:
|
4555
|
+
gasPerByte: bn16(gasPerByte),
|
4556
|
+
gasPriceFactor: bn16(gasPriceFactor),
|
4453
4557
|
abiMap,
|
4454
4558
|
maxInputs,
|
4455
4559
|
gasCosts
|
@@ -4703,7 +4807,7 @@ var Account = class extends AbstractAccount {
|
|
4703
4807
|
*/
|
4704
4808
|
get provider() {
|
4705
4809
|
if (!this._provider) {
|
4706
|
-
throw new
|
4810
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4707
4811
|
}
|
4708
4812
|
return this._provider;
|
4709
4813
|
}
|
@@ -4755,8 +4859,8 @@ var Account = class extends AbstractAccount {
|
|
4755
4859
|
if (!hasNextPage) {
|
4756
4860
|
break;
|
4757
4861
|
}
|
4758
|
-
throw new
|
4759
|
-
|
4862
|
+
throw new FuelError15(
|
4863
|
+
ErrorCode15.NOT_SUPPORTED,
|
4760
4864
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4761
4865
|
);
|
4762
4866
|
}
|
@@ -4781,8 +4885,8 @@ var Account = class extends AbstractAccount {
|
|
4781
4885
|
if (!hasNextPage) {
|
4782
4886
|
break;
|
4783
4887
|
}
|
4784
|
-
throw new
|
4785
|
-
|
4888
|
+
throw new FuelError15(
|
4889
|
+
ErrorCode15.NOT_SUPPORTED,
|
4786
4890
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4787
4891
|
);
|
4788
4892
|
}
|
@@ -4817,8 +4921,8 @@ var Account = class extends AbstractAccount {
|
|
4817
4921
|
if (!hasNextPage) {
|
4818
4922
|
break;
|
4819
4923
|
}
|
4820
|
-
throw new
|
4821
|
-
|
4924
|
+
throw new FuelError15(
|
4925
|
+
ErrorCode15.NOT_SUPPORTED,
|
4822
4926
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4823
4927
|
);
|
4824
4928
|
}
|
@@ -4834,7 +4938,7 @@ var Account = class extends AbstractAccount {
|
|
4834
4938
|
*/
|
4835
4939
|
async fund(request, coinQuantities, fee) {
|
4836
4940
|
const updatedQuantities = addAmountToAsset({
|
4837
|
-
amount:
|
4941
|
+
amount: bn17(fee),
|
4838
4942
|
assetId: BaseAssetId3,
|
4839
4943
|
coinQuantities
|
4840
4944
|
});
|
@@ -4842,7 +4946,7 @@ var Account = class extends AbstractAccount {
|
|
4842
4946
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4843
4947
|
quantitiesDict[assetId] = {
|
4844
4948
|
required: amount,
|
4845
|
-
owned:
|
4949
|
+
owned: bn17(0)
|
4846
4950
|
};
|
4847
4951
|
});
|
4848
4952
|
const cachedUtxos = [];
|
@@ -4855,7 +4959,7 @@ var Account = class extends AbstractAccount {
|
|
4855
4959
|
if (isCoin2) {
|
4856
4960
|
const assetId = String(input.assetId);
|
4857
4961
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4858
|
-
const amount =
|
4962
|
+
const amount = bn17(input.amount);
|
4859
4963
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4860
4964
|
cachedUtxos.push(input.id);
|
4861
4965
|
}
|
@@ -4901,8 +5005,8 @@ var Account = class extends AbstractAccount {
|
|
4901
5005
|
estimateTxDependencies: true,
|
4902
5006
|
resourcesOwner: this
|
4903
5007
|
});
|
4904
|
-
request.gasPrice =
|
4905
|
-
request.gasLimit =
|
5008
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
5009
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4906
5010
|
this.validateGas({
|
4907
5011
|
gasUsed,
|
4908
5012
|
gasPrice: request.gasPrice,
|
@@ -4923,9 +5027,9 @@ var Account = class extends AbstractAccount {
|
|
4923
5027
|
* @returns A promise that resolves to the transaction response.
|
4924
5028
|
*/
|
4925
5029
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4926
|
-
if (
|
4927
|
-
throw new
|
4928
|
-
|
5030
|
+
if (bn17(amount).lte(0)) {
|
5031
|
+
throw new FuelError15(
|
5032
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4929
5033
|
"Transfer amount must be a positive number."
|
4930
5034
|
);
|
4931
5035
|
}
|
@@ -4942,9 +5046,9 @@ var Account = class extends AbstractAccount {
|
|
4942
5046
|
* @returns A promise that resolves to the transaction response.
|
4943
5047
|
*/
|
4944
5048
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4945
|
-
if (
|
4946
|
-
throw new
|
4947
|
-
|
5049
|
+
if (bn17(amount).lte(0)) {
|
5050
|
+
throw new FuelError15(
|
5051
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4948
5052
|
"Transfer amount must be a positive number."
|
4949
5053
|
);
|
4950
5054
|
}
|
@@ -4953,7 +5057,7 @@ var Account = class extends AbstractAccount {
|
|
4953
5057
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4954
5058
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4955
5059
|
hexlifiedContractId: contractAddress.toB256(),
|
4956
|
-
amountToTransfer:
|
5060
|
+
amountToTransfer: bn17(amount),
|
4957
5061
|
assetId
|
4958
5062
|
});
|
4959
5063
|
const request = new ScriptTransactionRequest({
|
@@ -4964,9 +5068,9 @@ var Account = class extends AbstractAccount {
|
|
4964
5068
|
request.addContractInputAndOutput(contractAddress);
|
4965
5069
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4966
5070
|
request,
|
4967
|
-
[{ amount:
|
5071
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4968
5072
|
);
|
4969
|
-
request.gasLimit =
|
5073
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4970
5074
|
this.validateGas({
|
4971
5075
|
gasUsed,
|
4972
5076
|
gasPrice: request.gasPrice,
|
@@ -4991,7 +5095,7 @@ var Account = class extends AbstractAccount {
|
|
4991
5095
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4992
5096
|
);
|
4993
5097
|
const amountDataArray = arrayify14(
|
4994
|
-
"0x".concat(
|
5098
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
4995
5099
|
);
|
4996
5100
|
const script = new Uint8Array([
|
4997
5101
|
...arrayify14(withdrawScript.bytes),
|
@@ -5000,12 +5104,12 @@ var Account = class extends AbstractAccount {
|
|
5000
5104
|
]);
|
5001
5105
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5002
5106
|
const request = new ScriptTransactionRequest(params);
|
5003
|
-
const forwardingQuantities = [{ amount:
|
5107
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
5004
5108
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5005
5109
|
request,
|
5006
5110
|
forwardingQuantities
|
5007
5111
|
);
|
5008
|
-
request.gasLimit =
|
5112
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
5009
5113
|
this.validateGas({
|
5010
5114
|
gasUsed,
|
5011
5115
|
gasPrice: request.gasPrice,
|
@@ -5017,7 +5121,7 @@ var Account = class extends AbstractAccount {
|
|
5017
5121
|
}
|
5018
5122
|
async signMessage(message) {
|
5019
5123
|
if (!this._connector) {
|
5020
|
-
throw new
|
5124
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5021
5125
|
}
|
5022
5126
|
return this._connector.signMessage(this.address.toString(), message);
|
5023
5127
|
}
|
@@ -5029,8 +5133,8 @@ var Account = class extends AbstractAccount {
|
|
5029
5133
|
*/
|
5030
5134
|
async signTransaction(transactionRequestLike) {
|
5031
5135
|
if (!this._connector) {
|
5032
|
-
throw new
|
5033
|
-
|
5136
|
+
throw new FuelError15(
|
5137
|
+
ErrorCode15.MISSING_CONNECTOR,
|
5034
5138
|
"A connector is required to sign transactions."
|
5035
5139
|
);
|
5036
5140
|
}
|
@@ -5077,14 +5181,14 @@ var Account = class extends AbstractAccount {
|
|
5077
5181
|
minGasPrice
|
5078
5182
|
}) {
|
5079
5183
|
if (minGasPrice.gt(gasPrice)) {
|
5080
|
-
throw new
|
5081
|
-
|
5184
|
+
throw new FuelError15(
|
5185
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
5082
5186
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5083
5187
|
);
|
5084
5188
|
}
|
5085
5189
|
if (gasUsed.gt(gasLimit)) {
|
5086
|
-
throw new
|
5087
|
-
|
5190
|
+
throw new FuelError15(
|
5191
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
5088
5192
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5089
5193
|
);
|
5090
5194
|
}
|
@@ -5215,7 +5319,7 @@ import {
|
|
5215
5319
|
decryptJsonWalletData,
|
5216
5320
|
encryptJsonWalletData
|
5217
5321
|
} from "@fuel-ts/crypto";
|
5218
|
-
import { ErrorCode as
|
5322
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
5219
5323
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
5220
5324
|
import { v4 as uuidv4 } from "uuid";
|
5221
5325
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -5293,8 +5397,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5293
5397
|
const macHashUint8Array = keccak256(data);
|
5294
5398
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
5295
5399
|
if (mac !== macHash) {
|
5296
|
-
throw new
|
5297
|
-
|
5400
|
+
throw new FuelError16(
|
5401
|
+
ErrorCode16.INVALID_PASSWORD,
|
5298
5402
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5299
5403
|
);
|
5300
5404
|
}
|
@@ -5416,15 +5520,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5416
5520
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5417
5521
|
|
5418
5522
|
// src/hdwallet/hdwallet.ts
|
5419
|
-
import { ErrorCode as
|
5523
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5420
5524
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5421
|
-
import { bn as
|
5525
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5422
5526
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5423
5527
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5424
5528
|
|
5425
5529
|
// src/mnemonic/mnemonic.ts
|
5426
5530
|
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5427
|
-
import { ErrorCode as
|
5531
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5428
5532
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5429
5533
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5430
5534
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7488,7 +7592,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7488
7592
|
})(Language || {});
|
7489
7593
|
|
7490
7594
|
// src/mnemonic/utils.ts
|
7491
|
-
import { ErrorCode as
|
7595
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7492
7596
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7493
7597
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7494
7598
|
function toUtf8Bytes(stri) {
|
@@ -7505,8 +7609,8 @@ function toUtf8Bytes(stri) {
|
|
7505
7609
|
i += 1;
|
7506
7610
|
const c2 = str.charCodeAt(i);
|
7507
7611
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7508
|
-
throw new
|
7509
|
-
|
7612
|
+
throw new FuelError17(
|
7613
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7510
7614
|
"Invalid UTF-8 in the input string."
|
7511
7615
|
);
|
7512
7616
|
}
|
@@ -7569,8 +7673,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7569
7673
|
for (let i = 0; i < words.length; i += 1) {
|
7570
7674
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7571
7675
|
if (index === -1) {
|
7572
|
-
throw new
|
7573
|
-
|
7676
|
+
throw new FuelError17(
|
7677
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7574
7678
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7575
7679
|
);
|
7576
7680
|
}
|
@@ -7586,8 +7690,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7586
7690
|
const checksumMask = getUpperMask(checksumBits);
|
7587
7691
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7588
7692
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7589
|
-
throw new
|
7590
|
-
|
7693
|
+
throw new FuelError17(
|
7694
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7591
7695
|
"Checksum validation failed for the provided mnemonic."
|
7592
7696
|
);
|
7593
7697
|
}
|
@@ -7601,16 +7705,16 @@ var TestnetPRV = "0x04358394";
|
|
7601
7705
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7602
7706
|
function assertWordList(wordlist) {
|
7603
7707
|
if (wordlist.length !== 2048) {
|
7604
|
-
throw new
|
7605
|
-
|
7708
|
+
throw new FuelError18(
|
7709
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7606
7710
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7607
7711
|
);
|
7608
7712
|
}
|
7609
7713
|
}
|
7610
7714
|
function assertEntropy(entropy) {
|
7611
7715
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7612
|
-
throw new
|
7613
|
-
|
7716
|
+
throw new FuelError18(
|
7717
|
+
ErrorCode18.INVALID_ENTROPY,
|
7614
7718
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7615
7719
|
);
|
7616
7720
|
}
|
@@ -7620,7 +7724,7 @@ function assertMnemonic(words) {
|
|
7620
7724
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7621
7725
|
", "
|
7622
7726
|
)}] words, but got ${words.length}.`;
|
7623
|
-
throw new
|
7727
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7624
7728
|
}
|
7625
7729
|
}
|
7626
7730
|
var Mnemonic = class {
|
@@ -7738,8 +7842,8 @@ var Mnemonic = class {
|
|
7738
7842
|
static masterKeysFromSeed(seed) {
|
7739
7843
|
const seedArray = arrayify17(seed);
|
7740
7844
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7741
|
-
throw new
|
7742
|
-
|
7845
|
+
throw new FuelError18(
|
7846
|
+
ErrorCode18.INVALID_SEED,
|
7743
7847
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7744
7848
|
);
|
7745
7849
|
}
|
@@ -7816,7 +7920,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7816
7920
|
function parsePath(path, depth = 0) {
|
7817
7921
|
const components = path.split("/");
|
7818
7922
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7819
|
-
throw new
|
7923
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path}`);
|
7820
7924
|
}
|
7821
7925
|
if (components[0] === "m") {
|
7822
7926
|
components.shift();
|
@@ -7845,8 +7949,8 @@ var HDWallet = class {
|
|
7845
7949
|
this.privateKey = hexlify17(config.privateKey);
|
7846
7950
|
} else {
|
7847
7951
|
if (!config.publicKey) {
|
7848
|
-
throw new
|
7849
|
-
|
7952
|
+
throw new FuelError19(
|
7953
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7850
7954
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7851
7955
|
);
|
7852
7956
|
}
|
@@ -7875,8 +7979,8 @@ var HDWallet = class {
|
|
7875
7979
|
const data = new Uint8Array(37);
|
7876
7980
|
if (index & HARDENED_INDEX) {
|
7877
7981
|
if (!privateKey) {
|
7878
|
-
throw new
|
7879
|
-
|
7982
|
+
throw new FuelError19(
|
7983
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7880
7984
|
"Cannot derive a hardened index without a private Key."
|
7881
7985
|
);
|
7882
7986
|
}
|
@@ -7890,7 +7994,7 @@ var HDWallet = class {
|
|
7890
7994
|
const IR = bytes.slice(32);
|
7891
7995
|
if (privateKey) {
|
7892
7996
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7893
|
-
const ki =
|
7997
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7894
7998
|
return new HDWallet({
|
7895
7999
|
privateKey: ki,
|
7896
8000
|
chainCode: IR,
|
@@ -7928,8 +8032,8 @@ var HDWallet = class {
|
|
7928
8032
|
*/
|
7929
8033
|
toExtendedKey(isPublic = false, testnet = false) {
|
7930
8034
|
if (this.depth >= 256) {
|
7931
|
-
throw new
|
7932
|
-
|
8035
|
+
throw new FuelError19(
|
8036
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7933
8037
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7934
8038
|
);
|
7935
8039
|
}
|
@@ -7960,10 +8064,10 @@ var HDWallet = class {
|
|
7960
8064
|
const bytes = arrayify18(decoded);
|
7961
8065
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7962
8066
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7963
|
-
throw new
|
8067
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7964
8068
|
}
|
7965
8069
|
if (!validChecksum) {
|
7966
|
-
throw new
|
8070
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7967
8071
|
}
|
7968
8072
|
const depth = bytes[4];
|
7969
8073
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7971,14 +8075,14 @@ var HDWallet = class {
|
|
7971
8075
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7972
8076
|
const key = bytes.slice(45, 78);
|
7973
8077
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7974
|
-
throw new
|
7975
|
-
|
8078
|
+
throw new FuelError19(
|
8079
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7976
8080
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7977
8081
|
);
|
7978
8082
|
}
|
7979
8083
|
if (isPublicExtendedKey(bytes)) {
|
7980
8084
|
if (key[0] !== 3) {
|
7981
|
-
throw new
|
8085
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
7982
8086
|
}
|
7983
8087
|
return new HDWallet({
|
7984
8088
|
publicKey: key,
|
@@ -7989,7 +8093,7 @@ var HDWallet = class {
|
|
7989
8093
|
});
|
7990
8094
|
}
|
7991
8095
|
if (key[0] !== 0) {
|
7992
|
-
throw new
|
8096
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
7993
8097
|
}
|
7994
8098
|
return new HDWallet({
|
7995
8099
|
privateKey: key.slice(1),
|
@@ -8157,7 +8261,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8157
8261
|
// src/wallet-manager/wallet-manager.ts
|
8158
8262
|
import { Address as Address8 } from "@fuel-ts/address";
|
8159
8263
|
import { encrypt, decrypt } from "@fuel-ts/crypto";
|
8160
|
-
import { ErrorCode as
|
8264
|
+
import { ErrorCode as ErrorCode22, FuelError as FuelError22 } from "@fuel-ts/errors";
|
8161
8265
|
import { EventEmitter } from "events";
|
8162
8266
|
|
8163
8267
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8180,7 +8284,7 @@ var MemoryStorage = class {
|
|
8180
8284
|
|
8181
8285
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8182
8286
|
import { Address as Address6 } from "@fuel-ts/address";
|
8183
|
-
import { ErrorCode as
|
8287
|
+
import { ErrorCode as ErrorCode20, FuelError as FuelError20 } from "@fuel-ts/errors";
|
8184
8288
|
var _secret;
|
8185
8289
|
var MnemonicVault = class {
|
8186
8290
|
constructor(options) {
|
@@ -8236,8 +8340,8 @@ var MnemonicVault = class {
|
|
8236
8340
|
}
|
8237
8341
|
numberOfAccounts += 1;
|
8238
8342
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8239
|
-
throw new
|
8240
|
-
|
8343
|
+
throw new FuelError20(
|
8344
|
+
ErrorCode20.WALLET_MANAGER_ERROR,
|
8241
8345
|
`Account with address '${address}' not found in derived wallets.`
|
8242
8346
|
);
|
8243
8347
|
}
|
@@ -8251,7 +8355,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8251
8355
|
|
8252
8356
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8253
8357
|
import { Address as Address7 } from "@fuel-ts/address";
|
8254
|
-
import { ErrorCode as
|
8358
|
+
import { ErrorCode as ErrorCode21, FuelError as FuelError21 } from "@fuel-ts/errors";
|
8255
8359
|
var _privateKeys;
|
8256
8360
|
var PrivateKeyVault = class {
|
8257
8361
|
/**
|
@@ -8292,8 +8396,8 @@ var PrivateKeyVault = class {
|
|
8292
8396
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8293
8397
|
);
|
8294
8398
|
if (!privateKey) {
|
8295
|
-
throw new
|
8296
|
-
|
8399
|
+
throw new FuelError21(
|
8400
|
+
ErrorCode21.WALLET_MANAGER_ERROR,
|
8297
8401
|
`No private key found for address '${address}'.`
|
8298
8402
|
);
|
8299
8403
|
}
|
@@ -8317,7 +8421,7 @@ var ERROR_MESSAGES = {
|
|
8317
8421
|
};
|
8318
8422
|
function assert(condition, message) {
|
8319
8423
|
if (!condition) {
|
8320
|
-
throw new
|
8424
|
+
throw new FuelError22(ErrorCode22.WALLET_MANAGER_ERROR, message);
|
8321
8425
|
}
|
8322
8426
|
}
|
8323
8427
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8543,25 +8647,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8543
8647
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8544
8648
|
|
8545
8649
|
// src/wallet-manager/types.ts
|
8546
|
-
import { ErrorCode as
|
8650
|
+
import { ErrorCode as ErrorCode23, FuelError as FuelError23 } from "@fuel-ts/errors";
|
8547
8651
|
var Vault = class {
|
8548
8652
|
constructor(_options) {
|
8549
|
-
throw new
|
8653
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8550
8654
|
}
|
8551
8655
|
serialize() {
|
8552
|
-
throw new
|
8656
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8553
8657
|
}
|
8554
8658
|
getAccounts() {
|
8555
|
-
throw new
|
8659
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8556
8660
|
}
|
8557
8661
|
addAccount() {
|
8558
|
-
throw new
|
8662
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8559
8663
|
}
|
8560
8664
|
exportAccount(_address) {
|
8561
|
-
throw new
|
8665
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8562
8666
|
}
|
8563
8667
|
getWallet(_address) {
|
8564
|
-
throw new
|
8668
|
+
throw new FuelError23(ErrorCode23.NOT_IMPLEMENTED, "Not implemented.");
|
8565
8669
|
}
|
8566
8670
|
};
|
8567
8671
|
__publicField(Vault, "type");
|
@@ -8578,7 +8682,7 @@ import {
|
|
8578
8682
|
} from "@fuel-ts/abi-coder";
|
8579
8683
|
import { Address as Address9 } from "@fuel-ts/address";
|
8580
8684
|
import { BaseAssetId as BaseAssetId4 } from "@fuel-ts/address/configs";
|
8581
|
-
import { ErrorCode as
|
8685
|
+
import { ErrorCode as ErrorCode24, FuelError as FuelError24 } from "@fuel-ts/errors";
|
8582
8686
|
import { ByteArrayCoder, InputType as InputType7 } from "@fuel-ts/transactions";
|
8583
8687
|
import { arrayify as arrayify20, hexlify as hexlify19 } from "@fuel-ts/utils";
|
8584
8688
|
|
@@ -8706,8 +8810,8 @@ var Predicate = class extends Account {
|
|
8706
8810
|
if (jsonAbi) {
|
8707
8811
|
abiInterface = new Interface4(jsonAbi);
|
8708
8812
|
if (abiInterface.functions.main === void 0) {
|
8709
|
-
throw new
|
8710
|
-
|
8813
|
+
throw new FuelError24(
|
8814
|
+
ErrorCode24.ABI_MAIN_METHOD_MISSING,
|
8711
8815
|
'Cannot use ABI without "main" function.'
|
8712
8816
|
);
|
8713
8817
|
}
|
@@ -8752,8 +8856,8 @@ var Predicate = class extends Account {
|
|
8752
8856
|
mutatedBytes.set(encoded, offset);
|
8753
8857
|
});
|
8754
8858
|
} catch (err) {
|
8755
|
-
throw new
|
8756
|
-
|
8859
|
+
throw new FuelError24(
|
8860
|
+
ErrorCode24.INVALID_CONFIGURABLE_CONSTANTS,
|
8757
8861
|
`Error setting configurable constants: ${err.message}.`
|
8758
8862
|
);
|
8759
8863
|
}
|
@@ -8762,7 +8866,7 @@ var Predicate = class extends Account {
|
|
8762
8866
|
};
|
8763
8867
|
|
8764
8868
|
// src/connectors/fuel.ts
|
8765
|
-
import { ErrorCode as
|
8869
|
+
import { ErrorCode as ErrorCode25, FuelError as FuelError25 } from "@fuel-ts/errors";
|
8766
8870
|
|
8767
8871
|
// src/connectors/fuel-connector.ts
|
8768
8872
|
import { EventEmitter as EventEmitter2 } from "events";
|
@@ -9395,7 +9499,7 @@ var _Fuel = class extends FuelConnector {
|
|
9395
9499
|
const currentNetwork = await this.currentNetwork();
|
9396
9500
|
provider = await Provider.create(currentNetwork.url);
|
9397
9501
|
} else {
|
9398
|
-
throw new
|
9502
|
+
throw new FuelError25(ErrorCode25.INVALID_PROVIDER, "Provider is not valid.");
|
9399
9503
|
}
|
9400
9504
|
return provider;
|
9401
9505
|
}
|
@@ -9474,7 +9578,9 @@ export {
|
|
9474
9578
|
WalletUnlocked,
|
9475
9579
|
addAmountToAsset,
|
9476
9580
|
addOperation,
|
9581
|
+
assemblePanicError,
|
9477
9582
|
assembleReceiptByType,
|
9583
|
+
assembleRevertError,
|
9478
9584
|
assembleTransactionSummary,
|
9479
9585
|
assets,
|
9480
9586
|
buildBlockExplorerUrl,
|
@@ -9489,6 +9595,7 @@ export {
|
|
9489
9595
|
english,
|
9490
9596
|
extractBurnedAssetsFromReceipts,
|
9491
9597
|
extractMintedAssetsFromReceipts,
|
9598
|
+
extractTxError,
|
9492
9599
|
gasUsedByInputs,
|
9493
9600
|
getAssetEth,
|
9494
9601
|
getAssetFuel,
|