@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.js
CHANGED
@@ -58,15 +58,15 @@ module.exports = __toCommonJS(test_utils_exports);
|
|
58
58
|
|
59
59
|
// src/wallet/base-wallet-unlocked.ts
|
60
60
|
var import_hasher3 = require("@fuel-ts/hasher");
|
61
|
-
var
|
61
|
+
var import_utils31 = require("@fuel-ts/utils");
|
62
62
|
|
63
63
|
// src/account.ts
|
64
64
|
var import_address4 = require("@fuel-ts/address");
|
65
|
-
var
|
66
|
-
var
|
65
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
66
|
+
var import_errors16 = require("@fuel-ts/errors");
|
67
67
|
var import_interfaces = require("@fuel-ts/interfaces");
|
68
|
-
var
|
69
|
-
var
|
68
|
+
var import_math18 = require("@fuel-ts/math");
|
69
|
+
var import_utils28 = require("@fuel-ts/utils");
|
70
70
|
|
71
71
|
// src/providers/coin-quantity.ts
|
72
72
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -106,12 +106,12 @@ var addAmountToAsset = (params) => {
|
|
106
106
|
|
107
107
|
// src/providers/provider.ts
|
108
108
|
var import_address3 = require("@fuel-ts/address");
|
109
|
-
var
|
110
|
-
var
|
111
|
-
var
|
112
|
-
var
|
109
|
+
var import_errors14 = require("@fuel-ts/errors");
|
110
|
+
var import_math15 = require("@fuel-ts/math");
|
111
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
112
|
+
var import_utils23 = require("@fuel-ts/utils");
|
113
113
|
var import_versions = require("@fuel-ts/versions");
|
114
|
-
var
|
114
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
115
115
|
var import_ethers = require("ethers");
|
116
116
|
var import_graphql_request = require("graphql-request");
|
117
117
|
var import_ramda3 = require("ramda");
|
@@ -1051,6 +1051,7 @@ var MemoryCache = class {
|
|
1051
1051
|
};
|
1052
1052
|
|
1053
1053
|
// src/providers/transaction-request/input.ts
|
1054
|
+
var import_abi_coder = require("@fuel-ts/abi-coder");
|
1054
1055
|
var import_configs2 = require("@fuel-ts/address/configs");
|
1055
1056
|
var import_errors3 = require("@fuel-ts/errors");
|
1056
1057
|
var import_math2 = require("@fuel-ts/math");
|
@@ -1064,8 +1065,8 @@ var inputify = (value) => {
|
|
1064
1065
|
const predicateData = (0, import_utils3.arrayify)(value.predicateData ?? "0x");
|
1065
1066
|
return {
|
1066
1067
|
type: import_transactions.InputType.Coin,
|
1067
|
-
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0,
|
1068
|
-
outputIndex: (0, import_utils3.arrayify)(value.id)
|
1068
|
+
txID: (0, import_utils3.hexlify)((0, import_utils3.arrayify)(value.id).slice(0, import_abi_coder.BYTES_32)),
|
1069
|
+
outputIndex: (0, import_math2.toNumber)((0, import_utils3.arrayify)(value.id).slice(import_abi_coder.BYTES_32, import_abi_coder.UTXO_ID_LEN)),
|
1069
1070
|
owner: (0, import_utils3.hexlify)(value.owner),
|
1070
1071
|
amount: (0, import_math2.bn)(value.amount),
|
1071
1072
|
assetId: (0, import_utils3.hexlify)(value.assetId),
|
@@ -1183,10 +1184,12 @@ var outputify = (value) => {
|
|
1183
1184
|
};
|
1184
1185
|
|
1185
1186
|
// src/providers/transaction-request/transaction-request.ts
|
1187
|
+
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
1186
1188
|
var import_address = require("@fuel-ts/address");
|
1187
|
-
var
|
1188
|
-
var
|
1189
|
-
var
|
1189
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1190
|
+
var import_crypto = require("@fuel-ts/crypto");
|
1191
|
+
var import_math7 = require("@fuel-ts/math");
|
1192
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1190
1193
|
var import_utils9 = require("@fuel-ts/utils");
|
1191
1194
|
|
1192
1195
|
// src/providers/resource.ts
|
@@ -1517,6 +1520,78 @@ function sleep(time) {
|
|
1517
1520
|
});
|
1518
1521
|
}
|
1519
1522
|
|
1523
|
+
// src/providers/utils/extract-tx-error.ts
|
1524
|
+
var import_errors7 = require("@fuel-ts/errors");
|
1525
|
+
var import_math6 = require("@fuel-ts/math");
|
1526
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1527
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1528
|
+
var assemblePanicError = (status) => {
|
1529
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1530
|
+
const reason = status.reason;
|
1531
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1532
|
+
errorMessage = `${errorMessage}
|
1533
|
+
|
1534
|
+
You can read more about this error at:
|
1535
|
+
|
1536
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1537
|
+
}
|
1538
|
+
return { errorMessage, reason };
|
1539
|
+
};
|
1540
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1541
|
+
var assembleRevertError = (receipts, logs) => {
|
1542
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1543
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1544
|
+
let reason = "";
|
1545
|
+
if (revertReceipt) {
|
1546
|
+
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1547
|
+
switch (reasonHex) {
|
1548
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1549
|
+
reason = "require";
|
1550
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1551
|
+
break;
|
1552
|
+
}
|
1553
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1554
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1555
|
+
reason = "assert_eq";
|
1556
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1557
|
+
break;
|
1558
|
+
}
|
1559
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1560
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1561
|
+
reason = "assert_ne";
|
1562
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1563
|
+
break;
|
1564
|
+
}
|
1565
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1566
|
+
reason = "assert";
|
1567
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1568
|
+
break;
|
1569
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1570
|
+
reason = "MissingOutputChange";
|
1571
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1572
|
+
break;
|
1573
|
+
default:
|
1574
|
+
reason = "unknown";
|
1575
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1576
|
+
}
|
1577
|
+
}
|
1578
|
+
return { errorMessage, reason };
|
1579
|
+
};
|
1580
|
+
var extractTxError = (params) => {
|
1581
|
+
const { receipts, status, logs } = params;
|
1582
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1583
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1584
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1585
|
+
const metadata = {
|
1586
|
+
logs,
|
1587
|
+
receipts,
|
1588
|
+
panic: isPanic,
|
1589
|
+
revert: isRevert,
|
1590
|
+
reason
|
1591
|
+
};
|
1592
|
+
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1593
|
+
};
|
1594
|
+
|
1520
1595
|
// src/providers/transaction-request/errors.ts
|
1521
1596
|
var NoWitnessAtIndexError = class extends Error {
|
1522
1597
|
constructor(index) {
|
@@ -1567,10 +1642,10 @@ var BaseTransactionRequest = class {
|
|
1567
1642
|
outputs,
|
1568
1643
|
witnesses
|
1569
1644
|
} = {}) {
|
1570
|
-
this.gasPrice = (0,
|
1645
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1571
1646
|
this.maturity = maturity ?? 0;
|
1572
|
-
this.witnessLimit = witnessLimit ? (0,
|
1573
|
-
this.maxFee = maxFee ? (0,
|
1647
|
+
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1648
|
+
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1574
1649
|
this.inputs = inputs ?? [];
|
1575
1650
|
this.outputs = outputs ?? [];
|
1576
1651
|
this.witnesses = witnesses ?? [];
|
@@ -1579,20 +1654,20 @@ var BaseTransactionRequest = class {
|
|
1579
1654
|
let policyTypes = 0;
|
1580
1655
|
const policies = [];
|
1581
1656
|
if (req.gasPrice) {
|
1582
|
-
policyTypes +=
|
1583
|
-
policies.push({ data: req.gasPrice, type:
|
1657
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1658
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1584
1659
|
}
|
1585
1660
|
if (req.witnessLimit) {
|
1586
|
-
policyTypes +=
|
1587
|
-
policies.push({ data: req.witnessLimit, type:
|
1661
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1662
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1588
1663
|
}
|
1589
1664
|
if (req.maturity > 0) {
|
1590
|
-
policyTypes +=
|
1591
|
-
policies.push({ data: req.maturity, type:
|
1665
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1666
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1592
1667
|
}
|
1593
1668
|
if (req.maxFee) {
|
1594
|
-
policyTypes +=
|
1595
|
-
policies.push({ data: req.maxFee, type:
|
1669
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1670
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1596
1671
|
}
|
1597
1672
|
return {
|
1598
1673
|
policyTypes,
|
@@ -1626,7 +1701,7 @@ var BaseTransactionRequest = class {
|
|
1626
1701
|
* @returns The transaction bytes.
|
1627
1702
|
*/
|
1628
1703
|
toTransactionBytes() {
|
1629
|
-
return new
|
1704
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1630
1705
|
}
|
1631
1706
|
/**
|
1632
1707
|
* @hidden
|
@@ -1666,7 +1741,7 @@ var BaseTransactionRequest = class {
|
|
1666
1741
|
* @returns The index of the created witness.
|
1667
1742
|
*/
|
1668
1743
|
addEmptyWitness() {
|
1669
|
-
this.addWitness((0, import_utils9.concat)([
|
1744
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1670
1745
|
return this.witnesses.length - 1;
|
1671
1746
|
}
|
1672
1747
|
/**
|
@@ -1717,7 +1792,7 @@ var BaseTransactionRequest = class {
|
|
1717
1792
|
*/
|
1718
1793
|
getCoinInputs() {
|
1719
1794
|
return this.inputs.filter(
|
1720
|
-
(input) => input.type ===
|
1795
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1721
1796
|
);
|
1722
1797
|
}
|
1723
1798
|
/**
|
@@ -1727,7 +1802,7 @@ var BaseTransactionRequest = class {
|
|
1727
1802
|
*/
|
1728
1803
|
getCoinOutputs() {
|
1729
1804
|
return this.outputs.filter(
|
1730
|
-
(output) => output.type ===
|
1805
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1731
1806
|
);
|
1732
1807
|
}
|
1733
1808
|
/**
|
@@ -1737,7 +1812,7 @@ var BaseTransactionRequest = class {
|
|
1737
1812
|
*/
|
1738
1813
|
getChangeOutputs() {
|
1739
1814
|
return this.outputs.filter(
|
1740
|
-
(output) => output.type ===
|
1815
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1741
1816
|
);
|
1742
1817
|
}
|
1743
1818
|
/**
|
@@ -1749,9 +1824,9 @@ var BaseTransactionRequest = class {
|
|
1749
1824
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1750
1825
|
const found = this.inputs.find((input) => {
|
1751
1826
|
switch (input.type) {
|
1752
|
-
case
|
1827
|
+
case import_transactions6.InputType.Coin:
|
1753
1828
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1754
|
-
case
|
1829
|
+
case import_transactions6.InputType.Message:
|
1755
1830
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1756
1831
|
default:
|
1757
1832
|
return false;
|
@@ -1780,14 +1855,13 @@ var BaseTransactionRequest = class {
|
|
1780
1855
|
}
|
1781
1856
|
const input = {
|
1782
1857
|
...coin,
|
1783
|
-
type:
|
1858
|
+
type: import_transactions6.InputType.Coin,
|
1784
1859
|
owner: owner.toB256(),
|
1785
1860
|
amount,
|
1786
1861
|
assetId,
|
1787
1862
|
txPointer: "0x00000000000000000000000000000000",
|
1788
1863
|
witnessIndex,
|
1789
|
-
predicate: predicate?.bytes
|
1790
|
-
predicateData: predicate?.predicateDataBytes
|
1864
|
+
predicate: predicate?.bytes
|
1791
1865
|
};
|
1792
1866
|
this.pushInput(input);
|
1793
1867
|
this.addChangeOutput(owner, assetId);
|
@@ -1802,7 +1876,7 @@ var BaseTransactionRequest = class {
|
|
1802
1876
|
*/
|
1803
1877
|
addMessageInput(message, predicate) {
|
1804
1878
|
const { recipient, sender, amount } = message;
|
1805
|
-
const assetId =
|
1879
|
+
const assetId = import_configs7.BaseAssetId;
|
1806
1880
|
let witnessIndex;
|
1807
1881
|
if (predicate) {
|
1808
1882
|
witnessIndex = 0;
|
@@ -1814,13 +1888,12 @@ var BaseTransactionRequest = class {
|
|
1814
1888
|
}
|
1815
1889
|
const input = {
|
1816
1890
|
...message,
|
1817
|
-
type:
|
1891
|
+
type: import_transactions6.InputType.Message,
|
1818
1892
|
sender: sender.toB256(),
|
1819
1893
|
recipient: recipient.toB256(),
|
1820
1894
|
amount,
|
1821
1895
|
witnessIndex,
|
1822
|
-
predicate: predicate?.bytes
|
1823
|
-
predicateData: predicate?.predicateDataBytes
|
1896
|
+
predicate: predicate?.bytes
|
1824
1897
|
};
|
1825
1898
|
this.pushInput(input);
|
1826
1899
|
this.addChangeOutput(recipient, assetId);
|
@@ -1884,9 +1957,9 @@ var BaseTransactionRequest = class {
|
|
1884
1957
|
* @param amount - Amount of coin.
|
1885
1958
|
* @param assetId - Asset ID of coin.
|
1886
1959
|
*/
|
1887
|
-
addCoinOutput(to, amount, assetId =
|
1960
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1888
1961
|
this.pushOutput({
|
1889
|
-
type:
|
1962
|
+
type: import_transactions6.OutputType.Coin,
|
1890
1963
|
to: (0, import_address.addressify)(to).toB256(),
|
1891
1964
|
amount,
|
1892
1965
|
assetId
|
@@ -1902,7 +1975,7 @@ var BaseTransactionRequest = class {
|
|
1902
1975
|
addCoinOutputs(to, quantities) {
|
1903
1976
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
1904
1977
|
this.pushOutput({
|
1905
|
-
type:
|
1978
|
+
type: import_transactions6.OutputType.Coin,
|
1906
1979
|
to: (0, import_address.addressify)(to).toB256(),
|
1907
1980
|
amount: quantity.amount,
|
1908
1981
|
assetId: quantity.assetId
|
@@ -1916,13 +1989,13 @@ var BaseTransactionRequest = class {
|
|
1916
1989
|
* @param to - Address of the owner.
|
1917
1990
|
* @param assetId - Asset ID of coin.
|
1918
1991
|
*/
|
1919
|
-
addChangeOutput(to, assetId =
|
1992
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1920
1993
|
const changeOutput = this.getChangeOutputs().find(
|
1921
1994
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1922
1995
|
);
|
1923
1996
|
if (!changeOutput) {
|
1924
1997
|
this.pushOutput({
|
1925
|
-
type:
|
1998
|
+
type: import_transactions6.OutputType.Change,
|
1926
1999
|
to: (0, import_address.addressify)(to).toB256(),
|
1927
2000
|
assetId
|
1928
2001
|
});
|
@@ -1975,12 +2048,6 @@ var BaseTransactionRequest = class {
|
|
1975
2048
|
* @param quantities - CoinQuantity Array.
|
1976
2049
|
*/
|
1977
2050
|
fundWithFakeUtxos(quantities, resourcesOwner) {
|
1978
|
-
let idCounter = 0;
|
1979
|
-
const generateId = () => {
|
1980
|
-
const counterString = String(idCounter++);
|
1981
|
-
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
1982
|
-
return id;
|
1983
|
-
};
|
1984
2051
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
1985
2052
|
if ("assetId" in input) {
|
1986
2053
|
return input.assetId === assetId;
|
@@ -1990,23 +2057,23 @@ var BaseTransactionRequest = class {
|
|
1990
2057
|
const updateAssetInput = (assetId, quantity) => {
|
1991
2058
|
const assetInput = findAssetInput(assetId);
|
1992
2059
|
if (assetInput && "assetId" in assetInput) {
|
1993
|
-
assetInput.id =
|
2060
|
+
assetInput.id = (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN));
|
1994
2061
|
assetInput.amount = quantity;
|
1995
2062
|
} else {
|
1996
2063
|
this.addResources([
|
1997
2064
|
{
|
1998
|
-
id:
|
2065
|
+
id: (0, import_utils9.hexlify)((0, import_crypto.randomBytes)(import_abi_coder2.UTXO_ID_LEN)),
|
1999
2066
|
amount: quantity,
|
2000
2067
|
assetId,
|
2001
2068
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2002
2069
|
maturity: 0,
|
2003
|
-
blockCreated: (0,
|
2004
|
-
txCreatedIdx: (0,
|
2070
|
+
blockCreated: (0, import_math7.bn)(1),
|
2071
|
+
txCreatedIdx: (0, import_math7.bn)(1)
|
2005
2072
|
}
|
2006
2073
|
]);
|
2007
2074
|
}
|
2008
2075
|
};
|
2009
|
-
updateAssetInput(
|
2076
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2010
2077
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2011
2078
|
}
|
2012
2079
|
/**
|
@@ -2017,7 +2084,7 @@ var BaseTransactionRequest = class {
|
|
2017
2084
|
*/
|
2018
2085
|
getCoinOutputsQuantities() {
|
2019
2086
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2020
|
-
amount: (0,
|
2087
|
+
amount: (0, import_math7.bn)(amount),
|
2021
2088
|
assetId: assetId.toString()
|
2022
2089
|
}));
|
2023
2090
|
return coinsQuantities;
|
@@ -2035,18 +2102,18 @@ var BaseTransactionRequest = class {
|
|
2035
2102
|
this.inputs.forEach((i) => {
|
2036
2103
|
let correspondingInput;
|
2037
2104
|
switch (i.type) {
|
2038
|
-
case
|
2039
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2105
|
+
case import_transactions6.InputType.Coin:
|
2106
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2040
2107
|
break;
|
2041
|
-
case
|
2108
|
+
case import_transactions6.InputType.Message:
|
2042
2109
|
correspondingInput = inputs.find(
|
2043
|
-
(x) => x.type ===
|
2110
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2044
2111
|
);
|
2045
2112
|
break;
|
2046
2113
|
default:
|
2047
2114
|
return;
|
2048
2115
|
}
|
2049
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2116
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2050
2117
|
i.predicate = correspondingInput.predicate;
|
2051
2118
|
i.predicateData = correspondingInput.predicateData;
|
2052
2119
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2056,47 +2123,47 @@ var BaseTransactionRequest = class {
|
|
2056
2123
|
};
|
2057
2124
|
|
2058
2125
|
// src/providers/transaction-request/create-transaction-request.ts
|
2059
|
-
var
|
2060
|
-
var
|
2061
|
-
var
|
2126
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2127
|
+
var import_math9 = require("@fuel-ts/math");
|
2128
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2062
2129
|
var import_utils13 = require("@fuel-ts/utils");
|
2063
2130
|
|
2064
2131
|
// src/providers/transaction-request/hash-transaction.ts
|
2065
|
-
var
|
2132
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2066
2133
|
var import_hasher = require("@fuel-ts/hasher");
|
2067
|
-
var
|
2068
|
-
var
|
2134
|
+
var import_math8 = require("@fuel-ts/math");
|
2135
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2069
2136
|
var import_utils11 = require("@fuel-ts/utils");
|
2070
2137
|
var import_ramda2 = require("ramda");
|
2071
2138
|
function hashTransaction(transactionRequest, chainId) {
|
2072
2139
|
const transaction = transactionRequest.toTransaction();
|
2073
|
-
if (transaction.type ===
|
2074
|
-
transaction.receiptsRoot =
|
2140
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2141
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2075
2142
|
}
|
2076
2143
|
transaction.inputs = transaction.inputs.map((input) => {
|
2077
2144
|
const inputClone = (0, import_ramda2.clone)(input);
|
2078
2145
|
switch (inputClone.type) {
|
2079
|
-
case
|
2146
|
+
case import_transactions7.InputType.Coin: {
|
2080
2147
|
inputClone.txPointer = {
|
2081
2148
|
blockHeight: 0,
|
2082
2149
|
txIndex: 0
|
2083
2150
|
};
|
2084
|
-
inputClone.predicateGasUsed = (0,
|
2151
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2085
2152
|
return inputClone;
|
2086
2153
|
}
|
2087
|
-
case
|
2088
|
-
inputClone.predicateGasUsed = (0,
|
2154
|
+
case import_transactions7.InputType.Message: {
|
2155
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2089
2156
|
return inputClone;
|
2090
2157
|
}
|
2091
|
-
case
|
2158
|
+
case import_transactions7.InputType.Contract: {
|
2092
2159
|
inputClone.txPointer = {
|
2093
2160
|
blockHeight: 0,
|
2094
2161
|
txIndex: 0
|
2095
2162
|
};
|
2096
|
-
inputClone.txID =
|
2163
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2097
2164
|
inputClone.outputIndex = 0;
|
2098
|
-
inputClone.balanceRoot =
|
2099
|
-
inputClone.stateRoot =
|
2165
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2166
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2100
2167
|
return inputClone;
|
2101
2168
|
}
|
2102
2169
|
default:
|
@@ -2106,19 +2173,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2106
2173
|
transaction.outputs = transaction.outputs.map((output) => {
|
2107
2174
|
const outputClone = (0, import_ramda2.clone)(output);
|
2108
2175
|
switch (outputClone.type) {
|
2109
|
-
case
|
2110
|
-
outputClone.balanceRoot =
|
2111
|
-
outputClone.stateRoot =
|
2176
|
+
case import_transactions7.OutputType.Contract: {
|
2177
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2178
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2112
2179
|
return outputClone;
|
2113
2180
|
}
|
2114
|
-
case
|
2115
|
-
outputClone.amount = (0,
|
2181
|
+
case import_transactions7.OutputType.Change: {
|
2182
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2116
2183
|
return outputClone;
|
2117
2184
|
}
|
2118
|
-
case
|
2119
|
-
outputClone.to =
|
2120
|
-
outputClone.amount = (0,
|
2121
|
-
outputClone.assetId =
|
2185
|
+
case import_transactions7.OutputType.Variable: {
|
2186
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2187
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2188
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2122
2189
|
return outputClone;
|
2123
2190
|
}
|
2124
2191
|
default:
|
@@ -2128,7 +2195,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2128
2195
|
transaction.witnessesCount = 0;
|
2129
2196
|
transaction.witnesses = [];
|
2130
2197
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2131
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2198
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2132
2199
|
return (0, import_hasher.sha256)(concatenatedData);
|
2133
2200
|
}
|
2134
2201
|
|
@@ -2164,7 +2231,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2164
2231
|
return new this(obj);
|
2165
2232
|
}
|
2166
2233
|
/** Type of the transaction */
|
2167
|
-
type =
|
2234
|
+
type = import_transactions8.TransactionType.Create;
|
2168
2235
|
/** Witness index of contract bytecode to create */
|
2169
2236
|
bytecodeWitnessIndex;
|
2170
2237
|
/** Salt */
|
@@ -2184,7 +2251,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2184
2251
|
} = {}) {
|
2185
2252
|
super(rest);
|
2186
2253
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2187
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2254
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2188
2255
|
this.storageSlots = [...storageSlots ?? []];
|
2189
2256
|
}
|
2190
2257
|
/**
|
@@ -2197,12 +2264,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2197
2264
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2198
2265
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2199
2266
|
return {
|
2200
|
-
type:
|
2267
|
+
type: import_transactions8.TransactionType.Create,
|
2201
2268
|
...baseTransaction,
|
2202
2269
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2203
2270
|
bytecodeWitnessIndex,
|
2204
2271
|
storageSlotsCount: storageSlots.length,
|
2205
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2272
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2206
2273
|
storageSlots
|
2207
2274
|
};
|
2208
2275
|
}
|
@@ -2213,7 +2280,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2213
2280
|
*/
|
2214
2281
|
getContractCreatedOutputs() {
|
2215
2282
|
return this.outputs.filter(
|
2216
|
-
(output) => output.type ===
|
2283
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2217
2284
|
);
|
2218
2285
|
}
|
2219
2286
|
/**
|
@@ -2234,14 +2301,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2234
2301
|
*/
|
2235
2302
|
addContractCreatedOutput(contractId, stateRoot) {
|
2236
2303
|
this.pushOutput({
|
2237
|
-
type:
|
2304
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2238
2305
|
contractId,
|
2239
2306
|
stateRoot
|
2240
2307
|
});
|
2241
2308
|
}
|
2242
2309
|
metadataGas(gasCosts) {
|
2243
2310
|
return calculateMetadataGasForTxCreate({
|
2244
|
-
contractBytesSize: (0,
|
2311
|
+
contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2245
2312
|
gasCosts,
|
2246
2313
|
stateRootSize: this.storageSlots.length,
|
2247
2314
|
txBytesSize: this.byteSize()
|
@@ -2250,11 +2317,11 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2250
2317
|
};
|
2251
2318
|
|
2252
2319
|
// src/providers/transaction-request/script-transaction-request.ts
|
2253
|
-
var
|
2320
|
+
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
2254
2321
|
var import_address2 = require("@fuel-ts/address");
|
2255
|
-
var
|
2256
|
-
var
|
2257
|
-
var
|
2322
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2323
|
+
var import_math10 = require("@fuel-ts/math");
|
2324
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2258
2325
|
var import_utils15 = require("@fuel-ts/utils");
|
2259
2326
|
|
2260
2327
|
// src/providers/transaction-request/scripts.ts
|
@@ -2292,13 +2359,14 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2292
2359
|
return new this(obj);
|
2293
2360
|
}
|
2294
2361
|
/** Type of the transaction */
|
2295
|
-
type =
|
2362
|
+
type = import_transactions9.TransactionType.Script;
|
2296
2363
|
/** Gas limit for transaction */
|
2297
2364
|
gasLimit;
|
2298
2365
|
/** Script to execute */
|
2299
2366
|
script;
|
2300
2367
|
/** Script input data (parameters) */
|
2301
2368
|
scriptData;
|
2369
|
+
abis;
|
2302
2370
|
/**
|
2303
2371
|
* Constructor for `ScriptTransactionRequest`.
|
2304
2372
|
*
|
@@ -2306,9 +2374,10 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2306
2374
|
*/
|
2307
2375
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2308
2376
|
super(rest);
|
2309
|
-
this.gasLimit = (0,
|
2377
|
+
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2310
2378
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2311
2379
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2380
|
+
this.abis = rest.abis;
|
2312
2381
|
}
|
2313
2382
|
/**
|
2314
2383
|
* Converts the transaction request to a `TransactionScript`.
|
@@ -2319,12 +2388,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2319
2388
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2320
2389
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2321
2390
|
return {
|
2322
|
-
type:
|
2391
|
+
type: import_transactions9.TransactionType.Script,
|
2323
2392
|
scriptGasLimit: this.gasLimit,
|
2324
2393
|
...super.getBaseTransaction(),
|
2325
2394
|
scriptLength: script.length,
|
2326
2395
|
scriptDataLength: scriptData.length,
|
2327
|
-
receiptsRoot:
|
2396
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2328
2397
|
script: (0, import_utils15.hexlify)(script),
|
2329
2398
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2330
2399
|
};
|
@@ -2336,7 +2405,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2336
2405
|
*/
|
2337
2406
|
getContractInputs() {
|
2338
2407
|
return this.inputs.filter(
|
2339
|
-
(input) => input.type ===
|
2408
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2340
2409
|
);
|
2341
2410
|
}
|
2342
2411
|
/**
|
@@ -2346,7 +2415,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2346
2415
|
*/
|
2347
2416
|
getContractOutputs() {
|
2348
2417
|
return this.outputs.filter(
|
2349
|
-
(output) => output.type ===
|
2418
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2350
2419
|
);
|
2351
2420
|
}
|
2352
2421
|
/**
|
@@ -2356,7 +2425,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2356
2425
|
*/
|
2357
2426
|
getVariableOutputs() {
|
2358
2427
|
return this.outputs.filter(
|
2359
|
-
(output) => output.type ===
|
2428
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2360
2429
|
);
|
2361
2430
|
}
|
2362
2431
|
/**
|
@@ -2379,7 +2448,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2379
2448
|
let outputsNumber = numberOfVariables;
|
2380
2449
|
while (outputsNumber) {
|
2381
2450
|
this.pushOutput({
|
2382
|
-
type:
|
2451
|
+
type: import_transactions9.OutputType.Variable
|
2383
2452
|
});
|
2384
2453
|
outputsNumber -= 1;
|
2385
2454
|
}
|
@@ -2412,12 +2481,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2412
2481
|
return this;
|
2413
2482
|
}
|
2414
2483
|
const inputIndex = super.pushInput({
|
2415
|
-
type:
|
2484
|
+
type: import_transactions9.InputType.Contract,
|
2416
2485
|
contractId: contractAddress.toB256(),
|
2417
2486
|
txPointer: "0x00000000000000000000000000000000"
|
2418
2487
|
});
|
2419
2488
|
this.pushOutput({
|
2420
|
-
type:
|
2489
|
+
type: import_transactions9.OutputType.Contract,
|
2421
2490
|
inputIndex
|
2422
2491
|
});
|
2423
2492
|
return this;
|
@@ -2440,7 +2509,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2440
2509
|
* @returns The current instance of the `ScriptTransactionRequest`.
|
2441
2510
|
*/
|
2442
2511
|
setData(abi, args) {
|
2443
|
-
const abiInterface = new
|
2512
|
+
const abiInterface = new import_abi_coder3.Interface(abi);
|
2444
2513
|
this.scriptData = abiInterface.functions.main.encodeArguments(args);
|
2445
2514
|
return this;
|
2446
2515
|
}
|
@@ -2453,38 +2522,38 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2453
2522
|
};
|
2454
2523
|
|
2455
2524
|
// src/providers/transaction-request/utils.ts
|
2456
|
-
var
|
2457
|
-
var
|
2525
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2526
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2458
2527
|
var transactionRequestify = (obj) => {
|
2459
2528
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2460
2529
|
return obj;
|
2461
2530
|
}
|
2462
2531
|
const { type } = obj;
|
2463
2532
|
switch (obj.type) {
|
2464
|
-
case
|
2533
|
+
case import_transactions10.TransactionType.Script: {
|
2465
2534
|
return ScriptTransactionRequest.from(obj);
|
2466
2535
|
}
|
2467
|
-
case
|
2536
|
+
case import_transactions10.TransactionType.Create: {
|
2468
2537
|
return CreateTransactionRequest.from(obj);
|
2469
2538
|
}
|
2470
2539
|
default: {
|
2471
|
-
throw new
|
2540
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2472
2541
|
}
|
2473
2542
|
}
|
2474
2543
|
};
|
2475
2544
|
|
2476
2545
|
// src/providers/transaction-response/transaction-response.ts
|
2477
|
-
var
|
2478
|
-
var
|
2479
|
-
var
|
2546
|
+
var import_errors13 = require("@fuel-ts/errors");
|
2547
|
+
var import_math14 = require("@fuel-ts/math");
|
2548
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2480
2549
|
var import_utils21 = require("@fuel-ts/utils");
|
2481
2550
|
|
2482
2551
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2483
2552
|
var import_utils19 = require("@fuel-ts/utils");
|
2484
2553
|
|
2485
2554
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2486
|
-
var
|
2487
|
-
var
|
2555
|
+
var import_math11 = require("@fuel-ts/math");
|
2556
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2488
2557
|
var import_utils16 = require("@fuel-ts/utils");
|
2489
2558
|
var calculateTransactionFee = (params) => {
|
2490
2559
|
const {
|
@@ -2492,24 +2561,24 @@ var calculateTransactionFee = (params) => {
|
|
2492
2561
|
rawPayload,
|
2493
2562
|
consensusParameters: { gasCosts, feeParams }
|
2494
2563
|
} = params;
|
2495
|
-
const gasPerByte = (0,
|
2496
|
-
const gasPriceFactor = (0,
|
2564
|
+
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2565
|
+
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2497
2566
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2498
|
-
const [transaction] = new
|
2499
|
-
if (transaction.type ===
|
2567
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2568
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2500
2569
|
return {
|
2501
|
-
fee: (0,
|
2502
|
-
minFee: (0,
|
2503
|
-
maxFee: (0,
|
2504
|
-
feeFromGasUsed: (0,
|
2570
|
+
fee: (0, import_math11.bn)(0),
|
2571
|
+
minFee: (0, import_math11.bn)(0),
|
2572
|
+
maxFee: (0, import_math11.bn)(0),
|
2573
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2505
2574
|
};
|
2506
2575
|
}
|
2507
2576
|
const { type, witnesses, inputs, policies } = transaction;
|
2508
|
-
let metadataGas = (0,
|
2509
|
-
let gasLimit = (0,
|
2510
|
-
if (type ===
|
2577
|
+
let metadataGas = (0, import_math11.bn)(0);
|
2578
|
+
let gasLimit = (0, import_math11.bn)(0);
|
2579
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2511
2580
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2512
|
-
const contractBytesSize = (0,
|
2581
|
+
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2513
2582
|
metadataGas = calculateMetadataGasForTxCreate({
|
2514
2583
|
contractBytesSize,
|
2515
2584
|
gasCosts,
|
@@ -2528,13 +2597,13 @@ var calculateTransactionFee = (params) => {
|
|
2528
2597
|
}
|
2529
2598
|
const minGas = getMinGas({
|
2530
2599
|
gasCosts,
|
2531
|
-
gasPerByte: (0,
|
2600
|
+
gasPerByte: (0, import_math11.bn)(gasPerByte),
|
2532
2601
|
inputs,
|
2533
2602
|
metadataGas,
|
2534
2603
|
txBytesSize: transactionBytes.length
|
2535
2604
|
});
|
2536
|
-
const gasPrice = (0,
|
2537
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
2605
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2606
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2538
2607
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2539
2608
|
const maxGas = getMaxGas({
|
2540
2609
|
gasPerByte,
|
@@ -2556,23 +2625,23 @@ var calculateTransactionFee = (params) => {
|
|
2556
2625
|
};
|
2557
2626
|
|
2558
2627
|
// src/providers/transaction-summary/operations.ts
|
2559
|
-
var
|
2560
|
-
var
|
2561
|
-
var
|
2562
|
-
var
|
2628
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2629
|
+
var import_errors11 = require("@fuel-ts/errors");
|
2630
|
+
var import_math13 = require("@fuel-ts/math");
|
2631
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2563
2632
|
|
2564
2633
|
// src/providers/transaction-summary/call.ts
|
2565
|
-
var
|
2566
|
-
var
|
2634
|
+
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
2635
|
+
var import_math12 = require("@fuel-ts/math");
|
2567
2636
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2568
|
-
const abiInterface = new
|
2637
|
+
const abiInterface = new import_abi_coder4.Interface(abi);
|
2569
2638
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2570
2639
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2571
2640
|
const inputs = functionFragment.jsonFn.inputs;
|
2572
2641
|
let encodedArgs;
|
2573
2642
|
if (functionFragment.isInputDataPointer) {
|
2574
2643
|
if (rawPayload) {
|
2575
|
-
const argsOffset = (0,
|
2644
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder4.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2576
2645
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2577
2646
|
}
|
2578
2647
|
} else {
|
@@ -2606,8 +2675,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2606
2675
|
};
|
2607
2676
|
|
2608
2677
|
// src/providers/transaction-summary/input.ts
|
2609
|
-
var
|
2610
|
-
var
|
2678
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2679
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2611
2680
|
function getInputsByTypes(inputs, types) {
|
2612
2681
|
return inputs.filter((i) => types.includes(i.type));
|
2613
2682
|
}
|
@@ -2615,16 +2684,16 @@ function getInputsByType(inputs, type) {
|
|
2615
2684
|
return inputs.filter((i) => i.type === type);
|
2616
2685
|
}
|
2617
2686
|
function getInputsCoin(inputs) {
|
2618
|
-
return getInputsByType(inputs,
|
2687
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2619
2688
|
}
|
2620
2689
|
function getInputsMessage(inputs) {
|
2621
|
-
return getInputsByType(inputs,
|
2690
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2622
2691
|
}
|
2623
2692
|
function getInputsCoinAndMessage(inputs) {
|
2624
|
-
return getInputsByTypes(inputs, [
|
2693
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2625
2694
|
}
|
2626
2695
|
function getInputsContract(inputs) {
|
2627
|
-
return getInputsByType(inputs,
|
2696
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2628
2697
|
}
|
2629
2698
|
function getInputFromAssetId(inputs, assetId) {
|
2630
2699
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2643,40 +2712,40 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2643
2712
|
if (!contractInput) {
|
2644
2713
|
return void 0;
|
2645
2714
|
}
|
2646
|
-
if (contractInput.type !==
|
2647
|
-
throw new
|
2648
|
-
|
2715
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2716
|
+
throw new import_errors10.FuelError(
|
2717
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2649
2718
|
`Contract input should be of type 'contract'.`
|
2650
2719
|
);
|
2651
2720
|
}
|
2652
2721
|
return contractInput;
|
2653
2722
|
}
|
2654
2723
|
function getInputAccountAddress(input) {
|
2655
|
-
if (input.type ===
|
2724
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2656
2725
|
return input.owner.toString();
|
2657
2726
|
}
|
2658
|
-
if (input.type ===
|
2727
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2659
2728
|
return input.recipient.toString();
|
2660
2729
|
}
|
2661
2730
|
return "";
|
2662
2731
|
}
|
2663
2732
|
|
2664
2733
|
// src/providers/transaction-summary/output.ts
|
2665
|
-
var
|
2734
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2666
2735
|
function getOutputsByType(outputs, type) {
|
2667
2736
|
return outputs.filter((o) => o.type === type);
|
2668
2737
|
}
|
2669
2738
|
function getOutputsContractCreated(outputs) {
|
2670
|
-
return getOutputsByType(outputs,
|
2739
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2671
2740
|
}
|
2672
2741
|
function getOutputsCoin(outputs) {
|
2673
|
-
return getOutputsByType(outputs,
|
2742
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2674
2743
|
}
|
2675
2744
|
function getOutputsChange(outputs) {
|
2676
|
-
return getOutputsByType(outputs,
|
2745
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2677
2746
|
}
|
2678
2747
|
function getOutputsContract(outputs) {
|
2679
|
-
return getOutputsByType(outputs,
|
2748
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2680
2749
|
}
|
2681
2750
|
|
2682
2751
|
// src/providers/transaction-summary/operations.ts
|
@@ -2685,15 +2754,15 @@ function getReceiptsByType(receipts, type) {
|
|
2685
2754
|
}
|
2686
2755
|
function getTransactionTypeName(transactionType) {
|
2687
2756
|
switch (transactionType) {
|
2688
|
-
case
|
2757
|
+
case import_transactions14.TransactionType.Mint:
|
2689
2758
|
return "Mint" /* Mint */;
|
2690
|
-
case
|
2759
|
+
case import_transactions14.TransactionType.Create:
|
2691
2760
|
return "Create" /* Create */;
|
2692
|
-
case
|
2761
|
+
case import_transactions14.TransactionType.Script:
|
2693
2762
|
return "Script" /* Script */;
|
2694
2763
|
default:
|
2695
|
-
throw new
|
2696
|
-
|
2764
|
+
throw new import_errors11.FuelError(
|
2765
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
|
2697
2766
|
`Invalid transaction type: ${transactionType}.`
|
2698
2767
|
);
|
2699
2768
|
}
|
@@ -2712,10 +2781,10 @@ function isTypeScript(transactionType) {
|
|
2712
2781
|
return isType(transactionType, "Script" /* Script */);
|
2713
2782
|
}
|
2714
2783
|
function getReceiptsCall(receipts) {
|
2715
|
-
return getReceiptsByType(receipts,
|
2784
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
2716
2785
|
}
|
2717
2786
|
function getReceiptsMessageOut(receipts) {
|
2718
|
-
return getReceiptsByType(receipts,
|
2787
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
2719
2788
|
}
|
2720
2789
|
var mergeAssets = (op1, op2) => {
|
2721
2790
|
const assets1 = op1.assetsSent || [];
|
@@ -2728,7 +2797,7 @@ var mergeAssets = (op1, op2) => {
|
|
2728
2797
|
if (!matchingAsset) {
|
2729
2798
|
return asset1;
|
2730
2799
|
}
|
2731
|
-
const mergedAmount = (0,
|
2800
|
+
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
2732
2801
|
return { ...asset1, amount: mergedAmount };
|
2733
2802
|
});
|
2734
2803
|
return mergedAssets.concat(filteredAssets);
|
@@ -2854,7 +2923,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2854
2923
|
const { to: toAddress, assetId, amount } = receipt;
|
2855
2924
|
let { from: fromAddress } = receipt;
|
2856
2925
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2857
|
-
if (
|
2926
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2858
2927
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2859
2928
|
fromAddress = change?.to || fromAddress;
|
2860
2929
|
}
|
@@ -2911,11 +2980,11 @@ function getTransferOperations({
|
|
2911
2980
|
});
|
2912
2981
|
const transferReceipts = getReceiptsByType(
|
2913
2982
|
receipts,
|
2914
|
-
|
2983
|
+
import_transactions14.ReceiptType.Transfer
|
2915
2984
|
);
|
2916
2985
|
const transferOutReceipts = getReceiptsByType(
|
2917
2986
|
receipts,
|
2918
|
-
|
2987
|
+
import_transactions14.ReceiptType.TransferOut
|
2919
2988
|
);
|
2920
2989
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2921
2990
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3000,17 +3069,17 @@ function getOperations({
|
|
3000
3069
|
}
|
3001
3070
|
|
3002
3071
|
// src/providers/transaction-summary/receipt.ts
|
3003
|
-
var
|
3072
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3004
3073
|
var processGqlReceipt = (gqlReceipt) => {
|
3005
3074
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3006
3075
|
switch (receipt.type) {
|
3007
|
-
case
|
3076
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3008
3077
|
return {
|
3009
3078
|
...receipt,
|
3010
3079
|
data: gqlReceipt.data || "0x"
|
3011
3080
|
};
|
3012
3081
|
}
|
3013
|
-
case
|
3082
|
+
case import_transactions15.ReceiptType.LogData: {
|
3014
3083
|
return {
|
3015
3084
|
...receipt,
|
3016
3085
|
data: gqlReceipt.data || "0x"
|
@@ -3023,7 +3092,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3023
3092
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3024
3093
|
const mintedAssets = [];
|
3025
3094
|
receipts.forEach((receipt) => {
|
3026
|
-
if (receipt.type ===
|
3095
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3027
3096
|
mintedAssets.push({
|
3028
3097
|
subId: receipt.subId,
|
3029
3098
|
contractId: receipt.contractId,
|
@@ -3037,7 +3106,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3037
3106
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3038
3107
|
const burnedAssets = [];
|
3039
3108
|
receipts.forEach((receipt) => {
|
3040
|
-
if (receipt.type ===
|
3109
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3041
3110
|
burnedAssets.push({
|
3042
3111
|
subId: receipt.subId,
|
3043
3112
|
contractId: receipt.contractId,
|
@@ -3050,7 +3119,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3050
3119
|
};
|
3051
3120
|
|
3052
3121
|
// src/providers/transaction-summary/status.ts
|
3053
|
-
var
|
3122
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3054
3123
|
var getTransactionStatusName = (gqlStatus) => {
|
3055
3124
|
switch (gqlStatus) {
|
3056
3125
|
case "FailureStatus":
|
@@ -3062,8 +3131,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3062
3131
|
case "SqueezedOutStatus":
|
3063
3132
|
return "squeezedout" /* squeezedout */;
|
3064
3133
|
default:
|
3065
|
-
throw new
|
3066
|
-
|
3134
|
+
throw new import_errors12.FuelError(
|
3135
|
+
import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3067
3136
|
`Invalid transaction status: ${gqlStatus}.`
|
3068
3137
|
);
|
3069
3138
|
}
|
@@ -3174,6 +3243,21 @@ function assembleTransactionSummary(params) {
|
|
3174
3243
|
return transactionSummary;
|
3175
3244
|
}
|
3176
3245
|
|
3246
|
+
// src/providers/transaction-response/getDecodedLogs.ts
|
3247
|
+
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
3248
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3249
|
+
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3250
|
+
return receipts.reduce((logs, receipt) => {
|
3251
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3252
|
+
const interfaceToUse = new import_abi_coder5.Interface(externalAbis[receipt.id] || mainAbi);
|
3253
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder5.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3254
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3255
|
+
logs.push(decodedLog);
|
3256
|
+
}
|
3257
|
+
return logs;
|
3258
|
+
}, []);
|
3259
|
+
}
|
3260
|
+
|
3177
3261
|
// src/providers/transaction-response/transaction-response.ts
|
3178
3262
|
var TransactionResponse = class {
|
3179
3263
|
/** Transaction ID */
|
@@ -3181,18 +3265,20 @@ var TransactionResponse = class {
|
|
3181
3265
|
/** Current provider */
|
3182
3266
|
provider;
|
3183
3267
|
/** Gas used on the transaction */
|
3184
|
-
gasUsed = (0,
|
3268
|
+
gasUsed = (0, import_math14.bn)(0);
|
3185
3269
|
/** The graphql Transaction with receipts object. */
|
3186
3270
|
gqlTransaction;
|
3271
|
+
abis;
|
3187
3272
|
/**
|
3188
3273
|
* Constructor for `TransactionResponse`.
|
3189
3274
|
*
|
3190
3275
|
* @param id - The transaction ID.
|
3191
3276
|
* @param provider - The provider.
|
3192
3277
|
*/
|
3193
|
-
constructor(id, provider) {
|
3278
|
+
constructor(id, provider, abis) {
|
3194
3279
|
this.id = id;
|
3195
3280
|
this.provider = provider;
|
3281
|
+
this.abis = abis;
|
3196
3282
|
}
|
3197
3283
|
/**
|
3198
3284
|
* Async constructor for `TransactionResponse`. This method can be used to create
|
@@ -3202,8 +3288,8 @@ var TransactionResponse = class {
|
|
3202
3288
|
* @param id - The transaction ID.
|
3203
3289
|
* @param provider - The provider.
|
3204
3290
|
*/
|
3205
|
-
static async create(id, provider) {
|
3206
|
-
const response = new TransactionResponse(id, provider);
|
3291
|
+
static async create(id, provider, abis) {
|
3292
|
+
const response = new TransactionResponse(id, provider, abis);
|
3207
3293
|
await response.fetch();
|
3208
3294
|
return response;
|
3209
3295
|
}
|
@@ -3237,7 +3323,7 @@ var TransactionResponse = class {
|
|
3237
3323
|
* @returns The decoded transaction.
|
3238
3324
|
*/
|
3239
3325
|
decodeTransaction(transactionWithReceipts) {
|
3240
|
-
return new
|
3326
|
+
return new import_transactions17.TransactionCoder().decode(
|
3241
3327
|
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3242
3328
|
0
|
3243
3329
|
)?.[0];
|
@@ -3284,8 +3370,8 @@ var TransactionResponse = class {
|
|
3284
3370
|
});
|
3285
3371
|
for await (const { statusChange } of subscription) {
|
3286
3372
|
if (statusChange.type === "SqueezedOutStatus") {
|
3287
|
-
throw new
|
3288
|
-
|
3373
|
+
throw new import_errors13.FuelError(
|
3374
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3289
3375
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3290
3376
|
);
|
3291
3377
|
}
|
@@ -3307,6 +3393,26 @@ var TransactionResponse = class {
|
|
3307
3393
|
gqlTransaction: this.gqlTransaction,
|
3308
3394
|
...transactionSummary
|
3309
3395
|
};
|
3396
|
+
let logs = [];
|
3397
|
+
if (this.abis) {
|
3398
|
+
logs = getDecodedLogs(
|
3399
|
+
transactionSummary.receipts,
|
3400
|
+
this.abis.main,
|
3401
|
+
this.abis.otherContractsAbis
|
3402
|
+
);
|
3403
|
+
transactionResult.logs = logs;
|
3404
|
+
}
|
3405
|
+
if (transactionResult.isStatusFailure) {
|
3406
|
+
const {
|
3407
|
+
receipts,
|
3408
|
+
gqlTransaction: { status }
|
3409
|
+
} = transactionResult;
|
3410
|
+
throw extractTxError({
|
3411
|
+
receipts,
|
3412
|
+
status,
|
3413
|
+
logs
|
3414
|
+
});
|
3415
|
+
}
|
3310
3416
|
return transactionResult;
|
3311
3417
|
}
|
3312
3418
|
/**
|
@@ -3315,21 +3421,10 @@ var TransactionResponse = class {
|
|
3315
3421
|
* @param contractsAbiMap - The contracts ABI map.
|
3316
3422
|
*/
|
3317
3423
|
async wait(contractsAbiMap) {
|
3318
|
-
|
3319
|
-
if (result.isStatusFailure) {
|
3320
|
-
throw new import_errors12.FuelError(
|
3321
|
-
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3322
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3323
|
-
);
|
3324
|
-
}
|
3325
|
-
return result;
|
3424
|
+
return this.waitForResult(contractsAbiMap);
|
3326
3425
|
}
|
3327
3426
|
};
|
3328
3427
|
|
3329
|
-
// src/providers/transaction-response/getDecodedLogs.ts
|
3330
|
-
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3331
|
-
var import_transactions16 = require("@fuel-ts/transactions");
|
3332
|
-
|
3333
3428
|
// src/providers/utils/auto-retry-fetch.ts
|
3334
3429
|
function getWaitDelay(options, retryAttemptNum) {
|
3335
3430
|
const duration = options.baseDelay ?? 150;
|
@@ -3388,29 +3483,29 @@ var processGqlChain = (chain) => {
|
|
3388
3483
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3389
3484
|
return {
|
3390
3485
|
name,
|
3391
|
-
baseChainHeight: (0,
|
3486
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3392
3487
|
consensusParameters: {
|
3393
|
-
contractMaxSize: (0,
|
3394
|
-
maxInputs: (0,
|
3395
|
-
maxOutputs: (0,
|
3396
|
-
maxWitnesses: (0,
|
3397
|
-
maxGasPerTx: (0,
|
3398
|
-
maxScriptLength: (0,
|
3399
|
-
maxScriptDataLength: (0,
|
3400
|
-
maxStorageSlots: (0,
|
3401
|
-
maxPredicateLength: (0,
|
3402
|
-
maxPredicateDataLength: (0,
|
3403
|
-
maxGasPerPredicate: (0,
|
3404
|
-
gasPriceFactor: (0,
|
3405
|
-
gasPerByte: (0,
|
3406
|
-
maxMessageDataLength: (0,
|
3407
|
-
chainId: (0,
|
3488
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3489
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3490
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3491
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3492
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3493
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3494
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3495
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3496
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3497
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3498
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3499
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3500
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3501
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3502
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3408
3503
|
gasCosts
|
3409
3504
|
},
|
3410
3505
|
gasCosts,
|
3411
3506
|
latestBlock: {
|
3412
3507
|
id: latestBlock.id,
|
3413
|
-
height: (0,
|
3508
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3414
3509
|
time: latestBlock.header.time,
|
3415
3510
|
transactions: latestBlock.transactions.map((i) => ({
|
3416
3511
|
id: i.id
|
@@ -3480,8 +3575,8 @@ var _Provider = class {
|
|
3480
3575
|
getChain() {
|
3481
3576
|
const chain = _Provider.chainInfoCache[this.url];
|
3482
3577
|
if (!chain) {
|
3483
|
-
throw new
|
3484
|
-
|
3578
|
+
throw new import_errors14.FuelError(
|
3579
|
+
import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3485
3580
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3486
3581
|
);
|
3487
3582
|
}
|
@@ -3493,8 +3588,8 @@ var _Provider = class {
|
|
3493
3588
|
getNode() {
|
3494
3589
|
const node = _Provider.nodeInfoCache[this.url];
|
3495
3590
|
if (!node) {
|
3496
|
-
throw new
|
3497
|
-
|
3591
|
+
throw new import_errors14.FuelError(
|
3592
|
+
import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3498
3593
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3499
3594
|
);
|
3500
3595
|
}
|
@@ -3541,8 +3636,8 @@ var _Provider = class {
|
|
3541
3636
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3542
3637
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3543
3638
|
if (!isMajorSupported || !isMinorSupported) {
|
3544
|
-
throw new
|
3545
|
-
|
3639
|
+
throw new import_errors14.FuelError(
|
3640
|
+
import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3546
3641
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3547
3642
|
);
|
3548
3643
|
}
|
@@ -3605,7 +3700,7 @@ var _Provider = class {
|
|
3605
3700
|
*/
|
3606
3701
|
async getBlockNumber() {
|
3607
3702
|
const { chain } = await this.operations.getChain();
|
3608
|
-
return (0,
|
3703
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3609
3704
|
}
|
3610
3705
|
/**
|
3611
3706
|
* Returns the chain information.
|
@@ -3615,9 +3710,9 @@ var _Provider = class {
|
|
3615
3710
|
async fetchNode() {
|
3616
3711
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3617
3712
|
const processedNodeInfo = {
|
3618
|
-
maxDepth: (0,
|
3619
|
-
maxTx: (0,
|
3620
|
-
minGasPrice: (0,
|
3713
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3714
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3715
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3621
3716
|
nodeVersion: nodeInfo.nodeVersion,
|
3622
3717
|
utxoValidation: nodeInfo.utxoValidation,
|
3623
3718
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3663,13 +3758,17 @@ var _Provider = class {
|
|
3663
3758
|
if (estimateTxDependencies) {
|
3664
3759
|
await this.estimateTxDependencies(transactionRequest);
|
3665
3760
|
}
|
3666
|
-
const encodedTransaction = (0,
|
3761
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3762
|
+
let abis;
|
3763
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3764
|
+
abis = transactionRequest.abis;
|
3765
|
+
}
|
3667
3766
|
if (awaitExecution) {
|
3668
3767
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3669
3768
|
for await (const { submitAndAwait } of subscription) {
|
3670
3769
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3671
|
-
throw new
|
3672
|
-
|
3770
|
+
throw new import_errors14.FuelError(
|
3771
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3673
3772
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3674
3773
|
);
|
3675
3774
|
}
|
@@ -3678,14 +3777,14 @@ var _Provider = class {
|
|
3678
3777
|
}
|
3679
3778
|
}
|
3680
3779
|
const transactionId2 = transactionRequest.getTransactionId(this.getChainId());
|
3681
|
-
const response = new TransactionResponse(transactionId2, this);
|
3780
|
+
const response = new TransactionResponse(transactionId2, this, abis);
|
3682
3781
|
await response.fetch();
|
3683
3782
|
return response;
|
3684
3783
|
}
|
3685
3784
|
const {
|
3686
3785
|
submit: { id: transactionId }
|
3687
3786
|
} = await this.operations.submit({ encodedTransaction });
|
3688
|
-
return new TransactionResponse(transactionId, this);
|
3787
|
+
return new TransactionResponse(transactionId, this, abis);
|
3689
3788
|
}
|
3690
3789
|
/**
|
3691
3790
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -3702,7 +3801,7 @@ var _Provider = class {
|
|
3702
3801
|
if (estimateTxDependencies) {
|
3703
3802
|
return this.estimateTxDependencies(transactionRequest);
|
3704
3803
|
}
|
3705
|
-
const encodedTransaction = (0,
|
3804
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3706
3805
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3707
3806
|
encodedTransaction,
|
3708
3807
|
utxoValidation: utxoValidation || false
|
@@ -3721,13 +3820,13 @@ var _Provider = class {
|
|
3721
3820
|
async estimatePredicates(transactionRequest) {
|
3722
3821
|
const shouldEstimatePredicates = Boolean(
|
3723
3822
|
transactionRequest.inputs.find(
|
3724
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3823
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math15.BN(input.predicateGasUsed).isZero()
|
3725
3824
|
)
|
3726
3825
|
);
|
3727
3826
|
if (!shouldEstimatePredicates) {
|
3728
3827
|
return transactionRequest;
|
3729
3828
|
}
|
3730
|
-
const encodedTransaction = (0,
|
3829
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3731
3830
|
const response = await this.operations.estimatePredicates({
|
3732
3831
|
encodedTransaction
|
3733
3832
|
});
|
@@ -3736,7 +3835,7 @@ var _Provider = class {
|
|
3736
3835
|
} = response;
|
3737
3836
|
if (inputs) {
|
3738
3837
|
inputs.forEach((input, index) => {
|
3739
|
-
if ("predicateGasUsed" in input && (0,
|
3838
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3740
3839
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3741
3840
|
}
|
3742
3841
|
});
|
@@ -3757,7 +3856,7 @@ var _Provider = class {
|
|
3757
3856
|
* @returns A promise.
|
3758
3857
|
*/
|
3759
3858
|
async estimateTxDependencies(transactionRequest) {
|
3760
|
-
if (transactionRequest.type ===
|
3859
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3761
3860
|
return {
|
3762
3861
|
receipts: [],
|
3763
3862
|
outputVariables: 0,
|
@@ -3770,7 +3869,7 @@ var _Provider = class {
|
|
3770
3869
|
let outputVariables = 0;
|
3771
3870
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3772
3871
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3773
|
-
encodedTransaction: (0,
|
3872
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3774
3873
|
utxoValidation: false
|
3775
3874
|
});
|
3776
3875
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3793,6 +3892,36 @@ var _Provider = class {
|
|
3793
3892
|
missingContractIds
|
3794
3893
|
};
|
3795
3894
|
}
|
3895
|
+
/**
|
3896
|
+
* Estimates the transaction gas and fee based on the provided transaction request.
|
3897
|
+
* @param transactionRequest - The transaction request object.
|
3898
|
+
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
|
3899
|
+
*/
|
3900
|
+
estimateTxGasAndFee(params) {
|
3901
|
+
const { transactionRequest } = params;
|
3902
|
+
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3903
|
+
const chainInfo = this.getChain();
|
3904
|
+
const gasPrice = transactionRequest.gasPrice.eq(0) ? minGasPrice : transactionRequest.gasPrice;
|
3905
|
+
transactionRequest.gasPrice = gasPrice;
|
3906
|
+
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
3907
|
+
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3908
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3909
|
+
if (transactionRequest.gasLimit.eq(0)) {
|
3910
|
+
transactionRequest.gasLimit = minGas;
|
3911
|
+
transactionRequest.gasLimit = maxGasPerTx.sub(
|
3912
|
+
transactionRequest.calculateMaxGas(chainInfo, minGas)
|
3913
|
+
);
|
3914
|
+
}
|
3915
|
+
}
|
3916
|
+
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
3917
|
+
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3918
|
+
return {
|
3919
|
+
minGas,
|
3920
|
+
minFee,
|
3921
|
+
maxGas,
|
3922
|
+
maxFee
|
3923
|
+
};
|
3924
|
+
}
|
3796
3925
|
/**
|
3797
3926
|
* Executes a signed transaction without applying the states changes
|
3798
3927
|
* on the chain.
|
@@ -3808,7 +3937,7 @@ var _Provider = class {
|
|
3808
3937
|
if (estimateTxDependencies) {
|
3809
3938
|
return this.estimateTxDependencies(transactionRequest);
|
3810
3939
|
}
|
3811
|
-
const encodedTransaction = (0,
|
3940
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3812
3941
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3813
3942
|
encodedTransaction,
|
3814
3943
|
utxoValidation: true
|
@@ -3840,17 +3969,16 @@ var _Provider = class {
|
|
3840
3969
|
signatureCallback
|
3841
3970
|
} = {}) {
|
3842
3971
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3843
|
-
const
|
3844
|
-
const
|
3845
|
-
const
|
3846
|
-
const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
|
3972
|
+
const { minGasPrice } = this.getGasConfig();
|
3973
|
+
const setGasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3974
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3847
3975
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3848
3976
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3849
3977
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3978
|
+
if (isScriptTransaction) {
|
3979
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3980
|
+
}
|
3850
3981
|
if (estimatePredicates) {
|
3851
|
-
if (isScriptTransaction) {
|
3852
|
-
txRequestClone.gasLimit = (0, import_math14.bn)(0);
|
3853
|
-
}
|
3854
3982
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3855
3983
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
3856
3984
|
}
|
@@ -3859,36 +3987,34 @@ var _Provider = class {
|
|
3859
3987
|
if (signatureCallback && isScriptTransaction) {
|
3860
3988
|
await signatureCallback(txRequestClone);
|
3861
3989
|
}
|
3862
|
-
|
3863
|
-
|
3990
|
+
let { maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
3991
|
+
transactionRequest: txRequestClone
|
3992
|
+
});
|
3864
3993
|
let receipts = [];
|
3865
3994
|
let missingContractIds = [];
|
3866
3995
|
let outputVariables = 0;
|
3996
|
+
let gasUsed = (0, import_math15.bn)(0);
|
3867
3997
|
if (isScriptTransaction && estimateTxDependencies) {
|
3868
|
-
txRequestClone.gasPrice = (0,
|
3869
|
-
txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3998
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3870
3999
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3871
4000
|
receipts = result.receipts;
|
3872
4001
|
outputVariables = result.outputVariables;
|
3873
4002
|
missingContractIds = result.missingContractIds;
|
4003
|
+
gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : gasUsed;
|
4004
|
+
txRequestClone.gasLimit = gasUsed;
|
4005
|
+
txRequestClone.gasPrice = setGasPrice;
|
4006
|
+
({ maxFee, maxGas, minFee, minGas } = this.estimateTxGasAndFee({
|
4007
|
+
transactionRequest: txRequestClone
|
4008
|
+
}));
|
3874
4009
|
}
|
3875
|
-
const gasUsed = isScriptTransaction ? getGasUsedFromReceipts(receipts) : minGas;
|
3876
|
-
const usedFee = calculatePriceWithFactor(
|
3877
|
-
gasUsed,
|
3878
|
-
gasPrice,
|
3879
|
-
gasPriceFactor
|
3880
|
-
).normalizeZeroToOne();
|
3881
|
-
const minFee = calculatePriceWithFactor(minGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3882
|
-
const maxFee = calculatePriceWithFactor(maxGas, gasPrice, gasPriceFactor).normalizeZeroToOne();
|
3883
4010
|
return {
|
3884
4011
|
requiredQuantities: allQuantities,
|
3885
4012
|
receipts,
|
3886
4013
|
gasUsed,
|
3887
4014
|
minGasPrice,
|
3888
|
-
gasPrice,
|
4015
|
+
gasPrice: setGasPrice,
|
3889
4016
|
minGas,
|
3890
4017
|
maxGas,
|
3891
|
-
usedFee,
|
3892
4018
|
minFee,
|
3893
4019
|
maxFee,
|
3894
4020
|
estimatedInputs: txRequestClone.inputs,
|
@@ -3922,17 +4048,17 @@ var _Provider = class {
|
|
3922
4048
|
const result = await this.operations.getCoins({
|
3923
4049
|
first: 10,
|
3924
4050
|
...paginationArgs,
|
3925
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4051
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
3926
4052
|
});
|
3927
4053
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3928
4054
|
return coins.map((coin) => ({
|
3929
4055
|
id: coin.utxoId,
|
3930
4056
|
assetId: coin.assetId,
|
3931
|
-
amount: (0,
|
4057
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3932
4058
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3933
|
-
maturity: (0,
|
3934
|
-
blockCreated: (0,
|
3935
|
-
txCreatedIdx: (0,
|
4059
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4060
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4061
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
3936
4062
|
}));
|
3937
4063
|
}
|
3938
4064
|
/**
|
@@ -3946,19 +4072,19 @@ var _Provider = class {
|
|
3946
4072
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3947
4073
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3948
4074
|
const excludeInput = {
|
3949
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3950
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4075
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4076
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
3951
4077
|
};
|
3952
4078
|
if (this.cache) {
|
3953
4079
|
const uniqueUtxos = new Set(
|
3954
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4080
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
3955
4081
|
);
|
3956
4082
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3957
4083
|
}
|
3958
4084
|
const coinsQuery = {
|
3959
4085
|
owner: ownerAddress.toB256(),
|
3960
4086
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
3961
|
-
assetId: (0,
|
4087
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
3962
4088
|
amount: amount.toString(10),
|
3963
4089
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
3964
4090
|
})),
|
@@ -3969,9 +4095,9 @@ var _Provider = class {
|
|
3969
4095
|
switch (coin.__typename) {
|
3970
4096
|
case "MessageCoin":
|
3971
4097
|
return {
|
3972
|
-
amount: (0,
|
4098
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3973
4099
|
assetId: coin.assetId,
|
3974
|
-
daHeight: (0,
|
4100
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
3975
4101
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
3976
4102
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
3977
4103
|
nonce: coin.nonce
|
@@ -3979,12 +4105,12 @@ var _Provider = class {
|
|
3979
4105
|
case "Coin":
|
3980
4106
|
return {
|
3981
4107
|
id: coin.utxoId,
|
3982
|
-
amount: (0,
|
4108
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3983
4109
|
assetId: coin.assetId,
|
3984
4110
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3985
|
-
maturity: (0,
|
3986
|
-
blockCreated: (0,
|
3987
|
-
txCreatedIdx: (0,
|
4111
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4112
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4113
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
3988
4114
|
};
|
3989
4115
|
default:
|
3990
4116
|
return null;
|
@@ -4001,13 +4127,13 @@ var _Provider = class {
|
|
4001
4127
|
async getBlock(idOrHeight) {
|
4002
4128
|
let variables;
|
4003
4129
|
if (typeof idOrHeight === "number") {
|
4004
|
-
variables = { height: (0,
|
4130
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4005
4131
|
} else if (idOrHeight === "latest") {
|
4006
4132
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4007
4133
|
} else if (idOrHeight.length === 66) {
|
4008
4134
|
variables = { blockId: idOrHeight };
|
4009
4135
|
} else {
|
4010
|
-
variables = { blockId: (0,
|
4136
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4011
4137
|
}
|
4012
4138
|
const { block } = await this.operations.getBlock(variables);
|
4013
4139
|
if (!block) {
|
@@ -4015,7 +4141,7 @@ var _Provider = class {
|
|
4015
4141
|
}
|
4016
4142
|
return {
|
4017
4143
|
id: block.id,
|
4018
|
-
height: (0,
|
4144
|
+
height: (0, import_math15.bn)(block.header.height),
|
4019
4145
|
time: block.header.time,
|
4020
4146
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4021
4147
|
};
|
@@ -4030,7 +4156,7 @@ var _Provider = class {
|
|
4030
4156
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4031
4157
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4032
4158
|
id: block.id,
|
4033
|
-
height: (0,
|
4159
|
+
height: (0, import_math15.bn)(block.header.height),
|
4034
4160
|
time: block.header.time,
|
4035
4161
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4036
4162
|
}));
|
@@ -4045,7 +4171,7 @@ var _Provider = class {
|
|
4045
4171
|
async getBlockWithTransactions(idOrHeight) {
|
4046
4172
|
let variables;
|
4047
4173
|
if (typeof idOrHeight === "number") {
|
4048
|
-
variables = { blockHeight: (0,
|
4174
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4049
4175
|
} else if (idOrHeight === "latest") {
|
4050
4176
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4051
4177
|
} else {
|
@@ -4057,11 +4183,11 @@ var _Provider = class {
|
|
4057
4183
|
}
|
4058
4184
|
return {
|
4059
4185
|
id: block.id,
|
4060
|
-
height: (0,
|
4186
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4061
4187
|
time: block.header.time,
|
4062
4188
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4063
4189
|
transactions: block.transactions.map(
|
4064
|
-
(tx) => new
|
4190
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4065
4191
|
)
|
4066
4192
|
};
|
4067
4193
|
}
|
@@ -4076,8 +4202,8 @@ var _Provider = class {
|
|
4076
4202
|
if (!transaction) {
|
4077
4203
|
return null;
|
4078
4204
|
}
|
4079
|
-
return new
|
4080
|
-
(0,
|
4205
|
+
return new import_transactions18.TransactionCoder().decode(
|
4206
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4081
4207
|
0
|
4082
4208
|
)?.[0];
|
4083
4209
|
}
|
@@ -4104,9 +4230,9 @@ var _Provider = class {
|
|
4104
4230
|
async getContractBalance(contractId, assetId) {
|
4105
4231
|
const { contractBalance } = await this.operations.getContractBalance({
|
4106
4232
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4107
|
-
asset: (0,
|
4233
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4108
4234
|
});
|
4109
|
-
return (0,
|
4235
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4110
4236
|
}
|
4111
4237
|
/**
|
4112
4238
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4118,9 +4244,9 @@ var _Provider = class {
|
|
4118
4244
|
async getBalance(owner, assetId) {
|
4119
4245
|
const { balance } = await this.operations.getBalance({
|
4120
4246
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4121
|
-
assetId: (0,
|
4247
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4122
4248
|
});
|
4123
|
-
return (0,
|
4249
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4124
4250
|
}
|
4125
4251
|
/**
|
4126
4252
|
* Returns balances for the given owner.
|
@@ -4138,7 +4264,7 @@ var _Provider = class {
|
|
4138
4264
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4139
4265
|
return balances.map((balance) => ({
|
4140
4266
|
assetId: balance.assetId,
|
4141
|
-
amount: (0,
|
4267
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4142
4268
|
}));
|
4143
4269
|
}
|
4144
4270
|
/**
|
@@ -4156,19 +4282,19 @@ var _Provider = class {
|
|
4156
4282
|
});
|
4157
4283
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4158
4284
|
return messages.map((message) => ({
|
4159
|
-
messageId:
|
4285
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4160
4286
|
sender: message.sender,
|
4161
4287
|
recipient: message.recipient,
|
4162
4288
|
nonce: message.nonce,
|
4163
|
-
amount: (0,
|
4289
|
+
amount: (0, import_math15.bn)(message.amount),
|
4164
4290
|
data: message.data
|
4165
4291
|
}),
|
4166
4292
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4167
4293
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4168
4294
|
nonce: message.nonce,
|
4169
|
-
amount: (0,
|
4170
|
-
data:
|
4171
|
-
daHeight: (0,
|
4295
|
+
amount: (0, import_math15.bn)(message.amount),
|
4296
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4297
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4172
4298
|
}));
|
4173
4299
|
}
|
4174
4300
|
/**
|
@@ -4186,8 +4312,8 @@ var _Provider = class {
|
|
4186
4312
|
nonce
|
4187
4313
|
};
|
4188
4314
|
if (commitBlockId && commitBlockHeight) {
|
4189
|
-
throw new
|
4190
|
-
|
4315
|
+
throw new import_errors14.FuelError(
|
4316
|
+
import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4191
4317
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4192
4318
|
);
|
4193
4319
|
}
|
@@ -4221,41 +4347,41 @@ var _Provider = class {
|
|
4221
4347
|
} = result.messageProof;
|
4222
4348
|
return {
|
4223
4349
|
messageProof: {
|
4224
|
-
proofIndex: (0,
|
4350
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4225
4351
|
proofSet: messageProof.proofSet
|
4226
4352
|
},
|
4227
4353
|
blockProof: {
|
4228
|
-
proofIndex: (0,
|
4354
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4229
4355
|
proofSet: blockProof.proofSet
|
4230
4356
|
},
|
4231
4357
|
messageBlockHeader: {
|
4232
4358
|
id: messageBlockHeader.id,
|
4233
|
-
daHeight: (0,
|
4234
|
-
transactionsCount: (0,
|
4359
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4360
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4235
4361
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4236
|
-
height: (0,
|
4362
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4237
4363
|
prevRoot: messageBlockHeader.prevRoot,
|
4238
4364
|
time: messageBlockHeader.time,
|
4239
4365
|
applicationHash: messageBlockHeader.applicationHash,
|
4240
4366
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4241
|
-
messageReceiptCount: (0,
|
4367
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4242
4368
|
},
|
4243
4369
|
commitBlockHeader: {
|
4244
4370
|
id: commitBlockHeader.id,
|
4245
|
-
daHeight: (0,
|
4246
|
-
transactionsCount: (0,
|
4371
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4372
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4247
4373
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4248
|
-
height: (0,
|
4374
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4249
4375
|
prevRoot: commitBlockHeader.prevRoot,
|
4250
4376
|
time: commitBlockHeader.time,
|
4251
4377
|
applicationHash: commitBlockHeader.applicationHash,
|
4252
4378
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4253
|
-
messageReceiptCount: (0,
|
4379
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4254
4380
|
},
|
4255
4381
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4256
4382
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4257
4383
|
nonce,
|
4258
|
-
amount: (0,
|
4384
|
+
amount: (0, import_math15.bn)(amount),
|
4259
4385
|
data
|
4260
4386
|
};
|
4261
4387
|
}
|
@@ -4278,10 +4404,10 @@ var _Provider = class {
|
|
4278
4404
|
*/
|
4279
4405
|
async produceBlocks(amount, startTime) {
|
4280
4406
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4281
|
-
blocksToProduce: (0,
|
4282
|
-
startTimestamp: startTime ?
|
4407
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4408
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4283
4409
|
});
|
4284
|
-
return (0,
|
4410
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4285
4411
|
}
|
4286
4412
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4287
4413
|
async getTransactionResponse(transactionId) {
|
@@ -4295,7 +4421,7 @@ cacheInputs_fn = function(inputs) {
|
|
4295
4421
|
return;
|
4296
4422
|
}
|
4297
4423
|
inputs.forEach((input) => {
|
4298
|
-
if (input.type ===
|
4424
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4299
4425
|
this.cache?.set(input.id);
|
4300
4426
|
}
|
4301
4427
|
});
|
@@ -4304,10 +4430,10 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4304
4430
|
__publicField(Provider, "nodeInfoCache", {});
|
4305
4431
|
|
4306
4432
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4307
|
-
var
|
4308
|
-
var
|
4309
|
-
var
|
4310
|
-
var
|
4433
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4434
|
+
var import_math16 = require("@fuel-ts/math");
|
4435
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4436
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4311
4437
|
|
4312
4438
|
// src/providers/chains.ts
|
4313
4439
|
var CHAIN_IDS = {
|
@@ -4355,18 +4481,18 @@ var assets = [
|
|
4355
4481
|
];
|
4356
4482
|
|
4357
4483
|
// src/utils/formatTransferToContractScriptData.ts
|
4358
|
-
var
|
4359
|
-
var
|
4360
|
-
var
|
4484
|
+
var import_abi_coder6 = require("@fuel-ts/abi-coder");
|
4485
|
+
var import_math17 = require("@fuel-ts/math");
|
4486
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4361
4487
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4362
4488
|
var formatTransferToContractScriptData = (params) => {
|
4363
4489
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4364
|
-
const numberCoder = new
|
4365
|
-
const encoded = numberCoder.encode(new
|
4490
|
+
const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
|
4491
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4366
4492
|
const scriptData = Uint8Array.from([
|
4367
|
-
...(0,
|
4493
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4368
4494
|
...encoded,
|
4369
|
-
...(0,
|
4495
|
+
...(0, import_utils27.arrayify)(assetId)
|
4370
4496
|
]);
|
4371
4497
|
return scriptData;
|
4372
4498
|
};
|
@@ -4422,7 +4548,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4422
4548
|
*/
|
4423
4549
|
get provider() {
|
4424
4550
|
if (!this._provider) {
|
4425
|
-
throw new
|
4551
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4426
4552
|
}
|
4427
4553
|
return this._provider;
|
4428
4554
|
}
|
@@ -4474,8 +4600,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4474
4600
|
if (!hasNextPage) {
|
4475
4601
|
break;
|
4476
4602
|
}
|
4477
|
-
throw new
|
4478
|
-
|
4603
|
+
throw new import_errors16.FuelError(
|
4604
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4479
4605
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4480
4606
|
);
|
4481
4607
|
}
|
@@ -4500,8 +4626,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4500
4626
|
if (!hasNextPage) {
|
4501
4627
|
break;
|
4502
4628
|
}
|
4503
|
-
throw new
|
4504
|
-
|
4629
|
+
throw new import_errors16.FuelError(
|
4630
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4505
4631
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4506
4632
|
);
|
4507
4633
|
}
|
@@ -4513,7 +4639,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4513
4639
|
* @param assetId - The asset ID to check the balance for.
|
4514
4640
|
* @returns A promise that resolves to the balance amount.
|
4515
4641
|
*/
|
4516
|
-
async getBalance(assetId =
|
4642
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4517
4643
|
const amount = await this.provider.getBalance(this.address, assetId);
|
4518
4644
|
return amount;
|
4519
4645
|
}
|
@@ -4536,8 +4662,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4536
4662
|
if (!hasNextPage) {
|
4537
4663
|
break;
|
4538
4664
|
}
|
4539
|
-
throw new
|
4540
|
-
|
4665
|
+
throw new import_errors16.FuelError(
|
4666
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4541
4667
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4542
4668
|
);
|
4543
4669
|
}
|
@@ -4553,15 +4679,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4553
4679
|
*/
|
4554
4680
|
async fund(request, coinQuantities, fee) {
|
4555
4681
|
const updatedQuantities = addAmountToAsset({
|
4556
|
-
amount: (0,
|
4557
|
-
assetId:
|
4682
|
+
amount: (0, import_math18.bn)(fee),
|
4683
|
+
assetId: import_configs12.BaseAssetId,
|
4558
4684
|
coinQuantities
|
4559
4685
|
});
|
4560
4686
|
const quantitiesDict = {};
|
4561
4687
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4562
4688
|
quantitiesDict[assetId] = {
|
4563
4689
|
required: amount,
|
4564
|
-
owned: (0,
|
4690
|
+
owned: (0, import_math18.bn)(0)
|
4565
4691
|
};
|
4566
4692
|
});
|
4567
4693
|
const cachedUtxos = [];
|
@@ -4574,12 +4700,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4574
4700
|
if (isCoin2) {
|
4575
4701
|
const assetId = String(input.assetId);
|
4576
4702
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4577
|
-
const amount = (0,
|
4703
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4578
4704
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4579
4705
|
cachedUtxos.push(input.id);
|
4580
4706
|
}
|
4581
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4582
|
-
quantitiesDict[
|
4707
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4708
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4583
4709
|
cachedMessages.push(input.nonce);
|
4584
4710
|
}
|
4585
4711
|
}
|
@@ -4611,7 +4737,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4611
4737
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4612
4738
|
* @returns A promise that resolves to the prepared transaction request.
|
4613
4739
|
*/
|
4614
|
-
async createTransfer(destination, amount, assetId =
|
4740
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4615
4741
|
const { minGasPrice } = this.provider.getGasConfig();
|
4616
4742
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4617
4743
|
const request = new ScriptTransactionRequest(params);
|
@@ -4620,8 +4746,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4620
4746
|
estimateTxDependencies: true,
|
4621
4747
|
resourcesOwner: this
|
4622
4748
|
});
|
4623
|
-
request.gasPrice = (0,
|
4624
|
-
request.gasLimit = (0,
|
4749
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4750
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4625
4751
|
this.validateGas({
|
4626
4752
|
gasUsed,
|
4627
4753
|
gasPrice: request.gasPrice,
|
@@ -4641,10 +4767,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4641
4767
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4642
4768
|
* @returns A promise that resolves to the transaction response.
|
4643
4769
|
*/
|
4644
|
-
async transfer(destination, amount, assetId =
|
4645
|
-
if ((0,
|
4646
|
-
throw new
|
4647
|
-
|
4770
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4771
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4772
|
+
throw new import_errors16.FuelError(
|
4773
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4648
4774
|
"Transfer amount must be a positive number."
|
4649
4775
|
);
|
4650
4776
|
}
|
@@ -4660,10 +4786,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4660
4786
|
* @param txParams - The optional transaction parameters.
|
4661
4787
|
* @returns A promise that resolves to the transaction response.
|
4662
4788
|
*/
|
4663
|
-
async transferToContract(contractId, amount, assetId =
|
4664
|
-
if ((0,
|
4665
|
-
throw new
|
4666
|
-
|
4789
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4790
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4791
|
+
throw new import_errors16.FuelError(
|
4792
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4667
4793
|
"Transfer amount must be a positive number."
|
4668
4794
|
);
|
4669
4795
|
}
|
@@ -4672,7 +4798,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4672
4798
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4673
4799
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4674
4800
|
hexlifiedContractId: contractAddress.toB256(),
|
4675
|
-
amountToTransfer: (0,
|
4801
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4676
4802
|
assetId
|
4677
4803
|
});
|
4678
4804
|
const request = new ScriptTransactionRequest({
|
@@ -4683,9 +4809,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4683
4809
|
request.addContractInputAndOutput(contractAddress);
|
4684
4810
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4685
4811
|
request,
|
4686
|
-
[{ amount: (0,
|
4812
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4687
4813
|
);
|
4688
|
-
request.gasLimit = (0,
|
4814
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4689
4815
|
this.validateGas({
|
4690
4816
|
gasUsed,
|
4691
4817
|
gasPrice: request.gasPrice,
|
@@ -4706,25 +4832,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4706
4832
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4707
4833
|
const { minGasPrice } = this.provider.getGasConfig();
|
4708
4834
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4709
|
-
const recipientDataArray = (0,
|
4835
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
4710
4836
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4711
4837
|
);
|
4712
|
-
const amountDataArray = (0,
|
4713
|
-
"0x".concat((0,
|
4838
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4839
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4714
4840
|
);
|
4715
4841
|
const script = new Uint8Array([
|
4716
|
-
...(0,
|
4842
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
4717
4843
|
...recipientDataArray,
|
4718
4844
|
...amountDataArray
|
4719
4845
|
]);
|
4720
4846
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4721
4847
|
const request = new ScriptTransactionRequest(params);
|
4722
|
-
const forwardingQuantities = [{ amount: (0,
|
4848
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4723
4849
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4724
4850
|
request,
|
4725
4851
|
forwardingQuantities
|
4726
4852
|
);
|
4727
|
-
request.gasLimit = (0,
|
4853
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4728
4854
|
this.validateGas({
|
4729
4855
|
gasUsed,
|
4730
4856
|
gasPrice: request.gasPrice,
|
@@ -4736,7 +4862,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4736
4862
|
}
|
4737
4863
|
async signMessage(message) {
|
4738
4864
|
if (!this._connector) {
|
4739
|
-
throw new
|
4865
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4740
4866
|
}
|
4741
4867
|
return this._connector.signMessage(this.address.toString(), message);
|
4742
4868
|
}
|
@@ -4748,8 +4874,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4748
4874
|
*/
|
4749
4875
|
async signTransaction(transactionRequestLike) {
|
4750
4876
|
if (!this._connector) {
|
4751
|
-
throw new
|
4752
|
-
|
4877
|
+
throw new import_errors16.FuelError(
|
4878
|
+
import_errors16.ErrorCode.MISSING_CONNECTOR,
|
4753
4879
|
"A connector is required to sign transactions."
|
4754
4880
|
);
|
4755
4881
|
}
|
@@ -4796,14 +4922,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4796
4922
|
minGasPrice
|
4797
4923
|
}) {
|
4798
4924
|
if (minGasPrice.gt(gasPrice)) {
|
4799
|
-
throw new
|
4800
|
-
|
4925
|
+
throw new import_errors16.FuelError(
|
4926
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4801
4927
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4802
4928
|
);
|
4803
4929
|
}
|
4804
4930
|
if (gasUsed.gt(gasLimit)) {
|
4805
|
-
throw new
|
4806
|
-
|
4931
|
+
throw new import_errors16.FuelError(
|
4932
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4807
4933
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4808
4934
|
);
|
4809
4935
|
}
|
@@ -4812,10 +4938,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4812
4938
|
|
4813
4939
|
// src/signer/signer.ts
|
4814
4940
|
var import_address5 = require("@fuel-ts/address");
|
4815
|
-
var
|
4941
|
+
var import_crypto2 = require("@fuel-ts/crypto");
|
4816
4942
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4817
|
-
var
|
4818
|
-
var
|
4943
|
+
var import_math19 = require("@fuel-ts/math");
|
4944
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4819
4945
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4820
4946
|
var Signer = class {
|
4821
4947
|
address;
|
@@ -4834,10 +4960,10 @@ var Signer = class {
|
|
4834
4960
|
privateKey = `0x${privateKey}`;
|
4835
4961
|
}
|
4836
4962
|
}
|
4837
|
-
const privateKeyBytes = (0,
|
4838
|
-
this.privateKey = (0,
|
4839
|
-
this.publicKey = (0,
|
4840
|
-
this.compressedPublicKey = (0,
|
4963
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4964
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4965
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4966
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4841
4967
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4842
4968
|
}
|
4843
4969
|
/**
|
@@ -4851,11 +4977,11 @@ var Signer = class {
|
|
4851
4977
|
* @returns hashed signature
|
4852
4978
|
*/
|
4853
4979
|
sign(data) {
|
4854
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4855
|
-
const r = (0,
|
4856
|
-
const s = (0,
|
4980
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4981
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4982
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4857
4983
|
s[0] |= (signature.recovery || 0) << 7;
|
4858
|
-
return (0,
|
4984
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
4859
4985
|
}
|
4860
4986
|
/**
|
4861
4987
|
* Add point on the current elliptic curve
|
@@ -4864,8 +4990,8 @@ var Signer = class {
|
|
4864
4990
|
* @returns compressed point on the curve
|
4865
4991
|
*/
|
4866
4992
|
addPoint(point) {
|
4867
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4868
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4993
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4994
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
4869
4995
|
const result = p0.add(p1);
|
4870
4996
|
return `0x${result.toHex(true)}`;
|
4871
4997
|
}
|
@@ -4877,16 +5003,16 @@ var Signer = class {
|
|
4877
5003
|
* @returns public key from signature from the
|
4878
5004
|
*/
|
4879
5005
|
static recoverPublicKey(data, signature) {
|
4880
|
-
const signedMessageBytes = (0,
|
5006
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
4881
5007
|
const r = signedMessageBytes.slice(0, 32);
|
4882
5008
|
const s = signedMessageBytes.slice(32, 64);
|
4883
5009
|
const recoveryParam = (s[0] & 128) >> 7;
|
4884
5010
|
s[0] &= 127;
|
4885
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5011
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
4886
5012
|
recoveryParam
|
4887
5013
|
);
|
4888
|
-
const publicKey = sig.recoverPublicKey((0,
|
4889
|
-
return (0,
|
5014
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5015
|
+
return (0, import_utils29.hexlify)(publicKey);
|
4890
5016
|
}
|
4891
5017
|
/**
|
4892
5018
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4905,7 +5031,7 @@ var Signer = class {
|
|
4905
5031
|
* @returns random 32-byte hashed
|
4906
5032
|
*/
|
4907
5033
|
static generatePrivateKey(entropy) {
|
4908
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5034
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
|
4909
5035
|
}
|
4910
5036
|
/**
|
4911
5037
|
* Extended publicKey from a compact publicKey
|
@@ -4914,16 +5040,16 @@ var Signer = class {
|
|
4914
5040
|
* @returns extended publicKey
|
4915
5041
|
*/
|
4916
5042
|
static extendPublicKey(publicKey) {
|
4917
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4918
|
-
return (0,
|
5043
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5044
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
4919
5045
|
}
|
4920
5046
|
};
|
4921
5047
|
|
4922
5048
|
// src/wallet/keystore-wallet.ts
|
4923
5049
|
var import_address6 = require("@fuel-ts/address");
|
4924
|
-
var
|
4925
|
-
var
|
4926
|
-
var
|
5050
|
+
var import_crypto3 = require("@fuel-ts/crypto");
|
5051
|
+
var import_errors17 = require("@fuel-ts/errors");
|
5052
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4927
5053
|
var import_uuid = require("uuid");
|
4928
5054
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4929
5055
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -4937,22 +5063,22 @@ var removeHexPrefix = (hexString) => {
|
|
4937
5063
|
return hexString;
|
4938
5064
|
};
|
4939
5065
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
4940
|
-
const privateKeyBuffer = (0,
|
5066
|
+
const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
|
4941
5067
|
const ownerAddress = import_address6.Address.fromAddressOrString(address);
|
4942
|
-
const salt = (0,
|
4943
|
-
const key = (0,
|
4944
|
-
password: (0,
|
5068
|
+
const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
|
5069
|
+
const key = (0, import_crypto3.scrypt)({
|
5070
|
+
password: (0, import_crypto3.bufferFromString)(password),
|
4945
5071
|
salt,
|
4946
5072
|
dklen: DEFAULT_KEY_SIZE,
|
4947
5073
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
4948
5074
|
r: DEFAULT_KDF_PARAMS_R,
|
4949
5075
|
p: DEFAULT_KDF_PARAMS_P
|
4950
5076
|
});
|
4951
|
-
const iv = (0,
|
4952
|
-
const ciphertext = await (0,
|
5077
|
+
const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
|
5078
|
+
const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
|
4953
5079
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
4954
|
-
const macHashUint8Array = (0,
|
4955
|
-
const mac = (0,
|
5080
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5081
|
+
const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
4956
5082
|
const keystore = {
|
4957
5083
|
id: (0, import_uuid.v4)(),
|
4958
5084
|
version: 3,
|
@@ -4960,15 +5086,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
4960
5086
|
crypto: {
|
4961
5087
|
cipher: "aes-128-ctr",
|
4962
5088
|
mac,
|
4963
|
-
cipherparams: { iv: (0,
|
4964
|
-
ciphertext: (0,
|
5089
|
+
cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
|
5090
|
+
ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
|
4965
5091
|
kdf: "scrypt",
|
4966
5092
|
kdfparams: {
|
4967
5093
|
dklen: DEFAULT_KEY_SIZE,
|
4968
5094
|
n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
|
4969
5095
|
p: DEFAULT_KDF_PARAMS_P,
|
4970
5096
|
r: DEFAULT_KDF_PARAMS_R,
|
4971
|
-
salt: (0,
|
5097
|
+
salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
|
4972
5098
|
}
|
4973
5099
|
}
|
4974
5100
|
};
|
@@ -4984,11 +5110,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4984
5110
|
kdfparams: { dklen, n, r, p, salt }
|
4985
5111
|
}
|
4986
5112
|
} = keystoreWallet;
|
4987
|
-
const ciphertextBuffer = (0,
|
4988
|
-
const ivBuffer = (0,
|
4989
|
-
const saltBuffer = (0,
|
4990
|
-
const passwordBuffer = (0,
|
4991
|
-
const key = (0,
|
5113
|
+
const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
|
5114
|
+
const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
|
5115
|
+
const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
|
5116
|
+
const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
|
5117
|
+
const key = (0, import_crypto3.scrypt)({
|
4992
5118
|
password: passwordBuffer,
|
4993
5119
|
salt: saltBuffer,
|
4994
5120
|
n,
|
@@ -4997,16 +5123,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
4997
5123
|
dklen
|
4998
5124
|
});
|
4999
5125
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
|
5000
|
-
const macHashUint8Array = (0,
|
5001
|
-
const macHash = (0,
|
5126
|
+
const macHashUint8Array = (0, import_crypto3.keccak256)(data);
|
5127
|
+
const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
|
5002
5128
|
if (mac !== macHash) {
|
5003
|
-
throw new
|
5004
|
-
|
5129
|
+
throw new import_errors17.FuelError(
|
5130
|
+
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5005
5131
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5006
5132
|
);
|
5007
5133
|
}
|
5008
|
-
const buffer = await (0,
|
5009
|
-
const privateKey = (0,
|
5134
|
+
const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5135
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5010
5136
|
return privateKey;
|
5011
5137
|
}
|
5012
5138
|
|
@@ -5051,7 +5177,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5051
5177
|
*/
|
5052
5178
|
async signMessage(message) {
|
5053
5179
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5054
|
-
return (0,
|
5180
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5055
5181
|
}
|
5056
5182
|
/**
|
5057
5183
|
* Signs a transaction with the wallet's private key.
|
@@ -5064,7 +5190,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5064
5190
|
const chainId = this.provider.getChainId();
|
5065
5191
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5066
5192
|
const signature = await this.signer().sign(hashedTransaction);
|
5067
|
-
return (0,
|
5193
|
+
return (0, import_utils31.hexlify)(signature);
|
5068
5194
|
}
|
5069
5195
|
/**
|
5070
5196
|
* Populates a transaction with the witnesses signature.
|
@@ -5123,17 +5249,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5123
5249
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5124
5250
|
|
5125
5251
|
// src/hdwallet/hdwallet.ts
|
5126
|
-
var
|
5252
|
+
var import_errors20 = require("@fuel-ts/errors");
|
5127
5253
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5128
|
-
var
|
5129
|
-
var
|
5254
|
+
var import_math20 = require("@fuel-ts/math");
|
5255
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5130
5256
|
var import_ethers3 = require("ethers");
|
5131
5257
|
|
5132
5258
|
// src/mnemonic/mnemonic.ts
|
5133
|
-
var
|
5134
|
-
var
|
5259
|
+
var import_crypto4 = require("@fuel-ts/crypto");
|
5260
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5135
5261
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5136
|
-
var
|
5262
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5137
5263
|
var import_ethers2 = require("ethers");
|
5138
5264
|
|
5139
5265
|
// src/wordlists/words/english.ts
|
@@ -7189,9 +7315,9 @@ var english = [
|
|
7189
7315
|
];
|
7190
7316
|
|
7191
7317
|
// src/mnemonic/utils.ts
|
7192
|
-
var
|
7318
|
+
var import_errors18 = require("@fuel-ts/errors");
|
7193
7319
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7194
|
-
var
|
7320
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7195
7321
|
function toUtf8Bytes(stri) {
|
7196
7322
|
const str = stri.normalize("NFKD");
|
7197
7323
|
const result = [];
|
@@ -7206,8 +7332,8 @@ function toUtf8Bytes(stri) {
|
|
7206
7332
|
i += 1;
|
7207
7333
|
const c2 = str.charCodeAt(i);
|
7208
7334
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7209
|
-
throw new
|
7210
|
-
|
7335
|
+
throw new import_errors18.FuelError(
|
7336
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7211
7337
|
"Invalid UTF-8 in the input string."
|
7212
7338
|
);
|
7213
7339
|
}
|
@@ -7258,20 +7384,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7258
7384
|
}
|
7259
7385
|
}
|
7260
7386
|
const checksumBits = entropy.length / 4;
|
7261
|
-
const checksum = (0,
|
7387
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7262
7388
|
indices[indices.length - 1] <<= checksumBits;
|
7263
7389
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7264
7390
|
return indices;
|
7265
7391
|
}
|
7266
7392
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7267
7393
|
const size = Math.ceil(11 * words.length / 8);
|
7268
|
-
const entropy = (0,
|
7394
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7269
7395
|
let offset = 0;
|
7270
7396
|
for (let i = 0; i < words.length; i += 1) {
|
7271
7397
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7272
7398
|
if (index === -1) {
|
7273
|
-
throw new
|
7274
|
-
|
7399
|
+
throw new import_errors18.FuelError(
|
7400
|
+
import_errors18.ErrorCode.INVALID_MNEMONIC,
|
7275
7401
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7276
7402
|
);
|
7277
7403
|
}
|
@@ -7285,10 +7411,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7285
7411
|
const entropyBits = 32 * words.length / 3;
|
7286
7412
|
const checksumBits = words.length / 3;
|
7287
7413
|
const checksumMask = getUpperMask(checksumBits);
|
7288
|
-
const checksum = (0,
|
7414
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7289
7415
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7290
|
-
throw new
|
7291
|
-
|
7416
|
+
throw new import_errors18.FuelError(
|
7417
|
+
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
7292
7418
|
"Checksum validation failed for the provided mnemonic."
|
7293
7419
|
);
|
7294
7420
|
}
|
@@ -7302,16 +7428,16 @@ var TestnetPRV = "0x04358394";
|
|
7302
7428
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7303
7429
|
function assertWordList(wordlist) {
|
7304
7430
|
if (wordlist.length !== 2048) {
|
7305
|
-
throw new
|
7306
|
-
|
7431
|
+
throw new import_errors19.FuelError(
|
7432
|
+
import_errors19.ErrorCode.INVALID_WORD_LIST,
|
7307
7433
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7308
7434
|
);
|
7309
7435
|
}
|
7310
7436
|
}
|
7311
7437
|
function assertEntropy(entropy) {
|
7312
7438
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7313
|
-
throw new
|
7314
|
-
|
7439
|
+
throw new import_errors19.FuelError(
|
7440
|
+
import_errors19.ErrorCode.INVALID_ENTROPY,
|
7315
7441
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7316
7442
|
);
|
7317
7443
|
}
|
@@ -7321,7 +7447,7 @@ function assertMnemonic(words) {
|
|
7321
7447
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7322
7448
|
", "
|
7323
7449
|
)}] words, but got ${words.length}.`;
|
7324
|
-
throw new
|
7450
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7325
7451
|
}
|
7326
7452
|
}
|
7327
7453
|
var Mnemonic = class {
|
@@ -7360,7 +7486,7 @@ var Mnemonic = class {
|
|
7360
7486
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7361
7487
|
const words = getWords(phrase);
|
7362
7488
|
assertMnemonic(words);
|
7363
|
-
return (0,
|
7489
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7364
7490
|
}
|
7365
7491
|
/**
|
7366
7492
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7368,7 +7494,7 @@ var Mnemonic = class {
|
|
7368
7494
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7369
7495
|
*/
|
7370
7496
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7371
|
-
const entropyBytes = (0,
|
7497
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7372
7498
|
assertWordList(wordlist);
|
7373
7499
|
assertEntropy(entropyBytes);
|
7374
7500
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7437,14 +7563,14 @@ var Mnemonic = class {
|
|
7437
7563
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7438
7564
|
*/
|
7439
7565
|
static masterKeysFromSeed(seed) {
|
7440
|
-
const seedArray = (0,
|
7566
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7441
7567
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7442
|
-
throw new
|
7443
|
-
|
7568
|
+
throw new import_errors19.FuelError(
|
7569
|
+
import_errors19.ErrorCode.INVALID_SEED,
|
7444
7570
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7445
7571
|
);
|
7446
7572
|
}
|
7447
|
-
return (0,
|
7573
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7448
7574
|
}
|
7449
7575
|
/**
|
7450
7576
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7455,22 +7581,22 @@ var Mnemonic = class {
|
|
7455
7581
|
*/
|
7456
7582
|
static seedToExtendedKey(seed, testnet = false) {
|
7457
7583
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7458
|
-
const prefix = (0,
|
7584
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7459
7585
|
const depth = "0x00";
|
7460
7586
|
const fingerprint = "0x00000000";
|
7461
7587
|
const index = "0x00000000";
|
7462
7588
|
const chainCode = masterKey.slice(32);
|
7463
7589
|
const privateKey = masterKey.slice(0, 32);
|
7464
|
-
const extendedKey = (0,
|
7590
|
+
const extendedKey = (0, import_utils33.concat)([
|
7465
7591
|
prefix,
|
7466
7592
|
depth,
|
7467
7593
|
fingerprint,
|
7468
7594
|
index,
|
7469
7595
|
chainCode,
|
7470
|
-
(0,
|
7596
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7471
7597
|
]);
|
7472
7598
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7473
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7599
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7474
7600
|
}
|
7475
7601
|
/**
|
7476
7602
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7485,7 +7611,7 @@ var Mnemonic = class {
|
|
7485
7611
|
* @returns A randomly generated mnemonic
|
7486
7612
|
*/
|
7487
7613
|
static generate(size = 32, extraEntropy = "") {
|
7488
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7614
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
|
7489
7615
|
return Mnemonic.entropyToMnemonic(entropy);
|
7490
7616
|
}
|
7491
7617
|
};
|
@@ -7493,12 +7619,12 @@ var mnemonic_default = Mnemonic;
|
|
7493
7619
|
|
7494
7620
|
// src/hdwallet/hdwallet.ts
|
7495
7621
|
var HARDENED_INDEX = 2147483648;
|
7496
|
-
var MainnetPRV2 = (0,
|
7497
|
-
var MainnetPUB = (0,
|
7498
|
-
var TestnetPRV2 = (0,
|
7499
|
-
var TestnetPUB = (0,
|
7622
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7623
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7624
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7625
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7500
7626
|
function base58check(data) {
|
7501
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7627
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils35.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
7502
7628
|
}
|
7503
7629
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7504
7630
|
if (isPublic) {
|
@@ -7507,17 +7633,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7507
7633
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7508
7634
|
}
|
7509
7635
|
function isPublicExtendedKey(extendedKey) {
|
7510
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7636
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7511
7637
|
}
|
7512
7638
|
function isValidExtendedKey(extendedKey) {
|
7513
7639
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7514
|
-
(0,
|
7640
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7515
7641
|
);
|
7516
7642
|
}
|
7517
7643
|
function parsePath(path2, depth = 0) {
|
7518
7644
|
const components = path2.split("/");
|
7519
7645
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7520
|
-
throw new
|
7646
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7521
7647
|
}
|
7522
7648
|
if (components[0] === "m") {
|
7523
7649
|
components.shift();
|
@@ -7529,8 +7655,8 @@ function parsePath(path2, depth = 0) {
|
|
7529
7655
|
var HDWallet = class {
|
7530
7656
|
depth = 0;
|
7531
7657
|
index = 0;
|
7532
|
-
fingerprint = (0,
|
7533
|
-
parentFingerprint = (0,
|
7658
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7659
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7534
7660
|
privateKey;
|
7535
7661
|
publicKey;
|
7536
7662
|
chainCode;
|
@@ -7542,16 +7668,16 @@ var HDWallet = class {
|
|
7542
7668
|
constructor(config) {
|
7543
7669
|
if (config.privateKey) {
|
7544
7670
|
const signer = new Signer(config.privateKey);
|
7545
|
-
this.publicKey = (0,
|
7546
|
-
this.privateKey = (0,
|
7671
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7672
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7547
7673
|
} else {
|
7548
7674
|
if (!config.publicKey) {
|
7549
|
-
throw new
|
7550
|
-
|
7675
|
+
throw new import_errors20.FuelError(
|
7676
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7551
7677
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7552
7678
|
);
|
7553
7679
|
}
|
7554
|
-
this.publicKey = (0,
|
7680
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7555
7681
|
}
|
7556
7682
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7557
7683
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7570,28 +7696,28 @@ var HDWallet = class {
|
|
7570
7696
|
* @returns A new instance of HDWallet on the derived index
|
7571
7697
|
*/
|
7572
7698
|
deriveIndex(index) {
|
7573
|
-
const privateKey = this.privateKey && (0,
|
7574
|
-
const publicKey = (0,
|
7575
|
-
const chainCode = (0,
|
7699
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7700
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7701
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7576
7702
|
const data = new Uint8Array(37);
|
7577
7703
|
if (index & HARDENED_INDEX) {
|
7578
7704
|
if (!privateKey) {
|
7579
|
-
throw new
|
7580
|
-
|
7705
|
+
throw new import_errors20.FuelError(
|
7706
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7581
7707
|
"Cannot derive a hardened index without a private Key."
|
7582
7708
|
);
|
7583
7709
|
}
|
7584
7710
|
data.set(privateKey, 1);
|
7585
7711
|
} else {
|
7586
|
-
data.set((0,
|
7712
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7587
7713
|
}
|
7588
|
-
data.set((0,
|
7589
|
-
const bytes = (0,
|
7714
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7715
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7590
7716
|
const IL = bytes.slice(0, 32);
|
7591
7717
|
const IR = bytes.slice(32);
|
7592
7718
|
if (privateKey) {
|
7593
7719
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7594
|
-
const ki = (0,
|
7720
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7595
7721
|
return new HDWallet({
|
7596
7722
|
privateKey: ki,
|
7597
7723
|
chainCode: IR,
|
@@ -7600,7 +7726,7 @@ var HDWallet = class {
|
|
7600
7726
|
parentFingerprint: this.fingerprint
|
7601
7727
|
});
|
7602
7728
|
}
|
7603
|
-
const signer = new Signer((0,
|
7729
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7604
7730
|
const Ki = signer.addPoint(publicKey);
|
7605
7731
|
return new HDWallet({
|
7606
7732
|
publicKey: Ki,
|
@@ -7629,18 +7755,18 @@ var HDWallet = class {
|
|
7629
7755
|
*/
|
7630
7756
|
toExtendedKey(isPublic = false, testnet = false) {
|
7631
7757
|
if (this.depth >= 256) {
|
7632
|
-
throw new
|
7633
|
-
|
7758
|
+
throw new import_errors20.FuelError(
|
7759
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7634
7760
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7635
7761
|
);
|
7636
7762
|
}
|
7637
7763
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7638
|
-
const depth = (0,
|
7764
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7639
7765
|
const parentFingerprint = this.parentFingerprint;
|
7640
|
-
const index = (0,
|
7766
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7641
7767
|
const chainCode = this.chainCode;
|
7642
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7643
|
-
const extendedKey = (0,
|
7768
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7769
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7644
7770
|
return base58check(extendedKey);
|
7645
7771
|
}
|
7646
7772
|
/**
|
@@ -7652,34 +7778,34 @@ var HDWallet = class {
|
|
7652
7778
|
static fromSeed(seed) {
|
7653
7779
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7654
7780
|
return new HDWallet({
|
7655
|
-
chainCode: (0,
|
7656
|
-
privateKey: (0,
|
7781
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7782
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7657
7783
|
});
|
7658
7784
|
}
|
7659
7785
|
static fromExtendedKey(extendedKey) {
|
7660
7786
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7661
|
-
const bytes = (0,
|
7787
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7662
7788
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7663
7789
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7664
|
-
throw new
|
7790
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7665
7791
|
}
|
7666
7792
|
if (!validChecksum) {
|
7667
|
-
throw new
|
7793
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7668
7794
|
}
|
7669
7795
|
const depth = bytes[4];
|
7670
|
-
const parentFingerprint = (0,
|
7671
|
-
const index = parseInt((0,
|
7672
|
-
const chainCode = (0,
|
7796
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7797
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7798
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7673
7799
|
const key = bytes.slice(45, 78);
|
7674
7800
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7675
|
-
throw new
|
7676
|
-
|
7801
|
+
throw new import_errors20.FuelError(
|
7802
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7677
7803
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7678
7804
|
);
|
7679
7805
|
}
|
7680
7806
|
if (isPublicExtendedKey(bytes)) {
|
7681
7807
|
if (key[0] !== 3) {
|
7682
|
-
throw new
|
7808
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
7683
7809
|
}
|
7684
7810
|
return new HDWallet({
|
7685
7811
|
publicKey: key,
|
@@ -7690,7 +7816,7 @@ var HDWallet = class {
|
|
7690
7816
|
});
|
7691
7817
|
}
|
7692
7818
|
if (key[0] !== 0) {
|
7693
|
-
throw new
|
7819
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
7694
7820
|
}
|
7695
7821
|
return new HDWallet({
|
7696
7822
|
privateKey: key.slice(1),
|
@@ -7856,10 +7982,10 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
7856
7982
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
7857
7983
|
|
7858
7984
|
// src/test-utils/seedTestWallet.ts
|
7859
|
-
var
|
7985
|
+
var import_crypto5 = require("@fuel-ts/crypto");
|
7860
7986
|
var seedTestWallet = async (wallet, quantities) => {
|
7861
7987
|
const genesisWallet = new WalletUnlocked(
|
7862
|
-
process.env.GENESIS_SECRET || (0,
|
7988
|
+
process.env.GENESIS_SECRET || (0, import_crypto5.randomBytes)(32),
|
7863
7989
|
wallet.provider
|
7864
7990
|
);
|
7865
7991
|
const resources = await genesisWallet.getResourcesToSpend(quantities);
|
@@ -7883,12 +8009,12 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7883
8009
|
};
|
7884
8010
|
|
7885
8011
|
// src/test-utils/launchNode.ts
|
7886
|
-
var
|
7887
|
-
var
|
7888
|
-
var
|
8012
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
8013
|
+
var import_math21 = require("@fuel-ts/math");
|
8014
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7889
8015
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7890
8016
|
var import_child_process = require("child_process");
|
7891
|
-
var
|
8017
|
+
var import_crypto6 = require("crypto");
|
7892
8018
|
var import_fs = require("fs");
|
7893
8019
|
var import_os = __toESM(require("os"));
|
7894
8020
|
var import_path = __toESM(require("path"));
|
@@ -7943,7 +8069,7 @@ var launchNode = async ({
|
|
7943
8069
|
"--poa-instant"
|
7944
8070
|
]);
|
7945
8071
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7946
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8072
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
7947
8073
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7948
8074
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7949
8075
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -7960,7 +8086,7 @@ var launchNode = async ({
|
|
7960
8086
|
})).toString();
|
7961
8087
|
let chainConfigPathToUse;
|
7962
8088
|
const prefix = basePath || import_os.default.tmpdir();
|
7963
|
-
const suffix = basePath ? "" : (0,
|
8089
|
+
const suffix = basePath ? "" : (0, import_crypto6.randomUUID)();
|
7964
8090
|
const tempDirPath = import_path.default.join(prefix, ".fuels", suffix);
|
7965
8091
|
if (chainConfigPath) {
|
7966
8092
|
chainConfigPathToUse = chainConfigPath;
|
@@ -7969,21 +8095,21 @@ var launchNode = async ({
|
|
7969
8095
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
7970
8096
|
}
|
7971
8097
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
7972
|
-
let chainConfig =
|
8098
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
7973
8099
|
if (!process.env.GENESIS_SECRET) {
|
7974
8100
|
const pk = Signer.generatePrivateKey();
|
7975
8101
|
const signer = new Signer(pk);
|
7976
|
-
process.env.GENESIS_SECRET = (0,
|
8102
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
7977
8103
|
chainConfig = {
|
7978
|
-
...
|
8104
|
+
...import_utils36.defaultChainConfig,
|
7979
8105
|
initial_state: {
|
7980
|
-
...
|
8106
|
+
...import_utils36.defaultChainConfig.initial_state,
|
7981
8107
|
coins: [
|
7982
|
-
...
|
8108
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
7983
8109
|
{
|
7984
8110
|
owner: signer.address.toHexString(),
|
7985
|
-
amount: (0,
|
7986
|
-
asset_id:
|
8111
|
+
amount: (0, import_math21.toHex)(1e9),
|
8112
|
+
asset_id: import_configs13.BaseAssetId
|
7987
8113
|
}
|
7988
8114
|
]
|
7989
8115
|
}
|
@@ -8051,7 +8177,7 @@ var launchNode = async ({
|
|
8051
8177
|
var generateWallets = async (count, provider) => {
|
8052
8178
|
const wallets = [];
|
8053
8179
|
for (let i = 0; i < count; i += 1) {
|
8054
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8180
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8055
8181
|
wallets.push(wallet);
|
8056
8182
|
}
|
8057
8183
|
return wallets;
|