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