@fuel-ts/account 0.0.0-rc-1976-20240405090158 → 0.0.0-rc-1976-20240405092005
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @fuel-ts/account might be problematic. Click here for more details.
- package/dist/index.global.js +212 -38
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +540 -457
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +328 -240
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/extract-tx-error.d.ts +36 -0
- package/dist/providers/utils/extract-tx-error.d.ts.map +1 -0
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +212 -38
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +501 -424
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +298 -213
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
package/dist/test-utils.js
CHANGED
@@ -58,14 +58,14 @@ 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
|
65
|
+
var import_errors16 = require("@fuel-ts/errors");
|
66
66
|
var import_interfaces = require("@fuel-ts/interfaces");
|
67
|
-
var
|
68
|
-
var
|
67
|
+
var import_math18 = require("@fuel-ts/math");
|
68
|
+
var import_utils28 = require("@fuel-ts/utils");
|
69
69
|
|
70
70
|
// src/providers/coin-quantity.ts
|
71
71
|
var import_math = require("@fuel-ts/math");
|
@@ -104,12 +104,12 @@ var addAmountToAsset = (params) => {
|
|
104
104
|
|
105
105
|
// src/providers/provider.ts
|
106
106
|
var import_address3 = require("@fuel-ts/address");
|
107
|
-
var
|
108
|
-
var
|
109
|
-
var
|
110
|
-
var
|
107
|
+
var import_errors14 = require("@fuel-ts/errors");
|
108
|
+
var import_math15 = require("@fuel-ts/math");
|
109
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
110
|
+
var import_utils23 = require("@fuel-ts/utils");
|
111
111
|
var import_versions = require("@fuel-ts/versions");
|
112
|
-
var
|
112
|
+
var import_utils24 = require("@noble/curves/abstract/utils");
|
113
113
|
var import_ethers = require("ethers");
|
114
114
|
var import_graphql_request = require("graphql-request");
|
115
115
|
var import_ramda3 = require("ramda");
|
@@ -1182,9 +1182,9 @@ var outputify = (value) => {
|
|
1182
1182
|
|
1183
1183
|
// src/providers/transaction-request/transaction-request.ts
|
1184
1184
|
var import_address = require("@fuel-ts/address");
|
1185
|
-
var
|
1186
|
-
var
|
1187
|
-
var
|
1185
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1186
|
+
var import_math7 = require("@fuel-ts/math");
|
1187
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
1188
1188
|
var import_utils9 = require("@fuel-ts/utils");
|
1189
1189
|
|
1190
1190
|
// src/providers/resource.ts
|
@@ -1515,6 +1515,78 @@ function sleep(time) {
|
|
1515
1515
|
});
|
1516
1516
|
}
|
1517
1517
|
|
1518
|
+
// src/providers/utils/extract-tx-error.ts
|
1519
|
+
var import_errors7 = require("@fuel-ts/errors");
|
1520
|
+
var import_math6 = require("@fuel-ts/math");
|
1521
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1522
|
+
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1523
|
+
var assemblePanicError = (status) => {
|
1524
|
+
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1525
|
+
const reason = status.reason;
|
1526
|
+
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1527
|
+
errorMessage = `${errorMessage}
|
1528
|
+
|
1529
|
+
You can read more about this error at:
|
1530
|
+
|
1531
|
+
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1532
|
+
}
|
1533
|
+
return { errorMessage, reason };
|
1534
|
+
};
|
1535
|
+
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1536
|
+
var assembleRevertError = (receipts, logs) => {
|
1537
|
+
let errorMessage = "The transaction reverted with an unknown reason.";
|
1538
|
+
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1539
|
+
let reason = "";
|
1540
|
+
if (revertReceipt) {
|
1541
|
+
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1542
|
+
switch (reasonHex) {
|
1543
|
+
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1544
|
+
reason = "require";
|
1545
|
+
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1546
|
+
break;
|
1547
|
+
}
|
1548
|
+
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1549
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1550
|
+
reason = "assert_eq";
|
1551
|
+
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1552
|
+
break;
|
1553
|
+
}
|
1554
|
+
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1555
|
+
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1556
|
+
reason = "assert_ne";
|
1557
|
+
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1558
|
+
break;
|
1559
|
+
}
|
1560
|
+
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1561
|
+
reason = "assert";
|
1562
|
+
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1563
|
+
break;
|
1564
|
+
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1565
|
+
reason = "MissingOutputChange";
|
1566
|
+
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1567
|
+
break;
|
1568
|
+
default:
|
1569
|
+
reason = "unknown";
|
1570
|
+
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1571
|
+
}
|
1572
|
+
}
|
1573
|
+
return { errorMessage, reason };
|
1574
|
+
};
|
1575
|
+
var extractTxError = (params) => {
|
1576
|
+
const { receipts, status, logs } = params;
|
1577
|
+
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1578
|
+
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1579
|
+
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1580
|
+
const metadata = {
|
1581
|
+
logs,
|
1582
|
+
receipts,
|
1583
|
+
panic: isPanic,
|
1584
|
+
revert: isRevert,
|
1585
|
+
reason
|
1586
|
+
};
|
1587
|
+
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1588
|
+
};
|
1589
|
+
|
1518
1590
|
// src/providers/transaction-request/errors.ts
|
1519
1591
|
var NoWitnessAtIndexError = class extends Error {
|
1520
1592
|
constructor(index) {
|
@@ -1552,7 +1624,7 @@ var BaseTransactionRequest = class {
|
|
1552
1624
|
/** List of witnesses */
|
1553
1625
|
witnesses = [];
|
1554
1626
|
/** Base asset ID - should be fetched from the chain */
|
1555
|
-
baseAssetId =
|
1627
|
+
baseAssetId = import_configs6.ZeroBytes32;
|
1556
1628
|
/**
|
1557
1629
|
* Constructor for initializing a base transaction request.
|
1558
1630
|
*
|
@@ -1568,33 +1640,33 @@ var BaseTransactionRequest = class {
|
|
1568
1640
|
witnesses,
|
1569
1641
|
baseAssetId
|
1570
1642
|
} = {}) {
|
1571
|
-
this.gasPrice = (0,
|
1643
|
+
this.gasPrice = (0, import_math7.bn)(gasPrice);
|
1572
1644
|
this.maturity = maturity ?? 0;
|
1573
|
-
this.witnessLimit = witnessLimit ? (0,
|
1574
|
-
this.maxFee = maxFee ? (0,
|
1645
|
+
this.witnessLimit = witnessLimit ? (0, import_math7.bn)(witnessLimit) : void 0;
|
1646
|
+
this.maxFee = maxFee ? (0, import_math7.bn)(maxFee) : void 0;
|
1575
1647
|
this.inputs = inputs ?? [];
|
1576
1648
|
this.outputs = outputs ?? [];
|
1577
1649
|
this.witnesses = witnesses ?? [];
|
1578
|
-
this.baseAssetId = baseAssetId ??
|
1650
|
+
this.baseAssetId = baseAssetId ?? import_configs6.ZeroBytes32;
|
1579
1651
|
}
|
1580
1652
|
static getPolicyMeta(req) {
|
1581
1653
|
let policyTypes = 0;
|
1582
1654
|
const policies = [];
|
1583
1655
|
if (req.gasPrice) {
|
1584
|
-
policyTypes +=
|
1585
|
-
policies.push({ data: req.gasPrice, type:
|
1656
|
+
policyTypes += import_transactions6.PolicyType.GasPrice;
|
1657
|
+
policies.push({ data: req.gasPrice, type: import_transactions6.PolicyType.GasPrice });
|
1586
1658
|
}
|
1587
1659
|
if (req.witnessLimit) {
|
1588
|
-
policyTypes +=
|
1589
|
-
policies.push({ data: req.witnessLimit, type:
|
1660
|
+
policyTypes += import_transactions6.PolicyType.WitnessLimit;
|
1661
|
+
policies.push({ data: req.witnessLimit, type: import_transactions6.PolicyType.WitnessLimit });
|
1590
1662
|
}
|
1591
1663
|
if (req.maturity > 0) {
|
1592
|
-
policyTypes +=
|
1593
|
-
policies.push({ data: req.maturity, type:
|
1664
|
+
policyTypes += import_transactions6.PolicyType.Maturity;
|
1665
|
+
policies.push({ data: req.maturity, type: import_transactions6.PolicyType.Maturity });
|
1594
1666
|
}
|
1595
1667
|
if (req.maxFee) {
|
1596
|
-
policyTypes +=
|
1597
|
-
policies.push({ data: req.maxFee, type:
|
1668
|
+
policyTypes += import_transactions6.PolicyType.MaxFee;
|
1669
|
+
policies.push({ data: req.maxFee, type: import_transactions6.PolicyType.MaxFee });
|
1598
1670
|
}
|
1599
1671
|
return {
|
1600
1672
|
policyTypes,
|
@@ -1628,7 +1700,7 @@ var BaseTransactionRequest = class {
|
|
1628
1700
|
* @returns The transaction bytes.
|
1629
1701
|
*/
|
1630
1702
|
toTransactionBytes() {
|
1631
|
-
return new
|
1703
|
+
return new import_transactions6.TransactionCoder().encode(this.toTransaction());
|
1632
1704
|
}
|
1633
1705
|
/**
|
1634
1706
|
* @hidden
|
@@ -1668,7 +1740,7 @@ var BaseTransactionRequest = class {
|
|
1668
1740
|
* @returns The index of the created witness.
|
1669
1741
|
*/
|
1670
1742
|
addEmptyWitness() {
|
1671
|
-
this.addWitness((0, import_utils9.concat)([
|
1743
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1672
1744
|
return this.witnesses.length - 1;
|
1673
1745
|
}
|
1674
1746
|
/**
|
@@ -1719,7 +1791,7 @@ var BaseTransactionRequest = class {
|
|
1719
1791
|
*/
|
1720
1792
|
getCoinInputs() {
|
1721
1793
|
return this.inputs.filter(
|
1722
|
-
(input) => input.type ===
|
1794
|
+
(input) => input.type === import_transactions6.InputType.Coin
|
1723
1795
|
);
|
1724
1796
|
}
|
1725
1797
|
/**
|
@@ -1729,7 +1801,7 @@ var BaseTransactionRequest = class {
|
|
1729
1801
|
*/
|
1730
1802
|
getCoinOutputs() {
|
1731
1803
|
return this.outputs.filter(
|
1732
|
-
(output) => output.type ===
|
1804
|
+
(output) => output.type === import_transactions6.OutputType.Coin
|
1733
1805
|
);
|
1734
1806
|
}
|
1735
1807
|
/**
|
@@ -1739,7 +1811,7 @@ var BaseTransactionRequest = class {
|
|
1739
1811
|
*/
|
1740
1812
|
getChangeOutputs() {
|
1741
1813
|
return this.outputs.filter(
|
1742
|
-
(output) => output.type ===
|
1814
|
+
(output) => output.type === import_transactions6.OutputType.Change
|
1743
1815
|
);
|
1744
1816
|
}
|
1745
1817
|
/**
|
@@ -1751,9 +1823,9 @@ var BaseTransactionRequest = class {
|
|
1751
1823
|
const ownerAddress = (0, import_address.addressify)(owner);
|
1752
1824
|
const found = this.inputs.find((input) => {
|
1753
1825
|
switch (input.type) {
|
1754
|
-
case
|
1826
|
+
case import_transactions6.InputType.Coin:
|
1755
1827
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
1756
|
-
case
|
1828
|
+
case import_transactions6.InputType.Message:
|
1757
1829
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
1758
1830
|
default:
|
1759
1831
|
return false;
|
@@ -1782,7 +1854,7 @@ var BaseTransactionRequest = class {
|
|
1782
1854
|
}
|
1783
1855
|
const input = {
|
1784
1856
|
...coin,
|
1785
|
-
type:
|
1857
|
+
type: import_transactions6.InputType.Coin,
|
1786
1858
|
owner: owner.toB256(),
|
1787
1859
|
amount,
|
1788
1860
|
assetId,
|
@@ -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,
|
@@ -1886,7 +1958,7 @@ var BaseTransactionRequest = class {
|
|
1886
1958
|
*/
|
1887
1959
|
addCoinOutput(to, amount, assetId) {
|
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: assetId ?? this.baseAssetId
|
@@ -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
|
@@ -1922,7 +1994,7 @@ var BaseTransactionRequest = class {
|
|
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: assetId ?? this.baseAssetId
|
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_configs6.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(this.baseAssetId, (0,
|
2081
|
+
updateAssetInput(this.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_configs8 = 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_configs7 = 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_configs7.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_configs7.ZeroBytes32;
|
2097
2169
|
inputClone.outputIndex = 0;
|
2098
|
-
inputClone.balanceRoot =
|
2099
|
-
inputClone.stateRoot =
|
2170
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2171
|
+
inputClone.stateRoot = import_configs7.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_configs7.ZeroBytes32;
|
2183
|
+
outputClone.stateRoot = import_configs7.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_configs7.ZeroBytes32;
|
2192
|
+
outputClone.amount = (0, import_math8.bn)(0);
|
2193
|
+
outputClone.assetId = import_configs7.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_configs8.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_configs8.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_configs9 = 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_configs9.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_configs10 = 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_configs10.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,30 +3488,30 @@ 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
|
baseAssetId: consensusParameters.baseAssetId,
|
3432
3509
|
gasCosts
|
3433
3510
|
},
|
3434
3511
|
gasCosts,
|
3435
3512
|
latestBlock: {
|
3436
3513
|
id: latestBlock.id,
|
3437
|
-
height: (0,
|
3514
|
+
height: (0, import_math15.bn)(latestBlock.header.height),
|
3438
3515
|
time: latestBlock.header.time,
|
3439
3516
|
transactions: latestBlock.transactions.map((i) => ({
|
3440
3517
|
id: i.id
|
@@ -3504,8 +3581,8 @@ var _Provider = class {
|
|
3504
3581
|
getChain() {
|
3505
3582
|
const chain = _Provider.chainInfoCache[this.url];
|
3506
3583
|
if (!chain) {
|
3507
|
-
throw new
|
3508
|
-
|
3584
|
+
throw new import_errors14.FuelError(
|
3585
|
+
import_errors14.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3509
3586
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3510
3587
|
);
|
3511
3588
|
}
|
@@ -3517,8 +3594,8 @@ var _Provider = class {
|
|
3517
3594
|
getNode() {
|
3518
3595
|
const node = _Provider.nodeInfoCache[this.url];
|
3519
3596
|
if (!node) {
|
3520
|
-
throw new
|
3521
|
-
|
3597
|
+
throw new import_errors14.FuelError(
|
3598
|
+
import_errors14.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3522
3599
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3523
3600
|
);
|
3524
3601
|
}
|
@@ -3565,8 +3642,8 @@ var _Provider = class {
|
|
3565
3642
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3566
3643
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3567
3644
|
if (!isMajorSupported || !isMinorSupported) {
|
3568
|
-
throw new
|
3569
|
-
|
3645
|
+
throw new import_errors14.FuelError(
|
3646
|
+
import_errors14.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3570
3647
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3571
3648
|
);
|
3572
3649
|
}
|
@@ -3629,7 +3706,7 @@ var _Provider = class {
|
|
3629
3706
|
*/
|
3630
3707
|
async getBlockNumber() {
|
3631
3708
|
const { chain } = await this.operations.getChain();
|
3632
|
-
return (0,
|
3709
|
+
return (0, import_math15.bn)(chain.latestBlock.header.height, 10);
|
3633
3710
|
}
|
3634
3711
|
/**
|
3635
3712
|
* Returns the chain information.
|
@@ -3639,9 +3716,9 @@ var _Provider = class {
|
|
3639
3716
|
async fetchNode() {
|
3640
3717
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3641
3718
|
const processedNodeInfo = {
|
3642
|
-
maxDepth: (0,
|
3643
|
-
maxTx: (0,
|
3644
|
-
minGasPrice: (0,
|
3719
|
+
maxDepth: (0, import_math15.bn)(nodeInfo.maxDepth),
|
3720
|
+
maxTx: (0, import_math15.bn)(nodeInfo.maxTx),
|
3721
|
+
minGasPrice: (0, import_math15.bn)(nodeInfo.minGasPrice),
|
3645
3722
|
nodeVersion: nodeInfo.nodeVersion,
|
3646
3723
|
utxoValidation: nodeInfo.utxoValidation,
|
3647
3724
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3698,17 +3775,17 @@ var _Provider = class {
|
|
3698
3775
|
if (estimateTxDependencies) {
|
3699
3776
|
await this.estimateTxDependencies(transactionRequest);
|
3700
3777
|
}
|
3701
|
-
const encodedTransaction = (0,
|
3778
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3702
3779
|
let abis;
|
3703
|
-
if (transactionRequest.type ===
|
3780
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Script) {
|
3704
3781
|
abis = transactionRequest.abis;
|
3705
3782
|
}
|
3706
3783
|
if (awaitExecution) {
|
3707
3784
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
3708
3785
|
for await (const { submitAndAwait } of subscription) {
|
3709
3786
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
3710
|
-
throw new
|
3711
|
-
|
3787
|
+
throw new import_errors14.FuelError(
|
3788
|
+
import_errors14.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3712
3789
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
3713
3790
|
);
|
3714
3791
|
}
|
@@ -3741,7 +3818,7 @@ var _Provider = class {
|
|
3741
3818
|
if (estimateTxDependencies) {
|
3742
3819
|
return this.estimateTxDependencies(transactionRequest);
|
3743
3820
|
}
|
3744
|
-
const encodedTransaction = (0,
|
3821
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3745
3822
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3746
3823
|
encodedTransaction,
|
3747
3824
|
utxoValidation: utxoValidation || false
|
@@ -3760,13 +3837,13 @@ var _Provider = class {
|
|
3760
3837
|
async estimatePredicates(transactionRequest) {
|
3761
3838
|
const shouldEstimatePredicates = Boolean(
|
3762
3839
|
transactionRequest.inputs.find(
|
3763
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3840
|
+
(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()
|
3764
3841
|
)
|
3765
3842
|
);
|
3766
3843
|
if (!shouldEstimatePredicates) {
|
3767
3844
|
return transactionRequest;
|
3768
3845
|
}
|
3769
|
-
const encodedTransaction = (0,
|
3846
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3770
3847
|
const response = await this.operations.estimatePredicates({
|
3771
3848
|
encodedTransaction
|
3772
3849
|
});
|
@@ -3775,7 +3852,7 @@ var _Provider = class {
|
|
3775
3852
|
} = response;
|
3776
3853
|
if (inputs) {
|
3777
3854
|
inputs.forEach((input, index) => {
|
3778
|
-
if ("predicateGasUsed" in input && (0,
|
3855
|
+
if ("predicateGasUsed" in input && (0, import_math15.bn)(input.predicateGasUsed).gt(0)) {
|
3779
3856
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
3780
3857
|
}
|
3781
3858
|
});
|
@@ -3796,7 +3873,7 @@ var _Provider = class {
|
|
3796
3873
|
* @returns A promise.
|
3797
3874
|
*/
|
3798
3875
|
async estimateTxDependencies(transactionRequest) {
|
3799
|
-
if (transactionRequest.type ===
|
3876
|
+
if (transactionRequest.type === import_transactions18.TransactionType.Create) {
|
3800
3877
|
return {
|
3801
3878
|
receipts: [],
|
3802
3879
|
outputVariables: 0,
|
@@ -3809,7 +3886,7 @@ var _Provider = class {
|
|
3809
3886
|
let outputVariables = 0;
|
3810
3887
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
3811
3888
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3812
|
-
encodedTransaction: (0,
|
3889
|
+
encodedTransaction: (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes()),
|
3813
3890
|
utxoValidation: false
|
3814
3891
|
});
|
3815
3892
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -3847,7 +3924,7 @@ var _Provider = class {
|
|
3847
3924
|
if (estimateTxDependencies) {
|
3848
3925
|
return this.estimateTxDependencies(transactionRequest);
|
3849
3926
|
}
|
3850
|
-
const encodedTransaction = (0,
|
3927
|
+
const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
|
3851
3928
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
3852
3929
|
encodedTransaction,
|
3853
3930
|
utxoValidation: true
|
@@ -3881,14 +3958,14 @@ var _Provider = class {
|
|
3881
3958
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
3882
3959
|
const chainInfo = this.getChain();
|
3883
3960
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
3884
|
-
const gasPrice = (0,
|
3885
|
-
const isScriptTransaction = txRequestClone.type ===
|
3961
|
+
const gasPrice = (0, import_math15.max)(txRequestClone.gasPrice, minGasPrice);
|
3962
|
+
const isScriptTransaction = txRequestClone.type === import_transactions18.TransactionType.Script;
|
3886
3963
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
3887
3964
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
3888
3965
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
3889
3966
|
if (estimatePredicates) {
|
3890
3967
|
if (isScriptTransaction) {
|
3891
|
-
txRequestClone.gasLimit = (0,
|
3968
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(0);
|
3892
3969
|
}
|
3893
3970
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
3894
3971
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -3904,8 +3981,8 @@ var _Provider = class {
|
|
3904
3981
|
let missingContractIds = [];
|
3905
3982
|
let outputVariables = 0;
|
3906
3983
|
if (isScriptTransaction && estimateTxDependencies) {
|
3907
|
-
txRequestClone.gasPrice = (0,
|
3908
|
-
txRequestClone.gasLimit = (0,
|
3984
|
+
txRequestClone.gasPrice = (0, import_math15.bn)(0);
|
3985
|
+
txRequestClone.gasLimit = (0, import_math15.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
3909
3986
|
const result = await this.estimateTxDependencies(txRequestClone);
|
3910
3987
|
receipts = result.receipts;
|
3911
3988
|
outputVariables = result.outputVariables;
|
@@ -3961,17 +4038,17 @@ var _Provider = class {
|
|
3961
4038
|
const result = await this.operations.getCoins({
|
3962
4039
|
first: 10,
|
3963
4040
|
...paginationArgs,
|
3964
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4041
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
|
3965
4042
|
});
|
3966
4043
|
const coins = result.coins.edges.map((edge) => edge.node);
|
3967
4044
|
return coins.map((coin) => ({
|
3968
4045
|
id: coin.utxoId,
|
3969
4046
|
assetId: coin.assetId,
|
3970
|
-
amount: (0,
|
4047
|
+
amount: (0, import_math15.bn)(coin.amount),
|
3971
4048
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
3972
|
-
maturity: (0,
|
3973
|
-
blockCreated: (0,
|
3974
|
-
txCreatedIdx: (0,
|
4049
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4050
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4051
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
3975
4052
|
}));
|
3976
4053
|
}
|
3977
4054
|
/**
|
@@ -3985,19 +4062,19 @@ var _Provider = class {
|
|
3985
4062
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
3986
4063
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
3987
4064
|
const excludeInput = {
|
3988
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
3989
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4065
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
|
4066
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
|
3990
4067
|
};
|
3991
4068
|
if (this.cache) {
|
3992
4069
|
const uniqueUtxos = new Set(
|
3993
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4070
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
|
3994
4071
|
);
|
3995
4072
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
3996
4073
|
}
|
3997
4074
|
const coinsQuery = {
|
3998
4075
|
owner: ownerAddress.toB256(),
|
3999
4076
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4000
|
-
assetId: (0,
|
4077
|
+
assetId: (0, import_utils23.hexlify)(assetId),
|
4001
4078
|
amount: amount.toString(10),
|
4002
4079
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4003
4080
|
})),
|
@@ -4008,9 +4085,9 @@ var _Provider = class {
|
|
4008
4085
|
switch (coin.__typename) {
|
4009
4086
|
case "MessageCoin":
|
4010
4087
|
return {
|
4011
|
-
amount: (0,
|
4088
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4012
4089
|
assetId: coin.assetId,
|
4013
|
-
daHeight: (0,
|
4090
|
+
daHeight: (0, import_math15.bn)(coin.daHeight),
|
4014
4091
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4015
4092
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4016
4093
|
nonce: coin.nonce
|
@@ -4018,12 +4095,12 @@ var _Provider = class {
|
|
4018
4095
|
case "Coin":
|
4019
4096
|
return {
|
4020
4097
|
id: coin.utxoId,
|
4021
|
-
amount: (0,
|
4098
|
+
amount: (0, import_math15.bn)(coin.amount),
|
4022
4099
|
assetId: coin.assetId,
|
4023
4100
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4024
|
-
maturity: (0,
|
4025
|
-
blockCreated: (0,
|
4026
|
-
txCreatedIdx: (0,
|
4101
|
+
maturity: (0, import_math15.bn)(coin.maturity).toNumber(),
|
4102
|
+
blockCreated: (0, import_math15.bn)(coin.blockCreated),
|
4103
|
+
txCreatedIdx: (0, import_math15.bn)(coin.txCreatedIdx)
|
4027
4104
|
};
|
4028
4105
|
default:
|
4029
4106
|
return null;
|
@@ -4040,13 +4117,13 @@ var _Provider = class {
|
|
4040
4117
|
async getBlock(idOrHeight) {
|
4041
4118
|
let variables;
|
4042
4119
|
if (typeof idOrHeight === "number") {
|
4043
|
-
variables = { height: (0,
|
4120
|
+
variables = { height: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4044
4121
|
} else if (idOrHeight === "latest") {
|
4045
4122
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4046
4123
|
} else if (idOrHeight.length === 66) {
|
4047
4124
|
variables = { blockId: idOrHeight };
|
4048
4125
|
} else {
|
4049
|
-
variables = { blockId: (0,
|
4126
|
+
variables = { blockId: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4050
4127
|
}
|
4051
4128
|
const { block } = await this.operations.getBlock(variables);
|
4052
4129
|
if (!block) {
|
@@ -4054,7 +4131,7 @@ var _Provider = class {
|
|
4054
4131
|
}
|
4055
4132
|
return {
|
4056
4133
|
id: block.id,
|
4057
|
-
height: (0,
|
4134
|
+
height: (0, import_math15.bn)(block.header.height),
|
4058
4135
|
time: block.header.time,
|
4059
4136
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4060
4137
|
};
|
@@ -4069,7 +4146,7 @@ var _Provider = class {
|
|
4069
4146
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4070
4147
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4071
4148
|
id: block.id,
|
4072
|
-
height: (0,
|
4149
|
+
height: (0, import_math15.bn)(block.header.height),
|
4073
4150
|
time: block.header.time,
|
4074
4151
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4075
4152
|
}));
|
@@ -4084,7 +4161,7 @@ var _Provider = class {
|
|
4084
4161
|
async getBlockWithTransactions(idOrHeight) {
|
4085
4162
|
let variables;
|
4086
4163
|
if (typeof idOrHeight === "number") {
|
4087
|
-
variables = { blockHeight: (0,
|
4164
|
+
variables = { blockHeight: (0, import_math15.bn)(idOrHeight).toString(10) };
|
4088
4165
|
} else if (idOrHeight === "latest") {
|
4089
4166
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4090
4167
|
} else {
|
@@ -4096,11 +4173,11 @@ var _Provider = class {
|
|
4096
4173
|
}
|
4097
4174
|
return {
|
4098
4175
|
id: block.id,
|
4099
|
-
height: (0,
|
4176
|
+
height: (0, import_math15.bn)(block.header.height, 10),
|
4100
4177
|
time: block.header.time,
|
4101
4178
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4102
4179
|
transactions: block.transactions.map(
|
4103
|
-
(tx) => new
|
4180
|
+
(tx) => new import_transactions18.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
|
4104
4181
|
)
|
4105
4182
|
};
|
4106
4183
|
}
|
@@ -4115,8 +4192,8 @@ var _Provider = class {
|
|
4115
4192
|
if (!transaction) {
|
4116
4193
|
return null;
|
4117
4194
|
}
|
4118
|
-
return new
|
4119
|
-
(0,
|
4195
|
+
return new import_transactions18.TransactionCoder().decode(
|
4196
|
+
(0, import_utils23.arrayify)(transaction.rawPayload),
|
4120
4197
|
0
|
4121
4198
|
)?.[0];
|
4122
4199
|
}
|
@@ -4143,9 +4220,9 @@ var _Provider = class {
|
|
4143
4220
|
async getContractBalance(contractId, assetId) {
|
4144
4221
|
const { contractBalance } = await this.operations.getContractBalance({
|
4145
4222
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4146
|
-
asset: (0,
|
4223
|
+
asset: (0, import_utils23.hexlify)(assetId)
|
4147
4224
|
});
|
4148
|
-
return (0,
|
4225
|
+
return (0, import_math15.bn)(contractBalance.amount, 10);
|
4149
4226
|
}
|
4150
4227
|
/**
|
4151
4228
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4157,9 +4234,9 @@ var _Provider = class {
|
|
4157
4234
|
async getBalance(owner, assetId) {
|
4158
4235
|
const { balance } = await this.operations.getBalance({
|
4159
4236
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4160
|
-
assetId: (0,
|
4237
|
+
assetId: (0, import_utils23.hexlify)(assetId)
|
4161
4238
|
});
|
4162
|
-
return (0,
|
4239
|
+
return (0, import_math15.bn)(balance.amount, 10);
|
4163
4240
|
}
|
4164
4241
|
/**
|
4165
4242
|
* Returns balances for the given owner.
|
@@ -4177,7 +4254,7 @@ var _Provider = class {
|
|
4177
4254
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4178
4255
|
return balances.map((balance) => ({
|
4179
4256
|
assetId: balance.assetId,
|
4180
|
-
amount: (0,
|
4257
|
+
amount: (0, import_math15.bn)(balance.amount)
|
4181
4258
|
}));
|
4182
4259
|
}
|
4183
4260
|
/**
|
@@ -4195,19 +4272,19 @@ var _Provider = class {
|
|
4195
4272
|
});
|
4196
4273
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4197
4274
|
return messages.map((message) => ({
|
4198
|
-
messageId:
|
4275
|
+
messageId: import_transactions18.InputMessageCoder.getMessageId({
|
4199
4276
|
sender: message.sender,
|
4200
4277
|
recipient: message.recipient,
|
4201
4278
|
nonce: message.nonce,
|
4202
|
-
amount: (0,
|
4279
|
+
amount: (0, import_math15.bn)(message.amount),
|
4203
4280
|
data: message.data
|
4204
4281
|
}),
|
4205
4282
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4206
4283
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4207
4284
|
nonce: message.nonce,
|
4208
|
-
amount: (0,
|
4209
|
-
data:
|
4210
|
-
daHeight: (0,
|
4285
|
+
amount: (0, import_math15.bn)(message.amount),
|
4286
|
+
data: import_transactions18.InputMessageCoder.decodeData(message.data),
|
4287
|
+
daHeight: (0, import_math15.bn)(message.daHeight)
|
4211
4288
|
}));
|
4212
4289
|
}
|
4213
4290
|
/**
|
@@ -4225,8 +4302,8 @@ var _Provider = class {
|
|
4225
4302
|
nonce
|
4226
4303
|
};
|
4227
4304
|
if (commitBlockId && commitBlockHeight) {
|
4228
|
-
throw new
|
4229
|
-
|
4305
|
+
throw new import_errors14.FuelError(
|
4306
|
+
import_errors14.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4230
4307
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4231
4308
|
);
|
4232
4309
|
}
|
@@ -4260,41 +4337,41 @@ var _Provider = class {
|
|
4260
4337
|
} = result.messageProof;
|
4261
4338
|
return {
|
4262
4339
|
messageProof: {
|
4263
|
-
proofIndex: (0,
|
4340
|
+
proofIndex: (0, import_math15.bn)(messageProof.proofIndex),
|
4264
4341
|
proofSet: messageProof.proofSet
|
4265
4342
|
},
|
4266
4343
|
blockProof: {
|
4267
|
-
proofIndex: (0,
|
4344
|
+
proofIndex: (0, import_math15.bn)(blockProof.proofIndex),
|
4268
4345
|
proofSet: blockProof.proofSet
|
4269
4346
|
},
|
4270
4347
|
messageBlockHeader: {
|
4271
4348
|
id: messageBlockHeader.id,
|
4272
|
-
daHeight: (0,
|
4273
|
-
transactionsCount: (0,
|
4349
|
+
daHeight: (0, import_math15.bn)(messageBlockHeader.daHeight),
|
4350
|
+
transactionsCount: (0, import_math15.bn)(messageBlockHeader.transactionsCount),
|
4274
4351
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4275
|
-
height: (0,
|
4352
|
+
height: (0, import_math15.bn)(messageBlockHeader.height),
|
4276
4353
|
prevRoot: messageBlockHeader.prevRoot,
|
4277
4354
|
time: messageBlockHeader.time,
|
4278
4355
|
applicationHash: messageBlockHeader.applicationHash,
|
4279
4356
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4280
|
-
messageReceiptCount: (0,
|
4357
|
+
messageReceiptCount: (0, import_math15.bn)(messageBlockHeader.messageReceiptCount)
|
4281
4358
|
},
|
4282
4359
|
commitBlockHeader: {
|
4283
4360
|
id: commitBlockHeader.id,
|
4284
|
-
daHeight: (0,
|
4285
|
-
transactionsCount: (0,
|
4361
|
+
daHeight: (0, import_math15.bn)(commitBlockHeader.daHeight),
|
4362
|
+
transactionsCount: (0, import_math15.bn)(commitBlockHeader.transactionsCount),
|
4286
4363
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4287
|
-
height: (0,
|
4364
|
+
height: (0, import_math15.bn)(commitBlockHeader.height),
|
4288
4365
|
prevRoot: commitBlockHeader.prevRoot,
|
4289
4366
|
time: commitBlockHeader.time,
|
4290
4367
|
applicationHash: commitBlockHeader.applicationHash,
|
4291
4368
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4292
|
-
messageReceiptCount: (0,
|
4369
|
+
messageReceiptCount: (0, import_math15.bn)(commitBlockHeader.messageReceiptCount)
|
4293
4370
|
},
|
4294
4371
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4295
4372
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4296
4373
|
nonce,
|
4297
|
-
amount: (0,
|
4374
|
+
amount: (0, import_math15.bn)(amount),
|
4298
4375
|
data
|
4299
4376
|
};
|
4300
4377
|
}
|
@@ -4317,10 +4394,10 @@ var _Provider = class {
|
|
4317
4394
|
*/
|
4318
4395
|
async produceBlocks(amount, startTime) {
|
4319
4396
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4320
|
-
blocksToProduce: (0,
|
4321
|
-
startTimestamp: startTime ?
|
4397
|
+
blocksToProduce: (0, import_math15.bn)(amount).toString(10),
|
4398
|
+
startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4322
4399
|
});
|
4323
|
-
return (0,
|
4400
|
+
return (0, import_math15.bn)(latestBlockHeight);
|
4324
4401
|
}
|
4325
4402
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4326
4403
|
async getTransactionResponse(transactionId) {
|
@@ -4334,7 +4411,7 @@ cacheInputs_fn = function(inputs) {
|
|
4334
4411
|
return;
|
4335
4412
|
}
|
4336
4413
|
inputs.forEach((input) => {
|
4337
|
-
if (input.type ===
|
4414
|
+
if (input.type === import_transactions18.InputType.Coin) {
|
4338
4415
|
this.cache?.set(input.id);
|
4339
4416
|
}
|
4340
4417
|
});
|
@@ -4343,10 +4420,10 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4343
4420
|
__publicField(Provider, "nodeInfoCache", {});
|
4344
4421
|
|
4345
4422
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4346
|
-
var
|
4347
|
-
var
|
4348
|
-
var
|
4349
|
-
var
|
4423
|
+
var import_errors15 = require("@fuel-ts/errors");
|
4424
|
+
var import_math16 = require("@fuel-ts/math");
|
4425
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
4426
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4350
4427
|
|
4351
4428
|
// src/providers/chains.ts
|
4352
4429
|
var CHAIN_IDS = {
|
@@ -4395,17 +4472,17 @@ var assets = [
|
|
4395
4472
|
|
4396
4473
|
// src/utils/formatTransferToContractScriptData.ts
|
4397
4474
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4398
|
-
var
|
4399
|
-
var
|
4475
|
+
var import_math17 = require("@fuel-ts/math");
|
4476
|
+
var import_utils27 = require("@fuel-ts/utils");
|
4400
4477
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4401
4478
|
var formatTransferToContractScriptData = (params) => {
|
4402
4479
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4403
4480
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4404
|
-
const encoded = numberCoder.encode(new
|
4481
|
+
const encoded = numberCoder.encode(new import_math17.BN(amountToTransfer).toNumber());
|
4405
4482
|
const scriptData = Uint8Array.from([
|
4406
|
-
...(0,
|
4483
|
+
...(0, import_utils27.arrayify)(hexlifiedContractId),
|
4407
4484
|
...encoded,
|
4408
|
-
...(0,
|
4485
|
+
...(0, import_utils27.arrayify)(assetId)
|
4409
4486
|
]);
|
4410
4487
|
return scriptData;
|
4411
4488
|
};
|
@@ -4461,7 +4538,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4461
4538
|
*/
|
4462
4539
|
get provider() {
|
4463
4540
|
if (!this._provider) {
|
4464
|
-
throw new
|
4541
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4465
4542
|
}
|
4466
4543
|
return this._provider;
|
4467
4544
|
}
|
@@ -4513,8 +4590,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4513
4590
|
if (!hasNextPage) {
|
4514
4591
|
break;
|
4515
4592
|
}
|
4516
|
-
throw new
|
4517
|
-
|
4593
|
+
throw new import_errors16.FuelError(
|
4594
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4518
4595
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4519
4596
|
);
|
4520
4597
|
}
|
@@ -4539,8 +4616,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4539
4616
|
if (!hasNextPage) {
|
4540
4617
|
break;
|
4541
4618
|
}
|
4542
|
-
throw new
|
4543
|
-
|
4619
|
+
throw new import_errors16.FuelError(
|
4620
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4544
4621
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
4545
4622
|
);
|
4546
4623
|
}
|
@@ -4576,8 +4653,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4576
4653
|
if (!hasNextPage) {
|
4577
4654
|
break;
|
4578
4655
|
}
|
4579
|
-
throw new
|
4580
|
-
|
4656
|
+
throw new import_errors16.FuelError(
|
4657
|
+
import_errors16.ErrorCode.NOT_SUPPORTED,
|
4581
4658
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
4582
4659
|
);
|
4583
4660
|
}
|
@@ -4594,7 +4671,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4594
4671
|
async fund(request, coinQuantities, fee) {
|
4595
4672
|
const baseAssetId = this.provider.getBaseAssetId();
|
4596
4673
|
const updatedQuantities = addAmountToAsset({
|
4597
|
-
amount: (0,
|
4674
|
+
amount: (0, import_math18.bn)(fee),
|
4598
4675
|
assetId: baseAssetId,
|
4599
4676
|
coinQuantities
|
4600
4677
|
});
|
@@ -4602,7 +4679,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4602
4679
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
4603
4680
|
quantitiesDict[assetId] = {
|
4604
4681
|
required: amount,
|
4605
|
-
owned: (0,
|
4682
|
+
owned: (0, import_math18.bn)(0)
|
4606
4683
|
};
|
4607
4684
|
});
|
4608
4685
|
const cachedUtxos = [];
|
@@ -4615,7 +4692,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4615
4692
|
if (isCoin2) {
|
4616
4693
|
const assetId = String(input.assetId);
|
4617
4694
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
4618
|
-
const amount = (0,
|
4695
|
+
const amount = (0, import_math18.bn)(input.amount);
|
4619
4696
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
4620
4697
|
cachedUtxos.push(input.id);
|
4621
4698
|
}
|
@@ -4662,8 +4739,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4662
4739
|
estimateTxDependencies: true,
|
4663
4740
|
resourcesOwner: this
|
4664
4741
|
});
|
4665
|
-
request.gasPrice = (0,
|
4666
|
-
request.gasLimit = (0,
|
4742
|
+
request.gasPrice = (0, import_math18.bn)(txParams.gasPrice ?? minGasPrice);
|
4743
|
+
request.gasLimit = (0, import_math18.bn)(txParams.gasLimit ?? gasUsed);
|
4667
4744
|
this.validateGas({
|
4668
4745
|
gasUsed,
|
4669
4746
|
gasPrice: request.gasPrice,
|
@@ -4684,9 +4761,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4684
4761
|
* @returns A promise that resolves to the transaction response.
|
4685
4762
|
*/
|
4686
4763
|
async transfer(destination, amount, assetId, txParams = {}) {
|
4687
|
-
if ((0,
|
4688
|
-
throw new
|
4689
|
-
|
4764
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4765
|
+
throw new import_errors16.FuelError(
|
4766
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4690
4767
|
"Transfer amount must be a positive number."
|
4691
4768
|
);
|
4692
4769
|
}
|
@@ -4704,9 +4781,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4704
4781
|
* @returns A promise that resolves to the transaction response.
|
4705
4782
|
*/
|
4706
4783
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
4707
|
-
if ((0,
|
4708
|
-
throw new
|
4709
|
-
|
4784
|
+
if ((0, import_math18.bn)(amount).lte(0)) {
|
4785
|
+
throw new import_errors16.FuelError(
|
4786
|
+
import_errors16.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
4710
4787
|
"Transfer amount must be a positive number."
|
4711
4788
|
);
|
4712
4789
|
}
|
@@ -4716,7 +4793,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4716
4793
|
const params = { gasPrice: minGasPrice, ...txParams };
|
4717
4794
|
const { script, scriptData } = await assembleTransferToContractScript({
|
4718
4795
|
hexlifiedContractId: contractAddress.toB256(),
|
4719
|
-
amountToTransfer: (0,
|
4796
|
+
amountToTransfer: (0, import_math18.bn)(amount),
|
4720
4797
|
assetId: assetIdToTransfer
|
4721
4798
|
});
|
4722
4799
|
const request = new ScriptTransactionRequest({
|
@@ -4727,9 +4804,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4727
4804
|
request.addContractInputAndOutput(contractAddress);
|
4728
4805
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
4729
4806
|
request,
|
4730
|
-
[{ amount: (0,
|
4807
|
+
[{ amount: (0, import_math18.bn)(amount), assetId: String(assetIdToTransfer) }]
|
4731
4808
|
);
|
4732
|
-
request.gasLimit = (0,
|
4809
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4733
4810
|
this.validateGas({
|
4734
4811
|
gasUsed,
|
4735
4812
|
gasPrice: request.gasPrice,
|
@@ -4751,25 +4828,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4751
4828
|
const { minGasPrice } = this.provider.getGasConfig();
|
4752
4829
|
const baseAssetId = this.provider.getBaseAssetId();
|
4753
4830
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
4754
|
-
const recipientDataArray = (0,
|
4831
|
+
const recipientDataArray = (0, import_utils28.arrayify)(
|
4755
4832
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
4756
4833
|
);
|
4757
|
-
const amountDataArray = (0,
|
4758
|
-
"0x".concat((0,
|
4834
|
+
const amountDataArray = (0, import_utils28.arrayify)(
|
4835
|
+
"0x".concat((0, import_math18.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
4759
4836
|
);
|
4760
4837
|
const script = new Uint8Array([
|
4761
|
-
...(0,
|
4838
|
+
...(0, import_utils28.arrayify)(withdrawScript.bytes),
|
4762
4839
|
...recipientDataArray,
|
4763
4840
|
...amountDataArray
|
4764
4841
|
]);
|
4765
4842
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
4766
4843
|
const request = new ScriptTransactionRequest(params);
|
4767
|
-
const forwardingQuantities = [{ amount: (0,
|
4844
|
+
const forwardingQuantities = [{ amount: (0, import_math18.bn)(amount), assetId: baseAssetId }];
|
4768
4845
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
4769
4846
|
request,
|
4770
4847
|
forwardingQuantities
|
4771
4848
|
);
|
4772
|
-
request.gasLimit = (0,
|
4849
|
+
request.gasLimit = (0, import_math18.bn)(params.gasLimit ?? gasUsed);
|
4773
4850
|
this.validateGas({
|
4774
4851
|
gasUsed,
|
4775
4852
|
gasPrice: request.gasPrice,
|
@@ -4781,7 +4858,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4781
4858
|
}
|
4782
4859
|
async signMessage(message) {
|
4783
4860
|
if (!this._connector) {
|
4784
|
-
throw new
|
4861
|
+
throw new import_errors16.FuelError(import_errors16.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
4785
4862
|
}
|
4786
4863
|
return this._connector.signMessage(this.address.toString(), message);
|
4787
4864
|
}
|
@@ -4793,8 +4870,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4793
4870
|
*/
|
4794
4871
|
async signTransaction(transactionRequestLike) {
|
4795
4872
|
if (!this._connector) {
|
4796
|
-
throw new
|
4797
|
-
|
4873
|
+
throw new import_errors16.FuelError(
|
4874
|
+
import_errors16.ErrorCode.MISSING_CONNECTOR,
|
4798
4875
|
"A connector is required to sign transactions."
|
4799
4876
|
);
|
4800
4877
|
}
|
@@ -4841,14 +4918,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4841
4918
|
minGasPrice
|
4842
4919
|
}) {
|
4843
4920
|
if (minGasPrice.gt(gasPrice)) {
|
4844
|
-
throw new
|
4845
|
-
|
4921
|
+
throw new import_errors16.FuelError(
|
4922
|
+
import_errors16.ErrorCode.GAS_PRICE_TOO_LOW,
|
4846
4923
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
4847
4924
|
);
|
4848
4925
|
}
|
4849
4926
|
if (gasUsed.gt(gasLimit)) {
|
4850
|
-
throw new
|
4851
|
-
|
4927
|
+
throw new import_errors16.FuelError(
|
4928
|
+
import_errors16.ErrorCode.GAS_LIMIT_TOO_LOW,
|
4852
4929
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
4853
4930
|
);
|
4854
4931
|
}
|
@@ -4859,8 +4936,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4859
4936
|
var import_address5 = require("@fuel-ts/address");
|
4860
4937
|
var import_crypto = require("@fuel-ts/crypto");
|
4861
4938
|
var import_hasher2 = require("@fuel-ts/hasher");
|
4862
|
-
var
|
4863
|
-
var
|
4939
|
+
var import_math19 = require("@fuel-ts/math");
|
4940
|
+
var import_utils29 = require("@fuel-ts/utils");
|
4864
4941
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
4865
4942
|
var Signer = class {
|
4866
4943
|
address;
|
@@ -4879,10 +4956,10 @@ var Signer = class {
|
|
4879
4956
|
privateKey = `0x${privateKey}`;
|
4880
4957
|
}
|
4881
4958
|
}
|
4882
|
-
const privateKeyBytes = (0,
|
4883
|
-
this.privateKey = (0,
|
4884
|
-
this.publicKey = (0,
|
4885
|
-
this.compressedPublicKey = (0,
|
4959
|
+
const privateKeyBytes = (0, import_math19.toBytes)(privateKey, 32);
|
4960
|
+
this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
|
4961
|
+
this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
4962
|
+
this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
4886
4963
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
4887
4964
|
}
|
4888
4965
|
/**
|
@@ -4896,11 +4973,11 @@ var Signer = class {
|
|
4896
4973
|
* @returns hashed signature
|
4897
4974
|
*/
|
4898
4975
|
sign(data) {
|
4899
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
4900
|
-
const r = (0,
|
4901
|
-
const s = (0,
|
4976
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
|
4977
|
+
const r = (0, import_math19.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
4978
|
+
const s = (0, import_math19.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
4902
4979
|
s[0] |= (signature.recovery || 0) << 7;
|
4903
|
-
return (0,
|
4980
|
+
return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
|
4904
4981
|
}
|
4905
4982
|
/**
|
4906
4983
|
* Add point on the current elliptic curve
|
@@ -4909,8 +4986,8 @@ var Signer = class {
|
|
4909
4986
|
* @returns compressed point on the curve
|
4910
4987
|
*/
|
4911
4988
|
addPoint(point) {
|
4912
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4913
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4989
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
|
4990
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
|
4914
4991
|
const result = p0.add(p1);
|
4915
4992
|
return `0x${result.toHex(true)}`;
|
4916
4993
|
}
|
@@ -4922,16 +4999,16 @@ var Signer = class {
|
|
4922
4999
|
* @returns public key from signature from the
|
4923
5000
|
*/
|
4924
5001
|
static recoverPublicKey(data, signature) {
|
4925
|
-
const signedMessageBytes = (0,
|
5002
|
+
const signedMessageBytes = (0, import_utils29.arrayify)(signature);
|
4926
5003
|
const r = signedMessageBytes.slice(0, 32);
|
4927
5004
|
const s = signedMessageBytes.slice(32, 64);
|
4928
5005
|
const recoveryParam = (s[0] & 128) >> 7;
|
4929
5006
|
s[0] &= 127;
|
4930
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5007
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
|
4931
5008
|
recoveryParam
|
4932
5009
|
);
|
4933
|
-
const publicKey = sig.recoverPublicKey((0,
|
4934
|
-
return (0,
|
5010
|
+
const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
|
5011
|
+
return (0, import_utils29.hexlify)(publicKey);
|
4935
5012
|
}
|
4936
5013
|
/**
|
4937
5014
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -4950,7 +5027,7 @@ var Signer = class {
|
|
4950
5027
|
* @returns random 32-byte hashed
|
4951
5028
|
*/
|
4952
5029
|
static generatePrivateKey(entropy) {
|
4953
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5030
|
+
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);
|
4954
5031
|
}
|
4955
5032
|
/**
|
4956
5033
|
* Extended publicKey from a compact publicKey
|
@@ -4959,16 +5036,16 @@ var Signer = class {
|
|
4959
5036
|
* @returns extended publicKey
|
4960
5037
|
*/
|
4961
5038
|
static extendPublicKey(publicKey) {
|
4962
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
4963
|
-
return (0,
|
5039
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
|
5040
|
+
return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
|
4964
5041
|
}
|
4965
5042
|
};
|
4966
5043
|
|
4967
5044
|
// src/wallet/keystore-wallet.ts
|
4968
5045
|
var import_address6 = require("@fuel-ts/address");
|
4969
5046
|
var import_crypto2 = require("@fuel-ts/crypto");
|
4970
|
-
var
|
4971
|
-
var
|
5047
|
+
var import_errors17 = require("@fuel-ts/errors");
|
5048
|
+
var import_utils30 = require("@fuel-ts/utils");
|
4972
5049
|
var import_uuid = require("uuid");
|
4973
5050
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
4974
5051
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5045,13 +5122,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5045
5122
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5046
5123
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5047
5124
|
if (mac !== macHash) {
|
5048
|
-
throw new
|
5049
|
-
|
5125
|
+
throw new import_errors17.FuelError(
|
5126
|
+
import_errors17.ErrorCode.INVALID_PASSWORD,
|
5050
5127
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5051
5128
|
);
|
5052
5129
|
}
|
5053
5130
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5054
|
-
const privateKey = (0,
|
5131
|
+
const privateKey = (0, import_utils30.hexlify)(buffer);
|
5055
5132
|
return privateKey;
|
5056
5133
|
}
|
5057
5134
|
|
@@ -5096,7 +5173,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5096
5173
|
*/
|
5097
5174
|
async signMessage(message) {
|
5098
5175
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5099
|
-
return (0,
|
5176
|
+
return (0, import_utils31.hexlify)(signedMessage);
|
5100
5177
|
}
|
5101
5178
|
/**
|
5102
5179
|
* Signs a transaction with the wallet's private key.
|
@@ -5109,7 +5186,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5109
5186
|
const chainId = this.provider.getChainId();
|
5110
5187
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5111
5188
|
const signature = await this.signer().sign(hashedTransaction);
|
5112
|
-
return (0,
|
5189
|
+
return (0, import_utils31.hexlify)(signature);
|
5113
5190
|
}
|
5114
5191
|
/**
|
5115
5192
|
* Populates a transaction with the witnesses signature.
|
@@ -5168,17 +5245,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5168
5245
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5169
5246
|
|
5170
5247
|
// src/hdwallet/hdwallet.ts
|
5171
|
-
var
|
5248
|
+
var import_errors20 = require("@fuel-ts/errors");
|
5172
5249
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5173
|
-
var
|
5174
|
-
var
|
5250
|
+
var import_math20 = require("@fuel-ts/math");
|
5251
|
+
var import_utils35 = require("@fuel-ts/utils");
|
5175
5252
|
var import_ethers3 = require("ethers");
|
5176
5253
|
|
5177
5254
|
// src/mnemonic/mnemonic.ts
|
5178
5255
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5179
|
-
var
|
5256
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5180
5257
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5181
|
-
var
|
5258
|
+
var import_utils33 = require("@fuel-ts/utils");
|
5182
5259
|
var import_ethers2 = require("ethers");
|
5183
5260
|
|
5184
5261
|
// src/wordlists/words/english.ts
|
@@ -7234,9 +7311,9 @@ var english = [
|
|
7234
7311
|
];
|
7235
7312
|
|
7236
7313
|
// src/mnemonic/utils.ts
|
7237
|
-
var
|
7314
|
+
var import_errors18 = require("@fuel-ts/errors");
|
7238
7315
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7239
|
-
var
|
7316
|
+
var import_utils32 = require("@fuel-ts/utils");
|
7240
7317
|
function toUtf8Bytes(stri) {
|
7241
7318
|
const str = stri.normalize("NFKD");
|
7242
7319
|
const result = [];
|
@@ -7251,8 +7328,8 @@ function toUtf8Bytes(stri) {
|
|
7251
7328
|
i += 1;
|
7252
7329
|
const c2 = str.charCodeAt(i);
|
7253
7330
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7254
|
-
throw new
|
7255
|
-
|
7331
|
+
throw new import_errors18.FuelError(
|
7332
|
+
import_errors18.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7256
7333
|
"Invalid UTF-8 in the input string."
|
7257
7334
|
);
|
7258
7335
|
}
|
@@ -7303,20 +7380,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7303
7380
|
}
|
7304
7381
|
}
|
7305
7382
|
const checksumBits = entropy.length / 4;
|
7306
|
-
const checksum = (0,
|
7383
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7307
7384
|
indices[indices.length - 1] <<= checksumBits;
|
7308
7385
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7309
7386
|
return indices;
|
7310
7387
|
}
|
7311
7388
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7312
7389
|
const size = Math.ceil(11 * words.length / 8);
|
7313
|
-
const entropy = (0,
|
7390
|
+
const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
|
7314
7391
|
let offset = 0;
|
7315
7392
|
for (let i = 0; i < words.length; i += 1) {
|
7316
7393
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7317
7394
|
if (index === -1) {
|
7318
|
-
throw new
|
7319
|
-
|
7395
|
+
throw new import_errors18.FuelError(
|
7396
|
+
import_errors18.ErrorCode.INVALID_MNEMONIC,
|
7320
7397
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7321
7398
|
);
|
7322
7399
|
}
|
@@ -7330,10 +7407,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7330
7407
|
const entropyBits = 32 * words.length / 3;
|
7331
7408
|
const checksumBits = words.length / 3;
|
7332
7409
|
const checksumMask = getUpperMask(checksumBits);
|
7333
|
-
const checksum = (0,
|
7410
|
+
const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7334
7411
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7335
|
-
throw new
|
7336
|
-
|
7412
|
+
throw new import_errors18.FuelError(
|
7413
|
+
import_errors18.ErrorCode.INVALID_CHECKSUM,
|
7337
7414
|
"Checksum validation failed for the provided mnemonic."
|
7338
7415
|
);
|
7339
7416
|
}
|
@@ -7347,16 +7424,16 @@ var TestnetPRV = "0x04358394";
|
|
7347
7424
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7348
7425
|
function assertWordList(wordlist) {
|
7349
7426
|
if (wordlist.length !== 2048) {
|
7350
|
-
throw new
|
7351
|
-
|
7427
|
+
throw new import_errors19.FuelError(
|
7428
|
+
import_errors19.ErrorCode.INVALID_WORD_LIST,
|
7352
7429
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7353
7430
|
);
|
7354
7431
|
}
|
7355
7432
|
}
|
7356
7433
|
function assertEntropy(entropy) {
|
7357
7434
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7358
|
-
throw new
|
7359
|
-
|
7435
|
+
throw new import_errors19.FuelError(
|
7436
|
+
import_errors19.ErrorCode.INVALID_ENTROPY,
|
7360
7437
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7361
7438
|
);
|
7362
7439
|
}
|
@@ -7366,7 +7443,7 @@ function assertMnemonic(words) {
|
|
7366
7443
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7367
7444
|
", "
|
7368
7445
|
)}] words, but got ${words.length}.`;
|
7369
|
-
throw new
|
7446
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7370
7447
|
}
|
7371
7448
|
}
|
7372
7449
|
var Mnemonic = class {
|
@@ -7405,7 +7482,7 @@ var Mnemonic = class {
|
|
7405
7482
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7406
7483
|
const words = getWords(phrase);
|
7407
7484
|
assertMnemonic(words);
|
7408
|
-
return (0,
|
7485
|
+
return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7409
7486
|
}
|
7410
7487
|
/**
|
7411
7488
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7413,7 +7490,7 @@ var Mnemonic = class {
|
|
7413
7490
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7414
7491
|
*/
|
7415
7492
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7416
|
-
const entropyBytes = (0,
|
7493
|
+
const entropyBytes = (0, import_utils33.arrayify)(entropy);
|
7417
7494
|
assertWordList(wordlist);
|
7418
7495
|
assertEntropy(entropyBytes);
|
7419
7496
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7482,14 +7559,14 @@ var Mnemonic = class {
|
|
7482
7559
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7483
7560
|
*/
|
7484
7561
|
static masterKeysFromSeed(seed) {
|
7485
|
-
const seedArray = (0,
|
7562
|
+
const seedArray = (0, import_utils33.arrayify)(seed);
|
7486
7563
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7487
|
-
throw new
|
7488
|
-
|
7564
|
+
throw new import_errors19.FuelError(
|
7565
|
+
import_errors19.ErrorCode.INVALID_SEED,
|
7489
7566
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7490
7567
|
);
|
7491
7568
|
}
|
7492
|
-
return (0,
|
7569
|
+
return (0, import_utils33.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7493
7570
|
}
|
7494
7571
|
/**
|
7495
7572
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7500,22 +7577,22 @@ var Mnemonic = class {
|
|
7500
7577
|
*/
|
7501
7578
|
static seedToExtendedKey(seed, testnet = false) {
|
7502
7579
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7503
|
-
const prefix = (0,
|
7580
|
+
const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7504
7581
|
const depth = "0x00";
|
7505
7582
|
const fingerprint = "0x00000000";
|
7506
7583
|
const index = "0x00000000";
|
7507
7584
|
const chainCode = masterKey.slice(32);
|
7508
7585
|
const privateKey = masterKey.slice(0, 32);
|
7509
|
-
const extendedKey = (0,
|
7586
|
+
const extendedKey = (0, import_utils33.concat)([
|
7510
7587
|
prefix,
|
7511
7588
|
depth,
|
7512
7589
|
fingerprint,
|
7513
7590
|
index,
|
7514
7591
|
chainCode,
|
7515
|
-
(0,
|
7592
|
+
(0, import_utils33.concat)(["0x00", privateKey])
|
7516
7593
|
]);
|
7517
7594
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7518
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7595
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
|
7519
7596
|
}
|
7520
7597
|
/**
|
7521
7598
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7530,7 +7607,7 @@ var Mnemonic = class {
|
|
7530
7607
|
* @returns A randomly generated mnemonic
|
7531
7608
|
*/
|
7532
7609
|
static generate(size = 32, extraEntropy = "") {
|
7533
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7610
|
+
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);
|
7534
7611
|
return Mnemonic.entropyToMnemonic(entropy);
|
7535
7612
|
}
|
7536
7613
|
};
|
@@ -7538,12 +7615,12 @@ var mnemonic_default = Mnemonic;
|
|
7538
7615
|
|
7539
7616
|
// src/hdwallet/hdwallet.ts
|
7540
7617
|
var HARDENED_INDEX = 2147483648;
|
7541
|
-
var MainnetPRV2 = (0,
|
7542
|
-
var MainnetPUB = (0,
|
7543
|
-
var TestnetPRV2 = (0,
|
7544
|
-
var TestnetPUB = (0,
|
7618
|
+
var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
|
7619
|
+
var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
|
7620
|
+
var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
|
7621
|
+
var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
|
7545
7622
|
function base58check(data) {
|
7546
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7623
|
+
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)]));
|
7547
7624
|
}
|
7548
7625
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
7549
7626
|
if (isPublic) {
|
@@ -7552,17 +7629,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
7552
7629
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
7553
7630
|
}
|
7554
7631
|
function isPublicExtendedKey(extendedKey) {
|
7555
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7632
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
|
7556
7633
|
}
|
7557
7634
|
function isValidExtendedKey(extendedKey) {
|
7558
7635
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
7559
|
-
(0,
|
7636
|
+
(0, import_utils35.hexlify)(extendedKey.slice(0, 4))
|
7560
7637
|
);
|
7561
7638
|
}
|
7562
7639
|
function parsePath(path2, depth = 0) {
|
7563
7640
|
const components = path2.split("/");
|
7564
7641
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
7565
|
-
throw new
|
7642
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
7566
7643
|
}
|
7567
7644
|
if (components[0] === "m") {
|
7568
7645
|
components.shift();
|
@@ -7574,8 +7651,8 @@ function parsePath(path2, depth = 0) {
|
|
7574
7651
|
var HDWallet = class {
|
7575
7652
|
depth = 0;
|
7576
7653
|
index = 0;
|
7577
|
-
fingerprint = (0,
|
7578
|
-
parentFingerprint = (0,
|
7654
|
+
fingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7655
|
+
parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
|
7579
7656
|
privateKey;
|
7580
7657
|
publicKey;
|
7581
7658
|
chainCode;
|
@@ -7587,16 +7664,16 @@ var HDWallet = class {
|
|
7587
7664
|
constructor(config) {
|
7588
7665
|
if (config.privateKey) {
|
7589
7666
|
const signer = new Signer(config.privateKey);
|
7590
|
-
this.publicKey = (0,
|
7591
|
-
this.privateKey = (0,
|
7667
|
+
this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
|
7668
|
+
this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
|
7592
7669
|
} else {
|
7593
7670
|
if (!config.publicKey) {
|
7594
|
-
throw new
|
7595
|
-
|
7671
|
+
throw new import_errors20.FuelError(
|
7672
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7596
7673
|
"Both public and private Key cannot be missing. At least one should be provided."
|
7597
7674
|
);
|
7598
7675
|
}
|
7599
|
-
this.publicKey = (0,
|
7676
|
+
this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
|
7600
7677
|
}
|
7601
7678
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
7602
7679
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -7615,28 +7692,28 @@ var HDWallet = class {
|
|
7615
7692
|
* @returns A new instance of HDWallet on the derived index
|
7616
7693
|
*/
|
7617
7694
|
deriveIndex(index) {
|
7618
|
-
const privateKey = this.privateKey && (0,
|
7619
|
-
const publicKey = (0,
|
7620
|
-
const chainCode = (0,
|
7695
|
+
const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
|
7696
|
+
const publicKey = (0, import_utils35.arrayify)(this.publicKey);
|
7697
|
+
const chainCode = (0, import_utils35.arrayify)(this.chainCode);
|
7621
7698
|
const data = new Uint8Array(37);
|
7622
7699
|
if (index & HARDENED_INDEX) {
|
7623
7700
|
if (!privateKey) {
|
7624
|
-
throw new
|
7625
|
-
|
7701
|
+
throw new import_errors20.FuelError(
|
7702
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7626
7703
|
"Cannot derive a hardened index without a private Key."
|
7627
7704
|
);
|
7628
7705
|
}
|
7629
7706
|
data.set(privateKey, 1);
|
7630
7707
|
} else {
|
7631
|
-
data.set((0,
|
7708
|
+
data.set((0, import_utils35.arrayify)(this.publicKey));
|
7632
7709
|
}
|
7633
|
-
data.set((0,
|
7634
|
-
const bytes = (0,
|
7710
|
+
data.set((0, import_math20.toBytes)(index, 4), 33);
|
7711
|
+
const bytes = (0, import_utils35.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
7635
7712
|
const IL = bytes.slice(0, 32);
|
7636
7713
|
const IR = bytes.slice(32);
|
7637
7714
|
if (privateKey) {
|
7638
7715
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
7639
|
-
const ki = (0,
|
7716
|
+
const ki = (0, import_math20.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
7640
7717
|
return new HDWallet({
|
7641
7718
|
privateKey: ki,
|
7642
7719
|
chainCode: IR,
|
@@ -7645,7 +7722,7 @@ var HDWallet = class {
|
|
7645
7722
|
parentFingerprint: this.fingerprint
|
7646
7723
|
});
|
7647
7724
|
}
|
7648
|
-
const signer = new Signer((0,
|
7725
|
+
const signer = new Signer((0, import_utils35.hexlify)(IL));
|
7649
7726
|
const Ki = signer.addPoint(publicKey);
|
7650
7727
|
return new HDWallet({
|
7651
7728
|
publicKey: Ki,
|
@@ -7674,18 +7751,18 @@ var HDWallet = class {
|
|
7674
7751
|
*/
|
7675
7752
|
toExtendedKey(isPublic = false, testnet = false) {
|
7676
7753
|
if (this.depth >= 256) {
|
7677
|
-
throw new
|
7678
|
-
|
7754
|
+
throw new import_errors20.FuelError(
|
7755
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7679
7756
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
7680
7757
|
);
|
7681
7758
|
}
|
7682
7759
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
7683
|
-
const depth = (0,
|
7760
|
+
const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
|
7684
7761
|
const parentFingerprint = this.parentFingerprint;
|
7685
|
-
const index = (0,
|
7762
|
+
const index = (0, import_math20.toHex)(this.index, 4);
|
7686
7763
|
const chainCode = this.chainCode;
|
7687
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
7688
|
-
const extendedKey = (0,
|
7764
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
|
7765
|
+
const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
7689
7766
|
return base58check(extendedKey);
|
7690
7767
|
}
|
7691
7768
|
/**
|
@@ -7697,34 +7774,34 @@ var HDWallet = class {
|
|
7697
7774
|
static fromSeed(seed) {
|
7698
7775
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
7699
7776
|
return new HDWallet({
|
7700
|
-
chainCode: (0,
|
7701
|
-
privateKey: (0,
|
7777
|
+
chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
|
7778
|
+
privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
|
7702
7779
|
});
|
7703
7780
|
}
|
7704
7781
|
static fromExtendedKey(extendedKey) {
|
7705
7782
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
7706
|
-
const bytes = (0,
|
7783
|
+
const bytes = (0, import_utils35.arrayify)(decoded);
|
7707
7784
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
7708
7785
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
7709
|
-
throw new
|
7786
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
7710
7787
|
}
|
7711
7788
|
if (!validChecksum) {
|
7712
|
-
throw new
|
7789
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
7713
7790
|
}
|
7714
7791
|
const depth = bytes[4];
|
7715
|
-
const parentFingerprint = (0,
|
7716
|
-
const index = parseInt((0,
|
7717
|
-
const chainCode = (0,
|
7792
|
+
const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
|
7793
|
+
const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
7794
|
+
const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
|
7718
7795
|
const key = bytes.slice(45, 78);
|
7719
7796
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
7720
|
-
throw new
|
7721
|
-
|
7797
|
+
throw new import_errors20.FuelError(
|
7798
|
+
import_errors20.ErrorCode.HD_WALLET_ERROR,
|
7722
7799
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
7723
7800
|
);
|
7724
7801
|
}
|
7725
7802
|
if (isPublicExtendedKey(bytes)) {
|
7726
7803
|
if (key[0] !== 3) {
|
7727
|
-
throw new
|
7804
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
7728
7805
|
}
|
7729
7806
|
return new HDWallet({
|
7730
7807
|
publicKey: key,
|
@@ -7735,7 +7812,7 @@ var HDWallet = class {
|
|
7735
7812
|
});
|
7736
7813
|
}
|
7737
7814
|
if (key[0] !== 0) {
|
7738
|
-
throw new
|
7815
|
+
throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
7739
7816
|
}
|
7740
7817
|
return new HDWallet({
|
7741
7818
|
privateKey: key.slice(1),
|
@@ -7928,9 +8005,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
7928
8005
|
};
|
7929
8006
|
|
7930
8007
|
// src/test-utils/launchNode.ts
|
7931
|
-
var
|
7932
|
-
var
|
7933
|
-
var
|
8008
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
8009
|
+
var import_math21 = require("@fuel-ts/math");
|
8010
|
+
var import_utils36 = require("@fuel-ts/utils");
|
7934
8011
|
var import_cli_utils = require("@fuel-ts/utils/cli-utils");
|
7935
8012
|
var import_child_process = require("child_process");
|
7936
8013
|
var import_crypto5 = require("crypto");
|
@@ -7988,7 +8065,7 @@ var launchNode = async ({
|
|
7988
8065
|
"--poa-instant"
|
7989
8066
|
]);
|
7990
8067
|
const chainConfigPath = getFlagValueFromArgs(args, "--chain");
|
7991
|
-
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") ||
|
8068
|
+
const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
|
7992
8069
|
const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
|
7993
8070
|
const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
|
7994
8071
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
@@ -8014,21 +8091,21 @@ var launchNode = async ({
|
|
8014
8091
|
(0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
|
8015
8092
|
}
|
8016
8093
|
const tempChainConfigFilePath = import_path.default.join(tempDirPath, "chainConfig.json");
|
8017
|
-
let chainConfig =
|
8094
|
+
let chainConfig = import_utils36.defaultChainConfig;
|
8018
8095
|
if (!process.env.GENESIS_SECRET) {
|
8019
8096
|
const pk = Signer.generatePrivateKey();
|
8020
8097
|
const signer = new Signer(pk);
|
8021
|
-
process.env.GENESIS_SECRET = (0,
|
8098
|
+
process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
|
8022
8099
|
chainConfig = {
|
8023
|
-
...
|
8100
|
+
...import_utils36.defaultChainConfig,
|
8024
8101
|
initial_state: {
|
8025
|
-
...
|
8102
|
+
...import_utils36.defaultChainConfig.initial_state,
|
8026
8103
|
coins: [
|
8027
|
-
...
|
8104
|
+
...import_utils36.defaultChainConfig.initial_state.coins,
|
8028
8105
|
{
|
8029
8106
|
owner: signer.address.toHexString(),
|
8030
|
-
amount: (0,
|
8031
|
-
asset_id:
|
8107
|
+
amount: (0, import_math21.toHex)(1e9),
|
8108
|
+
asset_id: import_utils36.defaultChainConfig?.consensus_parameters?.base_asset_id ?? import_configs11.ZeroBytes32
|
8032
8109
|
}
|
8033
8110
|
]
|
8034
8111
|
}
|