@fuel-ts/account 0.78.0 → 0.80.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/configs.d.ts +1 -0
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +1 -0
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +3 -0
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +2 -0
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +388 -210
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +668 -550
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +422 -299
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +0 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +13 -2
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.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/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 +2 -2
- 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 +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 +390 -196
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +625 -499
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +392 -258
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.mjs
CHANGED
@@ -25,9 +25,9 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
25
25
|
// src/account.ts
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { BaseAssetId as BaseAssetId3 } from "@fuel-ts/address/configs";
|
28
|
-
import { ErrorCode as
|
28
|
+
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
29
29
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
30
|
-
import { bn as
|
30
|
+
import { bn as bn17 } from "@fuel-ts/math";
|
31
31
|
import { arrayify as arrayify14 } from "@fuel-ts/utils";
|
32
32
|
|
33
33
|
// src/providers/coin-quantity.ts
|
@@ -68,8 +68,8 @@ var addAmountToAsset = (params) => {
|
|
68
68
|
|
69
69
|
// src/providers/provider.ts
|
70
70
|
import { Address as Address2 } from "@fuel-ts/address";
|
71
|
-
import { ErrorCode as
|
72
|
-
import { BN, bn as
|
71
|
+
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
72
|
+
import { BN, bn as bn15, max } from "@fuel-ts/math";
|
73
73
|
import {
|
74
74
|
InputType as InputType6,
|
75
75
|
TransactionType as TransactionType8,
|
@@ -1018,6 +1018,7 @@ var MemoryCache = class {
|
|
1018
1018
|
};
|
1019
1019
|
|
1020
1020
|
// src/providers/transaction-request/input.ts
|
1021
|
+
import { BYTES_32, UTXO_ID_LEN } from "@fuel-ts/abi-coder";
|
1021
1022
|
import { ZeroBytes32 } from "@fuel-ts/address/configs";
|
1022
1023
|
import { ErrorCode as ErrorCode3, FuelError as FuelError3 } from "@fuel-ts/errors";
|
1023
1024
|
import { bn as bn2, toNumber } from "@fuel-ts/math";
|
@@ -1031,8 +1032,8 @@ var inputify = (value) => {
|
|
1031
1032
|
const predicateData = arrayify(value.predicateData ?? "0x");
|
1032
1033
|
return {
|
1033
1034
|
type: InputType.Coin,
|
1034
|
-
txID: hexlify3(arrayify(value.id).slice(0,
|
1035
|
-
outputIndex: arrayify(value.id)
|
1035
|
+
txID: hexlify3(arrayify(value.id).slice(0, BYTES_32)),
|
1036
|
+
outputIndex: toNumber(arrayify(value.id).slice(BYTES_32, UTXO_ID_LEN)),
|
1036
1037
|
owner: hexlify3(value.owner),
|
1037
1038
|
amount: bn2(value.amount),
|
1038
1039
|
assetId: hexlify3(value.assetId),
|
@@ -1150,9 +1151,11 @@ var outputify = (value) => {
|
|
1150
1151
|
};
|
1151
1152
|
|
1152
1153
|
// src/providers/transaction-request/transaction-request.ts
|
1154
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN2 } from "@fuel-ts/abi-coder";
|
1153
1155
|
import { Address, addressify } from "@fuel-ts/address";
|
1154
1156
|
import { BaseAssetId as BaseAssetId2, ZeroBytes32 as ZeroBytes324 } from "@fuel-ts/address/configs";
|
1155
|
-
import {
|
1157
|
+
import { randomBytes } from "@fuel-ts/crypto";
|
1158
|
+
import { bn as bn7 } from "@fuel-ts/math";
|
1156
1159
|
import {
|
1157
1160
|
PolicyType,
|
1158
1161
|
TransactionCoder,
|
@@ -1495,6 +1498,86 @@ function sleep(time) {
|
|
1495
1498
|
});
|
1496
1499
|
}
|
1497
1500
|
|
1501
|
+
// src/providers/utils/extract-tx-error.ts
|
1502
|
+
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1503
|
+
import { bn as bn6 } from "@fuel-ts/math";
|
1504
|
+
import { ReceiptType as ReceiptType3 } from "@fuel-ts/transactions";
|
1505
|
+
import {
|
1506
|
+
FAILED_REQUIRE_SIGNAL,
|
1507
|
+
FAILED_ASSERT_EQ_SIGNAL,
|
1508
|
+
FAILED_ASSERT_NE_SIGNAL,
|
1509
|
+
FAILED_ASSERT_SIGNAL,
|
1510
|
+
FAILED_TRANSFER_TO_ADDRESS_SIGNAL as FAILED_TRANSFER_TO_ADDRESS_SIGNAL2,
|
1511
|
+
PANIC_REASONS,
|
1512
|
+
PANIC_DOC_URL
|
1513
|
+
} from "@fuel-ts/transactions/configs";
|
1514
|
+
var assemblePanicError = (status) => {
|
1515
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1516
|
+
const reason = status.reason;
|
1517
|
+
if (PANIC_REASONS.includes(status.reason)) {
|
1518
|
+
errorMessage = `${errorMessage}
|
1519
|
+
|
1520
|
+
You can read more about this error at:
|
1521
|
+
|
1522
|
+
${PANIC_DOC_URL}#variant.${status.reason}`;
|
1523
|
+
}
|
1524
|
+
return { errorMessage, reason };
|
1525
|
+
};
|
1526
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1527
|
+
var assembleRevertError = (receipts, logs) => {
|
1528
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1529
|
+
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1530
|
+
let reason = "";
|
1531
|
+
if (revertReceipt) {
|
1532
|
+
const reasonHex = bn6(revertReceipt.val).toHex();
|
1533
|
+
switch (reasonHex) {
|
1534
|
+
case FAILED_REQUIRE_SIGNAL: {
|
1535
|
+
reason = "require";
|
1536
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1537
|
+
break;
|
1538
|
+
}
|
1539
|
+
case FAILED_ASSERT_EQ_SIGNAL: {
|
1540
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1541
|
+
reason = "assert_eq";
|
1542
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1543
|
+
break;
|
1544
|
+
}
|
1545
|
+
case FAILED_ASSERT_NE_SIGNAL: {
|
1546
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1547
|
+
reason = "assert_ne";
|
1548
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1549
|
+
break;
|
1550
|
+
}
|
1551
|
+
case FAILED_ASSERT_SIGNAL:
|
1552
|
+
reason = "assert";
|
1553
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1554
|
+
break;
|
1555
|
+
case FAILED_TRANSFER_TO_ADDRESS_SIGNAL2:
|
1556
|
+
reason = "MissingOutputChange";
|
1557
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1558
|
+
break;
|
1559
|
+
default:
|
1560
|
+
reason = "unknown";
|
1561
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1562
|
+
}
|
1563
|
+
}
|
1564
|
+
return { errorMessage, reason };
|
1565
|
+
};
|
1566
|
+
var extractTxError = (params) => {
|
1567
|
+
const { receipts, status, logs } = params;
|
1568
|
+
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1569
|
+
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1570
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1571
|
+
const metadata = {
|
1572
|
+
logs,
|
1573
|
+
receipts,
|
1574
|
+
panic: isPanic,
|
1575
|
+
revert: isRevert,
|
1576
|
+
reason
|
1577
|
+
};
|
1578
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, metadata);
|
1579
|
+
};
|
1580
|
+
|
1498
1581
|
// src/providers/transaction-request/errors.ts
|
1499
1582
|
var NoWitnessAtIndexError = class extends Error {
|
1500
1583
|
constructor(index) {
|
@@ -1545,10 +1628,10 @@ var BaseTransactionRequest = class {
|
|
1545
1628
|
outputs,
|
1546
1629
|
witnesses
|
1547
1630
|
} = {}) {
|
1548
|
-
this.gasPrice =
|
1631
|
+
this.gasPrice = bn7(gasPrice);
|
1549
1632
|
this.maturity = maturity ?? 0;
|
1550
|
-
this.witnessLimit = witnessLimit ?
|
1551
|
-
this.maxFee = maxFee ?
|
1633
|
+
this.witnessLimit = witnessLimit ? bn7(witnessLimit) : void 0;
|
1634
|
+
this.maxFee = maxFee ? bn7(maxFee) : void 0;
|
1552
1635
|
this.inputs = inputs ?? [];
|
1553
1636
|
this.outputs = outputs ?? [];
|
1554
1637
|
this.witnesses = witnesses ?? [];
|
@@ -1764,8 +1847,7 @@ var BaseTransactionRequest = class {
|
|
1764
1847
|
assetId,
|
1765
1848
|
txPointer: "0x00000000000000000000000000000000",
|
1766
1849
|
witnessIndex,
|
1767
|
-
predicate: predicate?.bytes
|
1768
|
-
predicateData: predicate?.predicateDataBytes
|
1850
|
+
predicate: predicate?.bytes
|
1769
1851
|
};
|
1770
1852
|
this.pushInput(input);
|
1771
1853
|
this.addChangeOutput(owner, assetId);
|
@@ -1797,8 +1879,7 @@ var BaseTransactionRequest = class {
|
|
1797
1879
|
recipient: recipient.toB256(),
|
1798
1880
|
amount,
|
1799
1881
|
witnessIndex,
|
1800
|
-
predicate: predicate?.bytes
|
1801
|
-
predicateData: predicate?.predicateDataBytes
|
1882
|
+
predicate: predicate?.bytes
|
1802
1883
|
};
|
1803
1884
|
this.pushInput(input);
|
1804
1885
|
this.addChangeOutput(recipient, assetId);
|
@@ -1953,12 +2034,6 @@ var BaseTransactionRequest = class {
|
|
1953
2034
|
* @param quantities - CoinQuantity Array.
|
1954
2035
|
*/
|
1955
2036
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
1956
|
-
let idCounter = 0;
|
1957
|
-
const generateId = () => {
|
1958
|
-
const counterString = String(idCounter++);
|
1959
|
-
const id = ZeroBytes324.slice(0, -counterString.length).concat(counterString);
|
1960
|
-
return id;
|
1961
|
-
};
|
1962
2037
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
1963
2038
|
if ("assetId" in input) {
|
1964
2039
|
return input.assetId === assetId;
|
@@ -1968,23 +2043,23 @@ var BaseTransactionRequest = class {
|
|
1968
2043
|
const updateAssetInput = (assetId, quantity) => {
|
1969
2044
|
const assetInput = findAssetInput(assetId);
|
1970
2045
|
if (assetInput && "assetId" in assetInput) {
|
1971
|
-
assetInput.id =
|
2046
|
+
assetInput.id = hexlify7(randomBytes(UTXO_ID_LEN2));
|
1972
2047
|
assetInput.amount = quantity;
|
1973
2048
|
} else {
|
1974
2049
|
this.addResources([
|
1975
2050
|
{
|
1976
|
-
id:
|
2051
|
+
id: hexlify7(randomBytes(UTXO_ID_LEN2)),
|
1977
2052
|
amount: quantity,
|
1978
2053
|
assetId,
|
1979
2054
|
owner: resourcesOwner || Address.fromRandom(),
|
1980
2055
|
maturity: 0,
|
1981
|
-
blockCreated:
|
1982
|
-
txCreatedIdx:
|
2056
|
+
blockCreated: bn7(1),
|
2057
|
+
txCreatedIdx: bn7(1)
|
1983
2058
|
}
|
1984
2059
|
]);
|
1985
2060
|
}
|
1986
2061
|
};
|
1987
|
-
updateAssetInput(BaseAssetId2,
|
2062
|
+
updateAssetInput(BaseAssetId2, bn7(1e11));
|
1988
2063
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
1989
2064
|
}
|
1990
2065
|
/**
|
@@ -1995,7 +2070,7 @@ var BaseTransactionRequest = class {
|
|
1995
2070
|
*/
|
1996
2071
|
getCoinOutputsQuantities() {
|
1997
2072
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
1998
|
-
amount:
|
2073
|
+
amount: bn7(amount),
|
1999
2074
|
assetId: assetId.toString()
|
2000
2075
|
}));
|
2001
2076
|
return coinsQuantities;
|
@@ -2024,7 +2099,7 @@ var BaseTransactionRequest = class {
|
|
2024
2099
|
default:
|
2025
2100
|
return;
|
2026
2101
|
}
|
2027
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput &&
|
2102
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && bn7(correspondingInput.predicateGasUsed).gt(0)) {
|
2028
2103
|
i.predicate = correspondingInput.predicate;
|
2029
2104
|
i.predicateData = correspondingInput.predicateData;
|
2030
2105
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2035,14 +2110,14 @@ var BaseTransactionRequest = class {
|
|
2035
2110
|
|
2036
2111
|
// src/providers/transaction-request/create-transaction-request.ts
|
2037
2112
|
import { ZeroBytes32 as ZeroBytes326 } from "@fuel-ts/address/configs";
|
2038
|
-
import { bn as
|
2113
|
+
import { bn as bn9 } from "@fuel-ts/math";
|
2039
2114
|
import { TransactionType as TransactionType3, OutputType as OutputType4 } from "@fuel-ts/transactions";
|
2040
2115
|
import { arrayify as arrayify6, hexlify as hexlify9 } from "@fuel-ts/utils";
|
2041
2116
|
|
2042
2117
|
// src/providers/transaction-request/hash-transaction.ts
|
2043
2118
|
import { ZeroBytes32 as ZeroBytes325 } from "@fuel-ts/address/configs";
|
2044
2119
|
import { uint64ToBytesBE, sha256 } from "@fuel-ts/hasher";
|
2045
|
-
import { bn as
|
2120
|
+
import { bn as bn8 } from "@fuel-ts/math";
|
2046
2121
|
import { TransactionType as TransactionType2, InputType as InputType3, OutputType as OutputType3, TransactionCoder as TransactionCoder2 } from "@fuel-ts/transactions";
|
2047
2122
|
import { concat as concat2 } from "@fuel-ts/utils";
|
2048
2123
|
import { clone as clone2 } from "ramda";
|
@@ -2059,11 +2134,11 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2059
2134
|
blockHeight: 0,
|
2060
2135
|
txIndex: 0
|
2061
2136
|
};
|
2062
|
-
inputClone.predicateGasUsed =
|
2137
|
+
inputClone.predicateGasUsed = bn8(0);
|
2063
2138
|
return inputClone;
|
2064
2139
|
}
|
2065
2140
|
case InputType3.Message: {
|
2066
|
-
inputClone.predicateGasUsed =
|
2141
|
+
inputClone.predicateGasUsed = bn8(0);
|
2067
2142
|
return inputClone;
|
2068
2143
|
}
|
2069
2144
|
case InputType3.Contract: {
|
@@ -2090,12 +2165,12 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2090
2165
|
return outputClone;
|
2091
2166
|
}
|
2092
2167
|
case OutputType3.Change: {
|
2093
|
-
outputClone.amount =
|
2168
|
+
outputClone.amount = bn8(0);
|
2094
2169
|
return outputClone;
|
2095
2170
|
}
|
2096
2171
|
case OutputType3.Variable: {
|
2097
2172
|
outputClone.to = ZeroBytes325;
|
2098
|
-
outputClone.amount =
|
2173
|
+
outputClone.amount = bn8(0);
|
2099
2174
|
outputClone.assetId = ZeroBytes325;
|
2100
2175
|
return outputClone;
|
2101
2176
|
}
|
@@ -2219,7 +2294,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2219
2294
|
}
|
2220
2295
|
metadataGas(gasCosts) {
|
2221
2296
|
return calculateMetadataGasForTxCreate({
|
2222
|
-
contractBytesSize:
|
2297
|
+
contractBytesSize: bn9(arrayify6(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2223
2298
|
gasCosts,
|
2224
2299
|
stateRootSize: this.storageSlots.length,
|
2225
2300
|
txBytesSize: this.byteSize()
|
@@ -2231,7 +2306,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2231
2306
|
import { Interface } from "@fuel-ts/abi-coder";
|
2232
2307
|
import { addressify as addressify2 } from "@fuel-ts/address";
|
2233
2308
|
import { ZeroBytes32 as ZeroBytes327 } from "@fuel-ts/address/configs";
|
2234
|
-
import { bn as
|
2309
|
+
import { bn as bn10 } from "@fuel-ts/math";
|
2235
2310
|
import { InputType as InputType4, OutputType as OutputType5, TransactionType as TransactionType4 } from "@fuel-ts/transactions";
|
2236
2311
|
import { arrayify as arrayify8, hexlify as hexlify10 } from "@fuel-ts/utils";
|
2237
2312
|
|
@@ -2277,6 +2352,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2277
2352
|
script;
|
2278
2353
|
/** Script input data (parameters) */
|
2279
2354
|
scriptData;
|
2355
|
+
abis;
|
2280
2356
|
/**
|
2281
2357
|
* Constructor for `ScriptTransactionRequest`.
|
2282
2358
|
*
|
@@ -2284,9 +2360,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2284
2360
|
*/
|
2285
2361
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2286
2362
|
super(rest);
|
2287
|
-
this.gasLimit =
|
2363
|
+
this.gasLimit = bn10(gasLimit);
|
2288
2364
|
this.script = arrayify8(script ?? returnZeroScript.bytes);
|
2289
2365
|
this.scriptData = arrayify8(scriptData ?? returnZeroScript.encodeScriptData());
|
2366
|
+
this.abis = rest.abis;
|
2290
2367
|
}
|
2291
2368
|
/**
|
2292
2369
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2431,7 +2508,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2431
2508
|
};
|
2432
2509
|
|
2433
2510
|
// src/providers/transaction-request/utils.ts
|
2434
|
-
import { ErrorCode as
|
2511
|
+
import { ErrorCode as ErrorCode8, FuelError as FuelError8 } from "@fuel-ts/errors";
|
2435
2512
|
import { TransactionType as TransactionType5 } from "@fuel-ts/transactions";
|
2436
2513
|
var transactionRequestify = (obj) => {
|
2437
2514
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
@@ -2446,14 +2523,14 @@ var transactionRequestify = (obj) => {
|
|
2446
2523
|
return CreateTransactionRequest.from(obj);
|
2447
2524
|
}
|
2448
2525
|
default: {
|
2449
|
-
throw new
|
2526
|
+
throw new FuelError8(ErrorCode8.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2450
2527
|
}
|
2451
2528
|
}
|
2452
2529
|
};
|
2453
2530
|
|
2454
2531
|
// src/providers/transaction-response/transaction-response.ts
|
2455
|
-
import { ErrorCode as
|
2456
|
-
import { bn as
|
2532
|
+
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2533
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
2457
2534
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2458
2535
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2459
2536
|
|
@@ -2461,7 +2538,7 @@ import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
|
2461
2538
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2462
2539
|
|
2463
2540
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2464
|
-
import { bn as
|
2541
|
+
import { bn as bn11 } from "@fuel-ts/math";
|
2465
2542
|
import { PolicyType as PolicyType2, TransactionCoder as TransactionCoder3, TransactionType as TransactionType6 } from "@fuel-ts/transactions";
|
2466
2543
|
import { arrayify as arrayify9 } from "@fuel-ts/utils";
|
2467
2544
|
var calculateTransactionFee = (params) => {
|
@@ -2470,24 +2547,24 @@ var calculateTransactionFee = (params) => {
|
|
2470
2547
|
rawPayload,
|
2471
2548
|
consensusParameters: { gasCosts, feeParams }
|
2472
2549
|
} = params;
|
2473
|
-
const gasPerByte =
|
2474
|
-
const gasPriceFactor =
|
2550
|
+
const gasPerByte = bn11(feeParams.gasPerByte);
|
2551
|
+
const gasPriceFactor = bn11(feeParams.gasPriceFactor);
|
2475
2552
|
const transactionBytes = arrayify9(rawPayload);
|
2476
2553
|
const [transaction] = new TransactionCoder3().decode(transactionBytes, 0);
|
2477
2554
|
if (transaction.type === TransactionType6.Mint) {
|
2478
2555
|
return {
|
2479
|
-
fee:
|
2480
|
-
minFee:
|
2481
|
-
maxFee:
|
2482
|
-
feeFromGasUsed:
|
2556
|
+
fee: bn11(0),
|
2557
|
+
minFee: bn11(0),
|
2558
|
+
maxFee: bn11(0),
|
2559
|
+
feeFromGasUsed: bn11(0)
|
2483
2560
|
};
|
2484
2561
|
}
|
2485
2562
|
const { type, witnesses, inputs, policies } = transaction;
|
2486
|
-
let metadataGas =
|
2487
|
-
let gasLimit =
|
2563
|
+
let metadataGas = bn11(0);
|
2564
|
+
let gasLimit = bn11(0);
|
2488
2565
|
if (type === TransactionType6.Create) {
|
2489
2566
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2490
|
-
const contractBytesSize =
|
2567
|
+
const contractBytesSize = bn11(arrayify9(witnesses[bytecodeWitnessIndex].data).length);
|
2491
2568
|
metadataGas = calculateMetadataGasForTxCreate({
|
2492
2569
|
contractBytesSize,
|
2493
2570
|
gasCosts,
|
@@ -2506,12 +2583,12 @@ var calculateTransactionFee = (params) => {
|
|
2506
2583
|
}
|
2507
2584
|
const minGas = getMinGas({
|
2508
2585
|
gasCosts,
|
2509
|
-
gasPerByte:
|
2586
|
+
gasPerByte: bn11(gasPerByte),
|
2510
2587
|
inputs,
|
2511
2588
|
metadataGas,
|
2512
2589
|
txBytesSize: transactionBytes.length
|
2513
2590
|
});
|
2514
|
-
const gasPrice =
|
2591
|
+
const gasPrice = bn11(policies.find((policy) => policy.type === PolicyType2.GasPrice)?.data);
|
2515
2592
|
const witnessLimit = policies.find((policy) => policy.type === PolicyType2.WitnessLimit)?.data;
|
2516
2593
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2517
2594
|
const maxGas = getMaxGas({
|
@@ -2535,13 +2612,13 @@ var calculateTransactionFee = (params) => {
|
|
2535
2612
|
|
2536
2613
|
// src/providers/transaction-summary/operations.ts
|
2537
2614
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2538
|
-
import { ErrorCode as
|
2539
|
-
import { bn as
|
2540
|
-
import { ReceiptType as
|
2615
|
+
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2616
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2617
|
+
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2541
2618
|
|
2542
2619
|
// src/providers/transaction-summary/call.ts
|
2543
2620
|
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2544
|
-
import { bn as
|
2621
|
+
import { bn as bn12 } from "@fuel-ts/math";
|
2545
2622
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2546
2623
|
const abiInterface = new Interface2(abi);
|
2547
2624
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2550,7 +2627,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2550
2627
|
let encodedArgs;
|
2551
2628
|
if (functionFragment.isInputDataPointer) {
|
2552
2629
|
if (rawPayload) {
|
2553
|
-
const argsOffset =
|
2630
|
+
const argsOffset = bn12(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2554
2631
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2555
2632
|
}
|
2556
2633
|
} else {
|
@@ -2584,7 +2661,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2584
2661
|
};
|
2585
2662
|
|
2586
2663
|
// src/providers/transaction-summary/input.ts
|
2587
|
-
import { ErrorCode as
|
2664
|
+
import { ErrorCode as ErrorCode9, FuelError as FuelError9 } from "@fuel-ts/errors";
|
2588
2665
|
import { InputType as InputType5 } from "@fuel-ts/transactions";
|
2589
2666
|
function getInputsByTypes(inputs, types) {
|
2590
2667
|
return inputs.filter((i) => types.includes(i.type));
|
@@ -2622,8 +2699,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2622
2699
|
return void 0;
|
2623
2700
|
}
|
2624
2701
|
if (contractInput.type !== InputType5.Contract) {
|
2625
|
-
throw new
|
2626
|
-
|
2702
|
+
throw new FuelError9(
|
2703
|
+
ErrorCode9.INVALID_TRANSACTION_INPUT,
|
2627
2704
|
`Contract input should be of type 'contract'.`
|
2628
2705
|
);
|
2629
2706
|
}
|
@@ -2670,8 +2747,8 @@ function getTransactionTypeName(transactionType) {
|
|
2670
2747
|
case TransactionType7.Script:
|
2671
2748
|
return "Script" /* Script */;
|
2672
2749
|
default:
|
2673
|
-
throw new
|
2674
|
-
|
2750
|
+
throw new FuelError10(
|
2751
|
+
ErrorCode10.INVALID_TRANSACTION_TYPE,
|
2675
2752
|
`Invalid transaction type: ${transactionType}.`
|
2676
2753
|
);
|
2677
2754
|
}
|
@@ -2690,10 +2767,10 @@ function isTypeScript(transactionType) {
|
|
2690
2767
|
return isType(transactionType, "Script" /* Script */);
|
2691
2768
|
}
|
2692
2769
|
function getReceiptsCall(receipts) {
|
2693
|
-
return getReceiptsByType(receipts,
|
2770
|
+
return getReceiptsByType(receipts, ReceiptType4.Call);
|
2694
2771
|
}
|
2695
2772
|
function getReceiptsMessageOut(receipts) {
|
2696
|
-
return getReceiptsByType(receipts,
|
2773
|
+
return getReceiptsByType(receipts, ReceiptType4.MessageOut);
|
2697
2774
|
}
|
2698
2775
|
var mergeAssets = (op1, op2) => {
|
2699
2776
|
const assets1 = op1.assetsSent || [];
|
@@ -2706,7 +2783,7 @@ var mergeAssets = (op1, op2) => {
|
|
2706
2783
|
if (!matchingAsset) {
|
2707
2784
|
return asset1;
|
2708
2785
|
}
|
2709
|
-
const mergedAmount =
|
2786
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2710
2787
|
return { ...asset1, amount: mergedAmount };
|
2711
2788
|
});
|
2712
2789
|
return mergedAssets.concat(filteredAssets);
|
@@ -2889,11 +2966,11 @@ function getTransferOperations({
|
|
2889
2966
|
});
|
2890
2967
|
const transferReceipts = getReceiptsByType(
|
2891
2968
|
receipts,
|
2892
|
-
|
2969
|
+
ReceiptType4.Transfer
|
2893
2970
|
);
|
2894
2971
|
const transferOutReceipts = getReceiptsByType(
|
2895
2972
|
receipts,
|
2896
|
-
|
2973
|
+
ReceiptType4.TransferOut
|
2897
2974
|
);
|
2898
2975
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2899
2976
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -2978,17 +3055,17 @@ function getOperations({
|
|
2978
3055
|
}
|
2979
3056
|
|
2980
3057
|
// src/providers/transaction-summary/receipt.ts
|
2981
|
-
import { ReceiptType as
|
3058
|
+
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
2982
3059
|
var processGqlReceipt = (gqlReceipt) => {
|
2983
3060
|
const receipt = assembleReceiptByType(gqlReceipt);
|
2984
3061
|
switch (receipt.type) {
|
2985
|
-
case
|
3062
|
+
case ReceiptType5.ReturnData: {
|
2986
3063
|
return {
|
2987
3064
|
...receipt,
|
2988
3065
|
data: gqlReceipt.data || "0x"
|
2989
3066
|
};
|
2990
3067
|
}
|
2991
|
-
case
|
3068
|
+
case ReceiptType5.LogData: {
|
2992
3069
|
return {
|
2993
3070
|
...receipt,
|
2994
3071
|
data: gqlReceipt.data || "0x"
|
@@ -3001,7 +3078,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3001
3078
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3002
3079
|
const mintedAssets = [];
|
3003
3080
|
receipts.forEach((receipt) => {
|
3004
|
-
if (receipt.type ===
|
3081
|
+
if (receipt.type === ReceiptType5.Mint) {
|
3005
3082
|
mintedAssets.push({
|
3006
3083
|
subId: receipt.subId,
|
3007
3084
|
contractId: receipt.contractId,
|
@@ -3015,7 +3092,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3015
3092
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3016
3093
|
const burnedAssets = [];
|
3017
3094
|
receipts.forEach((receipt) => {
|
3018
|
-
if (receipt.type ===
|
3095
|
+
if (receipt.type === ReceiptType5.Burn) {
|
3019
3096
|
burnedAssets.push({
|
3020
3097
|
subId: receipt.subId,
|
3021
3098
|
contractId: receipt.contractId,
|
@@ -3028,7 +3105,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3028
3105
|
};
|
3029
3106
|
|
3030
3107
|
// src/providers/transaction-summary/status.ts
|
3031
|
-
import { ErrorCode as
|
3108
|
+
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3032
3109
|
var getTransactionStatusName = (gqlStatus) => {
|
3033
3110
|
switch (gqlStatus) {
|
3034
3111
|
case "FailureStatus":
|
@@ -3040,8 +3117,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3040
3117
|
case "SqueezedOutStatus":
|
3041
3118
|
return "squeezedout" /* squeezedout */;
|
3042
3119
|
default:
|
3043
|
-
throw new
|
3044
|
-
|
3120
|
+
throw new FuelError11(
|
3121
|
+
ErrorCode11.INVALID_TRANSACTION_STATUS,
|
3045
3122
|
`Invalid transaction status: ${gqlStatus}.`
|
3046
3123
|
);
|
3047
3124
|
}
|
@@ -3152,6 +3229,21 @@ function assembleTransactionSummary(params) {
|
|
3152
3229
|
return transactionSummary;
|
3153
3230
|
}
|
3154
3231
|
|
3232
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
3233
|
+
import { Interface as Interface3, BigNumberCoder } from "@fuel-ts/abi-coder";
|
3234
|
+
import { ReceiptType as ReceiptType6 } from "@fuel-ts/transactions";
|
3235
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3236
|
+
return receipts.reduce((logs, receipt) => {
|
3237
|
+
if (receipt.type === ReceiptType6.LogData || receipt.type === ReceiptType6.Log) {
|
3238
|
+
const interfaceToUse = new Interface3(externalAbis[receipt.id] || mainAbi);
|
3239
|
+
const data = receipt.type === ReceiptType6.Log ? new BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3240
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3241
|
+
logs.push(decodedLog);
|
3242
|
+
}
|
3243
|
+
return logs;
|
3244
|
+
}, []);
|
3245
|
+
}
|
3246
|
+
|
3155
3247
|
// src/providers/transaction-response/transaction-response.ts
|
3156
3248
|
var TransactionResponse = class {
|
3157
3249
|
/** Transaction ID */
|
@@ -3159,18 +3251,20 @@ var TransactionResponse = class {
|
|
3159
3251
|
/** Current provider */
|
3160
3252
|
provider;
|
3161
3253
|
/** Gas used on the transaction */
|
3162
|
-
gasUsed =
|
3254
|
+
gasUsed = bn14(0);
|
3163
3255
|
/** The graphql Transaction with receipts object. */
|
3164
3256
|
gqlTransaction;
|
3257
|
+
abis;
|
3165
3258
|
/**
|
3166
3259
|
* Constructor for `TransactionResponse`.
|
3167
3260
|
*
|
3168
3261
|
* @param id - The transaction ID.
|
3169
3262
|
* @param provider - The provider.
|
3170
3263
|
*/
|
3171
|
-
constructor(id, provider) {
|
3264
|
+
constructor(id, provider, abis) {
|
3172
3265
|
this.id = id;
|
3173
3266
|
this.provider = provider;
|
3267
|
+
this.abis = abis;
|
3174
3268
|
}
|
3175
3269
|
/**
|
3176
3270
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -3180,8 +3274,8 @@ var TransactionResponse = class {
|
|
3180
3274
|
* @param id - The transaction ID.
|
3181
3275
|
* @param provider - The provider.
|
3182
3276
|
*/
|
3183
|
-
static async create(id, provider) {
|
3184
|
-
const response = new TransactionResponse(id, provider);
|
3277
|
+
static async create(id, provider, abis) {
|
3278
|
+
const response = new TransactionResponse(id, provider, abis);
|
3185
3279
|
await response.fetch();
|
3186
3280
|
return response;
|
3187
3281
|
}
|
@@ -3262,8 +3356,8 @@ var TransactionResponse = class {
|
|
3262
3356
|
});
|
3263
3357
|
for await (const { statusChange } of subscription) {
|
3264
3358
|
if (statusChange.type === "SqueezedOutStatus") {
|
3265
|
-
throw new
|
3266
|
-
|
3359
|
+
throw new FuelError12(
|
3360
|
+
ErrorCode12.TRANSACTION_SQUEEZED_OUT,
|
3267
3361
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3268
3362
|
);
|
3269
3363
|
}
|
@@ -3285,6 +3379,26 @@ var TransactionResponse = class {
|
|
3285
3379
|
gqlTransaction: this.gqlTransaction,
|
3286
3380
|
...transactionSummary
|
3287
3381
|
};
|
3382
|
+
let logs = [];
|
3383
|
+
if (this.abis) {
|
3384
|
+
logs = getDecodedLogs(
|
3385
|
+
transactionSummary.receipts,
|
3386
|
+
this.abis.main,
|
3387
|
+
this.abis.otherContractsAbis
|
3388
|
+
);
|
3389
|
+
transactionResult.logs = logs;
|
3390
|
+
}
|
3391
|
+
if (transactionResult.isStatusFailure) {
|
3392
|
+
const {
|
3393
|
+
receipts,
|
3394
|
+
gqlTransaction: { status }
|
3395
|
+
} = transactionResult;
|
3396
|
+
throw extractTxError({
|
3397
|
+
receipts,
|
3398
|
+
status,
|
3399
|
+
logs
|
3400
|
+
});
|
3401
|
+
}
|
3288
3402
|
return transactionResult;
|
3289
3403
|
}
|
3290
3404
|
/**
|
@@ -3293,21 +3407,10 @@ var TransactionResponse = class {
|
|
3293
3407
|
* @param contractsAbiMap - The contracts ABI map.
|
3294
3408
|
*/
|
3295
3409
|
async wait(contractsAbiMap) {
|
3296
|
-
|
3297
|
-
if (result.isStatusFailure) {
|
3298
|
-
throw new FuelError11(
|
3299
|
-
ErrorCode11.TRANSACTION_FAILED,
|
3300
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3301
|
-
);
|
3302
|
-
}
|
3303
|
-
return result;
|
3410
|
+
return this.waitForResult(contractsAbiMap);
|
3304
3411
|
}
|
3305
3412
|
};
|
3306
3413
|
|
3307
|
-
// src/providers/transaction-response/getDecodedLogs.ts
|
3308
|
-
import { BigNumberCoder } from "@fuel-ts/abi-coder";
|
3309
|
-
import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
|
3310
|
-
|
3311
3414
|
// src/providers/utils/auto-retry-fetch.ts
|
3312
3415
|
function getWaitDelay(options, retryAttemptNum) {
|
3313
3416
|
const duration = options.baseDelay ?? 150;
|
@@ -3366,29 +3469,29 @@ var processGqlChain = (chain) => {
|
|
3366
3469
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3367
3470
|
return {
|
3368
3471
|
name,
|
3369
|
-
baseChainHeight:
|
3472
|
+
baseChainHeight: bn15(daHeight),
|
3370
3473
|
consensusParameters: {
|
3371
|
-
contractMaxSize:
|
3372
|
-
maxInputs:
|
3373
|
-
maxOutputs:
|
3374
|
-
maxWitnesses:
|
3375
|
-
maxGasPerTx:
|
3376
|
-
maxScriptLength:
|
3377
|
-
maxScriptDataLength:
|
3378
|
-
maxStorageSlots:
|
3379
|
-
maxPredicateLength:
|
3380
|
-
maxPredicateDataLength:
|
3381
|
-
maxGasPerPredicate:
|
3382
|
-
gasPriceFactor:
|
3383
|
-
gasPerByte:
|
3384
|
-
maxMessageDataLength:
|
3385
|
-
chainId:
|
3474
|
+
contractMaxSize: bn15(contractParams.contractMaxSize),
|
3475
|
+
maxInputs: bn15(txParams.maxInputs),
|
3476
|
+
maxOutputs: bn15(txParams.maxOutputs),
|
3477
|
+
maxWitnesses: bn15(txParams.maxWitnesses),
|
3478
|
+
maxGasPerTx: bn15(txParams.maxGasPerTx),
|
3479
|
+
maxScriptLength: bn15(scriptParams.maxScriptLength),
|
3480
|
+
maxScriptDataLength: bn15(scriptParams.maxScriptDataLength),
|
3481
|
+
maxStorageSlots: bn15(contractParams.maxStorageSlots),
|
3482
|
+
maxPredicateLength: bn15(predicateParams.maxPredicateLength),
|
3483
|
+
maxPredicateDataLength: bn15(predicateParams.maxPredicateDataLength),
|
3484
|
+
maxGasPerPredicate: bn15(predicateParams.maxGasPerPredicate),
|
3485
|
+
gasPriceFactor: bn15(feeParams.gasPriceFactor),
|
3486
|
+
gasPerByte: bn15(feeParams.gasPerByte),
|
3487
|
+
maxMessageDataLength: bn15(predicateParams.maxMessageDataLength),
|
3488
|
+
chainId: bn15(consensusParameters.chainId),
|
3386
3489
|
gasCosts
|
3387
3490
|
},
|
3388
3491
|
gasCosts,
|
3389
3492
|
latestBlock: {
|
3390
3493
|
id: latestBlock.id,
|
3391
|
-
height:
|
3494
|
+
height: bn15(latestBlock.header.height),
|
3392
3495
|
time: latestBlock.header.time,
|
3393
3496
|
transactions: latestBlock.transactions.map((i) => ({
|
3394
3497
|
id: i.id
|
@@ -3458,8 +3561,8 @@ var _Provider = class {
|
|
3458
3561
|
getChain() {
|
3459
3562
|
const chain = _Provider.chainInfoCache[this.url];
|
3460
3563
|
if (!chain) {
|
3461
|
-
throw new
|
3462
|
-
|
3564
|
+
throw new FuelError13(
|
3565
|
+
ErrorCode13.CHAIN_INFO_CACHE_EMPTY,
|
3463
3566
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3464
3567
|
);
|
3465
3568
|
}
|
@@ -3471,8 +3574,8 @@ var _Provider = class {
|
|
3471
3574
|
getNode() {
|
3472
3575
|
const node = _Provider.nodeInfoCache[this.url];
|
3473
3576
|
if (!node) {
|
3474
|
-
throw new
|
3475
|
-
|
3577
|
+
throw new FuelError13(
|
3578
|
+
ErrorCode13.NODE_INFO_CACHE_EMPTY,
|
3476
3579
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3477
3580
|
);
|
3478
3581
|
}
|
@@ -3519,8 +3622,8 @@ var _Provider = class {
|
|
3519
3622
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3520
3623
|
const { isMajorSupported, isMinorSupported, supportedVersion } = checkFuelCoreVersionCompatibility(nodeInfo.nodeVersion);
|
3521
3624
|
if (!isMajorSupported || !isMinorSupported) {
|
3522
|
-
throw new
|
3523
|
-
|
3625
|
+
throw new FuelError13(
|
3626
|
+
FuelError13.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3524
3627
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3525
3628
|
);
|
3526
3629
|
}
|
@@ -3583,7 +3686,7 @@ var _Provider = class {
|
|
3583
3686
|
*/
|
3584
3687
|
async getBlockNumber() {
|
3585
3688
|
const { chain } = await this.operations.getChain();
|
3586
|
-
return
|
3689
|
+
return bn15(chain.latestBlock.header.height, 10);
|
3587
3690
|
}
|
3588
3691
|
/**
|
3589
3692
|
* Returns the chain information.
|
@@ -3593,9 +3696,9 @@ var _Provider = class {
|
|
3593
3696
|
async fetchNode() {
|
3594
3697
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3595
3698
|
const processedNodeInfo = {
|
3596
|
-
maxDepth:
|
3597
|
-
maxTx:
|
3598
|
-
minGasPrice:
|
3699
|
+
maxDepth: bn15(nodeInfo.maxDepth),
|
3700
|
+
maxTx: bn15(nodeInfo.maxTx),
|
3701
|
+
minGasPrice: bn15(nodeInfo.minGasPrice),
|
3599
3702
|
nodeVersion: nodeInfo.nodeVersion,
|
3600
3703
|
utxoValidation: nodeInfo.utxoValidation,
|
3601
3704
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3642,12 +3745,16 @@ var _Provider = class {
|
|
3642
3745
|
await this.estimateTxDependencies(transactionRequest);
|
3643
3746
|
}
|
3644
3747
|
const encodedTransaction = hexlify12(transactionRequest.toTransactionBytes());
|
3748
|
+
let abis;
|
3749
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3750
|
+
abis = transactionRequest.abis;
|
3751
|
+
}
|
3645
3752
|
if (awaitExecution) {
|
3646
3753
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3647
3754
|
for await (const { submitAndAwait } of subscription) {
|
3648
3755
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3649
|
-
throw new
|
3650
|
-
|
3756
|
+
throw new FuelError13(
|
3757
|
+
ErrorCode13.TRANSACTION_SQUEEZED_OUT,
|
3651
3758
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3652
3759
|
);
|
3653
3760
|
}
|
@@ -3656,14 +3763,14 @@ var _Provider = class {
|
|
3656
3763
|
}
|
3657
3764
|
}
|
3658
3765
|
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
3659
|
-
const response = new TransactionResponse(transactionId2, this);
|
3766
|
+
const response = new TransactionResponse(transactionId2, this, abis);
|
3660
3767
|
await response.fetch();
|
3661
3768
|
return response;
|
3662
3769
|
}
|
3663
3770
|
const {
|
3664
3771
|
submit: { id: transactionId }
|
3665
3772
|
} = await this.operations.submit({ encodedTransaction });
|
3666
|
-
return new TransactionResponse(transactionId, this);
|
3773
|
+
return new TransactionResponse(transactionId, this, abis);
|
3667
3774
|
}
|
3668
3775
|
/**
|
3669
3776
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -3714,7 +3821,7 @@ var _Provider = class {
|
|
3714
3821
|
} = response;
|
3715
3822
|
if (inputs) {
|
3716
3823
|
inputs.forEach((input, index) => {
|
3717
|
-
if ("predicateGasUsed" in input &&
|
3824
|
+
if ("predicateGasUsed" in input && bn15(input.predicateGasUsed).gt(0)) {
|
3718
3825
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3719
3826
|
}
|
3720
3827
|
});
|
@@ -3771,6 +3878,36 @@ var _Provider = class {
|
|
3771
3878
|
missingContractIds
|
3772
3879
|
};
|
3773
3880
|
}
|
3881
|
+
/**
|
3882
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3883
|
+
* @param transactionRequest - The transaction request object.
|
3884
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3885
|
+
*/
|
3886
|
+
estimateTxGasAndFee(params) {
|
3887
|
+
const { transactionRequest } = params;
|
3888
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3889
|
+
const chainInfo = this.getChain();
|
3890
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3891
|
+
transactionRequest.gasPrice = gasPrice;
|
3892
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3893
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3894
|
+
if (transactionRequest.type === TransactionType8.Script) {
|
3895
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3896
|
+
transactionRequest.gasLimit = minGas;
|
3897
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3898
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3899
|
+
);
|
3900
|
+
}
|
3901
|
+
}
|
3902
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3903
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3904
|
+
return {
|
3905
|
+
minGas,
|
3906
|
+
minFee,
|
3907
|
+
maxGas,
|
3908
|
+
maxFee
|
3909
|
+
};
|
3910
|
+
}
|
3774
3911
|
/**
|
3775
3912
|
* Executes a signed transaction without applying the states changes
|
3776
3913
|
* on the chain.
|
@@ -3818,17 +3955,16 @@ var _Provider = class {
|
|
3818
3955
|
signatureCallback
|
3819
3956
|
} = {}) {
|
3820
3957
|
const txRequestClone = clone3(transactionRequestify(transactionRequestLike));
|
3821
|
-
const
|
3822
|
-
const
|
3823
|
-
const gasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3958
|
+
const { minGasPrice } = this.getGasConfig();
|
3959
|
+
const setGasPrice = max(txRequestClone.gasPrice, minGasPrice);
|
3824
3960
|
const isScriptTransaction = txRequestClone.type === TransactionType8.Script;
|
3825
3961
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3826
3962
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3827
3963
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3964
|
+
if (isScriptTransaction) {
|
3965
|
+
txRequestClone.gasLimit = bn15(0);
|
3966
|
+
}
|
3828
3967
|
if (estimatePredicates) {
|
3829
|
-
if (isScriptTransaction) {
|
3830
|
-
txRequestClone.gasLimit = bn14(0);
|
3831
|
-
}
|
3832
3968
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3833
3969
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3834
3970
|
}
|
@@ -3837,36 +3973,34 @@ var _Provider = class {
|
|
3837
3973
|
if (signatureCallback && isScriptTransaction) {
|
3838
3974
|
await signatureCallback(txRequestClone);
|
3839
3975
|
}
|
3840
|
-
|
3841
|
-
|
3976
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3977
|
+
transactionRequest: txRequestClone
|
3978
|
+
});
|
3842
3979
|
let receipts = [];
|
3843
3980
|
let missingContractIds = [];
|
3844
3981
|
let outputVariables = 0;
|
3982
|
+
let gasUsed = bn15(0);
|
3845
3983
|
if (isScriptTransaction && estimateTxDependencies) {
|
3846
|
-
txRequestClone.gasPrice =
|
3847
|
-
txRequestClone.gasLimit = bn14(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3984
|
+
txRequestClone.gasPrice = bn15(0);
|
3848
3985
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3849
3986
|
receipts = result.receipts;
|
3850
3987
|
outputVariables = result.outputVariables;
|
3851
3988
|
missingContractIds = result.missingContractIds;
|
3989
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
3990
|
+
txRequestClone.gasLimit = gasUsed;
|
3991
|
+
txRequestClone.gasPrice = setGasPrice;
|
3992
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3993
|
+
transactionRequest: txRequestClone
|
3994
|
+
}));
|
3852
3995
|
}
|
3853
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3854
|
-
const usedFee = calculatePriceWithFactor(
|
3855
|
-
gasUsed,
|
3856
|
-
gasPrice,
|
3857
|
-
gasPriceFactor
|
3858
|
-
).normalizeZeroToOne();
|
3859
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3860
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3861
3996
|
return {
|
3862
3997
|
requiredQuantities: allQuantities,
|
3863
3998
|
receipts,
|
3864
3999
|
gasUsed,
|
3865
4000
|
minGasPrice,
|
3866
|
-
gasPrice,
|
4001
|
+
gasPrice: setGasPrice,
|
3867
4002
|
minGas,
|
3868
4003
|
maxGas,
|
3869
|
-
usedFee,
|
3870
4004
|
minFee,
|
3871
4005
|
maxFee,
|
3872
4006
|
estimatedInputs: txRequestClone.inputs,
|
@@ -3906,11 +4040,11 @@ var _Provider = class {
|
|
3906
4040
|
return coins.map((coin) => ({
|
3907
4041
|
id: coin.utxoId,
|
3908
4042
|
assetId: coin.assetId,
|
3909
|
-
amount:
|
4043
|
+
amount: bn15(coin.amount),
|
3910
4044
|
owner: Address2.fromAddressOrString(coin.owner),
|
3911
|
-
maturity:
|
3912
|
-
blockCreated:
|
3913
|
-
txCreatedIdx:
|
4045
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4046
|
+
blockCreated: bn15(coin.blockCreated),
|
4047
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3914
4048
|
}));
|
3915
4049
|
}
|
3916
4050
|
/**
|
@@ -3947,9 +4081,9 @@ var _Provider = class {
|
|
3947
4081
|
switch (coin.__typename) {
|
3948
4082
|
case "MessageCoin":
|
3949
4083
|
return {
|
3950
|
-
amount:
|
4084
|
+
amount: bn15(coin.amount),
|
3951
4085
|
assetId: coin.assetId,
|
3952
|
-
daHeight:
|
4086
|
+
daHeight: bn15(coin.daHeight),
|
3953
4087
|
sender: Address2.fromAddressOrString(coin.sender),
|
3954
4088
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
3955
4089
|
nonce: coin.nonce
|
@@ -3957,12 +4091,12 @@ var _Provider = class {
|
|
3957
4091
|
case "Coin":
|
3958
4092
|
return {
|
3959
4093
|
id: coin.utxoId,
|
3960
|
-
amount:
|
4094
|
+
amount: bn15(coin.amount),
|
3961
4095
|
assetId: coin.assetId,
|
3962
4096
|
owner: Address2.fromAddressOrString(coin.owner),
|
3963
|
-
maturity:
|
3964
|
-
blockCreated:
|
3965
|
-
txCreatedIdx:
|
4097
|
+
maturity: bn15(coin.maturity).toNumber(),
|
4098
|
+
blockCreated: bn15(coin.blockCreated),
|
4099
|
+
txCreatedIdx: bn15(coin.txCreatedIdx)
|
3966
4100
|
};
|
3967
4101
|
default:
|
3968
4102
|
return null;
|
@@ -3979,13 +4113,13 @@ var _Provider = class {
|
|
3979
4113
|
async getBlock(idOrHeight) {
|
3980
4114
|
let variables;
|
3981
4115
|
if (typeof idOrHeight === "number") {
|
3982
|
-
variables = { height:
|
4116
|
+
variables = { height: bn15(idOrHeight).toString(10) };
|
3983
4117
|
} else if (idOrHeight === "latest") {
|
3984
4118
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
3985
4119
|
} else if (idOrHeight.length === 66) {
|
3986
4120
|
variables = { blockId: idOrHeight };
|
3987
4121
|
} else {
|
3988
|
-
variables = { blockId:
|
4122
|
+
variables = { blockId: bn15(idOrHeight).toString(10) };
|
3989
4123
|
}
|
3990
4124
|
const { block } = await this.operations.getBlock(variables);
|
3991
4125
|
if (!block) {
|
@@ -3993,7 +4127,7 @@ var _Provider = class {
|
|
3993
4127
|
}
|
3994
4128
|
return {
|
3995
4129
|
id: block.id,
|
3996
|
-
height:
|
4130
|
+
height: bn15(block.header.height),
|
3997
4131
|
time: block.header.time,
|
3998
4132
|
transactionIds: block.transactions.map((tx) => tx.id)
|
3999
4133
|
};
|
@@ -4008,7 +4142,7 @@ var _Provider = class {
|
|
4008
4142
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4009
4143
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4010
4144
|
id: block.id,
|
4011
|
-
height:
|
4145
|
+
height: bn15(block.header.height),
|
4012
4146
|
time: block.header.time,
|
4013
4147
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4014
4148
|
}));
|
@@ -4023,7 +4157,7 @@ var _Provider = class {
|
|
4023
4157
|
async getBlockWithTransactions(idOrHeight) {
|
4024
4158
|
let variables;
|
4025
4159
|
if (typeof idOrHeight === "number") {
|
4026
|
-
variables = { blockHeight:
|
4160
|
+
variables = { blockHeight: bn15(idOrHeight).toString(10) };
|
4027
4161
|
} else if (idOrHeight === "latest") {
|
4028
4162
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4029
4163
|
} else {
|
@@ -4035,7 +4169,7 @@ var _Provider = class {
|
|
4035
4169
|
}
|
4036
4170
|
return {
|
4037
4171
|
id: block.id,
|
4038
|
-
height:
|
4172
|
+
height: bn15(block.header.height, 10),
|
4039
4173
|
time: block.header.time,
|
4040
4174
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4041
4175
|
transactions: block.transactions.map(
|
@@ -4084,7 +4218,7 @@ var _Provider = class {
|
|
4084
4218
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4085
4219
|
asset: hexlify12(assetId)
|
4086
4220
|
});
|
4087
|
-
return
|
4221
|
+
return bn15(contractBalance.amount, 10);
|
4088
4222
|
}
|
4089
4223
|
/**
|
4090
4224
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4098,7 +4232,7 @@ var _Provider = class {
|
|
4098
4232
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4099
4233
|
assetId: hexlify12(assetId)
|
4100
4234
|
});
|
4101
|
-
return
|
4235
|
+
return bn15(balance.amount, 10);
|
4102
4236
|
}
|
4103
4237
|
/**
|
4104
4238
|
* Returns balances for the given owner.
|
@@ -4116,7 +4250,7 @@ var _Provider = class {
|
|
4116
4250
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4117
4251
|
return balances.map((balance) => ({
|
4118
4252
|
assetId: balance.assetId,
|
4119
|
-
amount:
|
4253
|
+
amount: bn15(balance.amount)
|
4120
4254
|
}));
|
4121
4255
|
}
|
4122
4256
|
/**
|
@@ -4138,15 +4272,15 @@ var _Provider = class {
|
|
4138
4272
|
sender: message.sender,
|
4139
4273
|
recipient: message.recipient,
|
4140
4274
|
nonce: message.nonce,
|
4141
|
-
amount:
|
4275
|
+
amount: bn15(message.amount),
|
4142
4276
|
data: message.data
|
4143
4277
|
}),
|
4144
4278
|
sender: Address2.fromAddressOrString(message.sender),
|
4145
4279
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4146
4280
|
nonce: message.nonce,
|
4147
|
-
amount:
|
4281
|
+
amount: bn15(message.amount),
|
4148
4282
|
data: InputMessageCoder.decodeData(message.data),
|
4149
|
-
daHeight:
|
4283
|
+
daHeight: bn15(message.daHeight)
|
4150
4284
|
}));
|
4151
4285
|
}
|
4152
4286
|
/**
|
@@ -4164,8 +4298,8 @@ var _Provider = class {
|
|
4164
4298
|
nonce
|
4165
4299
|
};
|
4166
4300
|
if (commitBlockId && commitBlockHeight) {
|
4167
|
-
throw new
|
4168
|
-
|
4301
|
+
throw new FuelError13(
|
4302
|
+
ErrorCode13.INVALID_INPUT_PARAMETERS,
|
4169
4303
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4170
4304
|
);
|
4171
4305
|
}
|
@@ -4199,41 +4333,41 @@ var _Provider = class {
|
|
4199
4333
|
} = result.messageProof;
|
4200
4334
|
return {
|
4201
4335
|
messageProof: {
|
4202
|
-
proofIndex:
|
4336
|
+
proofIndex: bn15(messageProof.proofIndex),
|
4203
4337
|
proofSet: messageProof.proofSet
|
4204
4338
|
},
|
4205
4339
|
blockProof: {
|
4206
|
-
proofIndex:
|
4340
|
+
proofIndex: bn15(blockProof.proofIndex),
|
4207
4341
|
proofSet: blockProof.proofSet
|
4208
4342
|
},
|
4209
4343
|
messageBlockHeader: {
|
4210
4344
|
id: messageBlockHeader.id,
|
4211
|
-
daHeight:
|
4212
|
-
transactionsCount:
|
4345
|
+
daHeight: bn15(messageBlockHeader.daHeight),
|
4346
|
+
transactionsCount: bn15(messageBlockHeader.transactionsCount),
|
4213
4347
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4214
|
-
height:
|
4348
|
+
height: bn15(messageBlockHeader.height),
|
4215
4349
|
prevRoot: messageBlockHeader.prevRoot,
|
4216
4350
|
time: messageBlockHeader.time,
|
4217
4351
|
applicationHash: messageBlockHeader.applicationHash,
|
4218
4352
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4219
|
-
messageReceiptCount:
|
4353
|
+
messageReceiptCount: bn15(messageBlockHeader.messageReceiptCount)
|
4220
4354
|
},
|
4221
4355
|
commitBlockHeader: {
|
4222
4356
|
id: commitBlockHeader.id,
|
4223
|
-
daHeight:
|
4224
|
-
transactionsCount:
|
4357
|
+
daHeight: bn15(commitBlockHeader.daHeight),
|
4358
|
+
transactionsCount: bn15(commitBlockHeader.transactionsCount),
|
4225
4359
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4226
|
-
height:
|
4360
|
+
height: bn15(commitBlockHeader.height),
|
4227
4361
|
prevRoot: commitBlockHeader.prevRoot,
|
4228
4362
|
time: commitBlockHeader.time,
|
4229
4363
|
applicationHash: commitBlockHeader.applicationHash,
|
4230
4364
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4231
|
-
messageReceiptCount:
|
4365
|
+
messageReceiptCount: bn15(commitBlockHeader.messageReceiptCount)
|
4232
4366
|
},
|
4233
4367
|
sender: Address2.fromAddressOrString(sender),
|
4234
4368
|
recipient: Address2.fromAddressOrString(recipient),
|
4235
4369
|
nonce,
|
4236
|
-
amount:
|
4370
|
+
amount: bn15(amount),
|
4237
4371
|
data
|
4238
4372
|
};
|
4239
4373
|
}
|
@@ -4256,10 +4390,10 @@ var _Provider = class {
|
|
4256
4390
|
*/
|
4257
4391
|
async produceBlocks(amount, startTime) {
|
4258
4392
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4259
|
-
blocksToProduce:
|
4393
|
+
blocksToProduce: bn15(amount).toString(10),
|
4260
4394
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4261
4395
|
});
|
4262
|
-
return
|
4396
|
+
return bn15(latestBlockHeight);
|
4263
4397
|
}
|
4264
4398
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4265
4399
|
async getTransactionResponse(transactionId) {
|
@@ -4282,8 +4416,8 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4282
4416
|
__publicField(Provider, "nodeInfoCache", {});
|
4283
4417
|
|
4284
4418
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4285
|
-
import { ErrorCode as
|
4286
|
-
import { bn as
|
4419
|
+
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4420
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
4287
4421
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4288
4422
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4289
4423
|
|
@@ -4400,7 +4534,7 @@ var Account = class extends AbstractAccount {
|
|
4400
4534
|
*/
|
4401
4535
|
get provider() {
|
4402
4536
|
if (!this._provider) {
|
4403
|
-
throw new
|
4537
|
+
throw new FuelError15(ErrorCode15.MISSING_PROVIDER, "Provider not set");
|
4404
4538
|
}
|
4405
4539
|
return this._provider;
|
4406
4540
|
}
|
@@ -4452,8 +4586,8 @@ var Account = class extends AbstractAccount {
|
|
4452
4586
|
if (!hasNextPage) {
|
4453
4587
|
break;
|
4454
4588
|
}
|
4455
|
-
throw new
|
4456
|
-
|
4589
|
+
throw new FuelError15(
|
4590
|
+
ErrorCode15.NOT_SUPPORTED,
|
4457
4591
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4458
4592
|
);
|
4459
4593
|
}
|
@@ -4478,8 +4612,8 @@ var Account = class extends AbstractAccount {
|
|
4478
4612
|
if (!hasNextPage) {
|
4479
4613
|
break;
|
4480
4614
|
}
|
4481
|
-
throw new
|
4482
|
-
|
4615
|
+
throw new FuelError15(
|
4616
|
+
ErrorCode15.NOT_SUPPORTED,
|
4483
4617
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4484
4618
|
);
|
4485
4619
|
}
|
@@ -4514,8 +4648,8 @@ var Account = class extends AbstractAccount {
|
|
4514
4648
|
if (!hasNextPage) {
|
4515
4649
|
break;
|
4516
4650
|
}
|
4517
|
-
throw new
|
4518
|
-
|
4651
|
+
throw new FuelError15(
|
4652
|
+
ErrorCode15.NOT_SUPPORTED,
|
4519
4653
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4520
4654
|
);
|
4521
4655
|
}
|
@@ -4531,7 +4665,7 @@ var Account = class extends AbstractAccount {
|
|
4531
4665
|
*/
|
4532
4666
|
async fund(request, coinQuantities, fee) {
|
4533
4667
|
const updatedQuantities = addAmountToAsset({
|
4534
|
-
amount:
|
4668
|
+
amount: bn17(fee),
|
4535
4669
|
assetId: BaseAssetId3,
|
4536
4670
|
coinQuantities
|
4537
4671
|
});
|
@@ -4539,7 +4673,7 @@ var Account = class extends AbstractAccount {
|
|
4539
4673
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4540
4674
|
quantitiesDict[assetId] = {
|
4541
4675
|
required: amount,
|
4542
|
-
owned:
|
4676
|
+
owned: bn17(0)
|
4543
4677
|
};
|
4544
4678
|
});
|
4545
4679
|
const cachedUtxos = [];
|
@@ -4552,7 +4686,7 @@ var Account = class extends AbstractAccount {
|
|
4552
4686
|
if (isCoin2) {
|
4553
4687
|
const assetId = String(input.assetId);
|
4554
4688
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4555
|
-
const amount =
|
4689
|
+
const amount = bn17(input.amount);
|
4556
4690
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4557
4691
|
cachedUtxos.push(input.id);
|
4558
4692
|
}
|
@@ -4598,8 +4732,8 @@ var Account = class extends AbstractAccount {
|
|
4598
4732
|
estimateTxDependencies: true,
|
4599
4733
|
resourcesOwner: this
|
4600
4734
|
});
|
4601
|
-
request.gasPrice =
|
4602
|
-
request.gasLimit =
|
4735
|
+
request.gasPrice = bn17(txParams.gasPrice ?? minGasPrice);
|
4736
|
+
request.gasLimit = bn17(txParams.gasLimit ?? gasUsed);
|
4603
4737
|
this.validateGas({
|
4604
4738
|
gasUsed,
|
4605
4739
|
gasPrice: request.gasPrice,
|
@@ -4620,9 +4754,9 @@ var Account = class extends AbstractAccount {
|
|
4620
4754
|
* @returns A promise that resolves to the transaction response.
|
4621
4755
|
*/
|
4622
4756
|
async transfer(destination, amount, assetId = BaseAssetId3, txParams = {}) {
|
4623
|
-
if (
|
4624
|
-
throw new
|
4625
|
-
|
4757
|
+
if (bn17(amount).lte(0)) {
|
4758
|
+
throw new FuelError15(
|
4759
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4626
4760
|
"Transfer amount must be a positive number."
|
4627
4761
|
);
|
4628
4762
|
}
|
@@ -4639,9 +4773,9 @@ var Account = class extends AbstractAccount {
|
|
4639
4773
|
* @returns A promise that resolves to the transaction response.
|
4640
4774
|
*/
|
4641
4775
|
async transferToContract(contractId, amount, assetId = BaseAssetId3, txParams = {}) {
|
4642
|
-
if (
|
4643
|
-
throw new
|
4644
|
-
|
4776
|
+
if (bn17(amount).lte(0)) {
|
4777
|
+
throw new FuelError15(
|
4778
|
+
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
4645
4779
|
"Transfer amount must be a positive number."
|
4646
4780
|
);
|
4647
4781
|
}
|
@@ -4650,7 +4784,7 @@ var Account = class extends AbstractAccount {
|
|
4650
4784
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4651
4785
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4652
4786
|
hexlifiedContractId: contractAddress.toB256(),
|
4653
|
-
amountToTransfer:
|
4787
|
+
amountToTransfer: bn17(amount),
|
4654
4788
|
assetId
|
4655
4789
|
});
|
4656
4790
|
const request = new ScriptTransactionRequest({
|
@@ -4661,9 +4795,9 @@ var Account = class extends AbstractAccount {
|
|
4661
4795
|
request.addContractInputAndOutput(contractAddress);
|
4662
4796
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4663
4797
|
request,
|
4664
|
-
[{ amount:
|
4798
|
+
[{ amount: bn17(amount), assetId: String(assetId) }]
|
4665
4799
|
);
|
4666
|
-
request.gasLimit =
|
4800
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4667
4801
|
this.validateGas({
|
4668
4802
|
gasUsed,
|
4669
4803
|
gasPrice: request.gasPrice,
|
@@ -4688,7 +4822,7 @@ var Account = class extends AbstractAccount {
|
|
4688
4822
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4689
4823
|
);
|
4690
4824
|
const amountDataArray = arrayify14(
|
4691
|
-
"0x".concat(
|
4825
|
+
"0x".concat(bn17(amount).toHex().substring(2).padStart(16, "0"))
|
4692
4826
|
);
|
4693
4827
|
const script = new Uint8Array([
|
4694
4828
|
...arrayify14(withdrawScript.bytes),
|
@@ -4697,12 +4831,12 @@ var Account = class extends AbstractAccount {
|
|
4697
4831
|
]);
|
4698
4832
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4699
4833
|
const request = new ScriptTransactionRequest(params);
|
4700
|
-
const forwardingQuantities = [{ amount:
|
4834
|
+
const forwardingQuantities = [{ amount: bn17(amount), assetId: BaseAssetId3 }];
|
4701
4835
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4702
4836
|
request,
|
4703
4837
|
forwardingQuantities
|
4704
4838
|
);
|
4705
|
-
request.gasLimit =
|
4839
|
+
request.gasLimit = bn17(params.gasLimit ?? gasUsed);
|
4706
4840
|
this.validateGas({
|
4707
4841
|
gasUsed,
|
4708
4842
|
gasPrice: request.gasPrice,
|
@@ -4714,7 +4848,7 @@ var Account = class extends AbstractAccount {
|
|
4714
4848
|
}
|
4715
4849
|
async signMessage(message) {
|
4716
4850
|
if (!this._connector) {
|
4717
|
-
throw new
|
4851
|
+
throw new FuelError15(ErrorCode15.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4718
4852
|
}
|
4719
4853
|
return this._connector.signMessage(this.address.toString(), message);
|
4720
4854
|
}
|
@@ -4726,8 +4860,8 @@ var Account = class extends AbstractAccount {
|
|
4726
4860
|
*/
|
4727
4861
|
async signTransaction(transactionRequestLike) {
|
4728
4862
|
if (!this._connector) {
|
4729
|
-
throw new
|
4730
|
-
|
4863
|
+
throw new FuelError15(
|
4864
|
+
ErrorCode15.MISSING_CONNECTOR,
|
4731
4865
|
"A connector is required to sign transactions."
|
4732
4866
|
);
|
4733
4867
|
}
|
@@ -4774,14 +4908,14 @@ var Account = class extends AbstractAccount {
|
|
4774
4908
|
minGasPrice
|
4775
4909
|
}) {
|
4776
4910
|
if (minGasPrice.gt(gasPrice)) {
|
4777
|
-
throw new
|
4778
|
-
|
4911
|
+
throw new FuelError15(
|
4912
|
+
ErrorCode15.GAS_PRICE_TOO_LOW,
|
4779
4913
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4780
4914
|
);
|
4781
4915
|
}
|
4782
4916
|
if (gasUsed.gt(gasLimit)) {
|
4783
|
-
throw new
|
4784
|
-
|
4917
|
+
throw new FuelError15(
|
4918
|
+
ErrorCode15.GAS_LIMIT_TOO_LOW,
|
4785
4919
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4786
4920
|
);
|
4787
4921
|
}
|
@@ -4790,7 +4924,7 @@ var Account = class extends AbstractAccount {
|
|
4790
4924
|
|
4791
4925
|
// src/signer/signer.ts
|
4792
4926
|
import { Address as Address4 } from "@fuel-ts/address";
|
4793
|
-
import { randomBytes } from "@fuel-ts/crypto";
|
4927
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
4794
4928
|
import { hash } from "@fuel-ts/hasher";
|
4795
4929
|
import { toBytes } from "@fuel-ts/math";
|
4796
4930
|
import { hexlify as hexlify13, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
@@ -4883,7 +5017,7 @@ var Signer = class {
|
|
4883
5017
|
* @returns random 32-byte hashed
|
4884
5018
|
*/
|
4885
5019
|
static generatePrivateKey(entropy) {
|
4886
|
-
return entropy ? hash(concat3([
|
5020
|
+
return entropy ? hash(concat3([randomBytes2(32), arrayify15(entropy)])) : randomBytes2(32);
|
4887
5021
|
}
|
4888
5022
|
/**
|
4889
5023
|
* Extended publicKey from a compact publicKey
|
@@ -4902,13 +5036,13 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
4902
5036
|
import {
|
4903
5037
|
bufferFromString,
|
4904
5038
|
keccak256,
|
4905
|
-
randomBytes as
|
5039
|
+
randomBytes as randomBytes3,
|
4906
5040
|
scrypt,
|
4907
5041
|
stringFromBuffer,
|
4908
5042
|
decryptJsonWalletData,
|
4909
5043
|
encryptJsonWalletData
|
4910
5044
|
} from "@fuel-ts/crypto";
|
4911
|
-
import { ErrorCode as
|
5045
|
+
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
4912
5046
|
import { hexlify as hexlify14 } from "@fuel-ts/utils";
|
4913
5047
|
import { v4 as uuidv4 } from "uuid";
|
4914
5048
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
@@ -4925,7 +5059,7 @@ var removeHexPrefix = (hexString) => {
|
|
4925
5059
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
4926
5060
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
4927
5061
|
const ownerAddress = Address5.fromAddressOrString(address);
|
4928
|
-
const salt =
|
5062
|
+
const salt = randomBytes3(DEFAULT_KEY_SIZE);
|
4929
5063
|
const key = scrypt({
|
4930
5064
|
password: bufferFromString(password),
|
4931
5065
|
salt,
|
@@ -4934,7 +5068,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
4934
5068
|
r: DEFAULT_KDF_PARAMS_R,
|
4935
5069
|
p: DEFAULT_KDF_PARAMS_P
|
4936
5070
|
});
|
4937
|
-
const iv =
|
5071
|
+
const iv = randomBytes3(DEFAULT_IV_SIZE);
|
4938
5072
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
4939
5073
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
4940
5074
|
const macHashUint8Array = keccak256(data);
|
@@ -4986,8 +5120,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4986
5120
|
const macHashUint8Array = keccak256(data);
|
4987
5121
|
const macHash = stringFromBuffer(macHashUint8Array, "hex");
|
4988
5122
|
if (mac !== macHash) {
|
4989
|
-
throw new
|
4990
|
-
|
5123
|
+
throw new FuelError16(
|
5124
|
+
ErrorCode16.INVALID_PASSWORD,
|
4991
5125
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
4992
5126
|
);
|
4993
5127
|
}
|
@@ -5109,15 +5243,15 @@ var BaseWalletUnlocked = class extends Account {
|
|
5109
5243
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5110
5244
|
|
5111
5245
|
// src/hdwallet/hdwallet.ts
|
5112
|
-
import { ErrorCode as
|
5246
|
+
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5113
5247
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5114
|
-
import { bn as
|
5248
|
+
import { bn as bn18, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5115
5249
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5116
5250
|
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5117
5251
|
|
5118
5252
|
// src/mnemonic/mnemonic.ts
|
5119
|
-
import { randomBytes as
|
5120
|
-
import { ErrorCode as
|
5253
|
+
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5254
|
+
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5121
5255
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5122
5256
|
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5123
5257
|
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
@@ -7175,7 +7309,7 @@ var english = [
|
|
7175
7309
|
];
|
7176
7310
|
|
7177
7311
|
// src/mnemonic/utils.ts
|
7178
|
-
import { ErrorCode as
|
7312
|
+
import { ErrorCode as ErrorCode17, FuelError as FuelError17 } from "@fuel-ts/errors";
|
7179
7313
|
import { sha256 as sha2562 } from "@fuel-ts/hasher";
|
7180
7314
|
import { arrayify as arrayify16 } from "@fuel-ts/utils";
|
7181
7315
|
function toUtf8Bytes(stri) {
|
@@ -7192,8 +7326,8 @@ function toUtf8Bytes(stri) {
|
|
7192
7326
|
i += 1;
|
7193
7327
|
const c2 = str.charCodeAt(i);
|
7194
7328
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7195
|
-
throw new
|
7196
|
-
|
7329
|
+
throw new FuelError17(
|
7330
|
+
ErrorCode17.INVALID_INPUT_PARAMETERS,
|
7197
7331
|
"Invalid UTF-8 in the input string."
|
7198
7332
|
);
|
7199
7333
|
}
|
@@ -7256,8 +7390,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7256
7390
|
for (let i = 0; i < words.length; i += 1) {
|
7257
7391
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7258
7392
|
if (index === -1) {
|
7259
|
-
throw new
|
7260
|
-
|
7393
|
+
throw new FuelError17(
|
7394
|
+
ErrorCode17.INVALID_MNEMONIC,
|
7261
7395
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7262
7396
|
);
|
7263
7397
|
}
|
@@ -7273,8 +7407,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7273
7407
|
const checksumMask = getUpperMask(checksumBits);
|
7274
7408
|
const checksum = arrayify16(sha2562(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7275
7409
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7276
|
-
throw new
|
7277
|
-
|
7410
|
+
throw new FuelError17(
|
7411
|
+
ErrorCode17.INVALID_CHECKSUM,
|
7278
7412
|
"Checksum validation failed for the provided mnemonic."
|
7279
7413
|
);
|
7280
7414
|
}
|
@@ -7288,16 +7422,16 @@ var TestnetPRV = "0x04358394";
|
|
7288
7422
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7289
7423
|
function assertWordList(wordlist) {
|
7290
7424
|
if (wordlist.length !== 2048) {
|
7291
|
-
throw new
|
7292
|
-
|
7425
|
+
throw new FuelError18(
|
7426
|
+
ErrorCode18.INVALID_WORD_LIST,
|
7293
7427
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7294
7428
|
);
|
7295
7429
|
}
|
7296
7430
|
}
|
7297
7431
|
function assertEntropy(entropy) {
|
7298
7432
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7299
|
-
throw new
|
7300
|
-
|
7433
|
+
throw new FuelError18(
|
7434
|
+
ErrorCode18.INVALID_ENTROPY,
|
7301
7435
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7302
7436
|
);
|
7303
7437
|
}
|
@@ -7307,7 +7441,7 @@ function assertMnemonic(words) {
|
|
7307
7441
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7308
7442
|
", "
|
7309
7443
|
)}] words, but got ${words.length}.`;
|
7310
|
-
throw new
|
7444
|
+
throw new FuelError18(ErrorCode18.INVALID_MNEMONIC, errorMsg);
|
7311
7445
|
}
|
7312
7446
|
}
|
7313
7447
|
var Mnemonic = class {
|
@@ -7425,8 +7559,8 @@ var Mnemonic = class {
|
|
7425
7559
|
static masterKeysFromSeed(seed) {
|
7426
7560
|
const seedArray = arrayify17(seed);
|
7427
7561
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7428
|
-
throw new
|
7429
|
-
|
7562
|
+
throw new FuelError18(
|
7563
|
+
ErrorCode18.INVALID_SEED,
|
7430
7564
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7431
7565
|
);
|
7432
7566
|
}
|
@@ -7471,7 +7605,7 @@ var Mnemonic = class {
|
|
7471
7605
|
* @returns A randomly generated mnemonic
|
7472
7606
|
*/
|
7473
7607
|
static generate(size = 32, extraEntropy = "") {
|
7474
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
7608
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes4(size), arrayify17(extraEntropy)])) : randomBytes4(size);
|
7475
7609
|
return Mnemonic.entropyToMnemonic(entropy);
|
7476
7610
|
}
|
7477
7611
|
};
|
@@ -7503,7 +7637,7 @@ function isValidExtendedKey(extendedKey) {
|
|
7503
7637
|
function parsePath(path2, depth = 0) {
|
7504
7638
|
const components = path2.split("/");
|
7505
7639
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7506
|
-
throw new
|
7640
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7507
7641
|
}
|
7508
7642
|
if (components[0] === "m") {
|
7509
7643
|
components.shift();
|
@@ -7532,8 +7666,8 @@ var HDWallet = class {
|
|
7532
7666
|
this.privateKey = hexlify17(config.privateKey);
|
7533
7667
|
} else {
|
7534
7668
|
if (!config.publicKey) {
|
7535
|
-
throw new
|
7536
|
-
|
7669
|
+
throw new FuelError19(
|
7670
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7537
7671
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7538
7672
|
);
|
7539
7673
|
}
|
@@ -7562,8 +7696,8 @@ var HDWallet = class {
|
|
7562
7696
|
const data = new Uint8Array(37);
|
7563
7697
|
if (index & HARDENED_INDEX) {
|
7564
7698
|
if (!privateKey) {
|
7565
|
-
throw new
|
7566
|
-
|
7699
|
+
throw new FuelError19(
|
7700
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7567
7701
|
"Cannot derive a hardened index without a private Key."
|
7568
7702
|
);
|
7569
7703
|
}
|
@@ -7577,7 +7711,7 @@ var HDWallet = class {
|
|
7577
7711
|
const IR = bytes.slice(32);
|
7578
7712
|
if (privateKey) {
|
7579
7713
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7580
|
-
const ki =
|
7714
|
+
const ki = bn18(IL).add(privateKey).mod(N).toBytes(32);
|
7581
7715
|
return new HDWallet({
|
7582
7716
|
privateKey: ki,
|
7583
7717
|
chainCode: IR,
|
@@ -7615,8 +7749,8 @@ var HDWallet = class {
|
|
7615
7749
|
*/
|
7616
7750
|
toExtendedKey(isPublic = false, testnet = false) {
|
7617
7751
|
if (this.depth >= 256) {
|
7618
|
-
throw new
|
7619
|
-
|
7752
|
+
throw new FuelError19(
|
7753
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7620
7754
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7621
7755
|
);
|
7622
7756
|
}
|
@@ -7647,10 +7781,10 @@ var HDWallet = class {
|
|
7647
7781
|
const bytes = arrayify18(decoded);
|
7648
7782
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7649
7783
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7650
|
-
throw new
|
7784
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7651
7785
|
}
|
7652
7786
|
if (!validChecksum) {
|
7653
|
-
throw new
|
7787
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7654
7788
|
}
|
7655
7789
|
const depth = bytes[4];
|
7656
7790
|
const parentFingerprint = hexlify17(bytes.slice(5, 9));
|
@@ -7658,14 +7792,14 @@ var HDWallet = class {
|
|
7658
7792
|
const chainCode = hexlify17(bytes.slice(13, 45));
|
7659
7793
|
const key = bytes.slice(45, 78);
|
7660
7794
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7661
|
-
throw new
|
7662
|
-
|
7795
|
+
throw new FuelError19(
|
7796
|
+
ErrorCode19.HD_WALLET_ERROR,
|
7663
7797
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7664
7798
|
);
|
7665
7799
|
}
|
7666
7800
|
if (isPublicExtendedKey(bytes)) {
|
7667
7801
|
if (key[0] !== 3) {
|
7668
|
-
throw new
|
7802
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid public extended key.");
|
7669
7803
|
}
|
7670
7804
|
return new HDWallet({
|
7671
7805
|
publicKey: key,
|
@@ -7676,7 +7810,7 @@ var HDWallet = class {
|
|
7676
7810
|
});
|
7677
7811
|
}
|
7678
7812
|
if (key[0] !== 0) {
|
7679
|
-
throw new
|
7813
|
+
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Invalid private extended key.");
|
7680
7814
|
}
|
7681
7815
|
return new HDWallet({
|
7682
7816
|
privateKey: key.slice(1),
|
@@ -7842,10 +7976,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7842
7976
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7843
7977
|
|
7844
7978
|
// src/test-utils/seedTestWallet.ts
|
7845
|
-
import { randomBytes as
|
7979
|
+
import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
|
7846
7980
|
var seedTestWallet = async (wallet, quantities) => {
|
7847
7981
|
const genesisWallet = new WalletUnlocked(
|
7848
|
-
process.env.GENESIS_SECRET ||
|
7982
|
+
process.env.GENESIS_SECRET || randomBytes5(32),
|
7849
7983
|
wallet.provider
|
7850
7984
|
);
|
7851
7985
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|