@fuel-ts/account 0.0.0-rc-1832-20240402200757 → 0.0.0-rc-1895-20240403004459
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/index.global.js +164 -82
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +551 -468
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +328 -240
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +164 -82
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +511 -434
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +298 -213
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/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");
|
@@ -1184,9 +1184,9 @@ var outputify = (value) => {
|
|
1184
1184
|
|
1185
1185
|
// src/providers/transaction-request/transaction-request.ts
|
1186
1186
|
var import_address = require("@fuel-ts/address");
|
1187
|
-
var
|
1188
|
-
var
|
1189
|
-
var
|
1187
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
1188
|
+
var import_math7 = require("@fuel-ts/math");
|
1189
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1190
1190
|
var import_utils9 = require("@fuel-ts/utils");
|
1191
1191
|
|
1192
1192
|
// src/providers/resource.ts
|
@@ -1517,6 +1517,78 @@ function sleep(time) {
|
|
1517
1517
|
});
|
1518
1518
|
}
|
1519
1519
|
|
1520
|
+
// src/providers/utils/extract-tx-error.ts
|
1521
|
+
var import_errors7 = require("@fuel-ts/errors");
|
1522
|
+
var import_math6 = require("@fuel-ts/math");
|
1523
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1524
|
+
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1525
|
+
var assemblePanicError = (status) => {
|
1526
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1527
|
+
const reason = status.reason;
|
1528
|
+
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1529
|
+
errorMessage = `${errorMessage}
|
1530
|
+
|
1531
|
+
You can read more about this error at:
|
1532
|
+
|
1533
|
+
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1534
|
+
}
|
1535
|
+
return { errorMessage, reason };
|
1536
|
+
};
|
1537
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1538
|
+
var assembleRevertError = (receipts, logs) => {
|
1539
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1540
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1541
|
+
let reason = "";
|
1542
|
+
if (revertReceipt) {
|
1543
|
+
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1544
|
+
switch (reasonHex) {
|
1545
|
+
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1546
|
+
reason = "require";
|
1547
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1548
|
+
break;
|
1549
|
+
}
|
1550
|
+
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1551
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1552
|
+
reason = "assert_eq";
|
1553
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1554
|
+
break;
|
1555
|
+
}
|
1556
|
+
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1557
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1558
|
+
reason = "assert_ne";
|
1559
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1560
|
+
break;
|
1561
|
+
}
|
1562
|
+
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1563
|
+
reason = "assert";
|
1564
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1565
|
+
break;
|
1566
|
+
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1567
|
+
reason = "MissingOutputChange";
|
1568
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1569
|
+
break;
|
1570
|
+
default:
|
1571
|
+
reason = "unknown";
|
1572
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
return { errorMessage, reason };
|
1576
|
+
};
|
1577
|
+
var extractTxError = (params) => {
|
1578
|
+
const { receipts, status, logs } = params;
|
1579
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1580
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1581
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1582
|
+
const metadata = {
|
1583
|
+
logs,
|
1584
|
+
receipts,
|
1585
|
+
panic: isPanic,
|
1586
|
+
revert: isRevert,
|
1587
|
+
reason
|
1588
|
+
};
|
1589
|
+
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1590
|
+
};
|
1591
|
+
|
1520
1592
|
// src/providers/transaction-request/errors.ts
|
1521
1593
|
var NoWitnessAtIndexError = class extends Error {
|
1522
1594
|
constructor(index) {
|
@@ -1567,10 +1639,10 @@ var BaseTransactionRequest = class {
|
|
1567
1639
|
outputs,
|
1568
1640
|
witnesses
|
1569
1641
|
} = {}) {
|
1570
|
-
this.gasPrice = (0,
|
1642
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1571
1643
|
this.maturity = maturity ?? 0;
|
1572
|
-
this.witnessLimit = witnessLimit ? (0,
|
1573
|
-
this.maxFee = maxFee ? (0,
|
1644
|
+
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1645
|
+
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1574
1646
|
this.inputs = inputs ?? [];
|
1575
1647
|
this.outputs = outputs ?? [];
|
1576
1648
|
this.witnesses = witnesses ?? [];
|
@@ -1579,20 +1651,20 @@ var BaseTransactionRequest = class {
|
|
1579
1651
|
let policyTypes = 0;
|
1580
1652
|
const policies = [];
|
1581
1653
|
if (req.gasPrice) {
|
1582
|
-
policyTypes +=
|
1583
|
-
policies.push({ data: req.gasPrice, type:
|
1654
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1655
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1584
1656
|
}
|
1585
1657
|
if (req.witnessLimit) {
|
1586
|
-
policyTypes +=
|
1587
|
-
policies.push({ data: req.witnessLimit, type:
|
1658
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1659
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1588
1660
|
}
|
1589
1661
|
if (req.maturity > 0) {
|
1590
|
-
policyTypes +=
|
1591
|
-
policies.push({ data: req.maturity, type:
|
1662
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1663
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1592
1664
|
}
|
1593
1665
|
if (req.maxFee) {
|
1594
|
-
policyTypes +=
|
1595
|
-
policies.push({ data: req.maxFee, type:
|
1666
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1667
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1596
1668
|
}
|
1597
1669
|
return {
|
1598
1670
|
policyTypes,
|
@@ -1626,7 +1698,7 @@ var BaseTransactionRequest = class {
|
|
1626
1698
|
* @returns The transaction bytes.
|
1627
1699
|
*/
|
1628
1700
|
toTransactionBytes() {
|
1629
|
-
return new
|
1701
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1630
1702
|
}
|
1631
1703
|
/**
|
1632
1704
|
* @hidden
|
@@ -1666,7 +1738,7 @@ var BaseTransactionRequest = class {
|
|
1666
1738
|
* @returns The index of the created witness.
|
1667
1739
|
*/
|
1668
1740
|
addEmptyWitness() {
|
1669
|
-
this.addWitness((0, import_utils9.concat)([
|
1741
|
+
this.addWitness((0, import_utils9.concat)([import_configs7.ZeroBytes32, import_configs7.ZeroBytes32]));
|
1670
1742
|
return this.witnesses.length - 1;
|
1671
1743
|
}
|
1672
1744
|
/**
|
@@ -1717,7 +1789,7 @@ var BaseTransactionRequest = class {
|
|
1717
1789
|
*/
|
1718
1790
|
getCoinInputs() {
|
1719
1791
|
return this.inputs.filter(
|
1720
|
-
(input) => input.type ===
|
1792
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1721
1793
|
);
|
1722
1794
|
}
|
1723
1795
|
/**
|
@@ -1727,7 +1799,7 @@ var BaseTransactionRequest = class {
|
|
1727
1799
|
*/
|
1728
1800
|
getCoinOutputs() {
|
1729
1801
|
return this.outputs.filter(
|
1730
|
-
(output) => output.type ===
|
1802
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1731
1803
|
);
|
1732
1804
|
}
|
1733
1805
|
/**
|
@@ -1737,7 +1809,7 @@ var BaseTransactionRequest = class {
|
|
1737
1809
|
*/
|
1738
1810
|
getChangeOutputs() {
|
1739
1811
|
return this.outputs.filter(
|
1740
|
-
(output) => output.type ===
|
1812
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1741
1813
|
);
|
1742
1814
|
}
|
1743
1815
|
/**
|
@@ -1749,9 +1821,9 @@ var BaseTransactionRequest = class {
|
|
1749
1821
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1750
1822
|
const found = this.inputs.find((input) => {
|
1751
1823
|
switch (input.type) {
|
1752
|
-
case
|
1824
|
+
case import_transactions6.InputType.Coin:
|
1753
1825
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1754
|
-
case
|
1826
|
+
case import_transactions6.InputType.Message:
|
1755
1827
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1756
1828
|
default:
|
1757
1829
|
return false;
|
@@ -1780,7 +1852,7 @@ var BaseTransactionRequest = class {
|
|
1780
1852
|
}
|
1781
1853
|
const input = {
|
1782
1854
|
...coin,
|
1783
|
-
type:
|
1855
|
+
type: import_transactions6.InputType.Coin,
|
1784
1856
|
owner: owner.toB256(),
|
1785
1857
|
amount,
|
1786
1858
|
assetId,
|
@@ -1802,7 +1874,7 @@ var BaseTransactionRequest = class {
|
|
1802
1874
|
*/
|
1803
1875
|
addMessageInput(message, predicate) {
|
1804
1876
|
const { recipient, sender, amount } = message;
|
1805
|
-
const assetId =
|
1877
|
+
const assetId = import_configs7.BaseAssetId;
|
1806
1878
|
let witnessIndex;
|
1807
1879
|
if (predicate) {
|
1808
1880
|
witnessIndex = 0;
|
@@ -1814,7 +1886,7 @@ var BaseTransactionRequest = class {
|
|
1814
1886
|
}
|
1815
1887
|
const input = {
|
1816
1888
|
...message,
|
1817
|
-
type:
|
1889
|
+
type: import_transactions6.InputType.Message,
|
1818
1890
|
sender: sender.toB256(),
|
1819
1891
|
recipient: recipient.toB256(),
|
1820
1892
|
amount,
|
@@ -1884,9 +1956,9 @@ var BaseTransactionRequest = class {
|
|
1884
1956
|
* @param amount - Amount of coin.
|
1885
1957
|
* @param assetId - Asset ID of coin.
|
1886
1958
|
*/
|
1887
|
-
addCoinOutput(to, amount, assetId =
|
1959
|
+
addCoinOutput(to, amount, assetId = import_configs7.BaseAssetId) {
|
1888
1960
|
this.pushOutput({
|
1889
|
-
type:
|
1961
|
+
type: import_transactions6.OutputType.Coin,
|
1890
1962
|
to: (0, import_address.addressify)(to).toB256(),
|
1891
1963
|
amount,
|
1892
1964
|
assetId
|
@@ -1902,7 +1974,7 @@ var BaseTransactionRequest = class {
|
|
1902
1974
|
addCoinOutputs(to, quantities) {
|
1903
1975
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
1904
1976
|
this.pushOutput({
|
1905
|
-
type:
|
1977
|
+
type: import_transactions6.OutputType.Coin,
|
1906
1978
|
to: (0, import_address.addressify)(to).toB256(),
|
1907
1979
|
amount: quantity.amount,
|
1908
1980
|
assetId: quantity.assetId
|
@@ -1916,13 +1988,13 @@ var BaseTransactionRequest = class {
|
|
1916
1988
|
* @param to - Address of the owner.
|
1917
1989
|
* @param assetId - Asset ID of coin.
|
1918
1990
|
*/
|
1919
|
-
addChangeOutput(to, assetId =
|
1991
|
+
addChangeOutput(to, assetId = import_configs7.BaseAssetId) {
|
1920
1992
|
const changeOutput = this.getChangeOutputs().find(
|
1921
1993
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
1922
1994
|
);
|
1923
1995
|
if (!changeOutput) {
|
1924
1996
|
this.pushOutput({
|
1925
|
-
type:
|
1997
|
+
type: import_transactions6.OutputType.Change,
|
1926
1998
|
to: (0, import_address.addressify)(to).toB256(),
|
1927
1999
|
assetId
|
1928
2000
|
});
|
@@ -1978,7 +2050,7 @@ var BaseTransactionRequest = class {
|
|
1978
2050
|
let idCounter = 0;
|
1979
2051
|
const generateId = () => {
|
1980
2052
|
const counterString = String(idCounter++);
|
1981
|
-
const id =
|
2053
|
+
const id = import_configs7.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
1982
2054
|
return id;
|
1983
2055
|
};
|
1984
2056
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2000,13 +2072,13 @@ var BaseTransactionRequest = class {
|
|
2000
2072
|
assetId,
|
2001
2073
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2002
2074
|
maturity: 0,
|
2003
|
-
blockCreated: (0,
|
2004
|
-
txCreatedIdx: (0,
|
2075
|
+
blockCreated: (0, import_math7.bn)(1),
|
2076
|
+
txCreatedIdx: (0, import_math7.bn)(1)
|
2005
2077
|
}
|
2006
2078
|
]);
|
2007
2079
|
}
|
2008
2080
|
};
|
2009
|
-
updateAssetInput(
|
2081
|
+
updateAssetInput(import_configs7.BaseAssetId, (0, import_math7.bn)(1e11));
|
2010
2082
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2011
2083
|
}
|
2012
2084
|
/**
|
@@ -2017,7 +2089,7 @@ var BaseTransactionRequest = class {
|
|
2017
2089
|
*/
|
2018
2090
|
getCoinOutputsQuantities() {
|
2019
2091
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2020
|
-
amount: (0,
|
2092
|
+
amount: (0, import_math7.bn)(amount),
|
2021
2093
|
assetId: assetId.toString()
|
2022
2094
|
}));
|
2023
2095
|
return coinsQuantities;
|
@@ -2035,18 +2107,18 @@ var BaseTransactionRequest = class {
|
|
2035
2107
|
this.inputs.forEach((i) => {
|
2036
2108
|
let correspondingInput;
|
2037
2109
|
switch (i.type) {
|
2038
|
-
case
|
2039
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2110
|
+
case import_transactions6.InputType.Coin:
|
2111
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions6.InputType.Coin && x.owner === i.owner);
|
2040
2112
|
break;
|
2041
|
-
case
|
2113
|
+
case import_transactions6.InputType.Message:
|
2042
2114
|
correspondingInput = inputs.find(
|
2043
|
-
(x) => x.type ===
|
2115
|
+
(x) => x.type === import_transactions6.InputType.Message && x.sender === i.sender
|
2044
2116
|
);
|
2045
2117
|
break;
|
2046
2118
|
default:
|
2047
2119
|
return;
|
2048
2120
|
}
|
2049
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2121
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math7.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2050
2122
|
i.predicate = correspondingInput.predicate;
|
2051
2123
|
i.predicateData = correspondingInput.predicateData;
|
2052
2124
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2056,47 +2128,47 @@ var BaseTransactionRequest = class {
|
|
2056
2128
|
};
|
2057
2129
|
|
2058
2130
|
// src/providers/transaction-request/create-transaction-request.ts
|
2059
|
-
var
|
2060
|
-
var
|
2061
|
-
var
|
2131
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2132
|
+
var import_math9 = require("@fuel-ts/math");
|
2133
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2062
2134
|
var import_utils13 = require("@fuel-ts/utils");
|
2063
2135
|
|
2064
2136
|
// src/providers/transaction-request/hash-transaction.ts
|
2065
|
-
var
|
2137
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2066
2138
|
var import_hasher = require("@fuel-ts/hasher");
|
2067
|
-
var
|
2068
|
-
var
|
2139
|
+
var import_math8 = require("@fuel-ts/math");
|
2140
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2069
2141
|
var import_utils11 = require("@fuel-ts/utils");
|
2070
2142
|
var import_ramda2 = require("ramda");
|
2071
2143
|
function hashTransaction(transactionRequest, chainId) {
|
2072
2144
|
const transaction = transactionRequest.toTransaction();
|
2073
|
-
if (transaction.type ===
|
2074
|
-
transaction.receiptsRoot =
|
2145
|
+
if (transaction.type === import_transactions7.TransactionType.Script) {
|
2146
|
+
transaction.receiptsRoot = import_configs8.ZeroBytes32;
|
2075
2147
|
}
|
2076
2148
|
transaction.inputs = transaction.inputs.map((input) => {
|
2077
2149
|
const inputClone = (0, import_ramda2.clone)(input);
|
2078
2150
|
switch (inputClone.type) {
|
2079
|
-
case
|
2151
|
+
case import_transactions7.InputType.Coin: {
|
2080
2152
|
inputClone.txPointer = {
|
2081
2153
|
blockHeight: 0,
|
2082
2154
|
txIndex: 0
|
2083
2155
|
};
|
2084
|
-
inputClone.predicateGasUsed = (0,
|
2156
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2085
2157
|
return inputClone;
|
2086
2158
|
}
|
2087
|
-
case
|
2088
|
-
inputClone.predicateGasUsed = (0,
|
2159
|
+
case import_transactions7.InputType.Message: {
|
2160
|
+
inputClone.predicateGasUsed = (0, import_math8.bn)(0);
|
2089
2161
|
return inputClone;
|
2090
2162
|
}
|
2091
|
-
case
|
2163
|
+
case import_transactions7.InputType.Contract: {
|
2092
2164
|
inputClone.txPointer = {
|
2093
2165
|
blockHeight: 0,
|
2094
2166
|
txIndex: 0
|
2095
2167
|
};
|
2096
|
-
inputClone.txID =
|
2168
|
+
inputClone.txID = import_configs8.ZeroBytes32;
|
2097
2169
|
inputClone.outputIndex = 0;
|
2098
|
-
inputClone.balanceRoot =
|
2099
|
-
inputClone.stateRoot =
|
2170
|
+
inputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2171
|
+
inputClone.stateRoot = import_configs8.ZeroBytes32;
|
2100
2172
|
return inputClone;
|
2101
2173
|
}
|
2102
2174
|
default:
|
@@ -2106,19 +2178,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2106
2178
|
transaction.outputs = transaction.outputs.map((output) => {
|
2107
2179
|
const outputClone = (0, import_ramda2.clone)(output);
|
2108
2180
|
switch (outputClone.type) {
|
2109
|
-
case
|
2110
|
-
outputClone.balanceRoot =
|
2111
|
-
outputClone.stateRoot =
|
2181
|
+
case import_transactions7.OutputType.Contract: {
|
2182
|
+
outputClone.balanceRoot = import_configs8.ZeroBytes32;
|
2183
|
+
outputClone.stateRoot = import_configs8.ZeroBytes32;
|
2112
2184
|
return outputClone;
|
2113
2185
|
}
|
2114
|
-
case
|
2115
|
-
outputClone.amount = (0,
|
2186
|
+
case import_transactions7.OutputType.Change: {
|
2187
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2116
2188
|
return outputClone;
|
2117
2189
|
}
|
2118
|
-
case
|
2119
|
-
outputClone.to =
|
2120
|
-
outputClone.amount = (0,
|
2121
|
-
outputClone.assetId =
|
2190
|
+
case import_transactions7.OutputType.Variable: {
|
2191
|
+
outputClone.to = import_configs8.ZeroBytes32;
|
2192
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2193
|
+
outputClone.assetId = import_configs8.ZeroBytes32;
|
2122
2194
|
return outputClone;
|
2123
2195
|
}
|
2124
2196
|
default:
|
@@ -2128,7 +2200,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2128
2200
|
transaction.witnessesCount = 0;
|
2129
2201
|
transaction.witnesses = [];
|
2130
2202
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2131
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2203
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions7.TransactionCoder().encode(transaction)]);
|
2132
2204
|
return (0, import_hasher.sha256)(concatenatedData);
|
2133
2205
|
}
|
2134
2206
|
|
@@ -2164,7 +2236,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2164
2236
|
return new this(obj);
|
2165
2237
|
}
|
2166
2238
|
/** Type of the transaction */
|
2167
|
-
type =
|
2239
|
+
type = import_transactions8.TransactionType.Create;
|
2168
2240
|
/** Witness index of contract bytecode to create */
|
2169
2241
|
bytecodeWitnessIndex;
|
2170
2242
|
/** Salt */
|
@@ -2184,7 +2256,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2184
2256
|
} = {}) {
|
2185
2257
|
super(rest);
|
2186
2258
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2187
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2259
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs9.ZeroBytes32);
|
2188
2260
|
this.storageSlots = [...storageSlots ?? []];
|
2189
2261
|
}
|
2190
2262
|
/**
|
@@ -2197,12 +2269,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2197
2269
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2198
2270
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2199
2271
|
return {
|
2200
|
-
type:
|
2272
|
+
type: import_transactions8.TransactionType.Create,
|
2201
2273
|
...baseTransaction,
|
2202
2274
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2203
2275
|
bytecodeWitnessIndex,
|
2204
2276
|
storageSlotsCount: storageSlots.length,
|
2205
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2277
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs9.ZeroBytes32,
|
2206
2278
|
storageSlots
|
2207
2279
|
};
|
2208
2280
|
}
|
@@ -2213,7 +2285,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2213
2285
|
*/
|
2214
2286
|
getContractCreatedOutputs() {
|
2215
2287
|
return this.outputs.filter(
|
2216
|
-
(output) => output.type ===
|
2288
|
+
(output) => output.type === import_transactions8.OutputType.ContractCreated
|
2217
2289
|
);
|
2218
2290
|
}
|
2219
2291
|
/**
|
@@ -2234,14 +2306,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2234
2306
|
*/
|
2235
2307
|
addContractCreatedOutput(contractId, stateRoot) {
|
2236
2308
|
this.pushOutput({
|
2237
|
-
type:
|
2309
|
+
type: import_transactions8.OutputType.ContractCreated,
|
2238
2310
|
contractId,
|
2239
2311
|
stateRoot
|
2240
2312
|
});
|
2241
2313
|
}
|
2242
2314
|
metadataGas(gasCosts) {
|
2243
2315
|
return calculateMetadataGasForTxCreate({
|
2244
|
-
contractBytesSize: (0,
|
2316
|
+
contractBytesSize: (0, import_math9.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2245
2317
|
gasCosts,
|
2246
2318
|
stateRootSize: this.storageSlots.length,
|
2247
2319
|
txBytesSize: this.byteSize()
|
@@ -2252,9 +2324,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2252
2324
|
// src/providers/transaction-request/script-transaction-request.ts
|
2253
2325
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2254
2326
|
var import_address2 = require("@fuel-ts/address");
|
2255
|
-
var
|
2256
|
-
var
|
2257
|
-
var
|
2327
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2328
|
+
var import_math10 = require("@fuel-ts/math");
|
2329
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2258
2330
|
var import_utils15 = require("@fuel-ts/utils");
|
2259
2331
|
|
2260
2332
|
// src/providers/transaction-request/scripts.ts
|
@@ -2292,7 +2364,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2292
2364
|
return new this(obj);
|
2293
2365
|
}
|
2294
2366
|
/** Type of the transaction */
|
2295
|
-
type =
|
2367
|
+
type = import_transactions9.TransactionType.Script;
|
2296
2368
|
/** Gas limit for transaction */
|
2297
2369
|
gasLimit;
|
2298
2370
|
/** Script to execute */
|
@@ -2307,7 +2379,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2307
2379
|
*/
|
2308
2380
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2309
2381
|
super(rest);
|
2310
|
-
this.gasLimit = (0,
|
2382
|
+
this.gasLimit = (0, import_math10.bn)(gasLimit);
|
2311
2383
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2312
2384
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2313
2385
|
this.abis = rest.abis;
|
@@ -2321,12 +2393,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2321
2393
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2322
2394
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2323
2395
|
return {
|
2324
|
-
type:
|
2396
|
+
type: import_transactions9.TransactionType.Script,
|
2325
2397
|
scriptGasLimit: this.gasLimit,
|
2326
2398
|
...super.getBaseTransaction(),
|
2327
2399
|
scriptLength: script.length,
|
2328
2400
|
scriptDataLength: scriptData.length,
|
2329
|
-
receiptsRoot:
|
2401
|
+
receiptsRoot: import_configs10.ZeroBytes32,
|
2330
2402
|
script: (0, import_utils15.hexlify)(script),
|
2331
2403
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2332
2404
|
};
|
@@ -2338,7 +2410,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2338
2410
|
*/
|
2339
2411
|
getContractInputs() {
|
2340
2412
|
return this.inputs.filter(
|
2341
|
-
(input) => input.type ===
|
2413
|
+
(input) => input.type === import_transactions9.InputType.Contract
|
2342
2414
|
);
|
2343
2415
|
}
|
2344
2416
|
/**
|
@@ -2348,7 +2420,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2348
2420
|
*/
|
2349
2421
|
getContractOutputs() {
|
2350
2422
|
return this.outputs.filter(
|
2351
|
-
(output) => output.type ===
|
2423
|
+
(output) => output.type === import_transactions9.OutputType.Contract
|
2352
2424
|
);
|
2353
2425
|
}
|
2354
2426
|
/**
|
@@ -2358,7 +2430,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2358
2430
|
*/
|
2359
2431
|
getVariableOutputs() {
|
2360
2432
|
return this.outputs.filter(
|
2361
|
-
(output) => output.type ===
|
2433
|
+
(output) => output.type === import_transactions9.OutputType.Variable
|
2362
2434
|
);
|
2363
2435
|
}
|
2364
2436
|
/**
|
@@ -2381,7 +2453,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2381
2453
|
let outputsNumber = numberOfVariables;
|
2382
2454
|
while (outputsNumber) {
|
2383
2455
|
this.pushOutput({
|
2384
|
-
type:
|
2456
|
+
type: import_transactions9.OutputType.Variable
|
2385
2457
|
});
|
2386
2458
|
outputsNumber -= 1;
|
2387
2459
|
}
|
@@ -2414,12 +2486,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2414
2486
|
return this;
|
2415
2487
|
}
|
2416
2488
|
const inputIndex = super.pushInput({
|
2417
|
-
type:
|
2489
|
+
type: import_transactions9.InputType.Contract,
|
2418
2490
|
contractId: contractAddress.toB256(),
|
2419
2491
|
txPointer: "0x00000000000000000000000000000000"
|
2420
2492
|
});
|
2421
2493
|
this.pushOutput({
|
2422
|
-
type:
|
2494
|
+
type: import_transactions9.OutputType.Contract,
|
2423
2495
|
inputIndex
|
2424
2496
|
});
|
2425
2497
|
return this;
|
@@ -2455,38 +2527,38 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2455
2527
|
};
|
2456
2528
|
|
2457
2529
|
// src/providers/transaction-request/utils.ts
|
2458
|
-
var
|
2459
|
-
var
|
2530
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2531
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2460
2532
|
var transactionRequestify = (obj) => {
|
2461
2533
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2462
2534
|
return obj;
|
2463
2535
|
}
|
2464
2536
|
const { type } = obj;
|
2465
2537
|
switch (obj.type) {
|
2466
|
-
case
|
2538
|
+
case import_transactions10.TransactionType.Script: {
|
2467
2539
|
return ScriptTransactionRequest.from(obj);
|
2468
2540
|
}
|
2469
|
-
case
|
2541
|
+
case import_transactions10.TransactionType.Create: {
|
2470
2542
|
return CreateTransactionRequest.from(obj);
|
2471
2543
|
}
|
2472
2544
|
default: {
|
2473
|
-
throw new
|
2545
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2474
2546
|
}
|
2475
2547
|
}
|
2476
2548
|
};
|
2477
2549
|
|
2478
2550
|
// src/providers/transaction-response/transaction-response.ts
|
2479
|
-
var
|
2480
|
-
var
|
2481
|
-
var
|
2551
|
+
var import_errors13 = require("@fuel-ts/errors");
|
2552
|
+
var import_math14 = require("@fuel-ts/math");
|
2553
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
2482
2554
|
var import_utils21 = require("@fuel-ts/utils");
|
2483
2555
|
|
2484
2556
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2485
2557
|
var import_utils19 = require("@fuel-ts/utils");
|
2486
2558
|
|
2487
2559
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2488
|
-
var
|
2489
|
-
var
|
2560
|
+
var import_math11 = require("@fuel-ts/math");
|
2561
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2490
2562
|
var import_utils16 = require("@fuel-ts/utils");
|
2491
2563
|
var calculateTransactionFee = (params) => {
|
2492
2564
|
const {
|
@@ -2494,24 +2566,24 @@ var calculateTransactionFee = (params) => {
|
|
2494
2566
|
rawPayload,
|
2495
2567
|
consensusParameters: { gasCosts, feeParams }
|
2496
2568
|
} = params;
|
2497
|
-
const gasPerByte = (0,
|
2498
|
-
const gasPriceFactor = (0,
|
2569
|
+
const gasPerByte = (0, import_math11.bn)(feeParams.gasPerByte);
|
2570
|
+
const gasPriceFactor = (0, import_math11.bn)(feeParams.gasPriceFactor);
|
2499
2571
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2500
|
-
const [transaction] = new
|
2501
|
-
if (transaction.type ===
|
2572
|
+
const [transaction] = new import_transactions11.TransactionCoder().decode(transactionBytes, 0);
|
2573
|
+
if (transaction.type === import_transactions11.TransactionType.Mint) {
|
2502
2574
|
return {
|
2503
|
-
fee: (0,
|
2504
|
-
minFee: (0,
|
2505
|
-
maxFee: (0,
|
2506
|
-
feeFromGasUsed: (0,
|
2575
|
+
fee: (0, import_math11.bn)(0),
|
2576
|
+
minFee: (0, import_math11.bn)(0),
|
2577
|
+
maxFee: (0, import_math11.bn)(0),
|
2578
|
+
feeFromGasUsed: (0, import_math11.bn)(0)
|
2507
2579
|
};
|
2508
2580
|
}
|
2509
2581
|
const { type, witnesses, inputs, policies } = transaction;
|
2510
|
-
let metadataGas = (0,
|
2511
|
-
let gasLimit = (0,
|
2512
|
-
if (type ===
|
2582
|
+
let metadataGas = (0, import_math11.bn)(0);
|
2583
|
+
let gasLimit = (0, import_math11.bn)(0);
|
2584
|
+
if (type === import_transactions11.TransactionType.Create) {
|
2513
2585
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2514
|
-
const contractBytesSize = (0,
|
2586
|
+
const contractBytesSize = (0, import_math11.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2515
2587
|
metadataGas = calculateMetadataGasForTxCreate({
|
2516
2588
|
contractBytesSize,
|
2517
2589
|
gasCosts,
|
@@ -2530,13 +2602,13 @@ var calculateTransactionFee = (params) => {
|
|
2530
2602
|
}
|
2531
2603
|
const minGas = getMinGas({
|
2532
2604
|
gasCosts,
|
2533
|
-
gasPerByte: (0,
|
2605
|
+
gasPerByte: (0, import_math11.bn)(gasPerByte),
|
2534
2606
|
inputs,
|
2535
2607
|
metadataGas,
|
2536
2608
|
txBytesSize: transactionBytes.length
|
2537
2609
|
});
|
2538
|
-
const gasPrice = (0,
|
2539
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
2610
|
+
const gasPrice = (0, import_math11.bn)(policies.find((policy) => policy.type === import_transactions11.PolicyType.GasPrice)?.data);
|
2611
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions11.PolicyType.WitnessLimit)?.data;
|
2540
2612
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2541
2613
|
const maxGas = getMaxGas({
|
2542
2614
|
gasPerByte,
|
@@ -2558,14 +2630,14 @@ var calculateTransactionFee = (params) => {
|
|
2558
2630
|
};
|
2559
2631
|
|
2560
2632
|
// src/providers/transaction-summary/operations.ts
|
2561
|
-
var
|
2562
|
-
var
|
2563
|
-
var
|
2564
|
-
var
|
2633
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
2634
|
+
var import_errors11 = require("@fuel-ts/errors");
|
2635
|
+
var import_math13 = require("@fuel-ts/math");
|
2636
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
2565
2637
|
|
2566
2638
|
// src/providers/transaction-summary/call.ts
|
2567
2639
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2568
|
-
var
|
2640
|
+
var import_math12 = require("@fuel-ts/math");
|
2569
2641
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2570
2642
|
const abiInterface = new import_abi_coder2.Interface(abi);
|
2571
2643
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2574,7 +2646,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2574
2646
|
let encodedArgs;
|
2575
2647
|
if (functionFragment.isInputDataPointer) {
|
2576
2648
|
if (rawPayload) {
|
2577
|
-
const argsOffset = (0,
|
2649
|
+
const argsOffset = (0, import_math12.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2578
2650
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2579
2651
|
}
|
2580
2652
|
} else {
|
@@ -2608,8 +2680,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2608
2680
|
};
|
2609
2681
|
|
2610
2682
|
// src/providers/transaction-summary/input.ts
|
2611
|
-
var
|
2612
|
-
var
|
2683
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2684
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2613
2685
|
function getInputsByTypes(inputs, types) {
|
2614
2686
|
return inputs.filter((i) => types.includes(i.type));
|
2615
2687
|
}
|
@@ -2617,16 +2689,16 @@ function getInputsByType(inputs, type) {
|
|
2617
2689
|
return inputs.filter((i) => i.type === type);
|
2618
2690
|
}
|
2619
2691
|
function getInputsCoin(inputs) {
|
2620
|
-
return getInputsByType(inputs,
|
2692
|
+
return getInputsByType(inputs, import_transactions12.InputType.Coin);
|
2621
2693
|
}
|
2622
2694
|
function getInputsMessage(inputs) {
|
2623
|
-
return getInputsByType(inputs,
|
2695
|
+
return getInputsByType(inputs, import_transactions12.InputType.Message);
|
2624
2696
|
}
|
2625
2697
|
function getInputsCoinAndMessage(inputs) {
|
2626
|
-
return getInputsByTypes(inputs, [
|
2698
|
+
return getInputsByTypes(inputs, [import_transactions12.InputType.Coin, import_transactions12.InputType.Message]);
|
2627
2699
|
}
|
2628
2700
|
function getInputsContract(inputs) {
|
2629
|
-
return getInputsByType(inputs,
|
2701
|
+
return getInputsByType(inputs, import_transactions12.InputType.Contract);
|
2630
2702
|
}
|
2631
2703
|
function getInputFromAssetId(inputs, assetId) {
|
2632
2704
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2645,40 +2717,40 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2645
2717
|
if (!contractInput) {
|
2646
2718
|
return void 0;
|
2647
2719
|
}
|
2648
|
-
if (contractInput.type !==
|
2649
|
-
throw new
|
2650
|
-
|
2720
|
+
if (contractInput.type !== import_transactions12.InputType.Contract) {
|
2721
|
+
throw new import_errors10.FuelError(
|
2722
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2651
2723
|
`Contract input should be of type 'contract'.`
|
2652
2724
|
);
|
2653
2725
|
}
|
2654
2726
|
return contractInput;
|
2655
2727
|
}
|
2656
2728
|
function getInputAccountAddress(input) {
|
2657
|
-
if (input.type ===
|
2729
|
+
if (input.type === import_transactions12.InputType.Coin) {
|
2658
2730
|
return input.owner.toString();
|
2659
2731
|
}
|
2660
|
-
if (input.type ===
|
2732
|
+
if (input.type === import_transactions12.InputType.Message) {
|
2661
2733
|
return input.recipient.toString();
|
2662
2734
|
}
|
2663
2735
|
return "";
|
2664
2736
|
}
|
2665
2737
|
|
2666
2738
|
// src/providers/transaction-summary/output.ts
|
2667
|
-
var
|
2739
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2668
2740
|
function getOutputsByType(outputs, type) {
|
2669
2741
|
return outputs.filter((o) => o.type === type);
|
2670
2742
|
}
|
2671
2743
|
function getOutputsContractCreated(outputs) {
|
2672
|
-
return getOutputsByType(outputs,
|
2744
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.ContractCreated);
|
2673
2745
|
}
|
2674
2746
|
function getOutputsCoin(outputs) {
|
2675
|
-
return getOutputsByType(outputs,
|
2747
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Coin);
|
2676
2748
|
}
|
2677
2749
|
function getOutputsChange(outputs) {
|
2678
|
-
return getOutputsByType(outputs,
|
2750
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Change);
|
2679
2751
|
}
|
2680
2752
|
function getOutputsContract(outputs) {
|
2681
|
-
return getOutputsByType(outputs,
|
2753
|
+
return getOutputsByType(outputs, import_transactions13.OutputType.Contract);
|
2682
2754
|
}
|
2683
2755
|
|
2684
2756
|
// src/providers/transaction-summary/operations.ts
|
@@ -2687,15 +2759,15 @@ function getReceiptsByType(receipts, type) {
|
|
2687
2759
|
}
|
2688
2760
|
function getTransactionTypeName(transactionType) {
|
2689
2761
|
switch (transactionType) {
|
2690
|
-
case
|
2762
|
+
case import_transactions14.TransactionType.Mint:
|
2691
2763
|
return "Mint" /* Mint */;
|
2692
|
-
case
|
2764
|
+
case import_transactions14.TransactionType.Create:
|
2693
2765
|
return "Create" /* Create */;
|
2694
|
-
case
|
2766
|
+
case import_transactions14.TransactionType.Script:
|
2695
2767
|
return "Script" /* Script */;
|
2696
2768
|
default:
|
2697
|
-
throw new
|
2698
|
-
|
2769
|
+
throw new import_errors11.FuelError(
|
2770
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_TYPE,
|
2699
2771
|
`Invalid transaction type: ${transactionType}.`
|
2700
2772
|
);
|
2701
2773
|
}
|
@@ -2714,10 +2786,10 @@ function isTypeScript(transactionType) {
|
|
2714
2786
|
return isType(transactionType, "Script" /* Script */);
|
2715
2787
|
}
|
2716
2788
|
function getReceiptsCall(receipts) {
|
2717
|
-
return getReceiptsByType(receipts,
|
2789
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.Call);
|
2718
2790
|
}
|
2719
2791
|
function getReceiptsMessageOut(receipts) {
|
2720
|
-
return getReceiptsByType(receipts,
|
2792
|
+
return getReceiptsByType(receipts, import_transactions14.ReceiptType.MessageOut);
|
2721
2793
|
}
|
2722
2794
|
var mergeAssets = (op1, op2) => {
|
2723
2795
|
const assets1 = op1.assetsSent || [];
|
@@ -2730,7 +2802,7 @@ var mergeAssets = (op1, op2) => {
|
|
2730
2802
|
if (!matchingAsset) {
|
2731
2803
|
return asset1;
|
2732
2804
|
}
|
2733
|
-
const mergedAmount = (0,
|
2805
|
+
const mergedAmount = (0, import_math13.bn)(asset1.amount).add(matchingAsset.amount);
|
2734
2806
|
return { ...asset1, amount: mergedAmount };
|
2735
2807
|
});
|
2736
2808
|
return mergedAssets.concat(filteredAssets);
|
@@ -2856,7 +2928,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
2856
2928
|
const { to: toAddress, assetId, amount } = receipt;
|
2857
2929
|
let { from: fromAddress } = receipt;
|
2858
2930
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
2859
|
-
if (
|
2931
|
+
if (import_configs11.ZeroBytes32 === fromAddress) {
|
2860
2932
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
2861
2933
|
fromAddress = change?.to || fromAddress;
|
2862
2934
|
}
|
@@ -2913,11 +2985,11 @@ function getTransferOperations({
|
|
2913
2985
|
});
|
2914
2986
|
const transferReceipts = getReceiptsByType(
|
2915
2987
|
receipts,
|
2916
|
-
|
2988
|
+
import_transactions14.ReceiptType.Transfer
|
2917
2989
|
);
|
2918
2990
|
const transferOutReceipts = getReceiptsByType(
|
2919
2991
|
receipts,
|
2920
|
-
|
2992
|
+
import_transactions14.ReceiptType.TransferOut
|
2921
2993
|
);
|
2922
2994
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
2923
2995
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3002,17 +3074,17 @@ function getOperations({
|
|
3002
3074
|
}
|
3003
3075
|
|
3004
3076
|
// src/providers/transaction-summary/receipt.ts
|
3005
|
-
var
|
3077
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3006
3078
|
var processGqlReceipt = (gqlReceipt) => {
|
3007
3079
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3008
3080
|
switch (receipt.type) {
|
3009
|
-
case
|
3081
|
+
case import_transactions15.ReceiptType.ReturnData: {
|
3010
3082
|
return {
|
3011
3083
|
...receipt,
|
3012
3084
|
data: gqlReceipt.data || "0x"
|
3013
3085
|
};
|
3014
3086
|
}
|
3015
|
-
case
|
3087
|
+
case import_transactions15.ReceiptType.LogData: {
|
3016
3088
|
return {
|
3017
3089
|
...receipt,
|
3018
3090
|
data: gqlReceipt.data || "0x"
|
@@ -3025,7 +3097,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3025
3097
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3026
3098
|
const mintedAssets = [];
|
3027
3099
|
receipts.forEach((receipt) => {
|
3028
|
-
if (receipt.type ===
|
3100
|
+
if (receipt.type === import_transactions15.ReceiptType.Mint) {
|
3029
3101
|
mintedAssets.push({
|
3030
3102
|
subId: receipt.subId,
|
3031
3103
|
contractId: receipt.contractId,
|
@@ -3039,7 +3111,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3039
3111
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3040
3112
|
const burnedAssets = [];
|
3041
3113
|
receipts.forEach((receipt) => {
|
3042
|
-
if (receipt.type ===
|
3114
|
+
if (receipt.type === import_transactions15.ReceiptType.Burn) {
|
3043
3115
|
burnedAssets.push({
|
3044
3116
|
subId: receipt.subId,
|
3045
3117
|
contractId: receipt.contractId,
|
@@ -3052,7 +3124,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3052
3124
|
};
|
3053
3125
|
|
3054
3126
|
// src/providers/transaction-summary/status.ts
|
3055
|
-
var
|
3127
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3056
3128
|
var getTransactionStatusName = (gqlStatus) => {
|
3057
3129
|
switch (gqlStatus) {
|
3058
3130
|
case "FailureStatus":
|
@@ -3064,8 +3136,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3064
3136
|
case "SqueezedOutStatus":
|
3065
3137
|
return "squeezedout" /* squeezedout */;
|
3066
3138
|
default:
|
3067
|
-
throw new
|
3068
|
-
|
3139
|
+
throw new import_errors12.FuelError(
|
3140
|
+
import_errors12.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3069
3141
|
`Invalid transaction status: ${gqlStatus}.`
|
3070
3142
|
);
|
3071
3143
|
}
|
@@ -3178,12 +3250,12 @@ function assembleTransactionSummary(params) {
|
|
3178
3250
|
|
3179
3251
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3180
3252
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3181
|
-
var
|
3253
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
3182
3254
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3183
3255
|
return receipts.reduce((logs, receipt) => {
|
3184
|
-
if (receipt.type ===
|
3256
|
+
if (receipt.type === import_transactions16.ReceiptType.LogData || receipt.type === import_transactions16.ReceiptType.Log) {
|
3185
3257
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3186
|
-
const data = receipt.type ===
|
3258
|
+
const data = receipt.type === import_transactions16.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3187
3259
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3188
3260
|
logs.push(decodedLog);
|
3189
3261
|
}
|
@@ -3198,7 +3270,7 @@ var TransactionResponse = class {
|
|
3198
3270
|
/** Current provider */
|
3199
3271
|
provider;
|
3200
3272
|
/** Gas used on the transaction */
|
3201
|
-
gasUsed = (0,
|
3273
|
+
gasUsed = (0, import_math14.bn)(0);
|
3202
3274
|
/** The graphql Transaction with receipts object. */
|
3203
3275
|
gqlTransaction;
|
3204
3276
|
abis;
|
@@ -3256,7 +3328,7 @@ var TransactionResponse = class {
|
|
3256
3328
|
* @returns The decoded transaction.
|
3257
3329
|
*/
|
3258
3330
|
decodeTransaction(transactionWithReceipts) {
|
3259
|
-
return new
|
3331
|
+
return new import_transactions17.TransactionCoder().decode(
|
3260
3332
|
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3261
3333
|
0
|
3262
3334
|
)?.[0];
|
@@ -3303,8 +3375,8 @@ var TransactionResponse = class {
|
|
3303
3375
|
});
|
3304
3376
|
for await (const { statusChange } of subscription) {
|
3305
3377
|
if (statusChange.type === "SqueezedOutStatus") {
|
3306
|
-
throw new
|
3307
|
-
|
3378
|
+
throw new import_errors13.FuelError(
|
3379
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3308
3380
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3309
3381
|
);
|
3310
3382
|
}
|
@@ -3326,14 +3398,26 @@ var TransactionResponse = class {
|
|
3326
3398
|
gqlTransaction: this.gqlTransaction,
|
3327
3399
|
...transactionSummary
|
3328
3400
|
};
|
3401
|
+
let logs = [];
|
3329
3402
|
if (this.abis) {
|
3330
|
-
|
3403
|
+
logs = getDecodedLogs(
|
3331
3404
|
transactionSummary.receipts,
|
3332
3405
|
this.abis.main,
|
3333
3406
|
this.abis.otherContractsAbis
|
3334
3407
|
);
|
3335
3408
|
transactionResult.logs = logs;
|
3336
3409
|
}
|
3410
|
+
if (transactionResult.isStatusFailure) {
|
3411
|
+
const {
|
3412
|
+
receipts,
|
3413
|
+
gqlTransaction: { status }
|
3414
|
+
} = transactionResult;
|
3415
|
+
throw extractTxError({
|
3416
|
+
receipts,
|
3417
|
+
status,
|
3418
|
+
logs
|
3419
|
+
});
|
3420
|
+
}
|
3337
3421
|
return transactionResult;
|
3338
3422
|
}
|
3339
3423
|
/**
|
@@ -3342,14 +3426,7 @@ var TransactionResponse = class {
|
|
3342
3426
|
* @param contractsAbiMap - The contracts ABI map.
|
3343
3427
|
*/
|
3344
3428
|
async wait(contractsAbiMap) {
|
3345
|
-
|
3346
|
-
if (result.isStatusFailure) {
|
3347
|
-
throw new import_errors12.FuelError(
|
3348
|
-
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3349
|
-
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3350
|
-
);
|
3351
|
-
}
|
3352
|
-
return result;
|
3429
|
+
return this.waitForResult(contractsAbiMap);
|
3353
3430
|
}
|
3354
3431
|
};
|
3355
3432
|
|
@@ -3411,29 +3488,29 @@ var processGqlChain = (chain) => {
|
|
3411
3488
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3412
3489
|
return {
|
3413
3490
|
name,
|
3414
|
-
baseChainHeight: (0,
|
3491
|
+
baseChainHeight: (0, import_math15.bn)(daHeight),
|
3415
3492
|
consensusParameters: {
|
3416
|
-
contractMaxSize: (0,
|
3417
|
-
maxInputs: (0,
|
3418
|
-
maxOutputs: (0,
|
3419
|
-
maxWitnesses: (0,
|
3420
|
-
maxGasPerTx: (0,
|
3421
|
-
maxScriptLength: (0,
|
3422
|
-
maxScriptDataLength: (0,
|
3423
|
-
maxStorageSlots: (0,
|
3424
|
-
maxPredicateLength: (0,
|
3425
|
-
maxPredicateDataLength: (0,
|
3426
|
-
maxGasPerPredicate: (0,
|
3427
|
-
gasPriceFactor: (0,
|
3428
|
-
gasPerByte: (0,
|
3429
|
-
maxMessageDataLength: (0,
|
3430
|
-
chainId: (0,
|
3493
|
+
contractMaxSize: (0, import_math15.bn)(contractParams.contractMaxSize),
|
3494
|
+
maxInputs: (0, import_math15.bn)(txParams.maxInputs),
|
3495
|
+
maxOutputs: (0, import_math15.bn)(txParams.maxOutputs),
|
3496
|
+
maxWitnesses: (0, import_math15.bn)(txParams.maxWitnesses),
|
3497
|
+
maxGasPerTx: (0, import_math15.bn)(txParams.maxGasPerTx),
|
3498
|
+
maxScriptLength: (0, import_math15.bn)(scriptParams.maxScriptLength),
|
3499
|
+
maxScriptDataLength: (0, import_math15.bn)(scriptParams.maxScriptDataLength),
|
3500
|
+
maxStorageSlots: (0, import_math15.bn)(contractParams.maxStorageSlots),
|
3501
|
+
maxPredicateLength: (0, import_math15.bn)(predicateParams.maxPredicateLength),
|
3502
|
+
maxPredicateDataLength: (0, import_math15.bn)(predicateParams.maxPredicateDataLength),
|
3503
|
+
maxGasPerPredicate: (0, import_math15.bn)(predicateParams.maxGasPerPredicate),
|
3504
|
+
gasPriceFactor: (0, import_math15.bn)(feeParams.gasPriceFactor),
|
3505
|
+
gasPerByte: (0, import_math15.bn)(feeParams.gasPerByte),
|
3506
|
+
maxMessageDataLength: (0, import_math15.bn)(predicateParams.maxMessageDataLength),
|
3507
|
+
chainId: (0, import_math15.bn)(consensusParameters.chainId),
|
3431
3508
|
gasCosts
|
3432
3509
|
},
|
3433
3510
|
gasCosts,
|
3434
3511
|
latestBlock: {
|
3435
3512
|
id: latestBlock.id,
|
3436
|
-
height: (0,
|
3513
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3437
3514
|
time: latestBlock.header.time,
|
3438
3515
|
transactions: latestBlock.transactions.map((i) => ({
|
3439
3516
|
id: i.id
|
@@ -3503,8 +3580,8 @@ var _Provider = class {
|
|
3503
3580
|
getChain() {
|
3504
3581
|
const chain = _Provider.chainInfoCache[this.url];
|
3505
3582
|
if (!chain) {
|
3506
|
-
throw new
|
3507
|
-
|
3583
|
+
throw new import_errors14.FuelError(
|
3584
|
+
import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3508
3585
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3509
3586
|
);
|
3510
3587
|
}
|
@@ -3516,8 +3593,8 @@ var _Provider = class {
|
|
3516
3593
|
getNode() {
|
3517
3594
|
const node = _Provider.nodeInfoCache[this.url];
|
3518
3595
|
if (!node) {
|
3519
|
-
throw new
|
3520
|
-
|
3596
|
+
throw new import_errors14.FuelError(
|
3597
|
+
import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3521
3598
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3522
3599
|
);
|
3523
3600
|
}
|
@@ -3564,8 +3641,8 @@ var _Provider = class {
|
|
3564
3641
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3565
3642
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3566
3643
|
if (!isMajorSupported || !isMinorSupported) {
|
3567
|
-
throw new
|
3568
|
-
|
3644
|
+
throw new import_errors14.FuelError(
|
3645
|
+
import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3569
3646
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3570
3647
|
);
|
3571
3648
|
}
|
@@ -3628,7 +3705,7 @@ var _Provider = class {
|
|
3628
3705
|
*/
|
3629
3706
|
async getBlockNumber() {
|
3630
3707
|
const { chain } = await this.operations.getChain();
|
3631
|
-
return (0,
|
3708
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3632
3709
|
}
|
3633
3710
|
/**
|
3634
3711
|
* Returns the chain information.
|
@@ -3638,9 +3715,9 @@ var _Provider = class {
|
|
3638
3715
|
async fetchNode() {
|
3639
3716
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3640
3717
|
const processedNodeInfo = {
|
3641
|
-
maxDepth: (0,
|
3642
|
-
maxTx: (0,
|
3643
|
-
minGasPrice: (0,
|
3718
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3719
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3720
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3644
3721
|
nodeVersion: nodeInfo.nodeVersion,
|
3645
3722
|
utxoValidation: nodeInfo.utxoValidation,
|
3646
3723
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3686,17 +3763,17 @@ var _Provider = class {
|
|
3686
3763
|
if (estimateTxDependencies) {
|
3687
3764
|
await this.estimateTxDependencies(transactionRequest);
|
3688
3765
|
}
|
3689
|
-
const encodedTransaction = (0,
|
3766
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3690
3767
|
let abis;
|
3691
|
-
if (transactionRequest.type ===
|
3768
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3692
3769
|
abis = transactionRequest.abis;
|
3693
3770
|
}
|
3694
3771
|
if (awaitExecution) {
|
3695
3772
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3696
3773
|
for await (const { submitAndAwait } of subscription) {
|
3697
3774
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3698
|
-
throw new
|
3699
|
-
|
3775
|
+
throw new import_errors14.FuelError(
|
3776
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3700
3777
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3701
3778
|
);
|
3702
3779
|
}
|
@@ -3729,7 +3806,7 @@ var _Provider = class {
|
|
3729
3806
|
if (estimateTxDependencies) {
|
3730
3807
|
return this.estimateTxDependencies(transactionRequest);
|
3731
3808
|
}
|
3732
|
-
const encodedTransaction = (0,
|
3809
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3733
3810
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3734
3811
|
encodedTransaction,
|
3735
3812
|
utxoValidation: utxoValidation || false
|
@@ -3748,13 +3825,13 @@ var _Provider = class {
|
|
3748
3825
|
async estimatePredicates(transactionRequest) {
|
3749
3826
|
const shouldEstimatePredicates = Boolean(
|
3750
3827
|
transactionRequest.inputs.find(
|
3751
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3828
|
+
(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()
|
3752
3829
|
)
|
3753
3830
|
);
|
3754
3831
|
if (!shouldEstimatePredicates) {
|
3755
3832
|
return transactionRequest;
|
3756
3833
|
}
|
3757
|
-
const encodedTransaction = (0,
|
3834
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3758
3835
|
const response = await this.operations.estimatePredicates({
|
3759
3836
|
encodedTransaction
|
3760
3837
|
});
|
@@ -3763,7 +3840,7 @@ var _Provider = class {
|
|
3763
3840
|
} = response;
|
3764
3841
|
if (inputs) {
|
3765
3842
|
inputs.forEach((input, index) => {
|
3766
|
-
if ("predicateGasUsed" in input && (0,
|
3843
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3767
3844
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3768
3845
|
}
|
3769
3846
|
});
|
@@ -3784,7 +3861,7 @@ var _Provider = class {
|
|
3784
3861
|
* @returns A promise.
|
3785
3862
|
*/
|
3786
3863
|
async estimateTxDependencies(transactionRequest) {
|
3787
|
-
if (transactionRequest.type ===
|
3864
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3788
3865
|
return {
|
3789
3866
|
receipts: [],
|
3790
3867
|
outputVariables: 0,
|
@@ -3797,7 +3874,7 @@ var _Provider = class {
|
|
3797
3874
|
let outputVariables = 0;
|
3798
3875
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3799
3876
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3800
|
-
encodedTransaction: (0,
|
3877
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3801
3878
|
utxoValidation: false
|
3802
3879
|
});
|
3803
3880
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3835,7 +3912,7 @@ var _Provider = class {
|
|
3835
3912
|
if (estimateTxDependencies) {
|
3836
3913
|
return this.estimateTxDependencies(transactionRequest);
|
3837
3914
|
}
|
3838
|
-
const encodedTransaction = (0,
|
3915
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3839
3916
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3840
3917
|
encodedTransaction,
|
3841
3918
|
utxoValidation: true
|
@@ -3869,14 +3946,14 @@ var _Provider = class {
|
|
3869
3946
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3870
3947
|
const chainInfo = this.getChain();
|
3871
3948
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3872
|
-
const gasPrice = (0,
|
3873
|
-
const isScriptTransaction = txRequestClone.type ===
|
3949
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3950
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3874
3951
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3875
3952
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3876
3953
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3877
3954
|
if (estimatePredicates) {
|
3878
3955
|
if (isScriptTransaction) {
|
3879
|
-
txRequestClone.gasLimit = (0,
|
3956
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3880
3957
|
}
|
3881
3958
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3882
3959
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3892,8 +3969,8 @@ var _Provider = class {
|
|
3892
3969
|
let missingContractIds = [];
|
3893
3970
|
let outputVariables = 0;
|
3894
3971
|
if (isScriptTransaction && estimateTxDependencies) {
|
3895
|
-
txRequestClone.gasPrice = (0,
|
3896
|
-
txRequestClone.gasLimit = (0,
|
3972
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3973
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3897
3974
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3898
3975
|
receipts = result.receipts;
|
3899
3976
|
outputVariables = result.outputVariables;
|
@@ -3949,17 +4026,17 @@ var _Provider = class {
|
|
3949
4026
|
const result = await this.operations.getCoins({
|
3950
4027
|
first: 10,
|
3951
4028
|
...paginationArgs,
|
3952
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4029
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
3953
4030
|
});
|
3954
4031
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3955
4032
|
return coins.map((coin) => ({
|
3956
4033
|
id: coin.utxoId,
|
3957
4034
|
assetId: coin.assetId,
|
3958
|
-
amount: (0,
|
4035
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3959
4036
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3960
|
-
maturity: (0,
|
3961
|
-
blockCreated: (0,
|
3962
|
-
txCreatedIdx: (0,
|
4037
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4038
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4039
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
3963
4040
|
}));
|
3964
4041
|
}
|
3965
4042
|
/**
|
@@ -3973,19 +4050,19 @@ var _Provider = class {
|
|
3973
4050
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3974
4051
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3975
4052
|
const excludeInput = {
|
3976
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3977
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4053
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4054
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
3978
4055
|
};
|
3979
4056
|
if (this.cache) {
|
3980
4057
|
const uniqueUtxos = new Set(
|
3981
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4058
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
3982
4059
|
);
|
3983
4060
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3984
4061
|
}
|
3985
4062
|
const coinsQuery = {
|
3986
4063
|
owner: ownerAddress.toB256(),
|
3987
4064
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
3988
|
-
assetId: (0,
|
4065
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
3989
4066
|
amount: amount.toString(10),
|
3990
4067
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
3991
4068
|
})),
|
@@ -3996,9 +4073,9 @@ var _Provider = class {
|
|
3996
4073
|
switch (coin.__typename) {
|
3997
4074
|
case "MessageCoin":
|
3998
4075
|
return {
|
3999
|
-
amount: (0,
|
4076
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4000
4077
|
assetId: coin.assetId,
|
4001
|
-
daHeight: (0,
|
4078
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4002
4079
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4003
4080
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4004
4081
|
nonce: coin.nonce
|
@@ -4006,12 +4083,12 @@ var _Provider = class {
|
|
4006
4083
|
case "Coin":
|
4007
4084
|
return {
|
4008
4085
|
id: coin.utxoId,
|
4009
|
-
amount: (0,
|
4086
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4010
4087
|
assetId: coin.assetId,
|
4011
4088
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4012
|
-
maturity: (0,
|
4013
|
-
blockCreated: (0,
|
4014
|
-
txCreatedIdx: (0,
|
4089
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4090
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4091
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4015
4092
|
};
|
4016
4093
|
default:
|
4017
4094
|
return null;
|
@@ -4028,13 +4105,13 @@ var _Provider = class {
|
|
4028
4105
|
async getBlock(idOrHeight) {
|
4029
4106
|
let variables;
|
4030
4107
|
if (typeof idOrHeight === "number") {
|
4031
|
-
variables = { height: (0,
|
4108
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4032
4109
|
} else if (idOrHeight === "latest") {
|
4033
4110
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4034
4111
|
} else if (idOrHeight.length === 66) {
|
4035
4112
|
variables = { blockId: idOrHeight };
|
4036
4113
|
} else {
|
4037
|
-
variables = { blockId: (0,
|
4114
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4038
4115
|
}
|
4039
4116
|
const { block } = await this.operations.getBlock(variables);
|
4040
4117
|
if (!block) {
|
@@ -4042,7 +4119,7 @@ var _Provider = class {
|
|
4042
4119
|
}
|
4043
4120
|
return {
|
4044
4121
|
id: block.id,
|
4045
|
-
height: (0,
|
4122
|
+
height: (0, import_math15.bn)(block.header.height),
|
4046
4123
|
time: block.header.time,
|
4047
4124
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4048
4125
|
};
|
@@ -4057,7 +4134,7 @@ var _Provider = class {
|
|
4057
4134
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4058
4135
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4059
4136
|
id: block.id,
|
4060
|
-
height: (0,
|
4137
|
+
height: (0, import_math15.bn)(block.header.height),
|
4061
4138
|
time: block.header.time,
|
4062
4139
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4063
4140
|
}));
|
@@ -4072,7 +4149,7 @@ var _Provider = class {
|
|
4072
4149
|
async getBlockWithTransactions(idOrHeight) {
|
4073
4150
|
let variables;
|
4074
4151
|
if (typeof idOrHeight === "number") {
|
4075
|
-
variables = { blockHeight: (0,
|
4152
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4076
4153
|
} else if (idOrHeight === "latest") {
|
4077
4154
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4078
4155
|
} else {
|
@@ -4084,11 +4161,11 @@ var _Provider = class {
|
|
4084
4161
|
}
|
4085
4162
|
return {
|
4086
4163
|
id: block.id,
|
4087
|
-
height: (0,
|
4164
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4088
4165
|
time: block.header.time,
|
4089
4166
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4090
4167
|
transactions: block.transactions.map(
|
4091
|
-
(tx) => new
|
4168
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4092
4169
|
)
|
4093
4170
|
};
|
4094
4171
|
}
|
@@ -4103,8 +4180,8 @@ var _Provider = class {
|
|
4103
4180
|
if (!transaction) {
|
4104
4181
|
return null;
|
4105
4182
|
}
|
4106
|
-
return new
|
4107
|
-
(0,
|
4183
|
+
return new import_transactions18.TransactionCoder().decode(
|
4184
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4108
4185
|
0
|
4109
4186
|
)?.[0];
|
4110
4187
|
}
|
@@ -4131,9 +4208,9 @@ var _Provider = class {
|
|
4131
4208
|
async getContractBalance(contractId, assetId) {
|
4132
4209
|
const { contractBalance } = await this.operations.getContractBalance({
|
4133
4210
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4134
|
-
asset: (0,
|
4211
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4135
4212
|
});
|
4136
|
-
return (0,
|
4213
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4137
4214
|
}
|
4138
4215
|
/**
|
4139
4216
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4145,9 +4222,9 @@ var _Provider = class {
|
|
4145
4222
|
async getBalance(owner, assetId) {
|
4146
4223
|
const { balance } = await this.operations.getBalance({
|
4147
4224
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4148
|
-
assetId: (0,
|
4225
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4149
4226
|
});
|
4150
|
-
return (0,
|
4227
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4151
4228
|
}
|
4152
4229
|
/**
|
4153
4230
|
* Returns balances for the given owner.
|
@@ -4165,7 +4242,7 @@ var _Provider = class {
|
|
4165
4242
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4166
4243
|
return balances.map((balance) => ({
|
4167
4244
|
assetId: balance.assetId,
|
4168
|
-
amount: (0,
|
4245
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4169
4246
|
}));
|
4170
4247
|
}
|
4171
4248
|
/**
|
@@ -4183,19 +4260,19 @@ var _Provider = class {
|
|
4183
4260
|
});
|
4184
4261
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4185
4262
|
return messages.map((message) => ({
|
4186
|
-
messageId:
|
4263
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4187
4264
|
sender: message.sender,
|
4188
4265
|
recipient: message.recipient,
|
4189
4266
|
nonce: message.nonce,
|
4190
|
-
amount: (0,
|
4267
|
+
amount: (0, import_math15.bn)(message.amount),
|
4191
4268
|
data: message.data
|
4192
4269
|
}),
|
4193
4270
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4194
4271
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4195
4272
|
nonce: message.nonce,
|
4196
|
-
amount: (0,
|
4197
|
-
data:
|
4198
|
-
daHeight: (0,
|
4273
|
+
amount: (0, import_math15.bn)(message.amount),
|
4274
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4275
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4199
4276
|
}));
|
4200
4277
|
}
|
4201
4278
|
/**
|
@@ -4213,8 +4290,8 @@ var _Provider = class {
|
|
4213
4290
|
nonce
|
4214
4291
|
};
|
4215
4292
|
if (commitBlockId && commitBlockHeight) {
|
4216
|
-
throw new
|
4217
|
-
|
4293
|
+
throw new import_errors14.FuelError(
|
4294
|
+
import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4218
4295
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4219
4296
|
);
|
4220
4297
|
}
|
@@ -4248,41 +4325,41 @@ var _Provider = class {
|
|
4248
4325
|
} = result.messageProof;
|
4249
4326
|
return {
|
4250
4327
|
messageProof: {
|
4251
|
-
proofIndex: (0,
|
4328
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4252
4329
|
proofSet: messageProof.proofSet
|
4253
4330
|
},
|
4254
4331
|
blockProof: {
|
4255
|
-
proofIndex: (0,
|
4332
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4256
4333
|
proofSet: blockProof.proofSet
|
4257
4334
|
},
|
4258
4335
|
messageBlockHeader: {
|
4259
4336
|
id: messageBlockHeader.id,
|
4260
|
-
daHeight: (0,
|
4261
|
-
transactionsCount: (0,
|
4337
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4338
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4262
4339
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4263
|
-
height: (0,
|
4340
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4264
4341
|
prevRoot: messageBlockHeader.prevRoot,
|
4265
4342
|
time: messageBlockHeader.time,
|
4266
4343
|
applicationHash: messageBlockHeader.applicationHash,
|
4267
4344
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4268
|
-
messageReceiptCount: (0,
|
4345
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4269
4346
|
},
|
4270
4347
|
commitBlockHeader: {
|
4271
4348
|
id: commitBlockHeader.id,
|
4272
|
-
daHeight: (0,
|
4273
|
-
transactionsCount: (0,
|
4349
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4350
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4274
4351
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4275
|
-
height: (0,
|
4352
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4276
4353
|
prevRoot: commitBlockHeader.prevRoot,
|
4277
4354
|
time: commitBlockHeader.time,
|
4278
4355
|
applicationHash: commitBlockHeader.applicationHash,
|
4279
4356
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4280
|
-
messageReceiptCount: (0,
|
4357
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4281
4358
|
},
|
4282
4359
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4283
4360
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4284
4361
|
nonce,
|
4285
|
-
amount: (0,
|
4362
|
+
amount: (0, import_math15.bn)(amount),
|
4286
4363
|
data
|
4287
4364
|
};
|
4288
4365
|
}
|
@@ -4305,10 +4382,10 @@ var _Provider = class {
|
|
4305
4382
|
*/
|
4306
4383
|
async produceBlocks(amount, startTime) {
|
4307
4384
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4308
|
-
blocksToProduce: (0,
|
4309
|
-
startTimestamp: startTime ?
|
4385
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4386
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4310
4387
|
});
|
4311
|
-
return (0,
|
4388
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4312
4389
|
}
|
4313
4390
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4314
4391
|
async getTransactionResponse(transactionId) {
|
@@ -4322,7 +4399,7 @@ cacheInputs_fn = function(inputs) {
|
|
4322
4399
|
return;
|
4323
4400
|
}
|
4324
4401
|
inputs.forEach((input) => {
|
4325
|
-
if (input.type ===
|
4402
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4326
4403
|
this.cache?.set(input.id);
|
4327
4404
|
}
|
4328
4405
|
});
|
@@ -4331,10 +4408,10 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4331
4408
|
__publicField(Provider, "nodeInfoCache", {});
|
4332
4409
|
|
4333
4410
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4334
|
-
var
|
4335
|
-
var
|
4336
|
-
var
|
4337
|
-
var
|
4411
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4412
|
+
var import_math16 = require("@fuel-ts/math");
|
4413
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4414
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4338
4415
|
|
4339
4416
|
// src/providers/chains.ts
|
4340
4417
|
var CHAIN_IDS = {
|
@@ -4383,17 +4460,17 @@ var assets = [
|
|
4383
4460
|
|
4384
4461
|
// src/utils/formatTransferToContractScriptData.ts
|
4385
4462
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4386
|
-
var
|
4387
|
-
var
|
4463
|
+
var import_math17 = require("@fuel-ts/math");
|
4464
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4388
4465
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4389
4466
|
var formatTransferToContractScriptData = (params) => {
|
4390
4467
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4391
4468
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4392
|
-
const encoded = numberCoder.encode(new
|
4469
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4393
4470
|
const scriptData = Uint8Array.from([
|
4394
|
-
...(0,
|
4471
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4395
4472
|
...encoded,
|
4396
|
-
...(0,
|
4473
|
+
...(0, import_utils27.arrayify)(assetId)
|
4397
4474
|
]);
|
4398
4475
|
return scriptData;
|
4399
4476
|
};
|
@@ -4449,7 +4526,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4449
4526
|
*/
|
4450
4527
|
get provider() {
|
4451
4528
|
if (!this._provider) {
|
4452
|
-
throw new
|
4529
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4453
4530
|
}
|
4454
4531
|
return this._provider;
|
4455
4532
|
}
|
@@ -4501,8 +4578,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4501
4578
|
if (!hasNextPage) {
|
4502
4579
|
break;
|
4503
4580
|
}
|
4504
|
-
throw new
|
4505
|
-
|
4581
|
+
throw new import_errors16.FuelError(
|
4582
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4506
4583
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4507
4584
|
);
|
4508
4585
|
}
|
@@ -4527,8 +4604,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4527
4604
|
if (!hasNextPage) {
|
4528
4605
|
break;
|
4529
4606
|
}
|
4530
|
-
throw new
|
4531
|
-
|
4607
|
+
throw new import_errors16.FuelError(
|
4608
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4532
4609
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4533
4610
|
);
|
4534
4611
|
}
|
@@ -4540,7 +4617,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4540
4617
|
* @param assetId - The asset ID to check the balance for.
|
4541
4618
|
* @returns A promise that resolves to the balance amount.
|
4542
4619
|
*/
|
4543
|
-
async getBalance(assetId =
|
4620
|
+
async getBalance(assetId = import_configs12.BaseAssetId) {
|
4544
4621
|
const amount = await this.provider.getBalance(this.address, assetId);
|
4545
4622
|
return amount;
|
4546
4623
|
}
|
@@ -4563,8 +4640,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4563
4640
|
if (!hasNextPage) {
|
4564
4641
|
break;
|
4565
4642
|
}
|
4566
|
-
throw new
|
4567
|
-
|
4643
|
+
throw new import_errors16.FuelError(
|
4644
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4568
4645
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4569
4646
|
);
|
4570
4647
|
}
|
@@ -4580,15 +4657,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4580
4657
|
*/
|
4581
4658
|
async fund(request, coinQuantities, fee) {
|
4582
4659
|
const updatedQuantities = addAmountToAsset({
|
4583
|
-
amount: (0,
|
4584
|
-
assetId:
|
4660
|
+
amount: (0, import_math18.bn)(fee),
|
4661
|
+
assetId: import_configs12.BaseAssetId,
|
4585
4662
|
coinQuantities
|
4586
4663
|
});
|
4587
4664
|
const quantitiesDict = {};
|
4588
4665
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4589
4666
|
quantitiesDict[assetId] = {
|
4590
4667
|
required: amount,
|
4591
|
-
owned: (0,
|
4668
|
+
owned: (0, import_math18.bn)(0)
|
4592
4669
|
};
|
4593
4670
|
});
|
4594
4671
|
const cachedUtxos = [];
|
@@ -4601,12 +4678,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4601
4678
|
if (isCoin2) {
|
4602
4679
|
const assetId = String(input.assetId);
|
4603
4680
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4604
|
-
const amount = (0,
|
4681
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4605
4682
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4606
4683
|
cachedUtxos.push(input.id);
|
4607
4684
|
}
|
4608
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
4609
|
-
quantitiesDict[
|
4685
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs12.BaseAssetId]) {
|
4686
|
+
quantitiesDict[import_configs12.BaseAssetId].owned = quantitiesDict[import_configs12.BaseAssetId].owned.add(input.amount);
|
4610
4687
|
cachedMessages.push(input.nonce);
|
4611
4688
|
}
|
4612
4689
|
}
|
@@ -4638,7 +4715,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4638
4715
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4639
4716
|
* @returns A promise that resolves to the prepared transaction request.
|
4640
4717
|
*/
|
4641
|
-
async createTransfer(destination, amount, assetId =
|
4718
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4642
4719
|
const { minGasPrice } = this.provider.getGasConfig();
|
4643
4720
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4644
4721
|
const request = new ScriptTransactionRequest(params);
|
@@ -4647,8 +4724,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4647
4724
|
estimateTxDependencies: true,
|
4648
4725
|
resourcesOwner: this
|
4649
4726
|
});
|
4650
|
-
request.gasPrice = (0,
|
4651
|
-
request.gasLimit = (0,
|
4727
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4728
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4652
4729
|
this.validateGas({
|
4653
4730
|
gasUsed,
|
4654
4731
|
gasPrice: request.gasPrice,
|
@@ -4668,10 +4745,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4668
4745
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
4669
4746
|
* @returns A promise that resolves to the transaction response.
|
4670
4747
|
*/
|
4671
|
-
async transfer(destination, amount, assetId =
|
4672
|
-
if ((0,
|
4673
|
-
throw new
|
4674
|
-
|
4748
|
+
async transfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4749
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4750
|
+
throw new import_errors16.FuelError(
|
4751
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4675
4752
|
"Transfer amount must be a positive number."
|
4676
4753
|
);
|
4677
4754
|
}
|
@@ -4687,10 +4764,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4687
4764
|
* @param txParams - The optional transaction parameters.
|
4688
4765
|
* @returns A promise that resolves to the transaction response.
|
4689
4766
|
*/
|
4690
|
-
async transferToContract(contractId, amount, assetId =
|
4691
|
-
if ((0,
|
4692
|
-
throw new
|
4693
|
-
|
4767
|
+
async transferToContract(contractId, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
4768
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4769
|
+
throw new import_errors16.FuelError(
|
4770
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4694
4771
|
"Transfer amount must be a positive number."
|
4695
4772
|
);
|
4696
4773
|
}
|
@@ -4699,7 +4776,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4699
4776
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4700
4777
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4701
4778
|
hexlifiedContractId: contractAddress.toB256(),
|
4702
|
-
amountToTransfer: (0,
|
4779
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4703
4780
|
assetId
|
4704
4781
|
});
|
4705
4782
|
const request = new ScriptTransactionRequest({
|
@@ -4710,9 +4787,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4710
4787
|
request.addContractInputAndOutput(contractAddress);
|
4711
4788
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4712
4789
|
request,
|
4713
|
-
[{ amount: (0,
|
4790
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetId) }]
|
4714
4791
|
);
|
4715
|
-
request.gasLimit = (0,
|
4792
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4716
4793
|
this.validateGas({
|
4717
4794
|
gasUsed,
|
4718
4795
|
gasPrice: request.gasPrice,
|
@@ -4733,25 +4810,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4733
4810
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
4734
4811
|
const { minGasPrice } = this.provider.getGasConfig();
|
4735
4812
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4736
|
-
const recipientDataArray = (0,
|
4813
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
4737
4814
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4738
4815
|
);
|
4739
|
-
const amountDataArray = (0,
|
4740
|
-
"0x".concat((0,
|
4816
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4817
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4741
4818
|
);
|
4742
4819
|
const script = new Uint8Array([
|
4743
|
-
...(0,
|
4820
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
4744
4821
|
...recipientDataArray,
|
4745
4822
|
...amountDataArray
|
4746
4823
|
]);
|
4747
4824
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4748
4825
|
const request = new ScriptTransactionRequest(params);
|
4749
|
-
const forwardingQuantities = [{ amount: (0,
|
4826
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: import_configs12.BaseAssetId }];
|
4750
4827
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4751
4828
|
request,
|
4752
4829
|
forwardingQuantities
|
4753
4830
|
);
|
4754
|
-
request.gasLimit = (0,
|
4831
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4755
4832
|
this.validateGas({
|
4756
4833
|
gasUsed,
|
4757
4834
|
gasPrice: request.gasPrice,
|
@@ -4763,7 +4840,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4763
4840
|
}
|
4764
4841
|
async signMessage(message) {
|
4765
4842
|
if (!this._connector) {
|
4766
|
-
throw new
|
4843
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4767
4844
|
}
|
4768
4845
|
return this._connector.signMessage(this.address.toString(), message);
|
4769
4846
|
}
|
@@ -4775,8 +4852,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4775
4852
|
*/
|
4776
4853
|
async signTransaction(transactionRequestLike) {
|
4777
4854
|
if (!this._connector) {
|
4778
|
-
throw new
|
4779
|
-
|
4855
|
+
throw new import_errors16.FuelError(
|
4856
|
+
import_errors16.ErrorCode.MISSING_CONNECTOR,
|
4780
4857
|
"A connector is required to sign transactions."
|
4781
4858
|
);
|
4782
4859
|
}
|
@@ -4823,14 +4900,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4823
4900
|
minGasPrice
|
4824
4901
|
}) {
|
4825
4902
|
if (minGasPrice.gt(gasPrice)) {
|
4826
|
-
throw new
|
4827
|
-
|
4903
|
+
throw new import_errors16.FuelError(
|
4904
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4828
4905
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4829
4906
|
);
|
4830
4907
|
}
|
4831
4908
|
if (gasUsed.gt(gasLimit)) {
|
4832
|
-
throw new
|
4833
|
-
|
4909
|
+
throw new import_errors16.FuelError(
|
4910
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4834
4911
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4835
4912
|
);
|
4836
4913
|
}
|
@@ -4841,8 +4918,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4841
4918
|
var import_address5 = require("@fuel-ts/address");
|
4842
4919
|
var import_crypto = require("@fuel-ts/crypto");
|
4843
4920
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4844
|
-
var
|
4845
|
-
var
|
4921
|
+
var import_math19 = require("@fuel-ts/math");
|
4922
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4846
4923
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4847
4924
|
var Signer = class {
|
4848
4925
|
address;
|
@@ -4861,10 +4938,10 @@ var Signer = class {
|
|
4861
4938
|
privateKey = `0x${privateKey}`;
|
4862
4939
|
}
|
4863
4940
|
}
|
4864
|
-
const privateKeyBytes = (0,
|
4865
|
-
this.privateKey = (0,
|
4866
|
-
this.publicKey = (0,
|
4867
|
-
this.compressedPublicKey = (0,
|
4941
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4942
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4943
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4944
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4868
4945
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4869
4946
|
}
|
4870
4947
|
/**
|
@@ -4878,11 +4955,11 @@ var Signer = class {
|
|
4878
4955
|
* @returns hashed signature
|
4879
4956
|
*/
|
4880
4957
|
sign(data) {
|
4881
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4882
|
-
const r = (0,
|
4883
|
-
const s = (0,
|
4958
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4959
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4960
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4884
4961
|
s[0] |= (signature.recovery || 0) << 7;
|
4885
|
-
return (0,
|
4962
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
4886
4963
|
}
|
4887
4964
|
/**
|
4888
4965
|
* Add point on the current elliptic curve
|
@@ -4891,8 +4968,8 @@ var Signer = class {
|
|
4891
4968
|
* @returns compressed point on the curve
|
4892
4969
|
*/
|
4893
4970
|
addPoint(point) {
|
4894
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4895
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4971
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4972
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
4896
4973
|
const result = p0.add(p1);
|
4897
4974
|
return `0x${result.toHex(true)}`;
|
4898
4975
|
}
|
@@ -4904,16 +4981,16 @@ var Signer = class {
|
|
4904
4981
|
* @returns public key from signature from the
|
4905
4982
|
*/
|
4906
4983
|
static recoverPublicKey(data, signature) {
|
4907
|
-
const signedMessageBytes = (0,
|
4984
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
4908
4985
|
const r = signedMessageBytes.slice(0, 32);
|
4909
4986
|
const s = signedMessageBytes.slice(32, 64);
|
4910
4987
|
const recoveryParam = (s[0] & 128) >> 7;
|
4911
4988
|
s[0] &= 127;
|
4912
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
4989
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
4913
4990
|
recoveryParam
|
4914
4991
|
);
|
4915
|
-
const publicKey = sig.recoverPublicKey((0,
|
4916
|
-
return (0,
|
4992
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
4993
|
+
return (0, import_utils29.hexlify)(publicKey);
|
4917
4994
|
}
|
4918
4995
|
/**
|
4919
4996
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4932,7 +5009,7 @@ var Signer = class {
|
|
4932
5009
|
* @returns random 32-byte hashed
|
4933
5010
|
*/
|
4934
5011
|
static generatePrivateKey(entropy) {
|
4935
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5012
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
4936
5013
|
}
|
4937
5014
|
/**
|
4938
5015
|
* Extended publicKey from a compact publicKey
|
@@ -4941,16 +5018,16 @@ var Signer = class {
|
|
4941
5018
|
* @returns extended publicKey
|
4942
5019
|
*/
|
4943
5020
|
static extendPublicKey(publicKey) {
|
4944
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4945
|
-
return (0,
|
5021
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5022
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
4946
5023
|
}
|
4947
5024
|
};
|
4948
5025
|
|
4949
5026
|
// src/wallet/keystore-wallet.ts
|
4950
5027
|
var import_address6 = require("@fuel-ts/address");
|
4951
5028
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4952
|
-
var
|
4953
|
-
var
|
5029
|
+
var import_errors17 = require("@fuel-ts/errors");
|
5030
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4954
5031
|
var import_uuid = require("uuid");
|
4955
5032
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4956
5033
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5027,13 +5104,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5027
5104
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5028
5105
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5029
5106
|
if (mac !== macHash) {
|
5030
|
-
throw new
|
5031
|
-
|
5107
|
+
throw new import_errors17.FuelError(
|
5108
|
+
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5032
5109
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5033
5110
|
);
|
5034
5111
|
}
|
5035
5112
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5036
|
-
const privateKey = (0,
|
5113
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5037
5114
|
return privateKey;
|
5038
5115
|
}
|
5039
5116
|
|
@@ -5078,7 +5155,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5078
5155
|
*/
|
5079
5156
|
async signMessage(message) {
|
5080
5157
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5081
|
-
return (0,
|
5158
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5082
5159
|
}
|
5083
5160
|
/**
|
5084
5161
|
* Signs a transaction with the wallet's private key.
|
@@ -5091,7 +5168,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5091
5168
|
const chainId = this.provider.getChainId();
|
5092
5169
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5093
5170
|
const signature = await this.signer().sign(hashedTransaction);
|
5094
|
-
return (0,
|
5171
|
+
return (0, import_utils31.hexlify)(signature);
|
5095
5172
|
}
|
5096
5173
|
/**
|
5097
5174
|
* Populates a transaction with the witnesses signature.
|
@@ -5150,17 +5227,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5150
5227
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5151
5228
|
|
5152
5229
|
// src/hdwallet/hdwallet.ts
|
5153
|
-
var
|
5230
|
+
var import_errors20 = require("@fuel-ts/errors");
|
5154
5231
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5155
|
-
var
|
5156
|
-
var
|
5232
|
+
var import_math20 = require("@fuel-ts/math");
|
5233
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5157
5234
|
var import_ethers3 = require("ethers");
|
5158
5235
|
|
5159
5236
|
// src/mnemonic/mnemonic.ts
|
5160
5237
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5161
|
-
var
|
5238
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5162
5239
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5163
|
-
var
|
5240
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5164
5241
|
var import_ethers2 = require("ethers");
|
5165
5242
|
|
5166
5243
|
// src/wordlists/words/english.ts
|
@@ -7216,9 +7293,9 @@ var english = [
|
|
7216
7293
|
];
|
7217
7294
|
|
7218
7295
|
// src/mnemonic/utils.ts
|
7219
|
-
var
|
7296
|
+
var import_errors18 = require("@fuel-ts/errors");
|
7220
7297
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7221
|
-
var
|
7298
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7222
7299
|
function toUtf8Bytes(stri) {
|
7223
7300
|
const str = stri.normalize("NFKD");
|
7224
7301
|
const result = [];
|
@@ -7233,8 +7310,8 @@ function toUtf8Bytes(stri) {
|
|
7233
7310
|
i += 1;
|
7234
7311
|
const c2 = str.charCodeAt(i);
|
7235
7312
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7236
|
-
throw new
|
7237
|
-
|
7313
|
+
throw new import_errors18.FuelError(
|
7314
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7238
7315
|
"Invalid UTF-8 in the input string."
|
7239
7316
|
);
|
7240
7317
|
}
|
@@ -7285,20 +7362,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7285
7362
|
}
|
7286
7363
|
}
|
7287
7364
|
const checksumBits = entropy.length / 4;
|
7288
|
-
const checksum = (0,
|
7365
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7289
7366
|
indices[indices.length - 1] <<= checksumBits;
|
7290
7367
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7291
7368
|
return indices;
|
7292
7369
|
}
|
7293
7370
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7294
7371
|
const size = Math.ceil(11 * words.length / 8);
|
7295
|
-
const entropy = (0,
|
7372
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7296
7373
|
let offset = 0;
|
7297
7374
|
for (let i = 0; i < words.length; i += 1) {
|
7298
7375
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7299
7376
|
if (index === -1) {
|
7300
|
-
throw new
|
7301
|
-
|
7377
|
+
throw new import_errors18.FuelError(
|
7378
|
+
import_errors18.ErrorCode.INVALID_MNEMONIC,
|
7302
7379
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7303
7380
|
);
|
7304
7381
|
}
|
@@ -7312,10 +7389,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7312
7389
|
const entropyBits = 32 * words.length / 3;
|
7313
7390
|
const checksumBits = words.length / 3;
|
7314
7391
|
const checksumMask = getUpperMask(checksumBits);
|
7315
|
-
const checksum = (0,
|
7392
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7316
7393
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7317
|
-
throw new
|
7318
|
-
|
7394
|
+
throw new import_errors18.FuelError(
|
7395
|
+
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
7319
7396
|
"Checksum validation failed for the provided mnemonic."
|
7320
7397
|
);
|
7321
7398
|
}
|
@@ -7329,16 +7406,16 @@ var TestnetPRV = "0x04358394";
|
|
7329
7406
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7330
7407
|
function assertWordList(wordlist) {
|
7331
7408
|
if (wordlist.length !== 2048) {
|
7332
|
-
throw new
|
7333
|
-
|
7409
|
+
throw new import_errors19.FuelError(
|
7410
|
+
import_errors19.ErrorCode.INVALID_WORD_LIST,
|
7334
7411
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7335
7412
|
);
|
7336
7413
|
}
|
7337
7414
|
}
|
7338
7415
|
function assertEntropy(entropy) {
|
7339
7416
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7340
|
-
throw new
|
7341
|
-
|
7417
|
+
throw new import_errors19.FuelError(
|
7418
|
+
import_errors19.ErrorCode.INVALID_ENTROPY,
|
7342
7419
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7343
7420
|
);
|
7344
7421
|
}
|
@@ -7348,7 +7425,7 @@ function assertMnemonic(words) {
|
|
7348
7425
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7349
7426
|
", "
|
7350
7427
|
)}] words, but got ${words.length}.`;
|
7351
|
-
throw new
|
7428
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7352
7429
|
}
|
7353
7430
|
}
|
7354
7431
|
var Mnemonic = class {
|
@@ -7387,7 +7464,7 @@ var Mnemonic = class {
|
|
7387
7464
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7388
7465
|
const words = getWords(phrase);
|
7389
7466
|
assertMnemonic(words);
|
7390
|
-
return (0,
|
7467
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7391
7468
|
}
|
7392
7469
|
/**
|
7393
7470
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7395,7 +7472,7 @@ var Mnemonic = class {
|
|
7395
7472
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7396
7473
|
*/
|
7397
7474
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7398
|
-
const entropyBytes = (0,
|
7475
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7399
7476
|
assertWordList(wordlist);
|
7400
7477
|
assertEntropy(entropyBytes);
|
7401
7478
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7464,14 +7541,14 @@ var Mnemonic = class {
|
|
7464
7541
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7465
7542
|
*/
|
7466
7543
|
static masterKeysFromSeed(seed) {
|
7467
|
-
const seedArray = (0,
|
7544
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7468
7545
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7469
|
-
throw new
|
7470
|
-
|
7546
|
+
throw new import_errors19.FuelError(
|
7547
|
+
import_errors19.ErrorCode.INVALID_SEED,
|
7471
7548
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7472
7549
|
);
|
7473
7550
|
}
|
7474
|
-
return (0,
|
7551
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7475
7552
|
}
|
7476
7553
|
/**
|
7477
7554
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7482,22 +7559,22 @@ var Mnemonic = class {
|
|
7482
7559
|
*/
|
7483
7560
|
static seedToExtendedKey(seed, testnet = false) {
|
7484
7561
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7485
|
-
const prefix = (0,
|
7562
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7486
7563
|
const depth = "0x00";
|
7487
7564
|
const fingerprint = "0x00000000";
|
7488
7565
|
const index = "0x00000000";
|
7489
7566
|
const chainCode = masterKey.slice(32);
|
7490
7567
|
const privateKey = masterKey.slice(0, 32);
|
7491
|
-
const extendedKey = (0,
|
7568
|
+
const extendedKey = (0, import_utils33.concat)([
|
7492
7569
|
prefix,
|
7493
7570
|
depth,
|
7494
7571
|
fingerprint,
|
7495
7572
|
index,
|
7496
7573
|
chainCode,
|
7497
|
-
(0,
|
7574
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7498
7575
|
]);
|
7499
7576
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7500
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7577
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7501
7578
|
}
|
7502
7579
|
/**
|
7503
7580
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7512,7 +7589,7 @@ var Mnemonic = class {
|
|
7512
7589
|
* @returns A randomly generated mnemonic
|
7513
7590
|
*/
|
7514
7591
|
static generate(size = 32, extraEntropy = "") {
|
7515
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7592
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
7516
7593
|
return Mnemonic.entropyToMnemonic(entropy);
|
7517
7594
|
}
|
7518
7595
|
};
|
@@ -7520,12 +7597,12 @@ var mnemonic_default = Mnemonic;
|
|
7520
7597
|
|
7521
7598
|
// src/hdwallet/hdwallet.ts
|
7522
7599
|
var HARDENED_INDEX = 2147483648;
|
7523
|
-
var MainnetPRV2 = (0,
|
7524
|
-
var MainnetPUB = (0,
|
7525
|
-
var TestnetPRV2 = (0,
|
7526
|
-
var TestnetPUB = (0,
|
7600
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7601
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7602
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7603
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7527
7604
|
function base58check(data) {
|
7528
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7605
|
+
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)]));
|
7529
7606
|
}
|
7530
7607
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7531
7608
|
if (isPublic) {
|
@@ -7534,17 +7611,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7534
7611
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7535
7612
|
}
|
7536
7613
|
function isPublicExtendedKey(extendedKey) {
|
7537
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7614
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7538
7615
|
}
|
7539
7616
|
function isValidExtendedKey(extendedKey) {
|
7540
7617
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7541
|
-
(0,
|
7618
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7542
7619
|
);
|
7543
7620
|
}
|
7544
7621
|
function parsePath(path2, depth = 0) {
|
7545
7622
|
const components = path2.split("/");
|
7546
7623
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7547
|
-
throw new
|
7624
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7548
7625
|
}
|
7549
7626
|
if (components[0] === "m") {
|
7550
7627
|
components.shift();
|
@@ -7556,8 +7633,8 @@ function parsePath(path2, depth = 0) {
|
|
7556
7633
|
var HDWallet = class {
|
7557
7634
|
depth = 0;
|
7558
7635
|
index = 0;
|
7559
|
-
fingerprint = (0,
|
7560
|
-
parentFingerprint = (0,
|
7636
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7637
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7561
7638
|
privateKey;
|
7562
7639
|
publicKey;
|
7563
7640
|
chainCode;
|
@@ -7569,16 +7646,16 @@ var HDWallet = class {
|
|
7569
7646
|
constructor(config) {
|
7570
7647
|
if (config.privateKey) {
|
7571
7648
|
const signer = new Signer(config.privateKey);
|
7572
|
-
this.publicKey = (0,
|
7573
|
-
this.privateKey = (0,
|
7649
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7650
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7574
7651
|
} else {
|
7575
7652
|
if (!config.publicKey) {
|
7576
|
-
throw new
|
7577
|
-
|
7653
|
+
throw new import_errors20.FuelError(
|
7654
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7578
7655
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7579
7656
|
);
|
7580
7657
|
}
|
7581
|
-
this.publicKey = (0,
|
7658
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7582
7659
|
}
|
7583
7660
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7584
7661
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7597,28 +7674,28 @@ var HDWallet = class {
|
|
7597
7674
|
* @returns A new instance of HDWallet on the derived index
|
7598
7675
|
*/
|
7599
7676
|
deriveIndex(index) {
|
7600
|
-
const privateKey = this.privateKey && (0,
|
7601
|
-
const publicKey = (0,
|
7602
|
-
const chainCode = (0,
|
7677
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7678
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7679
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7603
7680
|
const data = new Uint8Array(37);
|
7604
7681
|
if (index & HARDENED_INDEX) {
|
7605
7682
|
if (!privateKey) {
|
7606
|
-
throw new
|
7607
|
-
|
7683
|
+
throw new import_errors20.FuelError(
|
7684
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7608
7685
|
"Cannot derive a hardened index without a private Key."
|
7609
7686
|
);
|
7610
7687
|
}
|
7611
7688
|
data.set(privateKey, 1);
|
7612
7689
|
} else {
|
7613
|
-
data.set((0,
|
7690
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7614
7691
|
}
|
7615
|
-
data.set((0,
|
7616
|
-
const bytes = (0,
|
7692
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7693
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7617
7694
|
const IL = bytes.slice(0, 32);
|
7618
7695
|
const IR = bytes.slice(32);
|
7619
7696
|
if (privateKey) {
|
7620
7697
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7621
|
-
const ki = (0,
|
7698
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7622
7699
|
return new HDWallet({
|
7623
7700
|
privateKey: ki,
|
7624
7701
|
chainCode: IR,
|
@@ -7627,7 +7704,7 @@ var HDWallet = class {
|
|
7627
7704
|
parentFingerprint: this.fingerprint
|
7628
7705
|
});
|
7629
7706
|
}
|
7630
|
-
const signer = new Signer((0,
|
7707
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7631
7708
|
const Ki = signer.addPoint(publicKey);
|
7632
7709
|
return new HDWallet({
|
7633
7710
|
publicKey: Ki,
|
@@ -7656,18 +7733,18 @@ var HDWallet = class {
|
|
7656
7733
|
*/
|
7657
7734
|
toExtendedKey(isPublic = false, testnet = false) {
|
7658
7735
|
if (this.depth >= 256) {
|
7659
|
-
throw new
|
7660
|
-
|
7736
|
+
throw new import_errors20.FuelError(
|
7737
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7661
7738
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7662
7739
|
);
|
7663
7740
|
}
|
7664
7741
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7665
|
-
const depth = (0,
|
7742
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7666
7743
|
const parentFingerprint = this.parentFingerprint;
|
7667
|
-
const index = (0,
|
7744
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7668
7745
|
const chainCode = this.chainCode;
|
7669
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7670
|
-
const extendedKey = (0,
|
7746
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7747
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7671
7748
|
return base58check(extendedKey);
|
7672
7749
|
}
|
7673
7750
|
/**
|
@@ -7679,34 +7756,34 @@ var HDWallet = class {
|
|
7679
7756
|
static fromSeed(seed) {
|
7680
7757
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7681
7758
|
return new HDWallet({
|
7682
|
-
chainCode: (0,
|
7683
|
-
privateKey: (0,
|
7759
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7760
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7684
7761
|
});
|
7685
7762
|
}
|
7686
7763
|
static fromExtendedKey(extendedKey) {
|
7687
7764
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7688
|
-
const bytes = (0,
|
7765
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7689
7766
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7690
7767
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7691
|
-
throw new
|
7768
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7692
7769
|
}
|
7693
7770
|
if (!validChecksum) {
|
7694
|
-
throw new
|
7771
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7695
7772
|
}
|
7696
7773
|
const depth = bytes[4];
|
7697
|
-
const parentFingerprint = (0,
|
7698
|
-
const index = parseInt((0,
|
7699
|
-
const chainCode = (0,
|
7774
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7775
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7776
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7700
7777
|
const key = bytes.slice(45, 78);
|
7701
7778
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7702
|
-
throw new
|
7703
|
-
|
7779
|
+
throw new import_errors20.FuelError(
|
7780
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7704
7781
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7705
7782
|
);
|
7706
7783
|
}
|
7707
7784
|
if (isPublicExtendedKey(bytes)) {
|
7708
7785
|
if (key[0] !== 3) {
|
7709
|
-
throw new
|
7786
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
7710
7787
|
}
|
7711
7788
|
return new HDWallet({
|
7712
7789
|
publicKey: key,
|
@@ -7717,7 +7794,7 @@ var HDWallet = class {
|
|
7717
7794
|
});
|
7718
7795
|
}
|
7719
7796
|
if (key[0] !== 0) {
|
7720
|
-
throw new
|
7797
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
7721
7798
|
}
|
7722
7799
|
return new HDWallet({
|
7723
7800
|
privateKey: key.slice(1),
|
@@ -7910,9 +7987,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7910
7987
|
};
|
7911
7988
|
|
7912
7989
|
// src/test-utils/launchNode.ts
|
7913
|
-
var
|
7914
|
-
var
|
7915
|
-
var
|
7990
|
+
var import_configs13 = require("@fuel-ts/address/configs");
|
7991
|
+
var import_math21 = require("@fuel-ts/math");
|
7992
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7916
7993
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7917
7994
|
var import_child_process = require("child_process");
|
7918
7995
|
var import_crypto5 = require("crypto");
|
@@ -7970,7 +8047,7 @@ var launchNode = async ({
|
|
7970
8047
|
"--poa-instant"
|
7971
8048
|
]);
|
7972
8049
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7973
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8050
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
7974
8051
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7975
8052
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7976
8053
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -7996,21 +8073,21 @@ var launchNode = async ({
|
|
7996
8073
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
7997
8074
|
}
|
7998
8075
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
7999
|
-
let chainConfig =
|
8076
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8000
8077
|
if (!process.env.GENESIS_SECRET) {
|
8001
8078
|
const pk = Signer.generatePrivateKey();
|
8002
8079
|
const signer = new Signer(pk);
|
8003
|
-
process.env.GENESIS_SECRET = (0,
|
8080
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8004
8081
|
chainConfig = {
|
8005
|
-
...
|
8082
|
+
...import_utils36.defaultChainConfig,
|
8006
8083
|
initial_state: {
|
8007
|
-
...
|
8084
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8008
8085
|
coins: [
|
8009
|
-
...
|
8086
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8010
8087
|
{
|
8011
8088
|
owner: signer.address.toHexString(),
|
8012
|
-
amount: (0,
|
8013
|
-
asset_id:
|
8089
|
+
amount: (0, import_math21.toHex)(1e9),
|
8090
|
+
asset_id: import_configs13.BaseAssetId
|
8014
8091
|
}
|
8015
8092
|
]
|
8016
8093
|
}
|
@@ -8078,7 +8155,7 @@ var launchNode = async ({
|
|
8078
8155
|
var generateWallets = async (count, provider) => {
|
8079
8156
|
const wallets = [];
|
8080
8157
|
for (let i = 0; i < count; i += 1) {
|
8081
|
-
const wallet = await generateTestWallet(provider, [[1e3,
|
8158
|
+
const wallet = await generateTestWallet(provider, [[1e3, import_configs13.BaseAssetId]]);
|
8082
8159
|
wallets.push(wallet);
|
8083
8160
|
}
|
8084
8161
|
return wallets;
|