@fuel-ts/account 0.0.0-rc-1976-20240404171500 → 0.0.0-rc-1976-20240405090158
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 +38 -212
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +457 -540
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -328
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +38 -212
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +424 -501
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +213 -298
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/providers/utils/extract-tx-error.d.ts +0 -36
- package/dist/providers/utils/extract-tx-error.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -88,7 +88,7 @@ __export(src_exports, {
|
|
88
88
|
StorageAbstract: () => StorageAbstract,
|
89
89
|
TransactionResponse: () => TransactionResponse,
|
90
90
|
TransactionStatus: () => TransactionStatus,
|
91
|
-
TransactionType: () =>
|
91
|
+
TransactionType: () => import_transactions5.TransactionType,
|
92
92
|
TransactionTypeName: () => TransactionTypeName,
|
93
93
|
Vault: () => Vault,
|
94
94
|
Wallet: () => Wallet,
|
@@ -97,9 +97,7 @@ __export(src_exports, {
|
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
98
|
addAmountToAsset: () => addAmountToAsset,
|
99
99
|
addOperation: () => addOperation,
|
100
|
-
assemblePanicError: () => assemblePanicError,
|
101
100
|
assembleReceiptByType: () => assembleReceiptByType,
|
102
|
-
assembleRevertError: () => assembleRevertError,
|
103
101
|
assembleTransactionSummary: () => assembleTransactionSummary,
|
104
102
|
assets: () => assets,
|
105
103
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
@@ -114,7 +112,6 @@ __export(src_exports, {
|
|
114
112
|
english: () => english,
|
115
113
|
extractBurnedAssetsFromReceipts: () => extractBurnedAssetsFromReceipts,
|
116
114
|
extractMintedAssetsFromReceipts: () => extractMintedAssetsFromReceipts,
|
117
|
-
extractTxError: () => extractTxError,
|
118
115
|
gasUsedByInputs: () => gasUsedByInputs,
|
119
116
|
getAssetEth: () => getAssetEth,
|
120
117
|
getAssetFuel: () => getAssetFuel,
|
@@ -184,10 +181,10 @@ module.exports = __toCommonJS(src_exports);
|
|
184
181
|
|
185
182
|
// src/account.ts
|
186
183
|
var import_address4 = require("@fuel-ts/address");
|
187
|
-
var
|
184
|
+
var import_errors15 = require("@fuel-ts/errors");
|
188
185
|
var import_interfaces = require("@fuel-ts/interfaces");
|
189
|
-
var
|
190
|
-
var
|
186
|
+
var import_math17 = require("@fuel-ts/math");
|
187
|
+
var import_utils27 = require("@fuel-ts/utils");
|
191
188
|
|
192
189
|
// src/providers/coin-quantity.ts
|
193
190
|
var import_math = require("@fuel-ts/math");
|
@@ -226,12 +223,12 @@ var addAmountToAsset = (params) => {
|
|
226
223
|
|
227
224
|
// src/providers/provider.ts
|
228
225
|
var import_address3 = require("@fuel-ts/address");
|
229
|
-
var
|
230
|
-
var
|
231
|
-
var
|
232
|
-
var
|
226
|
+
var import_errors13 = require("@fuel-ts/errors");
|
227
|
+
var import_math14 = require("@fuel-ts/math");
|
228
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
229
|
+
var import_utils22 = require("@fuel-ts/utils");
|
233
230
|
var import_versions = require("@fuel-ts/versions");
|
234
|
-
var
|
231
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
235
232
|
var import_ethers = require("ethers");
|
236
233
|
var import_graphql_request = require("graphql-request");
|
237
234
|
var import_ramda3 = require("ramda");
|
@@ -1304,9 +1301,9 @@ var outputify = (value) => {
|
|
1304
1301
|
|
1305
1302
|
// src/providers/transaction-request/transaction-request.ts
|
1306
1303
|
var import_address = require("@fuel-ts/address");
|
1307
|
-
var
|
1308
|
-
var
|
1309
|
-
var
|
1304
|
+
var import_configs5 = require("@fuel-ts/address/configs");
|
1305
|
+
var import_math6 = require("@fuel-ts/math");
|
1306
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1310
1307
|
var import_utils9 = require("@fuel-ts/utils");
|
1311
1308
|
|
1312
1309
|
// src/providers/resource.ts
|
@@ -1699,78 +1696,6 @@ function sleep(time) {
|
|
1699
1696
|
});
|
1700
1697
|
}
|
1701
1698
|
|
1702
|
-
// src/providers/utils/extract-tx-error.ts
|
1703
|
-
var import_errors7 = require("@fuel-ts/errors");
|
1704
|
-
var import_math6 = require("@fuel-ts/math");
|
1705
|
-
var import_transactions5 = require("@fuel-ts/transactions");
|
1706
|
-
var import_configs5 = require("@fuel-ts/transactions/configs");
|
1707
|
-
var assemblePanicError = (status) => {
|
1708
|
-
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1709
|
-
const reason = status.reason;
|
1710
|
-
if (import_configs5.PANIC_REASONS.includes(status.reason)) {
|
1711
|
-
errorMessage = `${errorMessage}
|
1712
|
-
|
1713
|
-
You can read more about this error at:
|
1714
|
-
|
1715
|
-
${import_configs5.PANIC_DOC_URL}#variant.${status.reason}`;
|
1716
|
-
}
|
1717
|
-
return { errorMessage, reason };
|
1718
|
-
};
|
1719
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1720
|
-
var assembleRevertError = (receipts, logs) => {
|
1721
|
-
let errorMessage = "The transaction reverted with an unknown reason.";
|
1722
|
-
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1723
|
-
let reason = "";
|
1724
|
-
if (revertReceipt) {
|
1725
|
-
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1726
|
-
switch (reasonHex) {
|
1727
|
-
case import_configs5.FAILED_REQUIRE_SIGNAL: {
|
1728
|
-
reason = "require";
|
1729
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1730
|
-
break;
|
1731
|
-
}
|
1732
|
-
case import_configs5.FAILED_ASSERT_EQ_SIGNAL: {
|
1733
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1734
|
-
reason = "assert_eq";
|
1735
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1736
|
-
break;
|
1737
|
-
}
|
1738
|
-
case import_configs5.FAILED_ASSERT_NE_SIGNAL: {
|
1739
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1740
|
-
reason = "assert_ne";
|
1741
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1742
|
-
break;
|
1743
|
-
}
|
1744
|
-
case import_configs5.FAILED_ASSERT_SIGNAL:
|
1745
|
-
reason = "assert";
|
1746
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1747
|
-
break;
|
1748
|
-
case import_configs5.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1749
|
-
reason = "MissingOutputChange";
|
1750
|
-
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1751
|
-
break;
|
1752
|
-
default:
|
1753
|
-
reason = "unknown";
|
1754
|
-
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1755
|
-
}
|
1756
|
-
}
|
1757
|
-
return { errorMessage, reason };
|
1758
|
-
};
|
1759
|
-
var extractTxError = (params) => {
|
1760
|
-
const { receipts, status, logs } = params;
|
1761
|
-
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1762
|
-
const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1763
|
-
const { errorMessage, reason } = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1764
|
-
const metadata = {
|
1765
|
-
logs,
|
1766
|
-
receipts,
|
1767
|
-
panic: isPanic,
|
1768
|
-
revert: isRevert,
|
1769
|
-
reason
|
1770
|
-
};
|
1771
|
-
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
|
1772
|
-
};
|
1773
|
-
|
1774
1699
|
// src/providers/transaction-request/errors.ts
|
1775
1700
|
var ChangeOutputCollisionError = class extends Error {
|
1776
1701
|
name = "ChangeOutputCollisionError";
|
@@ -1820,7 +1745,7 @@ var BaseTransactionRequest = class {
|
|
1820
1745
|
/** List of witnesses */
|
1821
1746
|
witnesses = [];
|
1822
1747
|
/** Base asset ID - should be fetched from the chain */
|
1823
|
-
baseAssetId =
|
1748
|
+
baseAssetId = import_configs5.ZeroBytes32;
|
1824
1749
|
/**
|
1825
1750
|
* Constructor for initializing a base transaction request.
|
1826
1751
|
*
|
@@ -1836,33 +1761,33 @@ var BaseTransactionRequest = class {
|
|
1836
1761
|
witnesses,
|
1837
1762
|
baseAssetId
|
1838
1763
|
} = {}) {
|
1839
|
-
this.gasPrice = (0,
|
1764
|
+
this.gasPrice = (0, import_math6.bn)(gasPrice);
|
1840
1765
|
this.maturity = maturity ?? 0;
|
1841
|
-
this.witnessLimit = witnessLimit ? (0,
|
1842
|
-
this.maxFee = maxFee ? (0,
|
1766
|
+
this.witnessLimit = witnessLimit ? (0, import_math6.bn)(witnessLimit) : void 0;
|
1767
|
+
this.maxFee = maxFee ? (0, import_math6.bn)(maxFee) : void 0;
|
1843
1768
|
this.inputs = inputs ?? [];
|
1844
1769
|
this.outputs = outputs ?? [];
|
1845
1770
|
this.witnesses = witnesses ?? [];
|
1846
|
-
this.baseAssetId = baseAssetId ??
|
1771
|
+
this.baseAssetId = baseAssetId ?? import_configs5.ZeroBytes32;
|
1847
1772
|
}
|
1848
1773
|
static getPolicyMeta(req) {
|
1849
1774
|
let policyTypes = 0;
|
1850
1775
|
const policies = [];
|
1851
1776
|
if (req.gasPrice) {
|
1852
|
-
policyTypes +=
|
1853
|
-
policies.push({ data: req.gasPrice, type:
|
1777
|
+
policyTypes += import_transactions5.PolicyType.GasPrice;
|
1778
|
+
policies.push({ data: req.gasPrice, type: import_transactions5.PolicyType.GasPrice });
|
1854
1779
|
}
|
1855
1780
|
if (req.witnessLimit) {
|
1856
|
-
policyTypes +=
|
1857
|
-
policies.push({ data: req.witnessLimit, type:
|
1781
|
+
policyTypes += import_transactions5.PolicyType.WitnessLimit;
|
1782
|
+
policies.push({ data: req.witnessLimit, type: import_transactions5.PolicyType.WitnessLimit });
|
1858
1783
|
}
|
1859
1784
|
if (req.maturity > 0) {
|
1860
|
-
policyTypes +=
|
1861
|
-
policies.push({ data: req.maturity, type:
|
1785
|
+
policyTypes += import_transactions5.PolicyType.Maturity;
|
1786
|
+
policies.push({ data: req.maturity, type: import_transactions5.PolicyType.Maturity });
|
1862
1787
|
}
|
1863
1788
|
if (req.maxFee) {
|
1864
|
-
policyTypes +=
|
1865
|
-
policies.push({ data: req.maxFee, type:
|
1789
|
+
policyTypes += import_transactions5.PolicyType.MaxFee;
|
1790
|
+
policies.push({ data: req.maxFee, type: import_transactions5.PolicyType.MaxFee });
|
1866
1791
|
}
|
1867
1792
|
return {
|
1868
1793
|
policyTypes,
|
@@ -1896,7 +1821,7 @@ var BaseTransactionRequest = class {
|
|
1896
1821
|
* @returns The transaction bytes.
|
1897
1822
|
*/
|
1898
1823
|
toTransactionBytes() {
|
1899
|
-
return new
|
1824
|
+
return new import_transactions5.TransactionCoder().encode(this.toTransaction());
|
1900
1825
|
}
|
1901
1826
|
/**
|
1902
1827
|
* @hidden
|
@@ -1936,7 +1861,7 @@ var BaseTransactionRequest = class {
|
|
1936
1861
|
* @returns The index of the created witness.
|
1937
1862
|
*/
|
1938
1863
|
addEmptyWitness() {
|
1939
|
-
this.addWitness((0, import_utils9.concat)([
|
1864
|
+
this.addWitness((0, import_utils9.concat)([import_configs5.ZeroBytes32, import_configs5.ZeroBytes32]));
|
1940
1865
|
return this.witnesses.length - 1;
|
1941
1866
|
}
|
1942
1867
|
/**
|
@@ -1987,7 +1912,7 @@ var BaseTransactionRequest = class {
|
|
1987
1912
|
*/
|
1988
1913
|
getCoinInputs() {
|
1989
1914
|
return this.inputs.filter(
|
1990
|
-
(input) => input.type ===
|
1915
|
+
(input) => input.type === import_transactions5.InputType.Coin
|
1991
1916
|
);
|
1992
1917
|
}
|
1993
1918
|
/**
|
@@ -1997,7 +1922,7 @@ var BaseTransactionRequest = class {
|
|
1997
1922
|
*/
|
1998
1923
|
getCoinOutputs() {
|
1999
1924
|
return this.outputs.filter(
|
2000
|
-
(output) => output.type ===
|
1925
|
+
(output) => output.type === import_transactions5.OutputType.Coin
|
2001
1926
|
);
|
2002
1927
|
}
|
2003
1928
|
/**
|
@@ -2007,7 +1932,7 @@ var BaseTransactionRequest = class {
|
|
2007
1932
|
*/
|
2008
1933
|
getChangeOutputs() {
|
2009
1934
|
return this.outputs.filter(
|
2010
|
-
(output) => output.type ===
|
1935
|
+
(output) => output.type === import_transactions5.OutputType.Change
|
2011
1936
|
);
|
2012
1937
|
}
|
2013
1938
|
/**
|
@@ -2019,9 +1944,9 @@ var BaseTransactionRequest = class {
|
|
2019
1944
|
const ownerAddress = (0, import_address.addressify)(owner);
|
2020
1945
|
const found = this.inputs.find((input) => {
|
2021
1946
|
switch (input.type) {
|
2022
|
-
case
|
1947
|
+
case import_transactions5.InputType.Coin:
|
2023
1948
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
2024
|
-
case
|
1949
|
+
case import_transactions5.InputType.Message:
|
2025
1950
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
2026
1951
|
default:
|
2027
1952
|
return false;
|
@@ -2050,7 +1975,7 @@ var BaseTransactionRequest = class {
|
|
2050
1975
|
}
|
2051
1976
|
const input = {
|
2052
1977
|
...coin,
|
2053
|
-
type:
|
1978
|
+
type: import_transactions5.InputType.Coin,
|
2054
1979
|
owner: owner.toB256(),
|
2055
1980
|
amount,
|
2056
1981
|
assetId,
|
@@ -2082,7 +2007,7 @@ var BaseTransactionRequest = class {
|
|
2082
2007
|
}
|
2083
2008
|
const input = {
|
2084
2009
|
...message,
|
2085
|
-
type:
|
2010
|
+
type: import_transactions5.InputType.Message,
|
2086
2011
|
sender: sender.toB256(),
|
2087
2012
|
recipient: recipient.toB256(),
|
2088
2013
|
amount,
|
@@ -2154,7 +2079,7 @@ var BaseTransactionRequest = class {
|
|
2154
2079
|
*/
|
2155
2080
|
addCoinOutput(to, amount, assetId) {
|
2156
2081
|
this.pushOutput({
|
2157
|
-
type:
|
2082
|
+
type: import_transactions5.OutputType.Coin,
|
2158
2083
|
to: (0, import_address.addressify)(to).toB256(),
|
2159
2084
|
amount,
|
2160
2085
|
assetId: assetId ?? this.baseAssetId
|
@@ -2170,7 +2095,7 @@ var BaseTransactionRequest = class {
|
|
2170
2095
|
addCoinOutputs(to, quantities) {
|
2171
2096
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2172
2097
|
this.pushOutput({
|
2173
|
-
type:
|
2098
|
+
type: import_transactions5.OutputType.Coin,
|
2174
2099
|
to: (0, import_address.addressify)(to).toB256(),
|
2175
2100
|
amount: quantity.amount,
|
2176
2101
|
assetId: quantity.assetId
|
@@ -2190,7 +2115,7 @@ var BaseTransactionRequest = class {
|
|
2190
2115
|
);
|
2191
2116
|
if (!changeOutput) {
|
2192
2117
|
this.pushOutput({
|
2193
|
-
type:
|
2118
|
+
type: import_transactions5.OutputType.Change,
|
2194
2119
|
to: (0, import_address.addressify)(to).toB256(),
|
2195
2120
|
assetId: assetId ?? this.baseAssetId
|
2196
2121
|
});
|
@@ -2246,7 +2171,7 @@ var BaseTransactionRequest = class {
|
|
2246
2171
|
let idCounter = 0;
|
2247
2172
|
const generateId = () => {
|
2248
2173
|
const counterString = String(idCounter++);
|
2249
|
-
const id =
|
2174
|
+
const id = import_configs5.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2250
2175
|
return id;
|
2251
2176
|
};
|
2252
2177
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2268,13 +2193,13 @@ var BaseTransactionRequest = class {
|
|
2268
2193
|
assetId,
|
2269
2194
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2270
2195
|
maturity: 0,
|
2271
|
-
blockCreated: (0,
|
2272
|
-
txCreatedIdx: (0,
|
2196
|
+
blockCreated: (0, import_math6.bn)(1),
|
2197
|
+
txCreatedIdx: (0, import_math6.bn)(1)
|
2273
2198
|
}
|
2274
2199
|
]);
|
2275
2200
|
}
|
2276
2201
|
};
|
2277
|
-
updateAssetInput(this.baseAssetId, (0,
|
2202
|
+
updateAssetInput(this.baseAssetId, (0, import_math6.bn)(1e11));
|
2278
2203
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2279
2204
|
}
|
2280
2205
|
/**
|
@@ -2285,7 +2210,7 @@ var BaseTransactionRequest = class {
|
|
2285
2210
|
*/
|
2286
2211
|
getCoinOutputsQuantities() {
|
2287
2212
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2288
|
-
amount: (0,
|
2213
|
+
amount: (0, import_math6.bn)(amount),
|
2289
2214
|
assetId: assetId.toString()
|
2290
2215
|
}));
|
2291
2216
|
return coinsQuantities;
|
@@ -2303,18 +2228,18 @@ var BaseTransactionRequest = class {
|
|
2303
2228
|
this.inputs.forEach((i) => {
|
2304
2229
|
let correspondingInput;
|
2305
2230
|
switch (i.type) {
|
2306
|
-
case
|
2307
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2231
|
+
case import_transactions5.InputType.Coin:
|
2232
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
|
2308
2233
|
break;
|
2309
|
-
case
|
2234
|
+
case import_transactions5.InputType.Message:
|
2310
2235
|
correspondingInput = inputs.find(
|
2311
|
-
(x) => x.type ===
|
2236
|
+
(x) => x.type === import_transactions5.InputType.Message && x.sender === i.sender
|
2312
2237
|
);
|
2313
2238
|
break;
|
2314
2239
|
default:
|
2315
2240
|
return;
|
2316
2241
|
}
|
2317
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2242
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2318
2243
|
i.predicate = correspondingInput.predicate;
|
2319
2244
|
i.predicateData = correspondingInput.predicateData;
|
2320
2245
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2324,47 +2249,47 @@ var BaseTransactionRequest = class {
|
|
2324
2249
|
};
|
2325
2250
|
|
2326
2251
|
// src/providers/transaction-request/create-transaction-request.ts
|
2327
|
-
var
|
2328
|
-
var
|
2329
|
-
var
|
2252
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2253
|
+
var import_math8 = require("@fuel-ts/math");
|
2254
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2330
2255
|
var import_utils13 = require("@fuel-ts/utils");
|
2331
2256
|
|
2332
2257
|
// src/providers/transaction-request/hash-transaction.ts
|
2333
|
-
var
|
2258
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
2334
2259
|
var import_hasher = require("@fuel-ts/hasher");
|
2335
|
-
var
|
2336
|
-
var
|
2260
|
+
var import_math7 = require("@fuel-ts/math");
|
2261
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
2337
2262
|
var import_utils11 = require("@fuel-ts/utils");
|
2338
2263
|
var import_ramda2 = require("ramda");
|
2339
2264
|
function hashTransaction(transactionRequest, chainId) {
|
2340
2265
|
const transaction = transactionRequest.toTransaction();
|
2341
|
-
if (transaction.type ===
|
2342
|
-
transaction.receiptsRoot =
|
2266
|
+
if (transaction.type === import_transactions6.TransactionType.Script) {
|
2267
|
+
transaction.receiptsRoot = import_configs6.ZeroBytes32;
|
2343
2268
|
}
|
2344
2269
|
transaction.inputs = transaction.inputs.map((input) => {
|
2345
2270
|
const inputClone = (0, import_ramda2.clone)(input);
|
2346
2271
|
switch (inputClone.type) {
|
2347
|
-
case
|
2272
|
+
case import_transactions6.InputType.Coin: {
|
2348
2273
|
inputClone.txPointer = {
|
2349
2274
|
blockHeight: 0,
|
2350
2275
|
txIndex: 0
|
2351
2276
|
};
|
2352
|
-
inputClone.predicateGasUsed = (0,
|
2277
|
+
inputClone.predicateGasUsed = (0, import_math7.bn)(0);
|
2353
2278
|
return inputClone;
|
2354
2279
|
}
|
2355
|
-
case
|
2356
|
-
inputClone.predicateGasUsed = (0,
|
2280
|
+
case import_transactions6.InputType.Message: {
|
2281
|
+
inputClone.predicateGasUsed = (0, import_math7.bn)(0);
|
2357
2282
|
return inputClone;
|
2358
2283
|
}
|
2359
|
-
case
|
2284
|
+
case import_transactions6.InputType.Contract: {
|
2360
2285
|
inputClone.txPointer = {
|
2361
2286
|
blockHeight: 0,
|
2362
2287
|
txIndex: 0
|
2363
2288
|
};
|
2364
|
-
inputClone.txID =
|
2289
|
+
inputClone.txID = import_configs6.ZeroBytes32;
|
2365
2290
|
inputClone.outputIndex = 0;
|
2366
|
-
inputClone.balanceRoot =
|
2367
|
-
inputClone.stateRoot =
|
2291
|
+
inputClone.balanceRoot = import_configs6.ZeroBytes32;
|
2292
|
+
inputClone.stateRoot = import_configs6.ZeroBytes32;
|
2368
2293
|
return inputClone;
|
2369
2294
|
}
|
2370
2295
|
default:
|
@@ -2374,19 +2299,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2374
2299
|
transaction.outputs = transaction.outputs.map((output) => {
|
2375
2300
|
const outputClone = (0, import_ramda2.clone)(output);
|
2376
2301
|
switch (outputClone.type) {
|
2377
|
-
case
|
2378
|
-
outputClone.balanceRoot =
|
2379
|
-
outputClone.stateRoot =
|
2302
|
+
case import_transactions6.OutputType.Contract: {
|
2303
|
+
outputClone.balanceRoot = import_configs6.ZeroBytes32;
|
2304
|
+
outputClone.stateRoot = import_configs6.ZeroBytes32;
|
2380
2305
|
return outputClone;
|
2381
2306
|
}
|
2382
|
-
case
|
2383
|
-
outputClone.amount = (0,
|
2307
|
+
case import_transactions6.OutputType.Change: {
|
2308
|
+
outputClone.amount = (0, import_math7.bn)(0);
|
2384
2309
|
return outputClone;
|
2385
2310
|
}
|
2386
|
-
case
|
2387
|
-
outputClone.to =
|
2388
|
-
outputClone.amount = (0,
|
2389
|
-
outputClone.assetId =
|
2311
|
+
case import_transactions6.OutputType.Variable: {
|
2312
|
+
outputClone.to = import_configs6.ZeroBytes32;
|
2313
|
+
outputClone.amount = (0, import_math7.bn)(0);
|
2314
|
+
outputClone.assetId = import_configs6.ZeroBytes32;
|
2390
2315
|
return outputClone;
|
2391
2316
|
}
|
2392
2317
|
default:
|
@@ -2396,7 +2321,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2396
2321
|
transaction.witnessesCount = 0;
|
2397
2322
|
transaction.witnesses = [];
|
2398
2323
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2399
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2324
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
|
2400
2325
|
return (0, import_hasher.sha256)(concatenatedData);
|
2401
2326
|
}
|
2402
2327
|
|
@@ -2432,7 +2357,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2432
2357
|
return new this(obj);
|
2433
2358
|
}
|
2434
2359
|
/** Type of the transaction */
|
2435
|
-
type =
|
2360
|
+
type = import_transactions7.TransactionType.Create;
|
2436
2361
|
/** Witness index of contract bytecode to create */
|
2437
2362
|
bytecodeWitnessIndex;
|
2438
2363
|
/** Salt */
|
@@ -2452,7 +2377,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2452
2377
|
} = {}) {
|
2453
2378
|
super(rest);
|
2454
2379
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2455
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2380
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs7.ZeroBytes32);
|
2456
2381
|
this.storageSlots = [...storageSlots ?? []];
|
2457
2382
|
}
|
2458
2383
|
/**
|
@@ -2465,12 +2390,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2465
2390
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2466
2391
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2467
2392
|
return {
|
2468
|
-
type:
|
2393
|
+
type: import_transactions7.TransactionType.Create,
|
2469
2394
|
...baseTransaction,
|
2470
2395
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2471
2396
|
bytecodeWitnessIndex,
|
2472
2397
|
storageSlotsCount: storageSlots.length,
|
2473
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2398
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs7.ZeroBytes32,
|
2474
2399
|
storageSlots
|
2475
2400
|
};
|
2476
2401
|
}
|
@@ -2481,7 +2406,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2481
2406
|
*/
|
2482
2407
|
getContractCreatedOutputs() {
|
2483
2408
|
return this.outputs.filter(
|
2484
|
-
(output) => output.type ===
|
2409
|
+
(output) => output.type === import_transactions7.OutputType.ContractCreated
|
2485
2410
|
);
|
2486
2411
|
}
|
2487
2412
|
/**
|
@@ -2502,14 +2427,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2502
2427
|
*/
|
2503
2428
|
addContractCreatedOutput(contractId, stateRoot) {
|
2504
2429
|
this.pushOutput({
|
2505
|
-
type:
|
2430
|
+
type: import_transactions7.OutputType.ContractCreated,
|
2506
2431
|
contractId,
|
2507
2432
|
stateRoot
|
2508
2433
|
});
|
2509
2434
|
}
|
2510
2435
|
metadataGas(gasCosts) {
|
2511
2436
|
return calculateMetadataGasForTxCreate({
|
2512
|
-
contractBytesSize: (0,
|
2437
|
+
contractBytesSize: (0, import_math8.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2513
2438
|
gasCosts,
|
2514
2439
|
stateRootSize: this.storageSlots.length,
|
2515
2440
|
txBytesSize: this.byteSize()
|
@@ -2520,9 +2445,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2520
2445
|
// src/providers/transaction-request/script-transaction-request.ts
|
2521
2446
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2522
2447
|
var import_address2 = require("@fuel-ts/address");
|
2523
|
-
var
|
2524
|
-
var
|
2525
|
-
var
|
2448
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2449
|
+
var import_math9 = require("@fuel-ts/math");
|
2450
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2526
2451
|
var import_utils15 = require("@fuel-ts/utils");
|
2527
2452
|
|
2528
2453
|
// src/providers/transaction-request/scripts.ts
|
@@ -2560,7 +2485,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2560
2485
|
return new this(obj);
|
2561
2486
|
}
|
2562
2487
|
/** Type of the transaction */
|
2563
|
-
type =
|
2488
|
+
type = import_transactions8.TransactionType.Script;
|
2564
2489
|
/** Gas limit for transaction */
|
2565
2490
|
gasLimit;
|
2566
2491
|
/** Script to execute */
|
@@ -2575,7 +2500,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2575
2500
|
*/
|
2576
2501
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2577
2502
|
super(rest);
|
2578
|
-
this.gasLimit = (0,
|
2503
|
+
this.gasLimit = (0, import_math9.bn)(gasLimit);
|
2579
2504
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2580
2505
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2581
2506
|
this.abis = rest.abis;
|
@@ -2589,12 +2514,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2589
2514
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2590
2515
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2591
2516
|
return {
|
2592
|
-
type:
|
2517
|
+
type: import_transactions8.TransactionType.Script,
|
2593
2518
|
scriptGasLimit: this.gasLimit,
|
2594
2519
|
...super.getBaseTransaction(),
|
2595
2520
|
scriptLength: script.length,
|
2596
2521
|
scriptDataLength: scriptData.length,
|
2597
|
-
receiptsRoot:
|
2522
|
+
receiptsRoot: import_configs8.ZeroBytes32,
|
2598
2523
|
script: (0, import_utils15.hexlify)(script),
|
2599
2524
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2600
2525
|
};
|
@@ -2606,7 +2531,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2606
2531
|
*/
|
2607
2532
|
getContractInputs() {
|
2608
2533
|
return this.inputs.filter(
|
2609
|
-
(input) => input.type ===
|
2534
|
+
(input) => input.type === import_transactions8.InputType.Contract
|
2610
2535
|
);
|
2611
2536
|
}
|
2612
2537
|
/**
|
@@ -2616,7 +2541,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2616
2541
|
*/
|
2617
2542
|
getContractOutputs() {
|
2618
2543
|
return this.outputs.filter(
|
2619
|
-
(output) => output.type ===
|
2544
|
+
(output) => output.type === import_transactions8.OutputType.Contract
|
2620
2545
|
);
|
2621
2546
|
}
|
2622
2547
|
/**
|
@@ -2626,7 +2551,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2626
2551
|
*/
|
2627
2552
|
getVariableOutputs() {
|
2628
2553
|
return this.outputs.filter(
|
2629
|
-
(output) => output.type ===
|
2554
|
+
(output) => output.type === import_transactions8.OutputType.Variable
|
2630
2555
|
);
|
2631
2556
|
}
|
2632
2557
|
/**
|
@@ -2649,7 +2574,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2649
2574
|
let outputsNumber = numberOfVariables;
|
2650
2575
|
while (outputsNumber) {
|
2651
2576
|
this.pushOutput({
|
2652
|
-
type:
|
2577
|
+
type: import_transactions8.OutputType.Variable
|
2653
2578
|
});
|
2654
2579
|
outputsNumber -= 1;
|
2655
2580
|
}
|
@@ -2682,12 +2607,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2682
2607
|
return this;
|
2683
2608
|
}
|
2684
2609
|
const inputIndex = super.pushInput({
|
2685
|
-
type:
|
2610
|
+
type: import_transactions8.InputType.Contract,
|
2686
2611
|
contractId: contractAddress.toB256(),
|
2687
2612
|
txPointer: "0x00000000000000000000000000000000"
|
2688
2613
|
});
|
2689
2614
|
this.pushOutput({
|
2690
|
-
type:
|
2615
|
+
type: import_transactions8.OutputType.Contract,
|
2691
2616
|
inputIndex
|
2692
2617
|
});
|
2693
2618
|
return this;
|
@@ -2723,38 +2648,38 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2723
2648
|
};
|
2724
2649
|
|
2725
2650
|
// src/providers/transaction-request/utils.ts
|
2726
|
-
var
|
2727
|
-
var
|
2651
|
+
var import_errors8 = require("@fuel-ts/errors");
|
2652
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2728
2653
|
var transactionRequestify = (obj) => {
|
2729
2654
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2730
2655
|
return obj;
|
2731
2656
|
}
|
2732
2657
|
const { type } = obj;
|
2733
2658
|
switch (obj.type) {
|
2734
|
-
case
|
2659
|
+
case import_transactions9.TransactionType.Script: {
|
2735
2660
|
return ScriptTransactionRequest.from(obj);
|
2736
2661
|
}
|
2737
|
-
case
|
2662
|
+
case import_transactions9.TransactionType.Create: {
|
2738
2663
|
return CreateTransactionRequest.from(obj);
|
2739
2664
|
}
|
2740
2665
|
default: {
|
2741
|
-
throw new
|
2666
|
+
throw new import_errors8.FuelError(import_errors8.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2742
2667
|
}
|
2743
2668
|
}
|
2744
2669
|
};
|
2745
2670
|
|
2746
2671
|
// src/providers/transaction-response/transaction-response.ts
|
2747
|
-
var
|
2748
|
-
var
|
2749
|
-
var
|
2672
|
+
var import_errors12 = require("@fuel-ts/errors");
|
2673
|
+
var import_math13 = require("@fuel-ts/math");
|
2674
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2750
2675
|
var import_utils21 = require("@fuel-ts/utils");
|
2751
2676
|
|
2752
2677
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2753
2678
|
var import_utils19 = require("@fuel-ts/utils");
|
2754
2679
|
|
2755
2680
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2756
|
-
var
|
2757
|
-
var
|
2681
|
+
var import_math10 = require("@fuel-ts/math");
|
2682
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2758
2683
|
var import_utils16 = require("@fuel-ts/utils");
|
2759
2684
|
var calculateTransactionFee = (params) => {
|
2760
2685
|
const {
|
@@ -2762,24 +2687,24 @@ var calculateTransactionFee = (params) => {
|
|
2762
2687
|
rawPayload,
|
2763
2688
|
consensusParameters: { gasCosts, feeParams }
|
2764
2689
|
} = params;
|
2765
|
-
const gasPerByte = (0,
|
2766
|
-
const gasPriceFactor = (0,
|
2690
|
+
const gasPerByte = (0, import_math10.bn)(feeParams.gasPerByte);
|
2691
|
+
const gasPriceFactor = (0, import_math10.bn)(feeParams.gasPriceFactor);
|
2767
2692
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2768
|
-
const [transaction] = new
|
2769
|
-
if (transaction.type ===
|
2693
|
+
const [transaction] = new import_transactions10.TransactionCoder().decode(transactionBytes, 0);
|
2694
|
+
if (transaction.type === import_transactions10.TransactionType.Mint) {
|
2770
2695
|
return {
|
2771
|
-
fee: (0,
|
2772
|
-
minFee: (0,
|
2773
|
-
maxFee: (0,
|
2774
|
-
feeFromGasUsed: (0,
|
2696
|
+
fee: (0, import_math10.bn)(0),
|
2697
|
+
minFee: (0, import_math10.bn)(0),
|
2698
|
+
maxFee: (0, import_math10.bn)(0),
|
2699
|
+
feeFromGasUsed: (0, import_math10.bn)(0)
|
2775
2700
|
};
|
2776
2701
|
}
|
2777
2702
|
const { type, witnesses, inputs, policies } = transaction;
|
2778
|
-
let metadataGas = (0,
|
2779
|
-
let gasLimit = (0,
|
2780
|
-
if (type ===
|
2703
|
+
let metadataGas = (0, import_math10.bn)(0);
|
2704
|
+
let gasLimit = (0, import_math10.bn)(0);
|
2705
|
+
if (type === import_transactions10.TransactionType.Create) {
|
2781
2706
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2782
|
-
const contractBytesSize = (0,
|
2707
|
+
const contractBytesSize = (0, import_math10.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2783
2708
|
metadataGas = calculateMetadataGasForTxCreate({
|
2784
2709
|
contractBytesSize,
|
2785
2710
|
gasCosts,
|
@@ -2798,13 +2723,13 @@ var calculateTransactionFee = (params) => {
|
|
2798
2723
|
}
|
2799
2724
|
const minGas = getMinGas({
|
2800
2725
|
gasCosts,
|
2801
|
-
gasPerByte: (0,
|
2726
|
+
gasPerByte: (0, import_math10.bn)(gasPerByte),
|
2802
2727
|
inputs,
|
2803
2728
|
metadataGas,
|
2804
2729
|
txBytesSize: transactionBytes.length
|
2805
2730
|
});
|
2806
|
-
const gasPrice = (0,
|
2807
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
2731
|
+
const gasPrice = (0, import_math10.bn)(policies.find((policy) => policy.type === import_transactions10.PolicyType.GasPrice)?.data);
|
2732
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions10.PolicyType.WitnessLimit)?.data;
|
2808
2733
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2809
2734
|
const maxGas = getMaxGas({
|
2810
2735
|
gasPerByte,
|
@@ -2826,14 +2751,14 @@ var calculateTransactionFee = (params) => {
|
|
2826
2751
|
};
|
2827
2752
|
|
2828
2753
|
// src/providers/transaction-summary/operations.ts
|
2829
|
-
var
|
2830
|
-
var
|
2831
|
-
var
|
2832
|
-
var
|
2754
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2755
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2756
|
+
var import_math12 = require("@fuel-ts/math");
|
2757
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2833
2758
|
|
2834
2759
|
// src/providers/transaction-summary/call.ts
|
2835
2760
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2836
|
-
var
|
2761
|
+
var import_math11 = require("@fuel-ts/math");
|
2837
2762
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2838
2763
|
const abiInterface = new import_abi_coder2.Interface(abi);
|
2839
2764
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2842,7 +2767,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2842
2767
|
let encodedArgs;
|
2843
2768
|
if (functionFragment.isInputDataPointer) {
|
2844
2769
|
if (rawPayload) {
|
2845
|
-
const argsOffset = (0,
|
2770
|
+
const argsOffset = (0, import_math11.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2846
2771
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2847
2772
|
}
|
2848
2773
|
} else {
|
@@ -2876,8 +2801,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2876
2801
|
};
|
2877
2802
|
|
2878
2803
|
// src/providers/transaction-summary/input.ts
|
2879
|
-
var
|
2880
|
-
var
|
2804
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2805
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2881
2806
|
function getInputsByTypes(inputs, types) {
|
2882
2807
|
return inputs.filter((i) => types.includes(i.type));
|
2883
2808
|
}
|
@@ -2885,16 +2810,16 @@ function getInputsByType(inputs, type) {
|
|
2885
2810
|
return inputs.filter((i) => i.type === type);
|
2886
2811
|
}
|
2887
2812
|
function getInputsCoin(inputs) {
|
2888
|
-
return getInputsByType(inputs,
|
2813
|
+
return getInputsByType(inputs, import_transactions11.InputType.Coin);
|
2889
2814
|
}
|
2890
2815
|
function getInputsMessage(inputs) {
|
2891
|
-
return getInputsByType(inputs,
|
2816
|
+
return getInputsByType(inputs, import_transactions11.InputType.Message);
|
2892
2817
|
}
|
2893
2818
|
function getInputsCoinAndMessage(inputs) {
|
2894
|
-
return getInputsByTypes(inputs, [
|
2819
|
+
return getInputsByTypes(inputs, [import_transactions11.InputType.Coin, import_transactions11.InputType.Message]);
|
2895
2820
|
}
|
2896
2821
|
function getInputsContract(inputs) {
|
2897
|
-
return getInputsByType(inputs,
|
2822
|
+
return getInputsByType(inputs, import_transactions11.InputType.Contract);
|
2898
2823
|
}
|
2899
2824
|
function getInputFromAssetId(inputs, assetId) {
|
2900
2825
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2913,43 +2838,43 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2913
2838
|
if (!contractInput) {
|
2914
2839
|
return void 0;
|
2915
2840
|
}
|
2916
|
-
if (contractInput.type !==
|
2917
|
-
throw new
|
2918
|
-
|
2841
|
+
if (contractInput.type !== import_transactions11.InputType.Contract) {
|
2842
|
+
throw new import_errors9.FuelError(
|
2843
|
+
import_errors9.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2919
2844
|
`Contract input should be of type 'contract'.`
|
2920
2845
|
);
|
2921
2846
|
}
|
2922
2847
|
return contractInput;
|
2923
2848
|
}
|
2924
2849
|
function getInputAccountAddress(input) {
|
2925
|
-
if (input.type ===
|
2850
|
+
if (input.type === import_transactions11.InputType.Coin) {
|
2926
2851
|
return input.owner.toString();
|
2927
2852
|
}
|
2928
|
-
if (input.type ===
|
2853
|
+
if (input.type === import_transactions11.InputType.Message) {
|
2929
2854
|
return input.recipient.toString();
|
2930
2855
|
}
|
2931
2856
|
return "";
|
2932
2857
|
}
|
2933
2858
|
|
2934
2859
|
// src/providers/transaction-summary/output.ts
|
2935
|
-
var
|
2860
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2936
2861
|
function getOutputsByType(outputs, type) {
|
2937
2862
|
return outputs.filter((o) => o.type === type);
|
2938
2863
|
}
|
2939
2864
|
function getOutputsContractCreated(outputs) {
|
2940
|
-
return getOutputsByType(outputs,
|
2865
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.ContractCreated);
|
2941
2866
|
}
|
2942
2867
|
function getOutputsCoin(outputs) {
|
2943
|
-
return getOutputsByType(outputs,
|
2868
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Coin);
|
2944
2869
|
}
|
2945
2870
|
function getOutputsChange(outputs) {
|
2946
|
-
return getOutputsByType(outputs,
|
2871
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Change);
|
2947
2872
|
}
|
2948
2873
|
function getOutputsContract(outputs) {
|
2949
|
-
return getOutputsByType(outputs,
|
2874
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Contract);
|
2950
2875
|
}
|
2951
2876
|
function getOutputsVariable(outputs) {
|
2952
|
-
return getOutputsByType(outputs,
|
2877
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Variable);
|
2953
2878
|
}
|
2954
2879
|
|
2955
2880
|
// src/providers/transaction-summary/types.ts
|
@@ -2996,15 +2921,15 @@ function getReceiptsByType(receipts, type) {
|
|
2996
2921
|
}
|
2997
2922
|
function getTransactionTypeName(transactionType) {
|
2998
2923
|
switch (transactionType) {
|
2999
|
-
case
|
2924
|
+
case import_transactions13.TransactionType.Mint:
|
3000
2925
|
return "Mint" /* Mint */;
|
3001
|
-
case
|
2926
|
+
case import_transactions13.TransactionType.Create:
|
3002
2927
|
return "Create" /* Create */;
|
3003
|
-
case
|
2928
|
+
case import_transactions13.TransactionType.Script:
|
3004
2929
|
return "Script" /* Script */;
|
3005
2930
|
default:
|
3006
|
-
throw new
|
3007
|
-
|
2931
|
+
throw new import_errors10.FuelError(
|
2932
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_TYPE,
|
3008
2933
|
`Invalid transaction type: ${transactionType}.`
|
3009
2934
|
);
|
3010
2935
|
}
|
@@ -3026,10 +2951,10 @@ function hasSameAssetId(a) {
|
|
3026
2951
|
return (b) => a.assetId === b.assetId;
|
3027
2952
|
}
|
3028
2953
|
function getReceiptsCall(receipts) {
|
3029
|
-
return getReceiptsByType(receipts,
|
2954
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.Call);
|
3030
2955
|
}
|
3031
2956
|
function getReceiptsMessageOut(receipts) {
|
3032
|
-
return getReceiptsByType(receipts,
|
2957
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.MessageOut);
|
3033
2958
|
}
|
3034
2959
|
var mergeAssets = (op1, op2) => {
|
3035
2960
|
const assets1 = op1.assetsSent || [];
|
@@ -3042,7 +2967,7 @@ var mergeAssets = (op1, op2) => {
|
|
3042
2967
|
if (!matchingAsset) {
|
3043
2968
|
return asset1;
|
3044
2969
|
}
|
3045
|
-
const mergedAmount = (0,
|
2970
|
+
const mergedAmount = (0, import_math12.bn)(asset1.amount).add(matchingAsset.amount);
|
3046
2971
|
return { ...asset1, amount: mergedAmount };
|
3047
2972
|
});
|
3048
2973
|
return mergedAssets.concat(filteredAssets);
|
@@ -3068,7 +2993,7 @@ function addOperation(operations, toAdd) {
|
|
3068
2993
|
return allOperations;
|
3069
2994
|
}
|
3070
2995
|
function getReceiptsTransferOut(receipts) {
|
3071
|
-
return getReceiptsByType(receipts,
|
2996
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.TransferOut);
|
3072
2997
|
}
|
3073
2998
|
function getWithdrawFromFuelOperations({
|
3074
2999
|
inputs,
|
@@ -3171,7 +3096,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3171
3096
|
const { to: toAddress, assetId, amount } = receipt;
|
3172
3097
|
let { from: fromAddress } = receipt;
|
3173
3098
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3174
|
-
if (
|
3099
|
+
if (import_configs9.ZeroBytes32 === fromAddress) {
|
3175
3100
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3176
3101
|
fromAddress = change?.to || fromAddress;
|
3177
3102
|
}
|
@@ -3228,11 +3153,11 @@ function getTransferOperations({
|
|
3228
3153
|
});
|
3229
3154
|
const transferReceipts = getReceiptsByType(
|
3230
3155
|
receipts,
|
3231
|
-
|
3156
|
+
import_transactions13.ReceiptType.Transfer
|
3232
3157
|
);
|
3233
3158
|
const transferOutReceipts = getReceiptsByType(
|
3234
3159
|
receipts,
|
3235
|
-
|
3160
|
+
import_transactions13.ReceiptType.TransferOut
|
3236
3161
|
);
|
3237
3162
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3238
3163
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3317,17 +3242,17 @@ function getOperations({
|
|
3317
3242
|
}
|
3318
3243
|
|
3319
3244
|
// src/providers/transaction-summary/receipt.ts
|
3320
|
-
var
|
3245
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
3321
3246
|
var processGqlReceipt = (gqlReceipt) => {
|
3322
3247
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3323
3248
|
switch (receipt.type) {
|
3324
|
-
case
|
3249
|
+
case import_transactions14.ReceiptType.ReturnData: {
|
3325
3250
|
return {
|
3326
3251
|
...receipt,
|
3327
3252
|
data: gqlReceipt.data || "0x"
|
3328
3253
|
};
|
3329
3254
|
}
|
3330
|
-
case
|
3255
|
+
case import_transactions14.ReceiptType.LogData: {
|
3331
3256
|
return {
|
3332
3257
|
...receipt,
|
3333
3258
|
data: gqlReceipt.data || "0x"
|
@@ -3340,7 +3265,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3340
3265
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3341
3266
|
const mintedAssets = [];
|
3342
3267
|
receipts.forEach((receipt) => {
|
3343
|
-
if (receipt.type ===
|
3268
|
+
if (receipt.type === import_transactions14.ReceiptType.Mint) {
|
3344
3269
|
mintedAssets.push({
|
3345
3270
|
subId: receipt.subId,
|
3346
3271
|
contractId: receipt.contractId,
|
@@ -3354,7 +3279,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3354
3279
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3355
3280
|
const burnedAssets = [];
|
3356
3281
|
receipts.forEach((receipt) => {
|
3357
|
-
if (receipt.type ===
|
3282
|
+
if (receipt.type === import_transactions14.ReceiptType.Burn) {
|
3358
3283
|
burnedAssets.push({
|
3359
3284
|
subId: receipt.subId,
|
3360
3285
|
contractId: receipt.contractId,
|
@@ -3367,7 +3292,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3367
3292
|
};
|
3368
3293
|
|
3369
3294
|
// src/providers/transaction-summary/status.ts
|
3370
|
-
var
|
3295
|
+
var import_errors11 = require("@fuel-ts/errors");
|
3371
3296
|
var getTransactionStatusName = (gqlStatus) => {
|
3372
3297
|
switch (gqlStatus) {
|
3373
3298
|
case "FailureStatus":
|
@@ -3379,8 +3304,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3379
3304
|
case "SqueezedOutStatus":
|
3380
3305
|
return "squeezedout" /* squeezedout */;
|
3381
3306
|
default:
|
3382
|
-
throw new
|
3383
|
-
|
3307
|
+
throw new import_errors11.FuelError(
|
3308
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3384
3309
|
`Invalid transaction status: ${gqlStatus}.`
|
3385
3310
|
);
|
3386
3311
|
}
|
@@ -3493,12 +3418,12 @@ function assembleTransactionSummary(params) {
|
|
3493
3418
|
|
3494
3419
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3495
3420
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3496
|
-
var
|
3421
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3497
3422
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3498
3423
|
return receipts.reduce((logs, receipt) => {
|
3499
|
-
if (receipt.type ===
|
3424
|
+
if (receipt.type === import_transactions15.ReceiptType.LogData || receipt.type === import_transactions15.ReceiptType.Log) {
|
3500
3425
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3501
|
-
const data = receipt.type ===
|
3426
|
+
const data = receipt.type === import_transactions15.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3502
3427
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3503
3428
|
logs.push(decodedLog);
|
3504
3429
|
}
|
@@ -3513,7 +3438,7 @@ var TransactionResponse = class {
|
|
3513
3438
|
/** Current provider */
|
3514
3439
|
provider;
|
3515
3440
|
/** Gas used on the transaction */
|
3516
|
-
gasUsed = (0,
|
3441
|
+
gasUsed = (0, import_math13.bn)(0);
|
3517
3442
|
/** The graphql Transaction with receipts object. */
|
3518
3443
|
gqlTransaction;
|
3519
3444
|
abis;
|
@@ -3571,7 +3496,7 @@ var TransactionResponse = class {
|
|
3571
3496
|
* @returns The decoded transaction.
|
3572
3497
|
*/
|
3573
3498
|
decodeTransaction(transactionWithReceipts) {
|
3574
|
-
return new
|
3499
|
+
return new import_transactions16.TransactionCoder().decode(
|
3575
3500
|
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3576
3501
|
0
|
3577
3502
|
)?.[0];
|
@@ -3618,8 +3543,8 @@ var TransactionResponse = class {
|
|
3618
3543
|
});
|
3619
3544
|
for await (const { statusChange } of subscription) {
|
3620
3545
|
if (statusChange.type === "SqueezedOutStatus") {
|
3621
|
-
throw new
|
3622
|
-
|
3546
|
+
throw new import_errors12.FuelError(
|
3547
|
+
import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3623
3548
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3624
3549
|
);
|
3625
3550
|
}
|
@@ -3641,26 +3566,14 @@ var TransactionResponse = class {
|
|
3641
3566
|
gqlTransaction: this.gqlTransaction,
|
3642
3567
|
...transactionSummary
|
3643
3568
|
};
|
3644
|
-
let logs = [];
|
3645
3569
|
if (this.abis) {
|
3646
|
-
logs = getDecodedLogs(
|
3570
|
+
const logs = getDecodedLogs(
|
3647
3571
|
transactionSummary.receipts,
|
3648
3572
|
this.abis.main,
|
3649
3573
|
this.abis.otherContractsAbis
|
3650
3574
|
);
|
3651
3575
|
transactionResult.logs = logs;
|
3652
3576
|
}
|
3653
|
-
if (transactionResult.isStatusFailure) {
|
3654
|
-
const {
|
3655
|
-
receipts,
|
3656
|
-
gqlTransaction: { status }
|
3657
|
-
} = transactionResult;
|
3658
|
-
throw extractTxError({
|
3659
|
-
receipts,
|
3660
|
-
status,
|
3661
|
-
logs
|
3662
|
-
});
|
3663
|
-
}
|
3664
3577
|
return transactionResult;
|
3665
3578
|
}
|
3666
3579
|
/**
|
@@ -3669,7 +3582,14 @@ var TransactionResponse = class {
|
|
3669
3582
|
* @param contractsAbiMap - The contracts ABI map.
|
3670
3583
|
*/
|
3671
3584
|
async wait(contractsAbiMap) {
|
3672
|
-
|
3585
|
+
const result = await this.waitForResult(contractsAbiMap);
|
3586
|
+
if (result.isStatusFailure) {
|
3587
|
+
throw new import_errors12.FuelError(
|
3588
|
+
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3589
|
+
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3590
|
+
);
|
3591
|
+
}
|
3592
|
+
return result;
|
3673
3593
|
}
|
3674
3594
|
};
|
3675
3595
|
|
@@ -3731,30 +3651,30 @@ var processGqlChain = (chain) => {
|
|
3731
3651
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3732
3652
|
return {
|
3733
3653
|
name,
|
3734
|
-
baseChainHeight: (0,
|
3654
|
+
baseChainHeight: (0, import_math14.bn)(daHeight),
|
3735
3655
|
consensusParameters: {
|
3736
|
-
contractMaxSize: (0,
|
3737
|
-
maxInputs: (0,
|
3738
|
-
maxOutputs: (0,
|
3739
|
-
maxWitnesses: (0,
|
3740
|
-
maxGasPerTx: (0,
|
3741
|
-
maxScriptLength: (0,
|
3742
|
-
maxScriptDataLength: (0,
|
3743
|
-
maxStorageSlots: (0,
|
3744
|
-
maxPredicateLength: (0,
|
3745
|
-
maxPredicateDataLength: (0,
|
3746
|
-
maxGasPerPredicate: (0,
|
3747
|
-
gasPriceFactor: (0,
|
3748
|
-
gasPerByte: (0,
|
3749
|
-
maxMessageDataLength: (0,
|
3750
|
-
chainId: (0,
|
3656
|
+
contractMaxSize: (0, import_math14.bn)(contractParams.contractMaxSize),
|
3657
|
+
maxInputs: (0, import_math14.bn)(txParams.maxInputs),
|
3658
|
+
maxOutputs: (0, import_math14.bn)(txParams.maxOutputs),
|
3659
|
+
maxWitnesses: (0, import_math14.bn)(txParams.maxWitnesses),
|
3660
|
+
maxGasPerTx: (0, import_math14.bn)(txParams.maxGasPerTx),
|
3661
|
+
maxScriptLength: (0, import_math14.bn)(scriptParams.maxScriptLength),
|
3662
|
+
maxScriptDataLength: (0, import_math14.bn)(scriptParams.maxScriptDataLength),
|
3663
|
+
maxStorageSlots: (0, import_math14.bn)(contractParams.maxStorageSlots),
|
3664
|
+
maxPredicateLength: (0, import_math14.bn)(predicateParams.maxPredicateLength),
|
3665
|
+
maxPredicateDataLength: (0, import_math14.bn)(predicateParams.maxPredicateDataLength),
|
3666
|
+
maxGasPerPredicate: (0, import_math14.bn)(predicateParams.maxGasPerPredicate),
|
3667
|
+
gasPriceFactor: (0, import_math14.bn)(feeParams.gasPriceFactor),
|
3668
|
+
gasPerByte: (0, import_math14.bn)(feeParams.gasPerByte),
|
3669
|
+
maxMessageDataLength: (0, import_math14.bn)(predicateParams.maxMessageDataLength),
|
3670
|
+
chainId: (0, import_math14.bn)(consensusParameters.chainId),
|
3751
3671
|
baseAssetId: consensusParameters.baseAssetId,
|
3752
3672
|
gasCosts
|
3753
3673
|
},
|
3754
3674
|
gasCosts,
|
3755
3675
|
latestBlock: {
|
3756
3676
|
id: latestBlock.id,
|
3757
|
-
height: (0,
|
3677
|
+
height: (0, import_math14.bn)(latestBlock.header.height),
|
3758
3678
|
time: latestBlock.header.time,
|
3759
3679
|
transactions: latestBlock.transactions.map((i) => ({
|
3760
3680
|
id: i.id
|
@@ -3824,8 +3744,8 @@ var _Provider = class {
|
|
3824
3744
|
getChain() {
|
3825
3745
|
const chain = _Provider.chainInfoCache[this.url];
|
3826
3746
|
if (!chain) {
|
3827
|
-
throw new
|
3828
|
-
|
3747
|
+
throw new import_errors13.FuelError(
|
3748
|
+
import_errors13.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3829
3749
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3830
3750
|
);
|
3831
3751
|
}
|
@@ -3837,8 +3757,8 @@ var _Provider = class {
|
|
3837
3757
|
getNode() {
|
3838
3758
|
const node = _Provider.nodeInfoCache[this.url];
|
3839
3759
|
if (!node) {
|
3840
|
-
throw new
|
3841
|
-
|
3760
|
+
throw new import_errors13.FuelError(
|
3761
|
+
import_errors13.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3842
3762
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3843
3763
|
);
|
3844
3764
|
}
|
@@ -3885,8 +3805,8 @@ var _Provider = class {
|
|
3885
3805
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3886
3806
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3887
3807
|
if (!isMajorSupported || !isMinorSupported) {
|
3888
|
-
throw new
|
3889
|
-
|
3808
|
+
throw new import_errors13.FuelError(
|
3809
|
+
import_errors13.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3890
3810
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3891
3811
|
);
|
3892
3812
|
}
|
@@ -3949,7 +3869,7 @@ var _Provider = class {
|
|
3949
3869
|
*/
|
3950
3870
|
async getBlockNumber() {
|
3951
3871
|
const { chain } = await this.operations.getChain();
|
3952
|
-
return (0,
|
3872
|
+
return (0, import_math14.bn)(chain.latestBlock.header.height, 10);
|
3953
3873
|
}
|
3954
3874
|
/**
|
3955
3875
|
* Returns the chain information.
|
@@ -3959,9 +3879,9 @@ var _Provider = class {
|
|
3959
3879
|
async fetchNode() {
|
3960
3880
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3961
3881
|
const processedNodeInfo = {
|
3962
|
-
maxDepth: (0,
|
3963
|
-
maxTx: (0,
|
3964
|
-
minGasPrice: (0,
|
3882
|
+
maxDepth: (0, import_math14.bn)(nodeInfo.maxDepth),
|
3883
|
+
maxTx: (0, import_math14.bn)(nodeInfo.maxTx),
|
3884
|
+
minGasPrice: (0, import_math14.bn)(nodeInfo.minGasPrice),
|
3965
3885
|
nodeVersion: nodeInfo.nodeVersion,
|
3966
3886
|
utxoValidation: nodeInfo.utxoValidation,
|
3967
3887
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -4018,17 +3938,17 @@ var _Provider = class {
|
|
4018
3938
|
if (estimateTxDependencies) {
|
4019
3939
|
await this.estimateTxDependencies(transactionRequest);
|
4020
3940
|
}
|
4021
|
-
const encodedTransaction = (0,
|
3941
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4022
3942
|
let abis;
|
4023
|
-
if (transactionRequest.type ===
|
3943
|
+
if (transactionRequest.type === import_transactions17.TransactionType.Script) {
|
4024
3944
|
abis = transactionRequest.abis;
|
4025
3945
|
}
|
4026
3946
|
if (awaitExecution) {
|
4027
3947
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
4028
3948
|
for await (const { submitAndAwait } of subscription) {
|
4029
3949
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
4030
|
-
throw new
|
4031
|
-
|
3950
|
+
throw new import_errors13.FuelError(
|
3951
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
4032
3952
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
4033
3953
|
);
|
4034
3954
|
}
|
@@ -4061,7 +3981,7 @@ var _Provider = class {
|
|
4061
3981
|
if (estimateTxDependencies) {
|
4062
3982
|
return this.estimateTxDependencies(transactionRequest);
|
4063
3983
|
}
|
4064
|
-
const encodedTransaction = (0,
|
3984
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4065
3985
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4066
3986
|
encodedTransaction,
|
4067
3987
|
utxoValidation: utxoValidation || false
|
@@ -4080,13 +4000,13 @@ var _Provider = class {
|
|
4080
4000
|
async estimatePredicates(transactionRequest) {
|
4081
4001
|
const shouldEstimatePredicates = Boolean(
|
4082
4002
|
transactionRequest.inputs.find(
|
4083
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
4003
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
|
4084
4004
|
)
|
4085
4005
|
);
|
4086
4006
|
if (!shouldEstimatePredicates) {
|
4087
4007
|
return transactionRequest;
|
4088
4008
|
}
|
4089
|
-
const encodedTransaction = (0,
|
4009
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4090
4010
|
const response = await this.operations.estimatePredicates({
|
4091
4011
|
encodedTransaction
|
4092
4012
|
});
|
@@ -4095,7 +4015,7 @@ var _Provider = class {
|
|
4095
4015
|
} = response;
|
4096
4016
|
if (inputs) {
|
4097
4017
|
inputs.forEach((input, index) => {
|
4098
|
-
if ("predicateGasUsed" in input && (0,
|
4018
|
+
if ("predicateGasUsed" in input && (0, import_math14.bn)(input.predicateGasUsed).gt(0)) {
|
4099
4019
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4100
4020
|
}
|
4101
4021
|
});
|
@@ -4116,7 +4036,7 @@ var _Provider = class {
|
|
4116
4036
|
* @returns A promise.
|
4117
4037
|
*/
|
4118
4038
|
async estimateTxDependencies(transactionRequest) {
|
4119
|
-
if (transactionRequest.type ===
|
4039
|
+
if (transactionRequest.type === import_transactions17.TransactionType.Create) {
|
4120
4040
|
return {
|
4121
4041
|
receipts: [],
|
4122
4042
|
outputVariables: 0,
|
@@ -4129,7 +4049,7 @@ var _Provider = class {
|
|
4129
4049
|
let outputVariables = 0;
|
4130
4050
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4131
4051
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4132
|
-
encodedTransaction: (0,
|
4052
|
+
encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
|
4133
4053
|
utxoValidation: false
|
4134
4054
|
});
|
4135
4055
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -4167,7 +4087,7 @@ var _Provider = class {
|
|
4167
4087
|
if (estimateTxDependencies) {
|
4168
4088
|
return this.estimateTxDependencies(transactionRequest);
|
4169
4089
|
}
|
4170
|
-
const encodedTransaction = (0,
|
4090
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4171
4091
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4172
4092
|
encodedTransaction,
|
4173
4093
|
utxoValidation: true
|
@@ -4201,14 +4121,14 @@ var _Provider = class {
|
|
4201
4121
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4202
4122
|
const chainInfo = this.getChain();
|
4203
4123
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4204
|
-
const gasPrice = (0,
|
4205
|
-
const isScriptTransaction = txRequestClone.type ===
|
4124
|
+
const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
|
4125
|
+
const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
|
4206
4126
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4207
4127
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4208
4128
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4209
4129
|
if (estimatePredicates) {
|
4210
4130
|
if (isScriptTransaction) {
|
4211
|
-
txRequestClone.gasLimit = (0,
|
4131
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(0);
|
4212
4132
|
}
|
4213
4133
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4214
4134
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4224,8 +4144,8 @@ var _Provider = class {
|
|
4224
4144
|
let missingContractIds = [];
|
4225
4145
|
let outputVariables = 0;
|
4226
4146
|
if (isScriptTransaction && estimateTxDependencies) {
|
4227
|
-
txRequestClone.gasPrice = (0,
|
4228
|
-
txRequestClone.gasLimit = (0,
|
4147
|
+
txRequestClone.gasPrice = (0, import_math14.bn)(0);
|
4148
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4229
4149
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4230
4150
|
receipts = result.receipts;
|
4231
4151
|
outputVariables = result.outputVariables;
|
@@ -4281,17 +4201,17 @@ var _Provider = class {
|
|
4281
4201
|
const result = await this.operations.getCoins({
|
4282
4202
|
first: 10,
|
4283
4203
|
...paginationArgs,
|
4284
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4204
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4285
4205
|
});
|
4286
4206
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4287
4207
|
return coins.map((coin) => ({
|
4288
4208
|
id: coin.utxoId,
|
4289
4209
|
assetId: coin.assetId,
|
4290
|
-
amount: (0,
|
4210
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4291
4211
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4292
|
-
maturity: (0,
|
4293
|
-
blockCreated: (0,
|
4294
|
-
txCreatedIdx: (0,
|
4212
|
+
maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
|
4213
|
+
blockCreated: (0, import_math14.bn)(coin.blockCreated),
|
4214
|
+
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4295
4215
|
}));
|
4296
4216
|
}
|
4297
4217
|
/**
|
@@ -4305,19 +4225,19 @@ var _Provider = class {
|
|
4305
4225
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4306
4226
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4307
4227
|
const excludeInput = {
|
4308
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4309
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4228
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4229
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4310
4230
|
};
|
4311
4231
|
if (this.cache) {
|
4312
4232
|
const uniqueUtxos = new Set(
|
4313
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4233
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4314
4234
|
);
|
4315
4235
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4316
4236
|
}
|
4317
4237
|
const coinsQuery = {
|
4318
4238
|
owner: ownerAddress.toB256(),
|
4319
4239
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4320
|
-
assetId: (0,
|
4240
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4321
4241
|
amount: amount.toString(10),
|
4322
4242
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4323
4243
|
})),
|
@@ -4328,9 +4248,9 @@ var _Provider = class {
|
|
4328
4248
|
switch (coin.__typename) {
|
4329
4249
|
case "MessageCoin":
|
4330
4250
|
return {
|
4331
|
-
amount: (0,
|
4251
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4332
4252
|
assetId: coin.assetId,
|
4333
|
-
daHeight: (0,
|
4253
|
+
daHeight: (0, import_math14.bn)(coin.daHeight),
|
4334
4254
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4335
4255
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4336
4256
|
nonce: coin.nonce
|
@@ -4338,12 +4258,12 @@ var _Provider = class {
|
|
4338
4258
|
case "Coin":
|
4339
4259
|
return {
|
4340
4260
|
id: coin.utxoId,
|
4341
|
-
amount: (0,
|
4261
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4342
4262
|
assetId: coin.assetId,
|
4343
4263
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4344
|
-
maturity: (0,
|
4345
|
-
blockCreated: (0,
|
4346
|
-
txCreatedIdx: (0,
|
4264
|
+
maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
|
4265
|
+
blockCreated: (0, import_math14.bn)(coin.blockCreated),
|
4266
|
+
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4347
4267
|
};
|
4348
4268
|
default:
|
4349
4269
|
return null;
|
@@ -4360,13 +4280,13 @@ var _Provider = class {
|
|
4360
4280
|
async getBlock(idOrHeight) {
|
4361
4281
|
let variables;
|
4362
4282
|
if (typeof idOrHeight === "number") {
|
4363
|
-
variables = { height: (0,
|
4283
|
+
variables = { height: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4364
4284
|
} else if (idOrHeight === "latest") {
|
4365
4285
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4366
4286
|
} else if (idOrHeight.length === 66) {
|
4367
4287
|
variables = { blockId: idOrHeight };
|
4368
4288
|
} else {
|
4369
|
-
variables = { blockId: (0,
|
4289
|
+
variables = { blockId: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4370
4290
|
}
|
4371
4291
|
const { block } = await this.operations.getBlock(variables);
|
4372
4292
|
if (!block) {
|
@@ -4374,7 +4294,7 @@ var _Provider = class {
|
|
4374
4294
|
}
|
4375
4295
|
return {
|
4376
4296
|
id: block.id,
|
4377
|
-
height: (0,
|
4297
|
+
height: (0, import_math14.bn)(block.header.height),
|
4378
4298
|
time: block.header.time,
|
4379
4299
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4380
4300
|
};
|
@@ -4389,7 +4309,7 @@ var _Provider = class {
|
|
4389
4309
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4390
4310
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4391
4311
|
id: block.id,
|
4392
|
-
height: (0,
|
4312
|
+
height: (0, import_math14.bn)(block.header.height),
|
4393
4313
|
time: block.header.time,
|
4394
4314
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4395
4315
|
}));
|
@@ -4404,7 +4324,7 @@ var _Provider = class {
|
|
4404
4324
|
async getBlockWithTransactions(idOrHeight) {
|
4405
4325
|
let variables;
|
4406
4326
|
if (typeof idOrHeight === "number") {
|
4407
|
-
variables = { blockHeight: (0,
|
4327
|
+
variables = { blockHeight: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4408
4328
|
} else if (idOrHeight === "latest") {
|
4409
4329
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4410
4330
|
} else {
|
@@ -4416,11 +4336,11 @@ var _Provider = class {
|
|
4416
4336
|
}
|
4417
4337
|
return {
|
4418
4338
|
id: block.id,
|
4419
|
-
height: (0,
|
4339
|
+
height: (0, import_math14.bn)(block.header.height, 10),
|
4420
4340
|
time: block.header.time,
|
4421
4341
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4422
4342
|
transactions: block.transactions.map(
|
4423
|
-
(tx) => new
|
4343
|
+
(tx) => new import_transactions17.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4424
4344
|
)
|
4425
4345
|
};
|
4426
4346
|
}
|
@@ -4435,8 +4355,8 @@ var _Provider = class {
|
|
4435
4355
|
if (!transaction) {
|
4436
4356
|
return null;
|
4437
4357
|
}
|
4438
|
-
return new
|
4439
|
-
(0,
|
4358
|
+
return new import_transactions17.TransactionCoder().decode(
|
4359
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4440
4360
|
0
|
4441
4361
|
)?.[0];
|
4442
4362
|
}
|
@@ -4463,9 +4383,9 @@ var _Provider = class {
|
|
4463
4383
|
async getContractBalance(contractId, assetId) {
|
4464
4384
|
const { contractBalance } = await this.operations.getContractBalance({
|
4465
4385
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4466
|
-
asset: (0,
|
4386
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4467
4387
|
});
|
4468
|
-
return (0,
|
4388
|
+
return (0, import_math14.bn)(contractBalance.amount, 10);
|
4469
4389
|
}
|
4470
4390
|
/**
|
4471
4391
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4477,9 +4397,9 @@ var _Provider = class {
|
|
4477
4397
|
async getBalance(owner, assetId) {
|
4478
4398
|
const { balance } = await this.operations.getBalance({
|
4479
4399
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4480
|
-
assetId: (0,
|
4400
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4481
4401
|
});
|
4482
|
-
return (0,
|
4402
|
+
return (0, import_math14.bn)(balance.amount, 10);
|
4483
4403
|
}
|
4484
4404
|
/**
|
4485
4405
|
* Returns balances for the given owner.
|
@@ -4497,7 +4417,7 @@ var _Provider = class {
|
|
4497
4417
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4498
4418
|
return balances.map((balance) => ({
|
4499
4419
|
assetId: balance.assetId,
|
4500
|
-
amount: (0,
|
4420
|
+
amount: (0, import_math14.bn)(balance.amount)
|
4501
4421
|
}));
|
4502
4422
|
}
|
4503
4423
|
/**
|
@@ -4515,19 +4435,19 @@ var _Provider = class {
|
|
4515
4435
|
});
|
4516
4436
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4517
4437
|
return messages.map((message) => ({
|
4518
|
-
messageId:
|
4438
|
+
messageId: import_transactions17.InputMessageCoder.getMessageId({
|
4519
4439
|
sender: message.sender,
|
4520
4440
|
recipient: message.recipient,
|
4521
4441
|
nonce: message.nonce,
|
4522
|
-
amount: (0,
|
4442
|
+
amount: (0, import_math14.bn)(message.amount),
|
4523
4443
|
data: message.data
|
4524
4444
|
}),
|
4525
4445
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4526
4446
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4527
4447
|
nonce: message.nonce,
|
4528
|
-
amount: (0,
|
4529
|
-
data:
|
4530
|
-
daHeight: (0,
|
4448
|
+
amount: (0, import_math14.bn)(message.amount),
|
4449
|
+
data: import_transactions17.InputMessageCoder.decodeData(message.data),
|
4450
|
+
daHeight: (0, import_math14.bn)(message.daHeight)
|
4531
4451
|
}));
|
4532
4452
|
}
|
4533
4453
|
/**
|
@@ -4545,8 +4465,8 @@ var _Provider = class {
|
|
4545
4465
|
nonce
|
4546
4466
|
};
|
4547
4467
|
if (commitBlockId && commitBlockHeight) {
|
4548
|
-
throw new
|
4549
|
-
|
4468
|
+
throw new import_errors13.FuelError(
|
4469
|
+
import_errors13.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4550
4470
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4551
4471
|
);
|
4552
4472
|
}
|
@@ -4580,41 +4500,41 @@ var _Provider = class {
|
|
4580
4500
|
} = result.messageProof;
|
4581
4501
|
return {
|
4582
4502
|
messageProof: {
|
4583
|
-
proofIndex: (0,
|
4503
|
+
proofIndex: (0, import_math14.bn)(messageProof.proofIndex),
|
4584
4504
|
proofSet: messageProof.proofSet
|
4585
4505
|
},
|
4586
4506
|
blockProof: {
|
4587
|
-
proofIndex: (0,
|
4507
|
+
proofIndex: (0, import_math14.bn)(blockProof.proofIndex),
|
4588
4508
|
proofSet: blockProof.proofSet
|
4589
4509
|
},
|
4590
4510
|
messageBlockHeader: {
|
4591
4511
|
id: messageBlockHeader.id,
|
4592
|
-
daHeight: (0,
|
4593
|
-
transactionsCount: (0,
|
4512
|
+
daHeight: (0, import_math14.bn)(messageBlockHeader.daHeight),
|
4513
|
+
transactionsCount: (0, import_math14.bn)(messageBlockHeader.transactionsCount),
|
4594
4514
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4595
|
-
height: (0,
|
4515
|
+
height: (0, import_math14.bn)(messageBlockHeader.height),
|
4596
4516
|
prevRoot: messageBlockHeader.prevRoot,
|
4597
4517
|
time: messageBlockHeader.time,
|
4598
4518
|
applicationHash: messageBlockHeader.applicationHash,
|
4599
4519
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4600
|
-
messageReceiptCount: (0,
|
4520
|
+
messageReceiptCount: (0, import_math14.bn)(messageBlockHeader.messageReceiptCount)
|
4601
4521
|
},
|
4602
4522
|
commitBlockHeader: {
|
4603
4523
|
id: commitBlockHeader.id,
|
4604
|
-
daHeight: (0,
|
4605
|
-
transactionsCount: (0,
|
4524
|
+
daHeight: (0, import_math14.bn)(commitBlockHeader.daHeight),
|
4525
|
+
transactionsCount: (0, import_math14.bn)(commitBlockHeader.transactionsCount),
|
4606
4526
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4607
|
-
height: (0,
|
4527
|
+
height: (0, import_math14.bn)(commitBlockHeader.height),
|
4608
4528
|
prevRoot: commitBlockHeader.prevRoot,
|
4609
4529
|
time: commitBlockHeader.time,
|
4610
4530
|
applicationHash: commitBlockHeader.applicationHash,
|
4611
4531
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4612
|
-
messageReceiptCount: (0,
|
4532
|
+
messageReceiptCount: (0, import_math14.bn)(commitBlockHeader.messageReceiptCount)
|
4613
4533
|
},
|
4614
4534
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4615
4535
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4616
4536
|
nonce,
|
4617
|
-
amount: (0,
|
4537
|
+
amount: (0, import_math14.bn)(amount),
|
4618
4538
|
data
|
4619
4539
|
};
|
4620
4540
|
}
|
@@ -4637,10 +4557,10 @@ var _Provider = class {
|
|
4637
4557
|
*/
|
4638
4558
|
async produceBlocks(amount, startTime) {
|
4639
4559
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4640
|
-
blocksToProduce: (0,
|
4641
|
-
startTimestamp: startTime ?
|
4560
|
+
blocksToProduce: (0, import_math14.bn)(amount).toString(10),
|
4561
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4642
4562
|
});
|
4643
|
-
return (0,
|
4563
|
+
return (0, import_math14.bn)(latestBlockHeight);
|
4644
4564
|
}
|
4645
4565
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4646
4566
|
async getTransactionResponse(transactionId) {
|
@@ -4654,7 +4574,7 @@ cacheInputs_fn = function(inputs) {
|
|
4654
4574
|
return;
|
4655
4575
|
}
|
4656
4576
|
inputs.forEach((input) => {
|
4657
|
-
if (input.type ===
|
4577
|
+
if (input.type === import_transactions17.InputType.Coin) {
|
4658
4578
|
this.cache?.set(input.id);
|
4659
4579
|
}
|
4660
4580
|
});
|
@@ -4663,23 +4583,23 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4663
4583
|
__publicField(Provider, "nodeInfoCache", {});
|
4664
4584
|
|
4665
4585
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4666
|
-
var
|
4667
|
-
var
|
4668
|
-
var
|
4669
|
-
var
|
4586
|
+
var import_errors14 = require("@fuel-ts/errors");
|
4587
|
+
var import_math15 = require("@fuel-ts/math");
|
4588
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
4589
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4670
4590
|
async function getTransactionSummary(params) {
|
4671
4591
|
const { id, provider, abiMap } = params;
|
4672
4592
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
4673
4593
|
transactionId: id
|
4674
4594
|
});
|
4675
4595
|
if (!gqlTransaction) {
|
4676
|
-
throw new
|
4677
|
-
|
4596
|
+
throw new import_errors14.FuelError(
|
4597
|
+
import_errors14.ErrorCode.TRANSACTION_NOT_FOUND,
|
4678
4598
|
`Transaction not found for given id: ${id}.`
|
4679
4599
|
);
|
4680
4600
|
}
|
4681
|
-
const [decodedTransaction] = new
|
4682
|
-
(0,
|
4601
|
+
const [decodedTransaction] = new import_transactions18.TransactionCoder().decode(
|
4602
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4683
4603
|
0
|
4684
4604
|
);
|
4685
4605
|
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
@@ -4690,10 +4610,10 @@ async function getTransactionSummary(params) {
|
|
4690
4610
|
id: gqlTransaction.id,
|
4691
4611
|
receipts,
|
4692
4612
|
transaction: decodedTransaction,
|
4693
|
-
transactionBytes: (0,
|
4613
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4694
4614
|
gqlTransactionStatus: gqlTransaction.status,
|
4695
|
-
gasPerByte: (0,
|
4696
|
-
gasPriceFactor: (0,
|
4615
|
+
gasPerByte: (0, import_math15.bn)(gasPerByte),
|
4616
|
+
gasPriceFactor: (0, import_math15.bn)(gasPriceFactor),
|
4697
4617
|
abiMap,
|
4698
4618
|
maxInputs,
|
4699
4619
|
gasCosts
|
@@ -4732,13 +4652,13 @@ async function getTransactionsSummaries(params) {
|
|
4732
4652
|
const transactions = edges.map((edge) => {
|
4733
4653
|
const { node: gqlTransaction } = edge;
|
4734
4654
|
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4735
|
-
const [decodedTransaction] = new
|
4655
|
+
const [decodedTransaction] = new import_transactions18.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4736
4656
|
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4737
4657
|
const transactionSummary = assembleTransactionSummary({
|
4738
4658
|
id,
|
4739
4659
|
receipts,
|
4740
4660
|
transaction: decodedTransaction,
|
4741
|
-
transactionBytes: (0,
|
4661
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4742
4662
|
gqlTransactionStatus: status,
|
4743
4663
|
abiMap,
|
4744
4664
|
gasPerByte,
|
@@ -4881,17 +4801,17 @@ var assets = [
|
|
4881
4801
|
|
4882
4802
|
// src/utils/formatTransferToContractScriptData.ts
|
4883
4803
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4884
|
-
var
|
4885
|
-
var
|
4804
|
+
var import_math16 = require("@fuel-ts/math");
|
4805
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4886
4806
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4887
4807
|
var formatTransferToContractScriptData = (params) => {
|
4888
4808
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4889
4809
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4890
|
-
const encoded = numberCoder.encode(new
|
4810
|
+
const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
|
4891
4811
|
const scriptData = Uint8Array.from([
|
4892
|
-
...(0,
|
4812
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4893
4813
|
...encoded,
|
4894
|
-
...(0,
|
4814
|
+
...(0, import_utils26.arrayify)(assetId)
|
4895
4815
|
]);
|
4896
4816
|
return scriptData;
|
4897
4817
|
};
|
@@ -4947,7 +4867,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4947
4867
|
*/
|
4948
4868
|
get provider() {
|
4949
4869
|
if (!this._provider) {
|
4950
|
-
throw new
|
4870
|
+
throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4951
4871
|
}
|
4952
4872
|
return this._provider;
|
4953
4873
|
}
|
@@ -4999,8 +4919,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4999
4919
|
if (!hasNextPage) {
|
5000
4920
|
break;
|
5001
4921
|
}
|
5002
|
-
throw new
|
5003
|
-
|
4922
|
+
throw new import_errors15.FuelError(
|
4923
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
5004
4924
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
5005
4925
|
);
|
5006
4926
|
}
|
@@ -5025,8 +4945,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5025
4945
|
if (!hasNextPage) {
|
5026
4946
|
break;
|
5027
4947
|
}
|
5028
|
-
throw new
|
5029
|
-
|
4948
|
+
throw new import_errors15.FuelError(
|
4949
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
5030
4950
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
5031
4951
|
);
|
5032
4952
|
}
|
@@ -5062,8 +4982,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5062
4982
|
if (!hasNextPage) {
|
5063
4983
|
break;
|
5064
4984
|
}
|
5065
|
-
throw new
|
5066
|
-
|
4985
|
+
throw new import_errors15.FuelError(
|
4986
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
5067
4987
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
5068
4988
|
);
|
5069
4989
|
}
|
@@ -5080,7 +5000,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5080
5000
|
async fund(request, coinQuantities, fee) {
|
5081
5001
|
const baseAssetId = this.provider.getBaseAssetId();
|
5082
5002
|
const updatedQuantities = addAmountToAsset({
|
5083
|
-
amount: (0,
|
5003
|
+
amount: (0, import_math17.bn)(fee),
|
5084
5004
|
assetId: baseAssetId,
|
5085
5005
|
coinQuantities
|
5086
5006
|
});
|
@@ -5088,7 +5008,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5088
5008
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
5089
5009
|
quantitiesDict[assetId] = {
|
5090
5010
|
required: amount,
|
5091
|
-
owned: (0,
|
5011
|
+
owned: (0, import_math17.bn)(0)
|
5092
5012
|
};
|
5093
5013
|
});
|
5094
5014
|
const cachedUtxos = [];
|
@@ -5101,7 +5021,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5101
5021
|
if (isCoin2) {
|
5102
5022
|
const assetId = String(input.assetId);
|
5103
5023
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
5104
|
-
const amount = (0,
|
5024
|
+
const amount = (0, import_math17.bn)(input.amount);
|
5105
5025
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5106
5026
|
cachedUtxos.push(input.id);
|
5107
5027
|
}
|
@@ -5148,8 +5068,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5148
5068
|
estimateTxDependencies: true,
|
5149
5069
|
resourcesOwner: this
|
5150
5070
|
});
|
5151
|
-
request.gasPrice = (0,
|
5152
|
-
request.gasLimit = (0,
|
5071
|
+
request.gasPrice = (0, import_math17.bn)(txParams.gasPrice ?? minGasPrice);
|
5072
|
+
request.gasLimit = (0, import_math17.bn)(txParams.gasLimit ?? gasUsed);
|
5153
5073
|
this.validateGas({
|
5154
5074
|
gasUsed,
|
5155
5075
|
gasPrice: request.gasPrice,
|
@@ -5170,9 +5090,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5170
5090
|
* @returns A promise that resolves to the transaction response.
|
5171
5091
|
*/
|
5172
5092
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5173
|
-
if ((0,
|
5174
|
-
throw new
|
5175
|
-
|
5093
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
5094
|
+
throw new import_errors15.FuelError(
|
5095
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5176
5096
|
"Transfer amount must be a positive number."
|
5177
5097
|
);
|
5178
5098
|
}
|
@@ -5190,9 +5110,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5190
5110
|
* @returns A promise that resolves to the transaction response.
|
5191
5111
|
*/
|
5192
5112
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5193
|
-
if ((0,
|
5194
|
-
throw new
|
5195
|
-
|
5113
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
5114
|
+
throw new import_errors15.FuelError(
|
5115
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5196
5116
|
"Transfer amount must be a positive number."
|
5197
5117
|
);
|
5198
5118
|
}
|
@@ -5202,7 +5122,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5202
5122
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5203
5123
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5204
5124
|
hexlifiedContractId: contractAddress.toB256(),
|
5205
|
-
amountToTransfer: (0,
|
5125
|
+
amountToTransfer: (0, import_math17.bn)(amount),
|
5206
5126
|
assetId: assetIdToTransfer
|
5207
5127
|
});
|
5208
5128
|
const request = new ScriptTransactionRequest({
|
@@ -5213,9 +5133,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5213
5133
|
request.addContractInputAndOutput(contractAddress);
|
5214
5134
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5215
5135
|
request,
|
5216
|
-
[{ amount: (0,
|
5136
|
+
[{ amount: (0, import_math17.bn)(amount), assetId: String(assetIdToTransfer) }]
|
5217
5137
|
);
|
5218
|
-
request.gasLimit = (0,
|
5138
|
+
request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
|
5219
5139
|
this.validateGas({
|
5220
5140
|
gasUsed,
|
5221
5141
|
gasPrice: request.gasPrice,
|
@@ -5237,25 +5157,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5237
5157
|
const { minGasPrice } = this.provider.getGasConfig();
|
5238
5158
|
const baseAssetId = this.provider.getBaseAssetId();
|
5239
5159
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5240
|
-
const recipientDataArray = (0,
|
5160
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5241
5161
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5242
5162
|
);
|
5243
|
-
const amountDataArray = (0,
|
5244
|
-
"0x".concat((0,
|
5163
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5164
|
+
"0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5245
5165
|
);
|
5246
5166
|
const script = new Uint8Array([
|
5247
|
-
...(0,
|
5167
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5248
5168
|
...recipientDataArray,
|
5249
5169
|
...amountDataArray
|
5250
5170
|
]);
|
5251
5171
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5252
5172
|
const request = new ScriptTransactionRequest(params);
|
5253
|
-
const forwardingQuantities = [{ amount: (0,
|
5173
|
+
const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: baseAssetId }];
|
5254
5174
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5255
5175
|
request,
|
5256
5176
|
forwardingQuantities
|
5257
5177
|
);
|
5258
|
-
request.gasLimit = (0,
|
5178
|
+
request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
|
5259
5179
|
this.validateGas({
|
5260
5180
|
gasUsed,
|
5261
5181
|
gasPrice: request.gasPrice,
|
@@ -5267,7 +5187,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5267
5187
|
}
|
5268
5188
|
async signMessage(message) {
|
5269
5189
|
if (!this._connector) {
|
5270
|
-
throw new
|
5190
|
+
throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5271
5191
|
}
|
5272
5192
|
return this._connector.signMessage(this.address.toString(), message);
|
5273
5193
|
}
|
@@ -5279,8 +5199,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5279
5199
|
*/
|
5280
5200
|
async signTransaction(transactionRequestLike) {
|
5281
5201
|
if (!this._connector) {
|
5282
|
-
throw new
|
5283
|
-
|
5202
|
+
throw new import_errors15.FuelError(
|
5203
|
+
import_errors15.ErrorCode.MISSING_CONNECTOR,
|
5284
5204
|
"A connector is required to sign transactions."
|
5285
5205
|
);
|
5286
5206
|
}
|
@@ -5327,14 +5247,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5327
5247
|
minGasPrice
|
5328
5248
|
}) {
|
5329
5249
|
if (minGasPrice.gt(gasPrice)) {
|
5330
|
-
throw new
|
5331
|
-
|
5250
|
+
throw new import_errors15.FuelError(
|
5251
|
+
import_errors15.ErrorCode.GAS_PRICE_TOO_LOW,
|
5332
5252
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5333
5253
|
);
|
5334
5254
|
}
|
5335
5255
|
if (gasUsed.gt(gasLimit)) {
|
5336
|
-
throw new
|
5337
|
-
|
5256
|
+
throw new import_errors15.FuelError(
|
5257
|
+
import_errors15.ErrorCode.GAS_LIMIT_TOO_LOW,
|
5338
5258
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5339
5259
|
);
|
5340
5260
|
}
|
@@ -5343,14 +5263,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5343
5263
|
|
5344
5264
|
// src/wallet/base-wallet-unlocked.ts
|
5345
5265
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5346
|
-
var
|
5266
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5347
5267
|
|
5348
5268
|
// src/signer/signer.ts
|
5349
5269
|
var import_address5 = require("@fuel-ts/address");
|
5350
5270
|
var import_crypto = require("@fuel-ts/crypto");
|
5351
5271
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5352
|
-
var
|
5353
|
-
var
|
5272
|
+
var import_math18 = require("@fuel-ts/math");
|
5273
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5354
5274
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5355
5275
|
var Signer = class {
|
5356
5276
|
address;
|
@@ -5369,10 +5289,10 @@ var Signer = class {
|
|
5369
5289
|
privateKey = `0x${privateKey}`;
|
5370
5290
|
}
|
5371
5291
|
}
|
5372
|
-
const privateKeyBytes = (0,
|
5373
|
-
this.privateKey = (0,
|
5374
|
-
this.publicKey = (0,
|
5375
|
-
this.compressedPublicKey = (0,
|
5292
|
+
const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
|
5293
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5294
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5295
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5376
5296
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5377
5297
|
}
|
5378
5298
|
/**
|
@@ -5386,11 +5306,11 @@ var Signer = class {
|
|
5386
5306
|
* @returns hashed signature
|
5387
5307
|
*/
|
5388
5308
|
sign(data) {
|
5389
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5390
|
-
const r = (0,
|
5391
|
-
const s = (0,
|
5309
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5310
|
+
const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5311
|
+
const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5392
5312
|
s[0] |= (signature.recovery || 0) << 7;
|
5393
|
-
return (0,
|
5313
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5394
5314
|
}
|
5395
5315
|
/**
|
5396
5316
|
* Add point on the current elliptic curve
|
@@ -5399,8 +5319,8 @@ var Signer = class {
|
|
5399
5319
|
* @returns compressed point on the curve
|
5400
5320
|
*/
|
5401
5321
|
addPoint(point) {
|
5402
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5403
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5322
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5323
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5404
5324
|
const result = p0.add(p1);
|
5405
5325
|
return `0x${result.toHex(true)}`;
|
5406
5326
|
}
|
@@ -5412,16 +5332,16 @@ var Signer = class {
|
|
5412
5332
|
* @returns public key from signature from the
|
5413
5333
|
*/
|
5414
5334
|
static recoverPublicKey(data, signature) {
|
5415
|
-
const signedMessageBytes = (0,
|
5335
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5416
5336
|
const r = signedMessageBytes.slice(0, 32);
|
5417
5337
|
const s = signedMessageBytes.slice(32, 64);
|
5418
5338
|
const recoveryParam = (s[0] & 128) >> 7;
|
5419
5339
|
s[0] &= 127;
|
5420
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5340
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5421
5341
|
recoveryParam
|
5422
5342
|
);
|
5423
|
-
const publicKey = sig.recoverPublicKey((0,
|
5424
|
-
return (0,
|
5343
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5344
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5425
5345
|
}
|
5426
5346
|
/**
|
5427
5347
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5440,7 +5360,7 @@ var Signer = class {
|
|
5440
5360
|
* @returns random 32-byte hashed
|
5441
5361
|
*/
|
5442
5362
|
static generatePrivateKey(entropy) {
|
5443
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5363
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5444
5364
|
}
|
5445
5365
|
/**
|
5446
5366
|
* Extended publicKey from a compact publicKey
|
@@ -5449,16 +5369,16 @@ var Signer = class {
|
|
5449
5369
|
* @returns extended publicKey
|
5450
5370
|
*/
|
5451
5371
|
static extendPublicKey(publicKey) {
|
5452
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5453
|
-
return (0,
|
5372
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5373
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5454
5374
|
}
|
5455
5375
|
};
|
5456
5376
|
|
5457
5377
|
// src/wallet/keystore-wallet.ts
|
5458
5378
|
var import_address6 = require("@fuel-ts/address");
|
5459
5379
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5460
|
-
var
|
5461
|
-
var
|
5380
|
+
var import_errors16 = require("@fuel-ts/errors");
|
5381
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5462
5382
|
var import_uuid = require("uuid");
|
5463
5383
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5464
5384
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5535,13 +5455,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5535
5455
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5536
5456
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5537
5457
|
if (mac !== macHash) {
|
5538
|
-
throw new
|
5539
|
-
|
5458
|
+
throw new import_errors16.FuelError(
|
5459
|
+
import_errors16.ErrorCode.INVALID_PASSWORD,
|
5540
5460
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5541
5461
|
);
|
5542
5462
|
}
|
5543
5463
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5544
|
-
const privateKey = (0,
|
5464
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5545
5465
|
return privateKey;
|
5546
5466
|
}
|
5547
5467
|
|
@@ -5586,7 +5506,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5586
5506
|
*/
|
5587
5507
|
async signMessage(message) {
|
5588
5508
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5589
|
-
return (0,
|
5509
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5590
5510
|
}
|
5591
5511
|
/**
|
5592
5512
|
* Signs a transaction with the wallet's private key.
|
@@ -5599,7 +5519,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5599
5519
|
const chainId = this.provider.getChainId();
|
5600
5520
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5601
5521
|
const signature = await this.signer().sign(hashedTransaction);
|
5602
|
-
return (0,
|
5522
|
+
return (0, import_utils30.hexlify)(signature);
|
5603
5523
|
}
|
5604
5524
|
/**
|
5605
5525
|
* Populates a transaction with the witnesses signature.
|
@@ -5658,17 +5578,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5658
5578
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5659
5579
|
|
5660
5580
|
// src/hdwallet/hdwallet.ts
|
5661
|
-
var
|
5581
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5662
5582
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5663
|
-
var
|
5664
|
-
var
|
5583
|
+
var import_math19 = require("@fuel-ts/math");
|
5584
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5665
5585
|
var import_ethers3 = require("ethers");
|
5666
5586
|
|
5667
5587
|
// src/mnemonic/mnemonic.ts
|
5668
5588
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5669
|
-
var
|
5589
|
+
var import_errors18 = require("@fuel-ts/errors");
|
5670
5590
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5671
|
-
var
|
5591
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5672
5592
|
var import_ethers2 = require("ethers");
|
5673
5593
|
|
5674
5594
|
// src/wordlists/words/english.ts
|
@@ -7730,9 +7650,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7730
7650
|
})(Language || {});
|
7731
7651
|
|
7732
7652
|
// src/mnemonic/utils.ts
|
7733
|
-
var
|
7653
|
+
var import_errors17 = require("@fuel-ts/errors");
|
7734
7654
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7735
|
-
var
|
7655
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7736
7656
|
function toUtf8Bytes(stri) {
|
7737
7657
|
const str = stri.normalize("NFKD");
|
7738
7658
|
const result = [];
|
@@ -7747,8 +7667,8 @@ function toUtf8Bytes(stri) {
|
|
7747
7667
|
i += 1;
|
7748
7668
|
const c2 = str.charCodeAt(i);
|
7749
7669
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7750
|
-
throw new
|
7751
|
-
|
7670
|
+
throw new import_errors17.FuelError(
|
7671
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7752
7672
|
"Invalid UTF-8 in the input string."
|
7753
7673
|
);
|
7754
7674
|
}
|
@@ -7799,20 +7719,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7799
7719
|
}
|
7800
7720
|
}
|
7801
7721
|
const checksumBits = entropy.length / 4;
|
7802
|
-
const checksum = (0,
|
7722
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7803
7723
|
indices[indices.length - 1] <<= checksumBits;
|
7804
7724
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7805
7725
|
return indices;
|
7806
7726
|
}
|
7807
7727
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7808
7728
|
const size = Math.ceil(11 * words.length / 8);
|
7809
|
-
const entropy = (0,
|
7729
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7810
7730
|
let offset = 0;
|
7811
7731
|
for (let i = 0; i < words.length; i += 1) {
|
7812
7732
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7813
7733
|
if (index === -1) {
|
7814
|
-
throw new
|
7815
|
-
|
7734
|
+
throw new import_errors17.FuelError(
|
7735
|
+
import_errors17.ErrorCode.INVALID_MNEMONIC,
|
7816
7736
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7817
7737
|
);
|
7818
7738
|
}
|
@@ -7826,10 +7746,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7826
7746
|
const entropyBits = 32 * words.length / 3;
|
7827
7747
|
const checksumBits = words.length / 3;
|
7828
7748
|
const checksumMask = getUpperMask(checksumBits);
|
7829
|
-
const checksum = (0,
|
7749
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7830
7750
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7831
|
-
throw new
|
7832
|
-
|
7751
|
+
throw new import_errors17.FuelError(
|
7752
|
+
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
7833
7753
|
"Checksum validation failed for the provided mnemonic."
|
7834
7754
|
);
|
7835
7755
|
}
|
@@ -7843,16 +7763,16 @@ var TestnetPRV = "0x04358394";
|
|
7843
7763
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7844
7764
|
function assertWordList(wordlist) {
|
7845
7765
|
if (wordlist.length !== 2048) {
|
7846
|
-
throw new
|
7847
|
-
|
7766
|
+
throw new import_errors18.FuelError(
|
7767
|
+
import_errors18.ErrorCode.INVALID_WORD_LIST,
|
7848
7768
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7849
7769
|
);
|
7850
7770
|
}
|
7851
7771
|
}
|
7852
7772
|
function assertEntropy(entropy) {
|
7853
7773
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7854
|
-
throw new
|
7855
|
-
|
7774
|
+
throw new import_errors18.FuelError(
|
7775
|
+
import_errors18.ErrorCode.INVALID_ENTROPY,
|
7856
7776
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7857
7777
|
);
|
7858
7778
|
}
|
@@ -7862,7 +7782,7 @@ function assertMnemonic(words) {
|
|
7862
7782
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7863
7783
|
", "
|
7864
7784
|
)}] words, but got ${words.length}.`;
|
7865
|
-
throw new
|
7785
|
+
throw new import_errors18.FuelError(import_errors18.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7866
7786
|
}
|
7867
7787
|
}
|
7868
7788
|
var Mnemonic = class {
|
@@ -7901,7 +7821,7 @@ var Mnemonic = class {
|
|
7901
7821
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7902
7822
|
const words = getWords(phrase);
|
7903
7823
|
assertMnemonic(words);
|
7904
|
-
return (0,
|
7824
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7905
7825
|
}
|
7906
7826
|
/**
|
7907
7827
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7909,7 +7829,7 @@ var Mnemonic = class {
|
|
7909
7829
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7910
7830
|
*/
|
7911
7831
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7912
|
-
const entropyBytes = (0,
|
7832
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7913
7833
|
assertWordList(wordlist);
|
7914
7834
|
assertEntropy(entropyBytes);
|
7915
7835
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7978,14 +7898,14 @@ var Mnemonic = class {
|
|
7978
7898
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7979
7899
|
*/
|
7980
7900
|
static masterKeysFromSeed(seed) {
|
7981
|
-
const seedArray = (0,
|
7901
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7982
7902
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7983
|
-
throw new
|
7984
|
-
|
7903
|
+
throw new import_errors18.FuelError(
|
7904
|
+
import_errors18.ErrorCode.INVALID_SEED,
|
7985
7905
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7986
7906
|
);
|
7987
7907
|
}
|
7988
|
-
return (0,
|
7908
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7989
7909
|
}
|
7990
7910
|
/**
|
7991
7911
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7996,22 +7916,22 @@ var Mnemonic = class {
|
|
7996
7916
|
*/
|
7997
7917
|
static seedToExtendedKey(seed, testnet = false) {
|
7998
7918
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7999
|
-
const prefix = (0,
|
7919
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
8000
7920
|
const depth = "0x00";
|
8001
7921
|
const fingerprint = "0x00000000";
|
8002
7922
|
const index = "0x00000000";
|
8003
7923
|
const chainCode = masterKey.slice(32);
|
8004
7924
|
const privateKey = masterKey.slice(0, 32);
|
8005
|
-
const extendedKey = (0,
|
7925
|
+
const extendedKey = (0, import_utils32.concat)([
|
8006
7926
|
prefix,
|
8007
7927
|
depth,
|
8008
7928
|
fingerprint,
|
8009
7929
|
index,
|
8010
7930
|
chainCode,
|
8011
|
-
(0,
|
7931
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
8012
7932
|
]);
|
8013
7933
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
8014
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7934
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
8015
7935
|
}
|
8016
7936
|
/**
|
8017
7937
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -8026,7 +7946,7 @@ var Mnemonic = class {
|
|
8026
7946
|
* @returns A randomly generated mnemonic
|
8027
7947
|
*/
|
8028
7948
|
static generate(size = 32, extraEntropy = "") {
|
8029
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7949
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8030
7950
|
return Mnemonic.entropyToMnemonic(entropy);
|
8031
7951
|
}
|
8032
7952
|
};
|
@@ -8034,12 +7954,12 @@ var mnemonic_default = Mnemonic;
|
|
8034
7954
|
|
8035
7955
|
// src/hdwallet/hdwallet.ts
|
8036
7956
|
var HARDENED_INDEX = 2147483648;
|
8037
|
-
var MainnetPRV2 = (0,
|
8038
|
-
var MainnetPUB = (0,
|
8039
|
-
var TestnetPRV2 = (0,
|
8040
|
-
var TestnetPUB = (0,
|
7957
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7958
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7959
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7960
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8041
7961
|
function base58check(data) {
|
8042
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7962
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8043
7963
|
}
|
8044
7964
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8045
7965
|
if (isPublic) {
|
@@ -8048,17 +7968,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8048
7968
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8049
7969
|
}
|
8050
7970
|
function isPublicExtendedKey(extendedKey) {
|
8051
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7971
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8052
7972
|
}
|
8053
7973
|
function isValidExtendedKey(extendedKey) {
|
8054
7974
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8055
|
-
(0,
|
7975
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8056
7976
|
);
|
8057
7977
|
}
|
8058
7978
|
function parsePath(path, depth = 0) {
|
8059
7979
|
const components = path.split("/");
|
8060
7980
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8061
|
-
throw new
|
7981
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
8062
7982
|
}
|
8063
7983
|
if (components[0] === "m") {
|
8064
7984
|
components.shift();
|
@@ -8070,8 +7990,8 @@ function parsePath(path, depth = 0) {
|
|
8070
7990
|
var HDWallet = class {
|
8071
7991
|
depth = 0;
|
8072
7992
|
index = 0;
|
8073
|
-
fingerprint = (0,
|
8074
|
-
parentFingerprint = (0,
|
7993
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7994
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8075
7995
|
privateKey;
|
8076
7996
|
publicKey;
|
8077
7997
|
chainCode;
|
@@ -8083,16 +8003,16 @@ var HDWallet = class {
|
|
8083
8003
|
constructor(config) {
|
8084
8004
|
if (config.privateKey) {
|
8085
8005
|
const signer = new Signer(config.privateKey);
|
8086
|
-
this.publicKey = (0,
|
8087
|
-
this.privateKey = (0,
|
8006
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
8007
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8088
8008
|
} else {
|
8089
8009
|
if (!config.publicKey) {
|
8090
|
-
throw new
|
8091
|
-
|
8010
|
+
throw new import_errors19.FuelError(
|
8011
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8092
8012
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8093
8013
|
);
|
8094
8014
|
}
|
8095
|
-
this.publicKey = (0,
|
8015
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8096
8016
|
}
|
8097
8017
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8098
8018
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8111,28 +8031,28 @@ var HDWallet = class {
|
|
8111
8031
|
* @returns A new instance of HDWallet on the derived index
|
8112
8032
|
*/
|
8113
8033
|
deriveIndex(index) {
|
8114
|
-
const privateKey = this.privateKey && (0,
|
8115
|
-
const publicKey = (0,
|
8116
|
-
const chainCode = (0,
|
8034
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8035
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8036
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8117
8037
|
const data = new Uint8Array(37);
|
8118
8038
|
if (index & HARDENED_INDEX) {
|
8119
8039
|
if (!privateKey) {
|
8120
|
-
throw new
|
8121
|
-
|
8040
|
+
throw new import_errors19.FuelError(
|
8041
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8122
8042
|
"Cannot derive a hardened index without a private Key."
|
8123
8043
|
);
|
8124
8044
|
}
|
8125
8045
|
data.set(privateKey, 1);
|
8126
8046
|
} else {
|
8127
|
-
data.set((0,
|
8047
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8128
8048
|
}
|
8129
|
-
data.set((0,
|
8130
|
-
const bytes = (0,
|
8049
|
+
data.set((0, import_math19.toBytes)(index, 4), 33);
|
8050
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8131
8051
|
const IL = bytes.slice(0, 32);
|
8132
8052
|
const IR = bytes.slice(32);
|
8133
8053
|
if (privateKey) {
|
8134
8054
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8135
|
-
const ki = (0,
|
8055
|
+
const ki = (0, import_math19.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8136
8056
|
return new HDWallet({
|
8137
8057
|
privateKey: ki,
|
8138
8058
|
chainCode: IR,
|
@@ -8141,7 +8061,7 @@ var HDWallet = class {
|
|
8141
8061
|
parentFingerprint: this.fingerprint
|
8142
8062
|
});
|
8143
8063
|
}
|
8144
|
-
const signer = new Signer((0,
|
8064
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8145
8065
|
const Ki = signer.addPoint(publicKey);
|
8146
8066
|
return new HDWallet({
|
8147
8067
|
publicKey: Ki,
|
@@ -8170,18 +8090,18 @@ var HDWallet = class {
|
|
8170
8090
|
*/
|
8171
8091
|
toExtendedKey(isPublic = false, testnet = false) {
|
8172
8092
|
if (this.depth >= 256) {
|
8173
|
-
throw new
|
8174
|
-
|
8093
|
+
throw new import_errors19.FuelError(
|
8094
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8175
8095
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8176
8096
|
);
|
8177
8097
|
}
|
8178
8098
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8179
|
-
const depth = (0,
|
8099
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8180
8100
|
const parentFingerprint = this.parentFingerprint;
|
8181
|
-
const index = (0,
|
8101
|
+
const index = (0, import_math19.toHex)(this.index, 4);
|
8182
8102
|
const chainCode = this.chainCode;
|
8183
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8184
|
-
const extendedKey = (0,
|
8103
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8104
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8185
8105
|
return base58check(extendedKey);
|
8186
8106
|
}
|
8187
8107
|
/**
|
@@ -8193,34 +8113,34 @@ var HDWallet = class {
|
|
8193
8113
|
static fromSeed(seed) {
|
8194
8114
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8195
8115
|
return new HDWallet({
|
8196
|
-
chainCode: (0,
|
8197
|
-
privateKey: (0,
|
8116
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8117
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8198
8118
|
});
|
8199
8119
|
}
|
8200
8120
|
static fromExtendedKey(extendedKey) {
|
8201
8121
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8202
|
-
const bytes = (0,
|
8122
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8203
8123
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8204
8124
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8205
|
-
throw new
|
8125
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8206
8126
|
}
|
8207
8127
|
if (!validChecksum) {
|
8208
|
-
throw new
|
8128
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8209
8129
|
}
|
8210
8130
|
const depth = bytes[4];
|
8211
|
-
const parentFingerprint = (0,
|
8212
|
-
const index = parseInt((0,
|
8213
|
-
const chainCode = (0,
|
8131
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8132
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8133
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8214
8134
|
const key = bytes.slice(45, 78);
|
8215
8135
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8216
|
-
throw new
|
8217
|
-
|
8136
|
+
throw new import_errors19.FuelError(
|
8137
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8218
8138
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8219
8139
|
);
|
8220
8140
|
}
|
8221
8141
|
if (isPublicExtendedKey(bytes)) {
|
8222
8142
|
if (key[0] !== 3) {
|
8223
|
-
throw new
|
8143
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
8224
8144
|
}
|
8225
8145
|
return new HDWallet({
|
8226
8146
|
publicKey: key,
|
@@ -8231,7 +8151,7 @@ var HDWallet = class {
|
|
8231
8151
|
});
|
8232
8152
|
}
|
8233
8153
|
if (key[0] !== 0) {
|
8234
|
-
throw new
|
8154
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
8235
8155
|
}
|
8236
8156
|
return new HDWallet({
|
8237
8157
|
privateKey: key.slice(1),
|
@@ -8399,7 +8319,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8399
8319
|
// src/wallet-manager/wallet-manager.ts
|
8400
8320
|
var import_address9 = require("@fuel-ts/address");
|
8401
8321
|
var import_crypto4 = require("@fuel-ts/crypto");
|
8402
|
-
var
|
8322
|
+
var import_errors22 = require("@fuel-ts/errors");
|
8403
8323
|
var import_events = require("events");
|
8404
8324
|
|
8405
8325
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8422,7 +8342,7 @@ var MemoryStorage = class {
|
|
8422
8342
|
|
8423
8343
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8424
8344
|
var import_address7 = require("@fuel-ts/address");
|
8425
|
-
var
|
8345
|
+
var import_errors20 = require("@fuel-ts/errors");
|
8426
8346
|
var _secret;
|
8427
8347
|
var MnemonicVault = class {
|
8428
8348
|
constructor(options) {
|
@@ -8478,8 +8398,8 @@ var MnemonicVault = class {
|
|
8478
8398
|
}
|
8479
8399
|
numberOfAccounts += 1;
|
8480
8400
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8481
|
-
throw new
|
8482
|
-
|
8401
|
+
throw new import_errors20.FuelError(
|
8402
|
+
import_errors20.ErrorCode.WALLET_MANAGER_ERROR,
|
8483
8403
|
`Account with address '${address}' not found in derived wallets.`
|
8484
8404
|
);
|
8485
8405
|
}
|
@@ -8493,7 +8413,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8493
8413
|
|
8494
8414
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8495
8415
|
var import_address8 = require("@fuel-ts/address");
|
8496
|
-
var
|
8416
|
+
var import_errors21 = require("@fuel-ts/errors");
|
8497
8417
|
var _privateKeys;
|
8498
8418
|
var PrivateKeyVault = class {
|
8499
8419
|
/**
|
@@ -8534,8 +8454,8 @@ var PrivateKeyVault = class {
|
|
8534
8454
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8535
8455
|
);
|
8536
8456
|
if (!privateKey) {
|
8537
|
-
throw new
|
8538
|
-
|
8457
|
+
throw new import_errors21.FuelError(
|
8458
|
+
import_errors21.ErrorCode.WALLET_MANAGER_ERROR,
|
8539
8459
|
`No private key found for address '${address}'.`
|
8540
8460
|
);
|
8541
8461
|
}
|
@@ -8559,7 +8479,7 @@ var ERROR_MESSAGES = {
|
|
8559
8479
|
};
|
8560
8480
|
function assert(condition, message) {
|
8561
8481
|
if (!condition) {
|
8562
|
-
throw new
|
8482
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.WALLET_MANAGER_ERROR, message);
|
8563
8483
|
}
|
8564
8484
|
}
|
8565
8485
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8785,25 +8705,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8785
8705
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8786
8706
|
|
8787
8707
|
// src/wallet-manager/types.ts
|
8788
|
-
var
|
8708
|
+
var import_errors23 = require("@fuel-ts/errors");
|
8789
8709
|
var Vault = class {
|
8790
8710
|
constructor(_options) {
|
8791
|
-
throw new
|
8711
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8792
8712
|
}
|
8793
8713
|
serialize() {
|
8794
|
-
throw new
|
8714
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8795
8715
|
}
|
8796
8716
|
getAccounts() {
|
8797
|
-
throw new
|
8717
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8798
8718
|
}
|
8799
8719
|
addAccount() {
|
8800
|
-
throw new
|
8720
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8801
8721
|
}
|
8802
8722
|
exportAccount(_address) {
|
8803
|
-
throw new
|
8723
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8804
8724
|
}
|
8805
8725
|
getWallet(_address) {
|
8806
|
-
throw new
|
8726
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8807
8727
|
}
|
8808
8728
|
};
|
8809
8729
|
__publicField(Vault, "type");
|
@@ -8813,20 +8733,20 @@ var StorageAbstract = class {
|
|
8813
8733
|
// src/predicate/predicate.ts
|
8814
8734
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
8815
8735
|
var import_address10 = require("@fuel-ts/address");
|
8816
|
-
var
|
8817
|
-
var
|
8818
|
-
var
|
8736
|
+
var import_errors24 = require("@fuel-ts/errors");
|
8737
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
8738
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8819
8739
|
|
8820
8740
|
// src/predicate/utils/getPredicateRoot.ts
|
8821
8741
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8822
8742
|
var import_merkle = require("@fuel-ts/merkle");
|
8823
|
-
var
|
8743
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8824
8744
|
var getPredicateRoot = (bytecode) => {
|
8825
8745
|
const chunkSize = 16 * 1024;
|
8826
|
-
const bytes = (0,
|
8827
|
-
const chunks = (0,
|
8828
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8829
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8746
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
8747
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
8748
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
8749
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8830
8750
|
return predicateRoot;
|
8831
8751
|
};
|
8832
8752
|
|
@@ -8875,7 +8795,7 @@ var Predicate = class extends Account {
|
|
8875
8795
|
const request = transactionRequestify(transactionRequestLike);
|
8876
8796
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8877
8797
|
request.inputs?.forEach((input) => {
|
8878
|
-
if (input.type ===
|
8798
|
+
if (input.type === import_transactions19.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
8879
8799
|
input.predicate = this.bytes;
|
8880
8800
|
input.predicateData = this.getPredicateData(policies.length);
|
8881
8801
|
}
|
@@ -8921,7 +8841,7 @@ var Predicate = class extends Account {
|
|
8921
8841
|
return new Uint8Array();
|
8922
8842
|
}
|
8923
8843
|
const mainFn = this.interface?.functions.main;
|
8924
|
-
const paddedCode = new
|
8844
|
+
const paddedCode = new import_transactions19.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8925
8845
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
8926
8846
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8927
8847
|
});
|
@@ -8937,13 +8857,13 @@ var Predicate = class extends Account {
|
|
8937
8857
|
* @returns An object containing the new predicate bytes and interface.
|
8938
8858
|
*/
|
8939
8859
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8940
|
-
let predicateBytes = (0,
|
8860
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8941
8861
|
let abiInterface;
|
8942
8862
|
if (jsonAbi) {
|
8943
8863
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
8944
8864
|
if (abiInterface.functions.main === void 0) {
|
8945
|
-
throw new
|
8946
|
-
|
8865
|
+
throw new import_errors24.FuelError(
|
8866
|
+
import_errors24.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
8947
8867
|
'Cannot use ABI without "main" function.'
|
8948
8868
|
);
|
8949
8869
|
}
|
@@ -8988,8 +8908,8 @@ var Predicate = class extends Account {
|
|
8988
8908
|
mutatedBytes.set(encoded, offset);
|
8989
8909
|
});
|
8990
8910
|
} catch (err) {
|
8991
|
-
throw new
|
8992
|
-
|
8911
|
+
throw new import_errors24.FuelError(
|
8912
|
+
import_errors24.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
8993
8913
|
`Error setting configurable constants: ${err.message}.`
|
8994
8914
|
);
|
8995
8915
|
}
|
@@ -8998,7 +8918,7 @@ var Predicate = class extends Account {
|
|
8998
8918
|
};
|
8999
8919
|
|
9000
8920
|
// src/connectors/fuel.ts
|
9001
|
-
var
|
8921
|
+
var import_errors25 = require("@fuel-ts/errors");
|
9002
8922
|
|
9003
8923
|
// src/connectors/fuel-connector.ts
|
9004
8924
|
var import_events2 = require("events");
|
@@ -9631,7 +9551,7 @@ var _Fuel = class extends FuelConnector {
|
|
9631
9551
|
const currentNetwork = await this.currentNetwork();
|
9632
9552
|
provider = await Provider.create(currentNetwork.url);
|
9633
9553
|
} else {
|
9634
|
-
throw new
|
9554
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
9635
9555
|
}
|
9636
9556
|
return provider;
|
9637
9557
|
}
|
@@ -9711,9 +9631,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9711
9631
|
WalletUnlocked,
|
9712
9632
|
addAmountToAsset,
|
9713
9633
|
addOperation,
|
9714
|
-
assemblePanicError,
|
9715
9634
|
assembleReceiptByType,
|
9716
|
-
assembleRevertError,
|
9717
9635
|
assembleTransactionSummary,
|
9718
9636
|
assets,
|
9719
9637
|
buildBlockExplorerUrl,
|
@@ -9728,7 +9646,6 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9728
9646
|
english,
|
9729
9647
|
extractBurnedAssetsFromReceipts,
|
9730
9648
|
extractMintedAssetsFromReceipts,
|
9731
|
-
extractTxError,
|
9732
9649
|
gasUsedByInputs,
|
9733
9650
|
getAssetEth,
|
9734
9651
|
getAssetFuel,
|