@fuel-ts/account 0.0.0-rc-1895-20240328113714 → 0.0.0-rc-1964-20240328124253
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 +10 -126
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +468 -541
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +240 -318
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils.global.js +10 -126
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +434 -501
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +213 -288
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- package/dist/providers/utils/extract-tx-error.d.ts +0 -14
- package/dist/providers/utils/extract-tx-error.d.ts.map +0 -1
package/dist/index.js
CHANGED
@@ -88,7 +88,7 @@ __export(src_exports, {
|
|
88
88
|
StorageAbstract: () => StorageAbstract,
|
89
89
|
TransactionResponse: () => TransactionResponse,
|
90
90
|
TransactionStatus: () => TransactionStatus,
|
91
|
-
TransactionType: () =>
|
91
|
+
TransactionType: () => import_transactions5.TransactionType,
|
92
92
|
TransactionTypeName: () => TransactionTypeName,
|
93
93
|
Vault: () => Vault,
|
94
94
|
Wallet: () => Wallet,
|
@@ -97,9 +97,7 @@ __export(src_exports, {
|
|
97
97
|
WalletUnlocked: () => WalletUnlocked,
|
98
98
|
addAmountToAsset: () => addAmountToAsset,
|
99
99
|
addOperation: () => addOperation,
|
100
|
-
assemblePanicError: () => assemblePanicError,
|
101
100
|
assembleReceiptByType: () => assembleReceiptByType,
|
102
|
-
assembleRevertError: () => assembleRevertError,
|
103
101
|
assembleTransactionSummary: () => assembleTransactionSummary,
|
104
102
|
assets: () => assets,
|
105
103
|
buildBlockExplorerUrl: () => buildBlockExplorerUrl,
|
@@ -114,7 +112,6 @@ __export(src_exports, {
|
|
114
112
|
english: () => english,
|
115
113
|
extractBurnedAssetsFromReceipts: () => extractBurnedAssetsFromReceipts,
|
116
114
|
extractMintedAssetsFromReceipts: () => extractMintedAssetsFromReceipts,
|
117
|
-
extractTxError: () => extractTxError,
|
118
115
|
gasUsedByInputs: () => gasUsedByInputs,
|
119
116
|
getAssetEth: () => getAssetEth,
|
120
117
|
getAssetFuel: () => getAssetFuel,
|
@@ -184,11 +181,11 @@ module.exports = __toCommonJS(src_exports);
|
|
184
181
|
|
185
182
|
// src/account.ts
|
186
183
|
var import_address4 = require("@fuel-ts/address");
|
187
|
-
var
|
188
|
-
var
|
184
|
+
var import_configs11 = require("@fuel-ts/address/configs");
|
185
|
+
var import_errors15 = require("@fuel-ts/errors");
|
189
186
|
var import_interfaces = require("@fuel-ts/interfaces");
|
190
|
-
var
|
191
|
-
var
|
187
|
+
var import_math17 = require("@fuel-ts/math");
|
188
|
+
var import_utils27 = require("@fuel-ts/utils");
|
192
189
|
|
193
190
|
// src/providers/coin-quantity.ts
|
194
191
|
var import_configs = require("@fuel-ts/address/configs");
|
@@ -228,12 +225,12 @@ var addAmountToAsset = (params) => {
|
|
228
225
|
|
229
226
|
// src/providers/provider.ts
|
230
227
|
var import_address3 = require("@fuel-ts/address");
|
231
|
-
var
|
232
|
-
var
|
233
|
-
var
|
234
|
-
var
|
228
|
+
var import_errors13 = require("@fuel-ts/errors");
|
229
|
+
var import_math14 = require("@fuel-ts/math");
|
230
|
+
var import_transactions17 = require("@fuel-ts/transactions");
|
231
|
+
var import_utils22 = require("@fuel-ts/utils");
|
235
232
|
var import_versions = require("@fuel-ts/versions");
|
236
|
-
var
|
233
|
+
var import_utils23 = require("@noble/curves/abstract/utils");
|
237
234
|
var import_ethers = require("ethers");
|
238
235
|
var import_graphql_request = require("graphql-request");
|
239
236
|
var import_ramda3 = require("ramda");
|
@@ -1306,9 +1303,9 @@ var outputify = (value) => {
|
|
1306
1303
|
|
1307
1304
|
// src/providers/transaction-request/transaction-request.ts
|
1308
1305
|
var import_address = require("@fuel-ts/address");
|
1309
|
-
var
|
1310
|
-
var
|
1311
|
-
var
|
1306
|
+
var import_configs6 = require("@fuel-ts/address/configs");
|
1307
|
+
var import_math6 = require("@fuel-ts/math");
|
1308
|
+
var import_transactions5 = require("@fuel-ts/transactions");
|
1312
1309
|
var import_utils9 = require("@fuel-ts/utils");
|
1313
1310
|
|
1314
1311
|
// src/providers/resource.ts
|
@@ -1701,68 +1698,6 @@ function sleep(time) {
|
|
1701
1698
|
});
|
1702
1699
|
}
|
1703
1700
|
|
1704
|
-
// src/providers/utils/extract-tx-error.ts
|
1705
|
-
var import_errors7 = require("@fuel-ts/errors");
|
1706
|
-
var import_math6 = require("@fuel-ts/math");
|
1707
|
-
var import_transactions5 = require("@fuel-ts/transactions");
|
1708
|
-
var import_configs6 = require("@fuel-ts/transactions/configs");
|
1709
|
-
var assemblePanicError = (status) => {
|
1710
|
-
let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
|
1711
|
-
if (import_configs6.PANIC_REASONS.includes(status.reason)) {
|
1712
|
-
errorMessage = `${errorMessage}
|
1713
|
-
|
1714
|
-
You can read more about this error at:
|
1715
|
-
|
1716
|
-
${import_configs6.PANIC_DOC_URL}#variant.${status.reason}`;
|
1717
|
-
}
|
1718
|
-
return errorMessage;
|
1719
|
-
};
|
1720
|
-
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1721
|
-
var assembleRevertError = (receipts, logs) => {
|
1722
|
-
let errorMessage = "The transaction reverted with an unknown reason.";
|
1723
|
-
const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
|
1724
|
-
if (revertReceipt) {
|
1725
|
-
const reasonHex = (0, import_math6.bn)(revertReceipt.val).toHex();
|
1726
|
-
switch (reasonHex) {
|
1727
|
-
case import_configs6.FAILED_REQUIRE_SIGNAL: {
|
1728
|
-
errorMessage = `The transaction reverted because a "require" statement has thrown ${logs.length ? stringify(logs[0]) : "an error."}.`;
|
1729
|
-
break;
|
1730
|
-
}
|
1731
|
-
case import_configs6.FAILED_ASSERT_EQ_SIGNAL: {
|
1732
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1733
|
-
errorMessage = `The transaction reverted because of an "assert_eq" statement${sufix}`;
|
1734
|
-
break;
|
1735
|
-
}
|
1736
|
-
case import_configs6.FAILED_ASSERT_NE_SIGNAL: {
|
1737
|
-
const sufix = logs.length >= 2 ? ` comparing ${stringify(logs[1])} and ${stringify(logs[0])}.` : ".";
|
1738
|
-
errorMessage = `The transaction reverted because of an "assert_ne" statement${sufix}`;
|
1739
|
-
break;
|
1740
|
-
}
|
1741
|
-
case import_configs6.FAILED_ASSERT_SIGNAL:
|
1742
|
-
errorMessage = `The transaction reverted because an "assert" statement failed to evaluate to true.`;
|
1743
|
-
break;
|
1744
|
-
case import_configs6.FAILED_TRANSFER_TO_ADDRESS_SIGNAL:
|
1745
|
-
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1746
|
-
break;
|
1747
|
-
default:
|
1748
|
-
errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
|
1749
|
-
}
|
1750
|
-
}
|
1751
|
-
return errorMessage;
|
1752
|
-
};
|
1753
|
-
var extractTxError = (params) => {
|
1754
|
-
const { receipts, status, logs } = params;
|
1755
|
-
const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
|
1756
|
-
let err = status?.type === "FailureStatus" && isPanic ? assemblePanicError(status) : assembleRevertError(receipts, logs);
|
1757
|
-
err += `
|
1758
|
-
|
1759
|
-
logs: ${JSON.stringify(logs, null, 2)}`;
|
1760
|
-
err += `
|
1761
|
-
|
1762
|
-
receipts: ${JSON.stringify(receipts, null, 2)}`;
|
1763
|
-
return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, err);
|
1764
|
-
};
|
1765
|
-
|
1766
1701
|
// src/providers/transaction-request/errors.ts
|
1767
1702
|
var ChangeOutputCollisionError = class extends Error {
|
1768
1703
|
name = "ChangeOutputCollisionError";
|
@@ -1825,10 +1760,10 @@ var BaseTransactionRequest = class {
|
|
1825
1760
|
outputs,
|
1826
1761
|
witnesses
|
1827
1762
|
} = {}) {
|
1828
|
-
this.gasPrice = (0,
|
1763
|
+
this.gasPrice = (0, import_math6.bn)(gasPrice);
|
1829
1764
|
this.maturity = maturity ?? 0;
|
1830
|
-
this.witnessLimit = witnessLimit ? (0,
|
1831
|
-
this.maxFee = maxFee ? (0,
|
1765
|
+
this.witnessLimit = witnessLimit ? (0, import_math6.bn)(witnessLimit) : void 0;
|
1766
|
+
this.maxFee = maxFee ? (0, import_math6.bn)(maxFee) : void 0;
|
1832
1767
|
this.inputs = inputs ?? [];
|
1833
1768
|
this.outputs = outputs ?? [];
|
1834
1769
|
this.witnesses = witnesses ?? [];
|
@@ -1837,20 +1772,20 @@ var BaseTransactionRequest = class {
|
|
1837
1772
|
let policyTypes = 0;
|
1838
1773
|
const policies = [];
|
1839
1774
|
if (req.gasPrice) {
|
1840
|
-
policyTypes +=
|
1841
|
-
policies.push({ data: req.gasPrice, type:
|
1775
|
+
policyTypes += import_transactions5.PolicyType.GasPrice;
|
1776
|
+
policies.push({ data: req.gasPrice, type: import_transactions5.PolicyType.GasPrice });
|
1842
1777
|
}
|
1843
1778
|
if (req.witnessLimit) {
|
1844
|
-
policyTypes +=
|
1845
|
-
policies.push({ data: req.witnessLimit, type:
|
1779
|
+
policyTypes += import_transactions5.PolicyType.WitnessLimit;
|
1780
|
+
policies.push({ data: req.witnessLimit, type: import_transactions5.PolicyType.WitnessLimit });
|
1846
1781
|
}
|
1847
1782
|
if (req.maturity > 0) {
|
1848
|
-
policyTypes +=
|
1849
|
-
policies.push({ data: req.maturity, type:
|
1783
|
+
policyTypes += import_transactions5.PolicyType.Maturity;
|
1784
|
+
policies.push({ data: req.maturity, type: import_transactions5.PolicyType.Maturity });
|
1850
1785
|
}
|
1851
1786
|
if (req.maxFee) {
|
1852
|
-
policyTypes +=
|
1853
|
-
policies.push({ data: req.maxFee, type:
|
1787
|
+
policyTypes += import_transactions5.PolicyType.MaxFee;
|
1788
|
+
policies.push({ data: req.maxFee, type: import_transactions5.PolicyType.MaxFee });
|
1854
1789
|
}
|
1855
1790
|
return {
|
1856
1791
|
policyTypes,
|
@@ -1884,7 +1819,7 @@ var BaseTransactionRequest = class {
|
|
1884
1819
|
* @returns The transaction bytes.
|
1885
1820
|
*/
|
1886
1821
|
toTransactionBytes() {
|
1887
|
-
return new
|
1822
|
+
return new import_transactions5.TransactionCoder().encode(this.toTransaction());
|
1888
1823
|
}
|
1889
1824
|
/**
|
1890
1825
|
* @hidden
|
@@ -1924,7 +1859,7 @@ var BaseTransactionRequest = class {
|
|
1924
1859
|
* @returns The index of the created witness.
|
1925
1860
|
*/
|
1926
1861
|
addEmptyWitness() {
|
1927
|
-
this.addWitness((0, import_utils9.concat)([
|
1862
|
+
this.addWitness((0, import_utils9.concat)([import_configs6.ZeroBytes32, import_configs6.ZeroBytes32]));
|
1928
1863
|
return this.witnesses.length - 1;
|
1929
1864
|
}
|
1930
1865
|
/**
|
@@ -1975,7 +1910,7 @@ var BaseTransactionRequest = class {
|
|
1975
1910
|
*/
|
1976
1911
|
getCoinInputs() {
|
1977
1912
|
return this.inputs.filter(
|
1978
|
-
(input) => input.type ===
|
1913
|
+
(input) => input.type === import_transactions5.InputType.Coin
|
1979
1914
|
);
|
1980
1915
|
}
|
1981
1916
|
/**
|
@@ -1985,7 +1920,7 @@ var BaseTransactionRequest = class {
|
|
1985
1920
|
*/
|
1986
1921
|
getCoinOutputs() {
|
1987
1922
|
return this.outputs.filter(
|
1988
|
-
(output) => output.type ===
|
1923
|
+
(output) => output.type === import_transactions5.OutputType.Coin
|
1989
1924
|
);
|
1990
1925
|
}
|
1991
1926
|
/**
|
@@ -1995,7 +1930,7 @@ var BaseTransactionRequest = class {
|
|
1995
1930
|
*/
|
1996
1931
|
getChangeOutputs() {
|
1997
1932
|
return this.outputs.filter(
|
1998
|
-
(output) => output.type ===
|
1933
|
+
(output) => output.type === import_transactions5.OutputType.Change
|
1999
1934
|
);
|
2000
1935
|
}
|
2001
1936
|
/**
|
@@ -2007,9 +1942,9 @@ var BaseTransactionRequest = class {
|
|
2007
1942
|
const ownerAddress = (0, import_address.addressify)(owner);
|
2008
1943
|
const found = this.inputs.find((input) => {
|
2009
1944
|
switch (input.type) {
|
2010
|
-
case
|
1945
|
+
case import_transactions5.InputType.Coin:
|
2011
1946
|
return (0, import_utils9.hexlify)(input.owner) === ownerAddress.toB256();
|
2012
|
-
case
|
1947
|
+
case import_transactions5.InputType.Message:
|
2013
1948
|
return (0, import_utils9.hexlify)(input.recipient) === ownerAddress.toB256();
|
2014
1949
|
default:
|
2015
1950
|
return false;
|
@@ -2038,7 +1973,7 @@ var BaseTransactionRequest = class {
|
|
2038
1973
|
}
|
2039
1974
|
const input = {
|
2040
1975
|
...coin,
|
2041
|
-
type:
|
1976
|
+
type: import_transactions5.InputType.Coin,
|
2042
1977
|
owner: owner.toB256(),
|
2043
1978
|
amount,
|
2044
1979
|
assetId,
|
@@ -2060,7 +1995,7 @@ var BaseTransactionRequest = class {
|
|
2060
1995
|
*/
|
2061
1996
|
addMessageInput(message, predicate) {
|
2062
1997
|
const { recipient, sender, amount } = message;
|
2063
|
-
const assetId =
|
1998
|
+
const assetId = import_configs6.BaseAssetId;
|
2064
1999
|
let witnessIndex;
|
2065
2000
|
if (predicate) {
|
2066
2001
|
witnessIndex = 0;
|
@@ -2072,7 +2007,7 @@ var BaseTransactionRequest = class {
|
|
2072
2007
|
}
|
2073
2008
|
const input = {
|
2074
2009
|
...message,
|
2075
|
-
type:
|
2010
|
+
type: import_transactions5.InputType.Message,
|
2076
2011
|
sender: sender.toB256(),
|
2077
2012
|
recipient: recipient.toB256(),
|
2078
2013
|
amount,
|
@@ -2142,9 +2077,9 @@ var BaseTransactionRequest = class {
|
|
2142
2077
|
* @param amount - Amount of coin.
|
2143
2078
|
* @param assetId - Asset ID of coin.
|
2144
2079
|
*/
|
2145
|
-
addCoinOutput(to, amount, assetId =
|
2080
|
+
addCoinOutput(to, amount, assetId = import_configs6.BaseAssetId) {
|
2146
2081
|
this.pushOutput({
|
2147
|
-
type:
|
2082
|
+
type: import_transactions5.OutputType.Coin,
|
2148
2083
|
to: (0, import_address.addressify)(to).toB256(),
|
2149
2084
|
amount,
|
2150
2085
|
assetId
|
@@ -2160,7 +2095,7 @@ var BaseTransactionRequest = class {
|
|
2160
2095
|
addCoinOutputs(to, quantities) {
|
2161
2096
|
quantities.map(coinQuantityfy).forEach((quantity) => {
|
2162
2097
|
this.pushOutput({
|
2163
|
-
type:
|
2098
|
+
type: import_transactions5.OutputType.Coin,
|
2164
2099
|
to: (0, import_address.addressify)(to).toB256(),
|
2165
2100
|
amount: quantity.amount,
|
2166
2101
|
assetId: quantity.assetId
|
@@ -2174,13 +2109,13 @@ var BaseTransactionRequest = class {
|
|
2174
2109
|
* @param to - Address of the owner.
|
2175
2110
|
* @param assetId - Asset ID of coin.
|
2176
2111
|
*/
|
2177
|
-
addChangeOutput(to, assetId =
|
2112
|
+
addChangeOutput(to, assetId = import_configs6.BaseAssetId) {
|
2178
2113
|
const changeOutput = this.getChangeOutputs().find(
|
2179
2114
|
(output) => (0, import_utils9.hexlify)(output.assetId) === assetId
|
2180
2115
|
);
|
2181
2116
|
if (!changeOutput) {
|
2182
2117
|
this.pushOutput({
|
2183
|
-
type:
|
2118
|
+
type: import_transactions5.OutputType.Change,
|
2184
2119
|
to: (0, import_address.addressify)(to).toB256(),
|
2185
2120
|
assetId
|
2186
2121
|
});
|
@@ -2236,7 +2171,7 @@ var BaseTransactionRequest = class {
|
|
2236
2171
|
let idCounter = 0;
|
2237
2172
|
const generateId = () => {
|
2238
2173
|
const counterString = String(idCounter++);
|
2239
|
-
const id =
|
2174
|
+
const id = import_configs6.ZeroBytes32.slice(0, -counterString.length).concat(counterString);
|
2240
2175
|
return id;
|
2241
2176
|
};
|
2242
2177
|
const findAssetInput = (assetId) => this.inputs.find((input) => {
|
@@ -2258,13 +2193,13 @@ var BaseTransactionRequest = class {
|
|
2258
2193
|
assetId,
|
2259
2194
|
owner: resourcesOwner || import_address.Address.fromRandom(),
|
2260
2195
|
maturity: 0,
|
2261
|
-
blockCreated: (0,
|
2262
|
-
txCreatedIdx: (0,
|
2196
|
+
blockCreated: (0, import_math6.bn)(1),
|
2197
|
+
txCreatedIdx: (0, import_math6.bn)(1)
|
2263
2198
|
}
|
2264
2199
|
]);
|
2265
2200
|
}
|
2266
2201
|
};
|
2267
|
-
updateAssetInput(
|
2202
|
+
updateAssetInput(import_configs6.BaseAssetId, (0, import_math6.bn)(1e11));
|
2268
2203
|
quantities.forEach((q) => updateAssetInput(q.assetId, q.amount));
|
2269
2204
|
}
|
2270
2205
|
/**
|
@@ -2275,7 +2210,7 @@ var BaseTransactionRequest = class {
|
|
2275
2210
|
*/
|
2276
2211
|
getCoinOutputsQuantities() {
|
2277
2212
|
const coinsQuantities = this.getCoinOutputs().map(({ amount, assetId }) => ({
|
2278
|
-
amount: (0,
|
2213
|
+
amount: (0, import_math6.bn)(amount),
|
2279
2214
|
assetId: assetId.toString()
|
2280
2215
|
}));
|
2281
2216
|
return coinsQuantities;
|
@@ -2293,18 +2228,18 @@ var BaseTransactionRequest = class {
|
|
2293
2228
|
this.inputs.forEach((i) => {
|
2294
2229
|
let correspondingInput;
|
2295
2230
|
switch (i.type) {
|
2296
|
-
case
|
2297
|
-
correspondingInput = inputs.find((x) => x.type ===
|
2231
|
+
case import_transactions5.InputType.Coin:
|
2232
|
+
correspondingInput = inputs.find((x) => x.type === import_transactions5.InputType.Coin && x.owner === i.owner);
|
2298
2233
|
break;
|
2299
|
-
case
|
2234
|
+
case import_transactions5.InputType.Message:
|
2300
2235
|
correspondingInput = inputs.find(
|
2301
|
-
(x) => x.type ===
|
2236
|
+
(x) => x.type === import_transactions5.InputType.Message && x.sender === i.sender
|
2302
2237
|
);
|
2303
2238
|
break;
|
2304
2239
|
default:
|
2305
2240
|
return;
|
2306
2241
|
}
|
2307
|
-
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0,
|
2242
|
+
if (correspondingInput && "predicateGasUsed" in correspondingInput && (0, import_math6.bn)(correspondingInput.predicateGasUsed).gt(0)) {
|
2308
2243
|
i.predicate = correspondingInput.predicate;
|
2309
2244
|
i.predicateData = correspondingInput.predicateData;
|
2310
2245
|
i.predicateGasUsed = correspondingInput.predicateGasUsed;
|
@@ -2314,47 +2249,47 @@ var BaseTransactionRequest = class {
|
|
2314
2249
|
};
|
2315
2250
|
|
2316
2251
|
// src/providers/transaction-request/create-transaction-request.ts
|
2317
|
-
var
|
2318
|
-
var
|
2319
|
-
var
|
2252
|
+
var import_configs8 = require("@fuel-ts/address/configs");
|
2253
|
+
var import_math8 = require("@fuel-ts/math");
|
2254
|
+
var import_transactions7 = require("@fuel-ts/transactions");
|
2320
2255
|
var import_utils13 = require("@fuel-ts/utils");
|
2321
2256
|
|
2322
2257
|
// src/providers/transaction-request/hash-transaction.ts
|
2323
|
-
var
|
2258
|
+
var import_configs7 = require("@fuel-ts/address/configs");
|
2324
2259
|
var import_hasher = require("@fuel-ts/hasher");
|
2325
|
-
var
|
2326
|
-
var
|
2260
|
+
var import_math7 = require("@fuel-ts/math");
|
2261
|
+
var import_transactions6 = require("@fuel-ts/transactions");
|
2327
2262
|
var import_utils11 = require("@fuel-ts/utils");
|
2328
2263
|
var import_ramda2 = require("ramda");
|
2329
2264
|
function hashTransaction(transactionRequest, chainId) {
|
2330
2265
|
const transaction = transactionRequest.toTransaction();
|
2331
|
-
if (transaction.type ===
|
2332
|
-
transaction.receiptsRoot =
|
2266
|
+
if (transaction.type === import_transactions6.TransactionType.Script) {
|
2267
|
+
transaction.receiptsRoot = import_configs7.ZeroBytes32;
|
2333
2268
|
}
|
2334
2269
|
transaction.inputs = transaction.inputs.map((input) => {
|
2335
2270
|
const inputClone = (0, import_ramda2.clone)(input);
|
2336
2271
|
switch (inputClone.type) {
|
2337
|
-
case
|
2272
|
+
case import_transactions6.InputType.Coin: {
|
2338
2273
|
inputClone.txPointer = {
|
2339
2274
|
blockHeight: 0,
|
2340
2275
|
txIndex: 0
|
2341
2276
|
};
|
2342
|
-
inputClone.predicateGasUsed = (0,
|
2277
|
+
inputClone.predicateGasUsed = (0, import_math7.bn)(0);
|
2343
2278
|
return inputClone;
|
2344
2279
|
}
|
2345
|
-
case
|
2346
|
-
inputClone.predicateGasUsed = (0,
|
2280
|
+
case import_transactions6.InputType.Message: {
|
2281
|
+
inputClone.predicateGasUsed = (0, import_math7.bn)(0);
|
2347
2282
|
return inputClone;
|
2348
2283
|
}
|
2349
|
-
case
|
2284
|
+
case import_transactions6.InputType.Contract: {
|
2350
2285
|
inputClone.txPointer = {
|
2351
2286
|
blockHeight: 0,
|
2352
2287
|
txIndex: 0
|
2353
2288
|
};
|
2354
|
-
inputClone.txID =
|
2289
|
+
inputClone.txID = import_configs7.ZeroBytes32;
|
2355
2290
|
inputClone.outputIndex = 0;
|
2356
|
-
inputClone.balanceRoot =
|
2357
|
-
inputClone.stateRoot =
|
2291
|
+
inputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2292
|
+
inputClone.stateRoot = import_configs7.ZeroBytes32;
|
2358
2293
|
return inputClone;
|
2359
2294
|
}
|
2360
2295
|
default:
|
@@ -2364,19 +2299,19 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2364
2299
|
transaction.outputs = transaction.outputs.map((output) => {
|
2365
2300
|
const outputClone = (0, import_ramda2.clone)(output);
|
2366
2301
|
switch (outputClone.type) {
|
2367
|
-
case
|
2368
|
-
outputClone.balanceRoot =
|
2369
|
-
outputClone.stateRoot =
|
2302
|
+
case import_transactions6.OutputType.Contract: {
|
2303
|
+
outputClone.balanceRoot = import_configs7.ZeroBytes32;
|
2304
|
+
outputClone.stateRoot = import_configs7.ZeroBytes32;
|
2370
2305
|
return outputClone;
|
2371
2306
|
}
|
2372
|
-
case
|
2373
|
-
outputClone.amount = (0,
|
2307
|
+
case import_transactions6.OutputType.Change: {
|
2308
|
+
outputClone.amount = (0, import_math7.bn)(0);
|
2374
2309
|
return outputClone;
|
2375
2310
|
}
|
2376
|
-
case
|
2377
|
-
outputClone.to =
|
2378
|
-
outputClone.amount = (0,
|
2379
|
-
outputClone.assetId =
|
2311
|
+
case import_transactions6.OutputType.Variable: {
|
2312
|
+
outputClone.to = import_configs7.ZeroBytes32;
|
2313
|
+
outputClone.amount = (0, import_math7.bn)(0);
|
2314
|
+
outputClone.assetId = import_configs7.ZeroBytes32;
|
2380
2315
|
return outputClone;
|
2381
2316
|
}
|
2382
2317
|
default:
|
@@ -2386,7 +2321,7 @@ function hashTransaction(transactionRequest, chainId) {
|
|
2386
2321
|
transaction.witnessesCount = 0;
|
2387
2322
|
transaction.witnesses = [];
|
2388
2323
|
const chainIdBytes = (0, import_hasher.uint64ToBytesBE)(chainId);
|
2389
|
-
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new
|
2324
|
+
const concatenatedData = (0, import_utils11.concat)([chainIdBytes, new import_transactions6.TransactionCoder().encode(transaction)]);
|
2390
2325
|
return (0, import_hasher.sha256)(concatenatedData);
|
2391
2326
|
}
|
2392
2327
|
|
@@ -2422,7 +2357,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2422
2357
|
return new this(obj);
|
2423
2358
|
}
|
2424
2359
|
/** Type of the transaction */
|
2425
|
-
type =
|
2360
|
+
type = import_transactions7.TransactionType.Create;
|
2426
2361
|
/** Witness index of contract bytecode to create */
|
2427
2362
|
bytecodeWitnessIndex;
|
2428
2363
|
/** Salt */
|
@@ -2442,7 +2377,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2442
2377
|
} = {}) {
|
2443
2378
|
super(rest);
|
2444
2379
|
this.bytecodeWitnessIndex = bytecodeWitnessIndex ?? 0;
|
2445
|
-
this.salt = (0, import_utils13.hexlify)(salt ??
|
2380
|
+
this.salt = (0, import_utils13.hexlify)(salt ?? import_configs8.ZeroBytes32);
|
2446
2381
|
this.storageSlots = [...storageSlots ?? []];
|
2447
2382
|
}
|
2448
2383
|
/**
|
@@ -2455,12 +2390,12 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2455
2390
|
const bytecodeWitnessIndex = this.bytecodeWitnessIndex;
|
2456
2391
|
const storageSlots = this.storageSlots?.map(storageSlotify) ?? [];
|
2457
2392
|
return {
|
2458
|
-
type:
|
2393
|
+
type: import_transactions7.TransactionType.Create,
|
2459
2394
|
...baseTransaction,
|
2460
2395
|
bytecodeLength: baseTransaction.witnesses[bytecodeWitnessIndex].dataLength / 4,
|
2461
2396
|
bytecodeWitnessIndex,
|
2462
2397
|
storageSlotsCount: storageSlots.length,
|
2463
|
-
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) :
|
2398
|
+
salt: this.salt ? (0, import_utils13.hexlify)(this.salt) : import_configs8.ZeroBytes32,
|
2464
2399
|
storageSlots
|
2465
2400
|
};
|
2466
2401
|
}
|
@@ -2471,7 +2406,7 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2471
2406
|
*/
|
2472
2407
|
getContractCreatedOutputs() {
|
2473
2408
|
return this.outputs.filter(
|
2474
|
-
(output) => output.type ===
|
2409
|
+
(output) => output.type === import_transactions7.OutputType.ContractCreated
|
2475
2410
|
);
|
2476
2411
|
}
|
2477
2412
|
/**
|
@@ -2492,14 +2427,14 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2492
2427
|
*/
|
2493
2428
|
addContractCreatedOutput(contractId, stateRoot) {
|
2494
2429
|
this.pushOutput({
|
2495
|
-
type:
|
2430
|
+
type: import_transactions7.OutputType.ContractCreated,
|
2496
2431
|
contractId,
|
2497
2432
|
stateRoot
|
2498
2433
|
});
|
2499
2434
|
}
|
2500
2435
|
metadataGas(gasCosts) {
|
2501
2436
|
return calculateMetadataGasForTxCreate({
|
2502
|
-
contractBytesSize: (0,
|
2437
|
+
contractBytesSize: (0, import_math8.bn)((0, import_utils13.arrayify)(this.witnesses[this.bytecodeWitnessIndex] || "0x").length),
|
2503
2438
|
gasCosts,
|
2504
2439
|
stateRootSize: this.storageSlots.length,
|
2505
2440
|
txBytesSize: this.byteSize()
|
@@ -2510,9 +2445,9 @@ var CreateTransactionRequest = class extends BaseTransactionRequest {
|
|
2510
2445
|
// src/providers/transaction-request/script-transaction-request.ts
|
2511
2446
|
var import_abi_coder = require("@fuel-ts/abi-coder");
|
2512
2447
|
var import_address2 = require("@fuel-ts/address");
|
2513
|
-
var
|
2514
|
-
var
|
2515
|
-
var
|
2448
|
+
var import_configs9 = require("@fuel-ts/address/configs");
|
2449
|
+
var import_math9 = require("@fuel-ts/math");
|
2450
|
+
var import_transactions8 = require("@fuel-ts/transactions");
|
2516
2451
|
var import_utils15 = require("@fuel-ts/utils");
|
2517
2452
|
|
2518
2453
|
// src/providers/transaction-request/scripts.ts
|
@@ -2550,7 +2485,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2550
2485
|
return new this(obj);
|
2551
2486
|
}
|
2552
2487
|
/** Type of the transaction */
|
2553
|
-
type =
|
2488
|
+
type = import_transactions8.TransactionType.Script;
|
2554
2489
|
/** Gas limit for transaction */
|
2555
2490
|
gasLimit;
|
2556
2491
|
/** Script to execute */
|
@@ -2565,7 +2500,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2565
2500
|
*/
|
2566
2501
|
constructor({ script, scriptData, gasLimit, ...rest } = {}) {
|
2567
2502
|
super(rest);
|
2568
|
-
this.gasLimit = (0,
|
2503
|
+
this.gasLimit = (0, import_math9.bn)(gasLimit);
|
2569
2504
|
this.script = (0, import_utils15.arrayify)(script ?? returnZeroScript.bytes);
|
2570
2505
|
this.scriptData = (0, import_utils15.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
2571
2506
|
this.abis = rest.abis;
|
@@ -2579,12 +2514,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2579
2514
|
const script = (0, import_utils15.arrayify)(this.script ?? "0x");
|
2580
2515
|
const scriptData = (0, import_utils15.arrayify)(this.scriptData ?? "0x");
|
2581
2516
|
return {
|
2582
|
-
type:
|
2517
|
+
type: import_transactions8.TransactionType.Script,
|
2583
2518
|
scriptGasLimit: this.gasLimit,
|
2584
2519
|
...super.getBaseTransaction(),
|
2585
2520
|
scriptLength: script.length,
|
2586
2521
|
scriptDataLength: scriptData.length,
|
2587
|
-
receiptsRoot:
|
2522
|
+
receiptsRoot: import_configs9.ZeroBytes32,
|
2588
2523
|
script: (0, import_utils15.hexlify)(script),
|
2589
2524
|
scriptData: (0, import_utils15.hexlify)(scriptData)
|
2590
2525
|
};
|
@@ -2596,7 +2531,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2596
2531
|
*/
|
2597
2532
|
getContractInputs() {
|
2598
2533
|
return this.inputs.filter(
|
2599
|
-
(input) => input.type ===
|
2534
|
+
(input) => input.type === import_transactions8.InputType.Contract
|
2600
2535
|
);
|
2601
2536
|
}
|
2602
2537
|
/**
|
@@ -2606,7 +2541,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2606
2541
|
*/
|
2607
2542
|
getContractOutputs() {
|
2608
2543
|
return this.outputs.filter(
|
2609
|
-
(output) => output.type ===
|
2544
|
+
(output) => output.type === import_transactions8.OutputType.Contract
|
2610
2545
|
);
|
2611
2546
|
}
|
2612
2547
|
/**
|
@@ -2616,7 +2551,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2616
2551
|
*/
|
2617
2552
|
getVariableOutputs() {
|
2618
2553
|
return this.outputs.filter(
|
2619
|
-
(output) => output.type ===
|
2554
|
+
(output) => output.type === import_transactions8.OutputType.Variable
|
2620
2555
|
);
|
2621
2556
|
}
|
2622
2557
|
/**
|
@@ -2639,7 +2574,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2639
2574
|
let outputsNumber = numberOfVariables;
|
2640
2575
|
while (outputsNumber) {
|
2641
2576
|
this.pushOutput({
|
2642
|
-
type:
|
2577
|
+
type: import_transactions8.OutputType.Variable
|
2643
2578
|
});
|
2644
2579
|
outputsNumber -= 1;
|
2645
2580
|
}
|
@@ -2672,12 +2607,12 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2672
2607
|
return this;
|
2673
2608
|
}
|
2674
2609
|
const inputIndex = super.pushInput({
|
2675
|
-
type:
|
2610
|
+
type: import_transactions8.InputType.Contract,
|
2676
2611
|
contractId: contractAddress.toB256(),
|
2677
2612
|
txPointer: "0x00000000000000000000000000000000"
|
2678
2613
|
});
|
2679
2614
|
this.pushOutput({
|
2680
|
-
type:
|
2615
|
+
type: import_transactions8.OutputType.Contract,
|
2681
2616
|
inputIndex
|
2682
2617
|
});
|
2683
2618
|
return this;
|
@@ -2713,38 +2648,38 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
2713
2648
|
};
|
2714
2649
|
|
2715
2650
|
// src/providers/transaction-request/utils.ts
|
2716
|
-
var
|
2717
|
-
var
|
2651
|
+
var import_errors8 = require("@fuel-ts/errors");
|
2652
|
+
var import_transactions9 = require("@fuel-ts/transactions");
|
2718
2653
|
var transactionRequestify = (obj) => {
|
2719
2654
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest) {
|
2720
2655
|
return obj;
|
2721
2656
|
}
|
2722
2657
|
const { type } = obj;
|
2723
2658
|
switch (obj.type) {
|
2724
|
-
case
|
2659
|
+
case import_transactions9.TransactionType.Script: {
|
2725
2660
|
return ScriptTransactionRequest.from(obj);
|
2726
2661
|
}
|
2727
|
-
case
|
2662
|
+
case import_transactions9.TransactionType.Create: {
|
2728
2663
|
return CreateTransactionRequest.from(obj);
|
2729
2664
|
}
|
2730
2665
|
default: {
|
2731
|
-
throw new
|
2666
|
+
throw new import_errors8.FuelError(import_errors8.ErrorCode.INVALID_TRANSACTION_TYPE, `Invalid transaction type: ${type}.`);
|
2732
2667
|
}
|
2733
2668
|
}
|
2734
2669
|
};
|
2735
2670
|
|
2736
2671
|
// src/providers/transaction-response/transaction-response.ts
|
2737
|
-
var
|
2738
|
-
var
|
2739
|
-
var
|
2672
|
+
var import_errors12 = require("@fuel-ts/errors");
|
2673
|
+
var import_math13 = require("@fuel-ts/math");
|
2674
|
+
var import_transactions16 = require("@fuel-ts/transactions");
|
2740
2675
|
var import_utils21 = require("@fuel-ts/utils");
|
2741
2676
|
|
2742
2677
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2743
2678
|
var import_utils19 = require("@fuel-ts/utils");
|
2744
2679
|
|
2745
2680
|
// src/providers/transaction-summary/calculate-transaction-fee.ts
|
2746
|
-
var
|
2747
|
-
var
|
2681
|
+
var import_math10 = require("@fuel-ts/math");
|
2682
|
+
var import_transactions10 = require("@fuel-ts/transactions");
|
2748
2683
|
var import_utils16 = require("@fuel-ts/utils");
|
2749
2684
|
var calculateTransactionFee = (params) => {
|
2750
2685
|
const {
|
@@ -2752,24 +2687,24 @@ var calculateTransactionFee = (params) => {
|
|
2752
2687
|
rawPayload,
|
2753
2688
|
consensusParameters: { gasCosts, feeParams }
|
2754
2689
|
} = params;
|
2755
|
-
const gasPerByte = (0,
|
2756
|
-
const gasPriceFactor = (0,
|
2690
|
+
const gasPerByte = (0, import_math10.bn)(feeParams.gasPerByte);
|
2691
|
+
const gasPriceFactor = (0, import_math10.bn)(feeParams.gasPriceFactor);
|
2757
2692
|
const transactionBytes = (0, import_utils16.arrayify)(rawPayload);
|
2758
|
-
const [transaction] = new
|
2759
|
-
if (transaction.type ===
|
2693
|
+
const [transaction] = new import_transactions10.TransactionCoder().decode(transactionBytes, 0);
|
2694
|
+
if (transaction.type === import_transactions10.TransactionType.Mint) {
|
2760
2695
|
return {
|
2761
|
-
fee: (0,
|
2762
|
-
minFee: (0,
|
2763
|
-
maxFee: (0,
|
2764
|
-
feeFromGasUsed: (0,
|
2696
|
+
fee: (0, import_math10.bn)(0),
|
2697
|
+
minFee: (0, import_math10.bn)(0),
|
2698
|
+
maxFee: (0, import_math10.bn)(0),
|
2699
|
+
feeFromGasUsed: (0, import_math10.bn)(0)
|
2765
2700
|
};
|
2766
2701
|
}
|
2767
2702
|
const { type, witnesses, inputs, policies } = transaction;
|
2768
|
-
let metadataGas = (0,
|
2769
|
-
let gasLimit = (0,
|
2770
|
-
if (type ===
|
2703
|
+
let metadataGas = (0, import_math10.bn)(0);
|
2704
|
+
let gasLimit = (0, import_math10.bn)(0);
|
2705
|
+
if (type === import_transactions10.TransactionType.Create) {
|
2771
2706
|
const { bytecodeWitnessIndex, storageSlots } = transaction;
|
2772
|
-
const contractBytesSize = (0,
|
2707
|
+
const contractBytesSize = (0, import_math10.bn)((0, import_utils16.arrayify)(witnesses[bytecodeWitnessIndex].data).length);
|
2773
2708
|
metadataGas = calculateMetadataGasForTxCreate({
|
2774
2709
|
contractBytesSize,
|
2775
2710
|
gasCosts,
|
@@ -2788,13 +2723,13 @@ var calculateTransactionFee = (params) => {
|
|
2788
2723
|
}
|
2789
2724
|
const minGas = getMinGas({
|
2790
2725
|
gasCosts,
|
2791
|
-
gasPerByte: (0,
|
2726
|
+
gasPerByte: (0, import_math10.bn)(gasPerByte),
|
2792
2727
|
inputs,
|
2793
2728
|
metadataGas,
|
2794
2729
|
txBytesSize: transactionBytes.length
|
2795
2730
|
});
|
2796
|
-
const gasPrice = (0,
|
2797
|
-
const witnessLimit = policies.find((policy) => policy.type ===
|
2731
|
+
const gasPrice = (0, import_math10.bn)(policies.find((policy) => policy.type === import_transactions10.PolicyType.GasPrice)?.data);
|
2732
|
+
const witnessLimit = policies.find((policy) => policy.type === import_transactions10.PolicyType.WitnessLimit)?.data;
|
2798
2733
|
const witnessesLength = witnesses.reduce((acc, wit) => acc + wit.dataLength, 0);
|
2799
2734
|
const maxGas = getMaxGas({
|
2800
2735
|
gasPerByte,
|
@@ -2816,14 +2751,14 @@ var calculateTransactionFee = (params) => {
|
|
2816
2751
|
};
|
2817
2752
|
|
2818
2753
|
// src/providers/transaction-summary/operations.ts
|
2819
|
-
var
|
2820
|
-
var
|
2821
|
-
var
|
2822
|
-
var
|
2754
|
+
var import_configs10 = require("@fuel-ts/address/configs");
|
2755
|
+
var import_errors10 = require("@fuel-ts/errors");
|
2756
|
+
var import_math12 = require("@fuel-ts/math");
|
2757
|
+
var import_transactions13 = require("@fuel-ts/transactions");
|
2823
2758
|
|
2824
2759
|
// src/providers/transaction-summary/call.ts
|
2825
2760
|
var import_abi_coder2 = require("@fuel-ts/abi-coder");
|
2826
|
-
var
|
2761
|
+
var import_math11 = require("@fuel-ts/math");
|
2827
2762
|
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2828
2763
|
const abiInterface = new import_abi_coder2.Interface(abi);
|
2829
2764
|
const callFunctionSelector = receipt.param1.toHex(8);
|
@@ -2832,7 +2767,7 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2832
2767
|
let encodedArgs;
|
2833
2768
|
if (functionFragment.isInputDataPointer) {
|
2834
2769
|
if (rawPayload) {
|
2835
|
-
const argsOffset = (0,
|
2770
|
+
const argsOffset = (0, import_math11.bn)(receipt.param2).sub((0, import_abi_coder2.calculateVmTxMemory)({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2836
2771
|
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2837
2772
|
}
|
2838
2773
|
} else {
|
@@ -2866,8 +2801,8 @@ var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
|
2866
2801
|
};
|
2867
2802
|
|
2868
2803
|
// src/providers/transaction-summary/input.ts
|
2869
|
-
var
|
2870
|
-
var
|
2804
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2805
|
+
var import_transactions11 = require("@fuel-ts/transactions");
|
2871
2806
|
function getInputsByTypes(inputs, types) {
|
2872
2807
|
return inputs.filter((i) => types.includes(i.type));
|
2873
2808
|
}
|
@@ -2875,16 +2810,16 @@ function getInputsByType(inputs, type) {
|
|
2875
2810
|
return inputs.filter((i) => i.type === type);
|
2876
2811
|
}
|
2877
2812
|
function getInputsCoin(inputs) {
|
2878
|
-
return getInputsByType(inputs,
|
2813
|
+
return getInputsByType(inputs, import_transactions11.InputType.Coin);
|
2879
2814
|
}
|
2880
2815
|
function getInputsMessage(inputs) {
|
2881
|
-
return getInputsByType(inputs,
|
2816
|
+
return getInputsByType(inputs, import_transactions11.InputType.Message);
|
2882
2817
|
}
|
2883
2818
|
function getInputsCoinAndMessage(inputs) {
|
2884
|
-
return getInputsByTypes(inputs, [
|
2819
|
+
return getInputsByTypes(inputs, [import_transactions11.InputType.Coin, import_transactions11.InputType.Message]);
|
2885
2820
|
}
|
2886
2821
|
function getInputsContract(inputs) {
|
2887
|
-
return getInputsByType(inputs,
|
2822
|
+
return getInputsByType(inputs, import_transactions11.InputType.Contract);
|
2888
2823
|
}
|
2889
2824
|
function getInputFromAssetId(inputs, assetId) {
|
2890
2825
|
const coinInputs = getInputsCoin(inputs);
|
@@ -2903,43 +2838,43 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
2903
2838
|
if (!contractInput) {
|
2904
2839
|
return void 0;
|
2905
2840
|
}
|
2906
|
-
if (contractInput.type !==
|
2907
|
-
throw new
|
2908
|
-
|
2841
|
+
if (contractInput.type !== import_transactions11.InputType.Contract) {
|
2842
|
+
throw new import_errors9.FuelError(
|
2843
|
+
import_errors9.ErrorCode.INVALID_TRANSACTION_INPUT,
|
2909
2844
|
`Contract input should be of type 'contract'.`
|
2910
2845
|
);
|
2911
2846
|
}
|
2912
2847
|
return contractInput;
|
2913
2848
|
}
|
2914
2849
|
function getInputAccountAddress(input) {
|
2915
|
-
if (input.type ===
|
2850
|
+
if (input.type === import_transactions11.InputType.Coin) {
|
2916
2851
|
return input.owner.toString();
|
2917
2852
|
}
|
2918
|
-
if (input.type ===
|
2853
|
+
if (input.type === import_transactions11.InputType.Message) {
|
2919
2854
|
return input.recipient.toString();
|
2920
2855
|
}
|
2921
2856
|
return "";
|
2922
2857
|
}
|
2923
2858
|
|
2924
2859
|
// src/providers/transaction-summary/output.ts
|
2925
|
-
var
|
2860
|
+
var import_transactions12 = require("@fuel-ts/transactions");
|
2926
2861
|
function getOutputsByType(outputs, type) {
|
2927
2862
|
return outputs.filter((o) => o.type === type);
|
2928
2863
|
}
|
2929
2864
|
function getOutputsContractCreated(outputs) {
|
2930
|
-
return getOutputsByType(outputs,
|
2865
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.ContractCreated);
|
2931
2866
|
}
|
2932
2867
|
function getOutputsCoin(outputs) {
|
2933
|
-
return getOutputsByType(outputs,
|
2868
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Coin);
|
2934
2869
|
}
|
2935
2870
|
function getOutputsChange(outputs) {
|
2936
|
-
return getOutputsByType(outputs,
|
2871
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Change);
|
2937
2872
|
}
|
2938
2873
|
function getOutputsContract(outputs) {
|
2939
|
-
return getOutputsByType(outputs,
|
2874
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Contract);
|
2940
2875
|
}
|
2941
2876
|
function getOutputsVariable(outputs) {
|
2942
|
-
return getOutputsByType(outputs,
|
2877
|
+
return getOutputsByType(outputs, import_transactions12.OutputType.Variable);
|
2943
2878
|
}
|
2944
2879
|
|
2945
2880
|
// src/providers/transaction-summary/types.ts
|
@@ -2986,15 +2921,15 @@ function getReceiptsByType(receipts, type) {
|
|
2986
2921
|
}
|
2987
2922
|
function getTransactionTypeName(transactionType) {
|
2988
2923
|
switch (transactionType) {
|
2989
|
-
case
|
2924
|
+
case import_transactions13.TransactionType.Mint:
|
2990
2925
|
return "Mint" /* Mint */;
|
2991
|
-
case
|
2926
|
+
case import_transactions13.TransactionType.Create:
|
2992
2927
|
return "Create" /* Create */;
|
2993
|
-
case
|
2928
|
+
case import_transactions13.TransactionType.Script:
|
2994
2929
|
return "Script" /* Script */;
|
2995
2930
|
default:
|
2996
|
-
throw new
|
2997
|
-
|
2931
|
+
throw new import_errors10.FuelError(
|
2932
|
+
import_errors10.ErrorCode.INVALID_TRANSACTION_TYPE,
|
2998
2933
|
`Invalid transaction type: ${transactionType}.`
|
2999
2934
|
);
|
3000
2935
|
}
|
@@ -3016,10 +2951,10 @@ function hasSameAssetId(a) {
|
|
3016
2951
|
return (b) => a.assetId === b.assetId;
|
3017
2952
|
}
|
3018
2953
|
function getReceiptsCall(receipts) {
|
3019
|
-
return getReceiptsByType(receipts,
|
2954
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.Call);
|
3020
2955
|
}
|
3021
2956
|
function getReceiptsMessageOut(receipts) {
|
3022
|
-
return getReceiptsByType(receipts,
|
2957
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.MessageOut);
|
3023
2958
|
}
|
3024
2959
|
var mergeAssets = (op1, op2) => {
|
3025
2960
|
const assets1 = op1.assetsSent || [];
|
@@ -3032,7 +2967,7 @@ var mergeAssets = (op1, op2) => {
|
|
3032
2967
|
if (!matchingAsset) {
|
3033
2968
|
return asset1;
|
3034
2969
|
}
|
3035
|
-
const mergedAmount = (0,
|
2970
|
+
const mergedAmount = (0, import_math12.bn)(asset1.amount).add(matchingAsset.amount);
|
3036
2971
|
return { ...asset1, amount: mergedAmount };
|
3037
2972
|
});
|
3038
2973
|
return mergedAssets.concat(filteredAssets);
|
@@ -3058,7 +2993,7 @@ function addOperation(operations, toAdd) {
|
|
3058
2993
|
return allOperations;
|
3059
2994
|
}
|
3060
2995
|
function getReceiptsTransferOut(receipts) {
|
3061
|
-
return getReceiptsByType(receipts,
|
2996
|
+
return getReceiptsByType(receipts, import_transactions13.ReceiptType.TransferOut);
|
3062
2997
|
}
|
3063
2998
|
function getWithdrawFromFuelOperations({
|
3064
2999
|
inputs,
|
@@ -3161,7 +3096,7 @@ function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutp
|
|
3161
3096
|
const { to: toAddress, assetId, amount } = receipt;
|
3162
3097
|
let { from: fromAddress } = receipt;
|
3163
3098
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3164
|
-
if (
|
3099
|
+
if (import_configs10.ZeroBytes32 === fromAddress) {
|
3165
3100
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
3166
3101
|
fromAddress = change?.to || fromAddress;
|
3167
3102
|
}
|
@@ -3218,11 +3153,11 @@ function getTransferOperations({
|
|
3218
3153
|
});
|
3219
3154
|
const transferReceipts = getReceiptsByType(
|
3220
3155
|
receipts,
|
3221
|
-
|
3156
|
+
import_transactions13.ReceiptType.Transfer
|
3222
3157
|
);
|
3223
3158
|
const transferOutReceipts = getReceiptsByType(
|
3224
3159
|
receipts,
|
3225
|
-
|
3160
|
+
import_transactions13.ReceiptType.TransferOut
|
3226
3161
|
);
|
3227
3162
|
[...transferReceipts, ...transferOutReceipts].forEach((receipt) => {
|
3228
3163
|
const operation = extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs);
|
@@ -3307,17 +3242,17 @@ function getOperations({
|
|
3307
3242
|
}
|
3308
3243
|
|
3309
3244
|
// src/providers/transaction-summary/receipt.ts
|
3310
|
-
var
|
3245
|
+
var import_transactions14 = require("@fuel-ts/transactions");
|
3311
3246
|
var processGqlReceipt = (gqlReceipt) => {
|
3312
3247
|
const receipt = assembleReceiptByType(gqlReceipt);
|
3313
3248
|
switch (receipt.type) {
|
3314
|
-
case
|
3249
|
+
case import_transactions14.ReceiptType.ReturnData: {
|
3315
3250
|
return {
|
3316
3251
|
...receipt,
|
3317
3252
|
data: gqlReceipt.data || "0x"
|
3318
3253
|
};
|
3319
3254
|
}
|
3320
|
-
case
|
3255
|
+
case import_transactions14.ReceiptType.LogData: {
|
3321
3256
|
return {
|
3322
3257
|
...receipt,
|
3323
3258
|
data: gqlReceipt.data || "0x"
|
@@ -3330,7 +3265,7 @@ var processGqlReceipt = (gqlReceipt) => {
|
|
3330
3265
|
var extractMintedAssetsFromReceipts = (receipts) => {
|
3331
3266
|
const mintedAssets = [];
|
3332
3267
|
receipts.forEach((receipt) => {
|
3333
|
-
if (receipt.type ===
|
3268
|
+
if (receipt.type === import_transactions14.ReceiptType.Mint) {
|
3334
3269
|
mintedAssets.push({
|
3335
3270
|
subId: receipt.subId,
|
3336
3271
|
contractId: receipt.contractId,
|
@@ -3344,7 +3279,7 @@ var extractMintedAssetsFromReceipts = (receipts) => {
|
|
3344
3279
|
var extractBurnedAssetsFromReceipts = (receipts) => {
|
3345
3280
|
const burnedAssets = [];
|
3346
3281
|
receipts.forEach((receipt) => {
|
3347
|
-
if (receipt.type ===
|
3282
|
+
if (receipt.type === import_transactions14.ReceiptType.Burn) {
|
3348
3283
|
burnedAssets.push({
|
3349
3284
|
subId: receipt.subId,
|
3350
3285
|
contractId: receipt.contractId,
|
@@ -3357,7 +3292,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3357
3292
|
};
|
3358
3293
|
|
3359
3294
|
// src/providers/transaction-summary/status.ts
|
3360
|
-
var
|
3295
|
+
var import_errors11 = require("@fuel-ts/errors");
|
3361
3296
|
var getTransactionStatusName = (gqlStatus) => {
|
3362
3297
|
switch (gqlStatus) {
|
3363
3298
|
case "FailureStatus":
|
@@ -3369,8 +3304,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
3369
3304
|
case "SqueezedOutStatus":
|
3370
3305
|
return "squeezedout" /* squeezedout */;
|
3371
3306
|
default:
|
3372
|
-
throw new
|
3373
|
-
|
3307
|
+
throw new import_errors11.FuelError(
|
3308
|
+
import_errors11.ErrorCode.INVALID_TRANSACTION_STATUS,
|
3374
3309
|
`Invalid transaction status: ${gqlStatus}.`
|
3375
3310
|
);
|
3376
3311
|
}
|
@@ -3483,12 +3418,12 @@ function assembleTransactionSummary(params) {
|
|
3483
3418
|
|
3484
3419
|
// src/providers/transaction-response/getDecodedLogs.ts
|
3485
3420
|
var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
3486
|
-
var
|
3421
|
+
var import_transactions15 = require("@fuel-ts/transactions");
|
3487
3422
|
function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
3488
3423
|
return receipts.reduce((logs, receipt) => {
|
3489
|
-
if (receipt.type ===
|
3424
|
+
if (receipt.type === import_transactions15.ReceiptType.LogData || receipt.type === import_transactions15.ReceiptType.Log) {
|
3490
3425
|
const interfaceToUse = new import_abi_coder3.Interface(externalAbis[receipt.id] || mainAbi);
|
3491
|
-
const data = receipt.type ===
|
3426
|
+
const data = receipt.type === import_transactions15.ReceiptType.Log ? new import_abi_coder3.BigNumberCoder("u64").encode(receipt.val0) : receipt.data;
|
3492
3427
|
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.val1.toNumber());
|
3493
3428
|
logs.push(decodedLog);
|
3494
3429
|
}
|
@@ -3503,7 +3438,7 @@ var TransactionResponse = class {
|
|
3503
3438
|
/** Current provider */
|
3504
3439
|
provider;
|
3505
3440
|
/** Gas used on the transaction */
|
3506
|
-
gasUsed = (0,
|
3441
|
+
gasUsed = (0, import_math13.bn)(0);
|
3507
3442
|
/** The graphql Transaction with receipts object. */
|
3508
3443
|
gqlTransaction;
|
3509
3444
|
abis;
|
@@ -3561,7 +3496,7 @@ var TransactionResponse = class {
|
|
3561
3496
|
* @returns The decoded transaction.
|
3562
3497
|
*/
|
3563
3498
|
decodeTransaction(transactionWithReceipts) {
|
3564
|
-
return new
|
3499
|
+
return new import_transactions16.TransactionCoder().decode(
|
3565
3500
|
(0, import_utils21.arrayify)(transactionWithReceipts.rawPayload),
|
3566
3501
|
0
|
3567
3502
|
)?.[0];
|
@@ -3608,8 +3543,8 @@ var TransactionResponse = class {
|
|
3608
3543
|
});
|
3609
3544
|
for await (const { statusChange } of subscription) {
|
3610
3545
|
if (statusChange.type === "SqueezedOutStatus") {
|
3611
|
-
throw new
|
3612
|
-
|
3546
|
+
throw new import_errors12.FuelError(
|
3547
|
+
import_errors12.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
3613
3548
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
3614
3549
|
);
|
3615
3550
|
}
|
@@ -3631,26 +3566,14 @@ var TransactionResponse = class {
|
|
3631
3566
|
gqlTransaction: this.gqlTransaction,
|
3632
3567
|
...transactionSummary
|
3633
3568
|
};
|
3634
|
-
let logs = [];
|
3635
3569
|
if (this.abis) {
|
3636
|
-
logs = getDecodedLogs(
|
3570
|
+
const logs = getDecodedLogs(
|
3637
3571
|
transactionSummary.receipts,
|
3638
3572
|
this.abis.main,
|
3639
3573
|
this.abis.otherContractsAbis
|
3640
3574
|
);
|
3641
3575
|
transactionResult.logs = logs;
|
3642
3576
|
}
|
3643
|
-
if (transactionResult.isStatusFailure) {
|
3644
|
-
const {
|
3645
|
-
receipts,
|
3646
|
-
gqlTransaction: { status }
|
3647
|
-
} = transactionResult;
|
3648
|
-
throw extractTxError({
|
3649
|
-
receipts,
|
3650
|
-
status,
|
3651
|
-
logs
|
3652
|
-
});
|
3653
|
-
}
|
3654
3577
|
return transactionResult;
|
3655
3578
|
}
|
3656
3579
|
/**
|
@@ -3659,7 +3582,14 @@ var TransactionResponse = class {
|
|
3659
3582
|
* @param contractsAbiMap - The contracts ABI map.
|
3660
3583
|
*/
|
3661
3584
|
async wait(contractsAbiMap) {
|
3662
|
-
|
3585
|
+
const result = await this.waitForResult(contractsAbiMap);
|
3586
|
+
if (result.isStatusFailure) {
|
3587
|
+
throw new import_errors12.FuelError(
|
3588
|
+
import_errors12.ErrorCode.TRANSACTION_FAILED,
|
3589
|
+
`Transaction failed: ${result.gqlTransaction.status.reason}`
|
3590
|
+
);
|
3591
|
+
}
|
3592
|
+
return result;
|
3663
3593
|
}
|
3664
3594
|
};
|
3665
3595
|
|
@@ -3721,29 +3651,29 @@ var processGqlChain = (chain) => {
|
|
3721
3651
|
const { contractParams, feeParams, predicateParams, scriptParams, txParams, gasCosts } = consensusParameters;
|
3722
3652
|
return {
|
3723
3653
|
name,
|
3724
|
-
baseChainHeight: (0,
|
3654
|
+
baseChainHeight: (0, import_math14.bn)(daHeight),
|
3725
3655
|
consensusParameters: {
|
3726
|
-
contractMaxSize: (0,
|
3727
|
-
maxInputs: (0,
|
3728
|
-
maxOutputs: (0,
|
3729
|
-
maxWitnesses: (0,
|
3730
|
-
maxGasPerTx: (0,
|
3731
|
-
maxScriptLength: (0,
|
3732
|
-
maxScriptDataLength: (0,
|
3733
|
-
maxStorageSlots: (0,
|
3734
|
-
maxPredicateLength: (0,
|
3735
|
-
maxPredicateDataLength: (0,
|
3736
|
-
maxGasPerPredicate: (0,
|
3737
|
-
gasPriceFactor: (0,
|
3738
|
-
gasPerByte: (0,
|
3739
|
-
maxMessageDataLength: (0,
|
3740
|
-
chainId: (0,
|
3656
|
+
contractMaxSize: (0, import_math14.bn)(contractParams.contractMaxSize),
|
3657
|
+
maxInputs: (0, import_math14.bn)(txParams.maxInputs),
|
3658
|
+
maxOutputs: (0, import_math14.bn)(txParams.maxOutputs),
|
3659
|
+
maxWitnesses: (0, import_math14.bn)(txParams.maxWitnesses),
|
3660
|
+
maxGasPerTx: (0, import_math14.bn)(txParams.maxGasPerTx),
|
3661
|
+
maxScriptLength: (0, import_math14.bn)(scriptParams.maxScriptLength),
|
3662
|
+
maxScriptDataLength: (0, import_math14.bn)(scriptParams.maxScriptDataLength),
|
3663
|
+
maxStorageSlots: (0, import_math14.bn)(contractParams.maxStorageSlots),
|
3664
|
+
maxPredicateLength: (0, import_math14.bn)(predicateParams.maxPredicateLength),
|
3665
|
+
maxPredicateDataLength: (0, import_math14.bn)(predicateParams.maxPredicateDataLength),
|
3666
|
+
maxGasPerPredicate: (0, import_math14.bn)(predicateParams.maxGasPerPredicate),
|
3667
|
+
gasPriceFactor: (0, import_math14.bn)(feeParams.gasPriceFactor),
|
3668
|
+
gasPerByte: (0, import_math14.bn)(feeParams.gasPerByte),
|
3669
|
+
maxMessageDataLength: (0, import_math14.bn)(predicateParams.maxMessageDataLength),
|
3670
|
+
chainId: (0, import_math14.bn)(consensusParameters.chainId),
|
3741
3671
|
gasCosts
|
3742
3672
|
},
|
3743
3673
|
gasCosts,
|
3744
3674
|
latestBlock: {
|
3745
3675
|
id: latestBlock.id,
|
3746
|
-
height: (0,
|
3676
|
+
height: (0, import_math14.bn)(latestBlock.header.height),
|
3747
3677
|
time: latestBlock.header.time,
|
3748
3678
|
transactions: latestBlock.transactions.map((i) => ({
|
3749
3679
|
id: i.id
|
@@ -3813,8 +3743,8 @@ var _Provider = class {
|
|
3813
3743
|
getChain() {
|
3814
3744
|
const chain = _Provider.chainInfoCache[this.url];
|
3815
3745
|
if (!chain) {
|
3816
|
-
throw new
|
3817
|
-
|
3746
|
+
throw new import_errors13.FuelError(
|
3747
|
+
import_errors13.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
3818
3748
|
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3819
3749
|
);
|
3820
3750
|
}
|
@@ -3826,8 +3756,8 @@ var _Provider = class {
|
|
3826
3756
|
getNode() {
|
3827
3757
|
const node = _Provider.nodeInfoCache[this.url];
|
3828
3758
|
if (!node) {
|
3829
|
-
throw new
|
3830
|
-
|
3759
|
+
throw new import_errors13.FuelError(
|
3760
|
+
import_errors13.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
3831
3761
|
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
3832
3762
|
);
|
3833
3763
|
}
|
@@ -3874,8 +3804,8 @@ var _Provider = class {
|
|
3874
3804
|
static ensureClientVersionIsSupported(nodeInfo) {
|
3875
3805
|
const { isMajorSupported, isMinorSupported, supportedVersion } = (0, import_versions.checkFuelCoreVersionCompatibility)(nodeInfo.nodeVersion);
|
3876
3806
|
if (!isMajorSupported || !isMinorSupported) {
|
3877
|
-
throw new
|
3878
|
-
|
3807
|
+
throw new import_errors13.FuelError(
|
3808
|
+
import_errors13.FuelError.CODES.UNSUPPORTED_FUEL_CLIENT_VERSION,
|
3879
3809
|
`Fuel client version: ${nodeInfo.nodeVersion}, Supported version: ${supportedVersion}`
|
3880
3810
|
);
|
3881
3811
|
}
|
@@ -3938,7 +3868,7 @@ var _Provider = class {
|
|
3938
3868
|
*/
|
3939
3869
|
async getBlockNumber() {
|
3940
3870
|
const { chain } = await this.operations.getChain();
|
3941
|
-
return (0,
|
3871
|
+
return (0, import_math14.bn)(chain.latestBlock.header.height, 10);
|
3942
3872
|
}
|
3943
3873
|
/**
|
3944
3874
|
* Returns the chain information.
|
@@ -3948,9 +3878,9 @@ var _Provider = class {
|
|
3948
3878
|
async fetchNode() {
|
3949
3879
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3950
3880
|
const processedNodeInfo = {
|
3951
|
-
maxDepth: (0,
|
3952
|
-
maxTx: (0,
|
3953
|
-
minGasPrice: (0,
|
3881
|
+
maxDepth: (0, import_math14.bn)(nodeInfo.maxDepth),
|
3882
|
+
maxTx: (0, import_math14.bn)(nodeInfo.maxTx),
|
3883
|
+
minGasPrice: (0, import_math14.bn)(nodeInfo.minGasPrice),
|
3954
3884
|
nodeVersion: nodeInfo.nodeVersion,
|
3955
3885
|
utxoValidation: nodeInfo.utxoValidation,
|
3956
3886
|
vmBacktrace: nodeInfo.vmBacktrace,
|
@@ -3996,17 +3926,17 @@ var _Provider = class {
|
|
3996
3926
|
if (estimateTxDependencies) {
|
3997
3927
|
await this.estimateTxDependencies(transactionRequest);
|
3998
3928
|
}
|
3999
|
-
const encodedTransaction = (0,
|
3929
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4000
3930
|
let abis;
|
4001
|
-
if (transactionRequest.type ===
|
3931
|
+
if (transactionRequest.type === import_transactions17.TransactionType.Script) {
|
4002
3932
|
abis = transactionRequest.abis;
|
4003
3933
|
}
|
4004
3934
|
if (awaitExecution) {
|
4005
3935
|
const subscription = this.operations.submitAndAwait({ encodedTransaction });
|
4006
3936
|
for await (const { submitAndAwait } of subscription) {
|
4007
3937
|
if (submitAndAwait.type === "SqueezedOutStatus") {
|
4008
|
-
throw new
|
4009
|
-
|
3938
|
+
throw new import_errors13.FuelError(
|
3939
|
+
import_errors13.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
4010
3940
|
`Transaction Squeezed Out with reason: ${submitAndAwait.reason}`
|
4011
3941
|
);
|
4012
3942
|
}
|
@@ -4039,7 +3969,7 @@ var _Provider = class {
|
|
4039
3969
|
if (estimateTxDependencies) {
|
4040
3970
|
return this.estimateTxDependencies(transactionRequest);
|
4041
3971
|
}
|
4042
|
-
const encodedTransaction = (0,
|
3972
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4043
3973
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4044
3974
|
encodedTransaction,
|
4045
3975
|
utxoValidation: utxoValidation || false
|
@@ -4058,13 +3988,13 @@ var _Provider = class {
|
|
4058
3988
|
async estimatePredicates(transactionRequest) {
|
4059
3989
|
const shouldEstimatePredicates = Boolean(
|
4060
3990
|
transactionRequest.inputs.find(
|
4061
|
-
(input) => "predicate" in input && input.predicate && !(0,
|
3991
|
+
(input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math14.BN(input.predicateGasUsed).isZero()
|
4062
3992
|
)
|
4063
3993
|
);
|
4064
3994
|
if (!shouldEstimatePredicates) {
|
4065
3995
|
return transactionRequest;
|
4066
3996
|
}
|
4067
|
-
const encodedTransaction = (0,
|
3997
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4068
3998
|
const response = await this.operations.estimatePredicates({
|
4069
3999
|
encodedTransaction
|
4070
4000
|
});
|
@@ -4073,7 +4003,7 @@ var _Provider = class {
|
|
4073
4003
|
} = response;
|
4074
4004
|
if (inputs) {
|
4075
4005
|
inputs.forEach((input, index) => {
|
4076
|
-
if ("predicateGasUsed" in input && (0,
|
4006
|
+
if ("predicateGasUsed" in input && (0, import_math14.bn)(input.predicateGasUsed).gt(0)) {
|
4077
4007
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4078
4008
|
}
|
4079
4009
|
});
|
@@ -4094,7 +4024,7 @@ var _Provider = class {
|
|
4094
4024
|
* @returns A promise.
|
4095
4025
|
*/
|
4096
4026
|
async estimateTxDependencies(transactionRequest) {
|
4097
|
-
if (transactionRequest.type ===
|
4027
|
+
if (transactionRequest.type === import_transactions17.TransactionType.Create) {
|
4098
4028
|
return {
|
4099
4029
|
receipts: [],
|
4100
4030
|
outputVariables: 0,
|
@@ -4107,7 +4037,7 @@ var _Provider = class {
|
|
4107
4037
|
let outputVariables = 0;
|
4108
4038
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
4109
4039
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4110
|
-
encodedTransaction: (0,
|
4040
|
+
encodedTransaction: (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes()),
|
4111
4041
|
utxoValidation: false
|
4112
4042
|
});
|
4113
4043
|
receipts = gqlReceipts.map(processGqlReceipt);
|
@@ -4145,7 +4075,7 @@ var _Provider = class {
|
|
4145
4075
|
if (estimateTxDependencies) {
|
4146
4076
|
return this.estimateTxDependencies(transactionRequest);
|
4147
4077
|
}
|
4148
|
-
const encodedTransaction = (0,
|
4078
|
+
const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
|
4149
4079
|
const { dryRun: gqlReceipts } = await this.operations.dryRun({
|
4150
4080
|
encodedTransaction,
|
4151
4081
|
utxoValidation: true
|
@@ -4179,14 +4109,14 @@ var _Provider = class {
|
|
4179
4109
|
const txRequestClone = (0, import_ramda3.clone)(transactionRequestify(transactionRequestLike));
|
4180
4110
|
const chainInfo = this.getChain();
|
4181
4111
|
const { gasPriceFactor, minGasPrice, maxGasPerTx } = this.getGasConfig();
|
4182
|
-
const gasPrice = (0,
|
4183
|
-
const isScriptTransaction = txRequestClone.type ===
|
4112
|
+
const gasPrice = (0, import_math14.max)(txRequestClone.gasPrice, minGasPrice);
|
4113
|
+
const isScriptTransaction = txRequestClone.type === import_transactions17.TransactionType.Script;
|
4184
4114
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
4185
4115
|
const allQuantities = mergeQuantities(coinOutputsQuantities, forwardingQuantities);
|
4186
4116
|
txRequestClone.fundWithFakeUtxos(allQuantities, resourcesOwner?.address);
|
4187
4117
|
if (estimatePredicates) {
|
4188
4118
|
if (isScriptTransaction) {
|
4189
|
-
txRequestClone.gasLimit = (0,
|
4119
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(0);
|
4190
4120
|
}
|
4191
4121
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4192
4122
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4202,8 +4132,8 @@ var _Provider = class {
|
|
4202
4132
|
let missingContractIds = [];
|
4203
4133
|
let outputVariables = 0;
|
4204
4134
|
if (isScriptTransaction && estimateTxDependencies) {
|
4205
|
-
txRequestClone.gasPrice = (0,
|
4206
|
-
txRequestClone.gasLimit = (0,
|
4135
|
+
txRequestClone.gasPrice = (0, import_math14.bn)(0);
|
4136
|
+
txRequestClone.gasLimit = (0, import_math14.bn)(maxGasPerTx.sub(maxGas).toNumber() * 0.9);
|
4207
4137
|
const result = await this.estimateTxDependencies(txRequestClone);
|
4208
4138
|
receipts = result.receipts;
|
4209
4139
|
outputVariables = result.outputVariables;
|
@@ -4259,17 +4189,17 @@ var _Provider = class {
|
|
4259
4189
|
const result = await this.operations.getCoins({
|
4260
4190
|
first: 10,
|
4261
4191
|
...paginationArgs,
|
4262
|
-
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0,
|
4192
|
+
filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
|
4263
4193
|
});
|
4264
4194
|
const coins = result.coins.edges.map((edge) => edge.node);
|
4265
4195
|
return coins.map((coin) => ({
|
4266
4196
|
id: coin.utxoId,
|
4267
4197
|
assetId: coin.assetId,
|
4268
|
-
amount: (0,
|
4198
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4269
4199
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4270
|
-
maturity: (0,
|
4271
|
-
blockCreated: (0,
|
4272
|
-
txCreatedIdx: (0,
|
4200
|
+
maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
|
4201
|
+
blockCreated: (0, import_math14.bn)(coin.blockCreated),
|
4202
|
+
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4273
4203
|
}));
|
4274
4204
|
}
|
4275
4205
|
/**
|
@@ -4283,19 +4213,19 @@ var _Provider = class {
|
|
4283
4213
|
async getResourcesToSpend(owner, quantities, excludedIds) {
|
4284
4214
|
const ownerAddress = import_address3.Address.fromAddressOrString(owner);
|
4285
4215
|
const excludeInput = {
|
4286
|
-
messages: excludedIds?.messages?.map((nonce) => (0,
|
4287
|
-
utxos: excludedIds?.utxos?.map((id) => (0,
|
4216
|
+
messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
|
4217
|
+
utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
|
4288
4218
|
};
|
4289
4219
|
if (this.cache) {
|
4290
4220
|
const uniqueUtxos = new Set(
|
4291
|
-
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0,
|
4221
|
+
excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
|
4292
4222
|
);
|
4293
4223
|
excludeInput.utxos = Array.from(uniqueUtxos);
|
4294
4224
|
}
|
4295
4225
|
const coinsQuery = {
|
4296
4226
|
owner: ownerAddress.toB256(),
|
4297
4227
|
queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
|
4298
|
-
assetId: (0,
|
4228
|
+
assetId: (0, import_utils22.hexlify)(assetId),
|
4299
4229
|
amount: amount.toString(10),
|
4300
4230
|
max: maxPerAsset ? maxPerAsset.toString(10) : void 0
|
4301
4231
|
})),
|
@@ -4306,9 +4236,9 @@ var _Provider = class {
|
|
4306
4236
|
switch (coin.__typename) {
|
4307
4237
|
case "MessageCoin":
|
4308
4238
|
return {
|
4309
|
-
amount: (0,
|
4239
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4310
4240
|
assetId: coin.assetId,
|
4311
|
-
daHeight: (0,
|
4241
|
+
daHeight: (0, import_math14.bn)(coin.daHeight),
|
4312
4242
|
sender: import_address3.Address.fromAddressOrString(coin.sender),
|
4313
4243
|
recipient: import_address3.Address.fromAddressOrString(coin.recipient),
|
4314
4244
|
nonce: coin.nonce
|
@@ -4316,12 +4246,12 @@ var _Provider = class {
|
|
4316
4246
|
case "Coin":
|
4317
4247
|
return {
|
4318
4248
|
id: coin.utxoId,
|
4319
|
-
amount: (0,
|
4249
|
+
amount: (0, import_math14.bn)(coin.amount),
|
4320
4250
|
assetId: coin.assetId,
|
4321
4251
|
owner: import_address3.Address.fromAddressOrString(coin.owner),
|
4322
|
-
maturity: (0,
|
4323
|
-
blockCreated: (0,
|
4324
|
-
txCreatedIdx: (0,
|
4252
|
+
maturity: (0, import_math14.bn)(coin.maturity).toNumber(),
|
4253
|
+
blockCreated: (0, import_math14.bn)(coin.blockCreated),
|
4254
|
+
txCreatedIdx: (0, import_math14.bn)(coin.txCreatedIdx)
|
4325
4255
|
};
|
4326
4256
|
default:
|
4327
4257
|
return null;
|
@@ -4338,13 +4268,13 @@ var _Provider = class {
|
|
4338
4268
|
async getBlock(idOrHeight) {
|
4339
4269
|
let variables;
|
4340
4270
|
if (typeof idOrHeight === "number") {
|
4341
|
-
variables = { height: (0,
|
4271
|
+
variables = { height: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4342
4272
|
} else if (idOrHeight === "latest") {
|
4343
4273
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4344
4274
|
} else if (idOrHeight.length === 66) {
|
4345
4275
|
variables = { blockId: idOrHeight };
|
4346
4276
|
} else {
|
4347
|
-
variables = { blockId: (0,
|
4277
|
+
variables = { blockId: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4348
4278
|
}
|
4349
4279
|
const { block } = await this.operations.getBlock(variables);
|
4350
4280
|
if (!block) {
|
@@ -4352,7 +4282,7 @@ var _Provider = class {
|
|
4352
4282
|
}
|
4353
4283
|
return {
|
4354
4284
|
id: block.id,
|
4355
|
-
height: (0,
|
4285
|
+
height: (0, import_math14.bn)(block.header.height),
|
4356
4286
|
time: block.header.time,
|
4357
4287
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4358
4288
|
};
|
@@ -4367,7 +4297,7 @@ var _Provider = class {
|
|
4367
4297
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4368
4298
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4369
4299
|
id: block.id,
|
4370
|
-
height: (0,
|
4300
|
+
height: (0, import_math14.bn)(block.header.height),
|
4371
4301
|
time: block.header.time,
|
4372
4302
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4373
4303
|
}));
|
@@ -4382,7 +4312,7 @@ var _Provider = class {
|
|
4382
4312
|
async getBlockWithTransactions(idOrHeight) {
|
4383
4313
|
let variables;
|
4384
4314
|
if (typeof idOrHeight === "number") {
|
4385
|
-
variables = { blockHeight: (0,
|
4315
|
+
variables = { blockHeight: (0, import_math14.bn)(idOrHeight).toString(10) };
|
4386
4316
|
} else if (idOrHeight === "latest") {
|
4387
4317
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4388
4318
|
} else {
|
@@ -4394,11 +4324,11 @@ var _Provider = class {
|
|
4394
4324
|
}
|
4395
4325
|
return {
|
4396
4326
|
id: block.id,
|
4397
|
-
height: (0,
|
4327
|
+
height: (0, import_math14.bn)(block.header.height, 10),
|
4398
4328
|
time: block.header.time,
|
4399
4329
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4400
4330
|
transactions: block.transactions.map(
|
4401
|
-
(tx) => new
|
4331
|
+
(tx) => new import_transactions17.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
|
4402
4332
|
)
|
4403
4333
|
};
|
4404
4334
|
}
|
@@ -4413,8 +4343,8 @@ var _Provider = class {
|
|
4413
4343
|
if (!transaction) {
|
4414
4344
|
return null;
|
4415
4345
|
}
|
4416
|
-
return new
|
4417
|
-
(0,
|
4346
|
+
return new import_transactions17.TransactionCoder().decode(
|
4347
|
+
(0, import_utils22.arrayify)(transaction.rawPayload),
|
4418
4348
|
0
|
4419
4349
|
)?.[0];
|
4420
4350
|
}
|
@@ -4441,9 +4371,9 @@ var _Provider = class {
|
|
4441
4371
|
async getContractBalance(contractId, assetId) {
|
4442
4372
|
const { contractBalance } = await this.operations.getContractBalance({
|
4443
4373
|
contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
|
4444
|
-
asset: (0,
|
4374
|
+
asset: (0, import_utils22.hexlify)(assetId)
|
4445
4375
|
});
|
4446
|
-
return (0,
|
4376
|
+
return (0, import_math14.bn)(contractBalance.amount, 10);
|
4447
4377
|
}
|
4448
4378
|
/**
|
4449
4379
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4455,9 +4385,9 @@ var _Provider = class {
|
|
4455
4385
|
async getBalance(owner, assetId) {
|
4456
4386
|
const { balance } = await this.operations.getBalance({
|
4457
4387
|
owner: import_address3.Address.fromAddressOrString(owner).toB256(),
|
4458
|
-
assetId: (0,
|
4388
|
+
assetId: (0, import_utils22.hexlify)(assetId)
|
4459
4389
|
});
|
4460
|
-
return (0,
|
4390
|
+
return (0, import_math14.bn)(balance.amount, 10);
|
4461
4391
|
}
|
4462
4392
|
/**
|
4463
4393
|
* Returns balances for the given owner.
|
@@ -4475,7 +4405,7 @@ var _Provider = class {
|
|
4475
4405
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4476
4406
|
return balances.map((balance) => ({
|
4477
4407
|
assetId: balance.assetId,
|
4478
|
-
amount: (0,
|
4408
|
+
amount: (0, import_math14.bn)(balance.amount)
|
4479
4409
|
}));
|
4480
4410
|
}
|
4481
4411
|
/**
|
@@ -4493,19 +4423,19 @@ var _Provider = class {
|
|
4493
4423
|
});
|
4494
4424
|
const messages = result.messages.edges.map((edge) => edge.node);
|
4495
4425
|
return messages.map((message) => ({
|
4496
|
-
messageId:
|
4426
|
+
messageId: import_transactions17.InputMessageCoder.getMessageId({
|
4497
4427
|
sender: message.sender,
|
4498
4428
|
recipient: message.recipient,
|
4499
4429
|
nonce: message.nonce,
|
4500
|
-
amount: (0,
|
4430
|
+
amount: (0, import_math14.bn)(message.amount),
|
4501
4431
|
data: message.data
|
4502
4432
|
}),
|
4503
4433
|
sender: import_address3.Address.fromAddressOrString(message.sender),
|
4504
4434
|
recipient: import_address3.Address.fromAddressOrString(message.recipient),
|
4505
4435
|
nonce: message.nonce,
|
4506
|
-
amount: (0,
|
4507
|
-
data:
|
4508
|
-
daHeight: (0,
|
4436
|
+
amount: (0, import_math14.bn)(message.amount),
|
4437
|
+
data: import_transactions17.InputMessageCoder.decodeData(message.data),
|
4438
|
+
daHeight: (0, import_math14.bn)(message.daHeight)
|
4509
4439
|
}));
|
4510
4440
|
}
|
4511
4441
|
/**
|
@@ -4523,8 +4453,8 @@ var _Provider = class {
|
|
4523
4453
|
nonce
|
4524
4454
|
};
|
4525
4455
|
if (commitBlockId && commitBlockHeight) {
|
4526
|
-
throw new
|
4527
|
-
|
4456
|
+
throw new import_errors13.FuelError(
|
4457
|
+
import_errors13.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4528
4458
|
"commitBlockId and commitBlockHeight cannot be used together"
|
4529
4459
|
);
|
4530
4460
|
}
|
@@ -4558,41 +4488,41 @@ var _Provider = class {
|
|
4558
4488
|
} = result.messageProof;
|
4559
4489
|
return {
|
4560
4490
|
messageProof: {
|
4561
|
-
proofIndex: (0,
|
4491
|
+
proofIndex: (0, import_math14.bn)(messageProof.proofIndex),
|
4562
4492
|
proofSet: messageProof.proofSet
|
4563
4493
|
},
|
4564
4494
|
blockProof: {
|
4565
|
-
proofIndex: (0,
|
4495
|
+
proofIndex: (0, import_math14.bn)(blockProof.proofIndex),
|
4566
4496
|
proofSet: blockProof.proofSet
|
4567
4497
|
},
|
4568
4498
|
messageBlockHeader: {
|
4569
4499
|
id: messageBlockHeader.id,
|
4570
|
-
daHeight: (0,
|
4571
|
-
transactionsCount: (0,
|
4500
|
+
daHeight: (0, import_math14.bn)(messageBlockHeader.daHeight),
|
4501
|
+
transactionsCount: (0, import_math14.bn)(messageBlockHeader.transactionsCount),
|
4572
4502
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4573
|
-
height: (0,
|
4503
|
+
height: (0, import_math14.bn)(messageBlockHeader.height),
|
4574
4504
|
prevRoot: messageBlockHeader.prevRoot,
|
4575
4505
|
time: messageBlockHeader.time,
|
4576
4506
|
applicationHash: messageBlockHeader.applicationHash,
|
4577
4507
|
messageReceiptRoot: messageBlockHeader.messageReceiptRoot,
|
4578
|
-
messageReceiptCount: (0,
|
4508
|
+
messageReceiptCount: (0, import_math14.bn)(messageBlockHeader.messageReceiptCount)
|
4579
4509
|
},
|
4580
4510
|
commitBlockHeader: {
|
4581
4511
|
id: commitBlockHeader.id,
|
4582
|
-
daHeight: (0,
|
4583
|
-
transactionsCount: (0,
|
4512
|
+
daHeight: (0, import_math14.bn)(commitBlockHeader.daHeight),
|
4513
|
+
transactionsCount: (0, import_math14.bn)(commitBlockHeader.transactionsCount),
|
4584
4514
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4585
|
-
height: (0,
|
4515
|
+
height: (0, import_math14.bn)(commitBlockHeader.height),
|
4586
4516
|
prevRoot: commitBlockHeader.prevRoot,
|
4587
4517
|
time: commitBlockHeader.time,
|
4588
4518
|
applicationHash: commitBlockHeader.applicationHash,
|
4589
4519
|
messageReceiptRoot: commitBlockHeader.messageReceiptRoot,
|
4590
|
-
messageReceiptCount: (0,
|
4520
|
+
messageReceiptCount: (0, import_math14.bn)(commitBlockHeader.messageReceiptCount)
|
4591
4521
|
},
|
4592
4522
|
sender: import_address3.Address.fromAddressOrString(sender),
|
4593
4523
|
recipient: import_address3.Address.fromAddressOrString(recipient),
|
4594
4524
|
nonce,
|
4595
|
-
amount: (0,
|
4525
|
+
amount: (0, import_math14.bn)(amount),
|
4596
4526
|
data
|
4597
4527
|
};
|
4598
4528
|
}
|
@@ -4615,10 +4545,10 @@ var _Provider = class {
|
|
4615
4545
|
*/
|
4616
4546
|
async produceBlocks(amount, startTime) {
|
4617
4547
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4618
|
-
blocksToProduce: (0,
|
4619
|
-
startTimestamp: startTime ?
|
4548
|
+
blocksToProduce: (0, import_math14.bn)(amount).toString(10),
|
4549
|
+
startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4620
4550
|
});
|
4621
|
-
return (0,
|
4551
|
+
return (0, import_math14.bn)(latestBlockHeight);
|
4622
4552
|
}
|
4623
4553
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4624
4554
|
async getTransactionResponse(transactionId) {
|
@@ -4632,7 +4562,7 @@ cacheInputs_fn = function(inputs) {
|
|
4632
4562
|
return;
|
4633
4563
|
}
|
4634
4564
|
inputs.forEach((input) => {
|
4635
|
-
if (input.type ===
|
4565
|
+
if (input.type === import_transactions17.InputType.Coin) {
|
4636
4566
|
this.cache?.set(input.id);
|
4637
4567
|
}
|
4638
4568
|
});
|
@@ -4641,23 +4571,23 @@ __publicField(Provider, "chainInfoCache", {});
|
|
4641
4571
|
__publicField(Provider, "nodeInfoCache", {});
|
4642
4572
|
|
4643
4573
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4644
|
-
var
|
4645
|
-
var
|
4646
|
-
var
|
4647
|
-
var
|
4574
|
+
var import_errors14 = require("@fuel-ts/errors");
|
4575
|
+
var import_math15 = require("@fuel-ts/math");
|
4576
|
+
var import_transactions18 = require("@fuel-ts/transactions");
|
4577
|
+
var import_utils25 = require("@fuel-ts/utils");
|
4648
4578
|
async function getTransactionSummary(params) {
|
4649
4579
|
const { id, provider, abiMap } = params;
|
4650
4580
|
const { transaction: gqlTransaction } = await provider.operations.getTransactionWithReceipts({
|
4651
4581
|
transactionId: id
|
4652
4582
|
});
|
4653
4583
|
if (!gqlTransaction) {
|
4654
|
-
throw new
|
4655
|
-
|
4584
|
+
throw new import_errors14.FuelError(
|
4585
|
+
import_errors14.ErrorCode.TRANSACTION_NOT_FOUND,
|
4656
4586
|
`Transaction not found for given id: ${id}.`
|
4657
4587
|
);
|
4658
4588
|
}
|
4659
|
-
const [decodedTransaction] = new
|
4660
|
-
(0,
|
4589
|
+
const [decodedTransaction] = new import_transactions18.TransactionCoder().decode(
|
4590
|
+
(0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4661
4591
|
0
|
4662
4592
|
);
|
4663
4593
|
const receipts = gqlTransaction.receipts?.map(processGqlReceipt) || [];
|
@@ -4668,10 +4598,10 @@ async function getTransactionSummary(params) {
|
|
4668
4598
|
id: gqlTransaction.id,
|
4669
4599
|
receipts,
|
4670
4600
|
transaction: decodedTransaction,
|
4671
|
-
transactionBytes: (0,
|
4601
|
+
transactionBytes: (0, import_utils25.arrayify)(gqlTransaction.rawPayload),
|
4672
4602
|
gqlTransactionStatus: gqlTransaction.status,
|
4673
|
-
gasPerByte: (0,
|
4674
|
-
gasPriceFactor: (0,
|
4603
|
+
gasPerByte: (0, import_math15.bn)(gasPerByte),
|
4604
|
+
gasPriceFactor: (0, import_math15.bn)(gasPriceFactor),
|
4675
4605
|
abiMap,
|
4676
4606
|
maxInputs,
|
4677
4607
|
gasCosts
|
@@ -4710,13 +4640,13 @@ async function getTransactionsSummaries(params) {
|
|
4710
4640
|
const transactions = edges.map((edge) => {
|
4711
4641
|
const { node: gqlTransaction } = edge;
|
4712
4642
|
const { id, rawPayload, receipts: gqlReceipts, status } = gqlTransaction;
|
4713
|
-
const [decodedTransaction] = new
|
4643
|
+
const [decodedTransaction] = new import_transactions18.TransactionCoder().decode((0, import_utils25.arrayify)(rawPayload), 0);
|
4714
4644
|
const receipts = gqlReceipts?.map(processGqlReceipt) || [];
|
4715
4645
|
const transactionSummary = assembleTransactionSummary({
|
4716
4646
|
id,
|
4717
4647
|
receipts,
|
4718
4648
|
transaction: decodedTransaction,
|
4719
|
-
transactionBytes: (0,
|
4649
|
+
transactionBytes: (0, import_utils25.arrayify)(rawPayload),
|
4720
4650
|
gqlTransactionStatus: status,
|
4721
4651
|
abiMap,
|
4722
4652
|
gasPerByte,
|
@@ -4859,17 +4789,17 @@ var assets = [
|
|
4859
4789
|
|
4860
4790
|
// src/utils/formatTransferToContractScriptData.ts
|
4861
4791
|
var import_abi_coder4 = require("@fuel-ts/abi-coder");
|
4862
|
-
var
|
4863
|
-
var
|
4792
|
+
var import_math16 = require("@fuel-ts/math");
|
4793
|
+
var import_utils26 = require("@fuel-ts/utils");
|
4864
4794
|
var asm = __toESM(require("@fuels/vm-asm"));
|
4865
4795
|
var formatTransferToContractScriptData = (params) => {
|
4866
4796
|
const { assetId, amountToTransfer, hexlifiedContractId } = params;
|
4867
4797
|
const numberCoder = new import_abi_coder4.BigNumberCoder("u64");
|
4868
|
-
const encoded = numberCoder.encode(new
|
4798
|
+
const encoded = numberCoder.encode(new import_math16.BN(amountToTransfer).toNumber());
|
4869
4799
|
const scriptData = Uint8Array.from([
|
4870
|
-
...(0,
|
4800
|
+
...(0, import_utils26.arrayify)(hexlifiedContractId),
|
4871
4801
|
...encoded,
|
4872
|
-
...(0,
|
4802
|
+
...(0, import_utils26.arrayify)(assetId)
|
4873
4803
|
]);
|
4874
4804
|
return scriptData;
|
4875
4805
|
};
|
@@ -4925,7 +4855,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4925
4855
|
*/
|
4926
4856
|
get provider() {
|
4927
4857
|
if (!this._provider) {
|
4928
|
-
throw new
|
4858
|
+
throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
4929
4859
|
}
|
4930
4860
|
return this._provider;
|
4931
4861
|
}
|
@@ -4977,8 +4907,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
4977
4907
|
if (!hasNextPage) {
|
4978
4908
|
break;
|
4979
4909
|
}
|
4980
|
-
throw new
|
4981
|
-
|
4910
|
+
throw new import_errors15.FuelError(
|
4911
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
4982
4912
|
`Wallets containing more than ${pageSize} coins exceed the current supported limit.`
|
4983
4913
|
);
|
4984
4914
|
}
|
@@ -5003,8 +4933,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5003
4933
|
if (!hasNextPage) {
|
5004
4934
|
break;
|
5005
4935
|
}
|
5006
|
-
throw new
|
5007
|
-
|
4936
|
+
throw new import_errors15.FuelError(
|
4937
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
5008
4938
|
`Wallets containing more than ${pageSize} messages exceed the current supported limit.`
|
5009
4939
|
);
|
5010
4940
|
}
|
@@ -5016,7 +4946,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5016
4946
|
* @param assetId - The asset ID to check the balance for.
|
5017
4947
|
* @returns A promise that resolves to the balance amount.
|
5018
4948
|
*/
|
5019
|
-
async getBalance(assetId =
|
4949
|
+
async getBalance(assetId = import_configs11.BaseAssetId) {
|
5020
4950
|
const amount = await this.provider.getBalance(this.address, assetId);
|
5021
4951
|
return amount;
|
5022
4952
|
}
|
@@ -5039,8 +4969,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5039
4969
|
if (!hasNextPage) {
|
5040
4970
|
break;
|
5041
4971
|
}
|
5042
|
-
throw new
|
5043
|
-
|
4972
|
+
throw new import_errors15.FuelError(
|
4973
|
+
import_errors15.ErrorCode.NOT_SUPPORTED,
|
5044
4974
|
`Wallets containing more than ${pageSize} balances exceed the current supported limit.`
|
5045
4975
|
);
|
5046
4976
|
}
|
@@ -5056,15 +4986,15 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5056
4986
|
*/
|
5057
4987
|
async fund(request, coinQuantities, fee) {
|
5058
4988
|
const updatedQuantities = addAmountToAsset({
|
5059
|
-
amount: (0,
|
5060
|
-
assetId:
|
4989
|
+
amount: (0, import_math17.bn)(fee),
|
4990
|
+
assetId: import_configs11.BaseAssetId,
|
5061
4991
|
coinQuantities
|
5062
4992
|
});
|
5063
4993
|
const quantitiesDict = {};
|
5064
4994
|
updatedQuantities.forEach(({ amount, assetId }) => {
|
5065
4995
|
quantitiesDict[assetId] = {
|
5066
4996
|
required: amount,
|
5067
|
-
owned: (0,
|
4997
|
+
owned: (0, import_math17.bn)(0)
|
5068
4998
|
};
|
5069
4999
|
});
|
5070
5000
|
const cachedUtxos = [];
|
@@ -5077,12 +5007,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5077
5007
|
if (isCoin2) {
|
5078
5008
|
const assetId = String(input.assetId);
|
5079
5009
|
if (input.owner === owner && quantitiesDict[assetId]) {
|
5080
|
-
const amount = (0,
|
5010
|
+
const amount = (0, import_math17.bn)(input.amount);
|
5081
5011
|
quantitiesDict[assetId].owned = quantitiesDict[assetId].owned.add(amount);
|
5082
5012
|
cachedUtxos.push(input.id);
|
5083
5013
|
}
|
5084
|
-
} else if (input.recipient === owner && input.amount && quantitiesDict[
|
5085
|
-
quantitiesDict[
|
5014
|
+
} else if (input.recipient === owner && input.amount && quantitiesDict[import_configs11.BaseAssetId]) {
|
5015
|
+
quantitiesDict[import_configs11.BaseAssetId].owned = quantitiesDict[import_configs11.BaseAssetId].owned.add(input.amount);
|
5086
5016
|
cachedMessages.push(input.nonce);
|
5087
5017
|
}
|
5088
5018
|
}
|
@@ -5114,7 +5044,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5114
5044
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5115
5045
|
* @returns A promise that resolves to the prepared transaction request.
|
5116
5046
|
*/
|
5117
|
-
async createTransfer(destination, amount, assetId =
|
5047
|
+
async createTransfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
5118
5048
|
const { minGasPrice } = this.provider.getGasConfig();
|
5119
5049
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5120
5050
|
const request = new ScriptTransactionRequest(params);
|
@@ -5123,8 +5053,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5123
5053
|
estimateTxDependencies: true,
|
5124
5054
|
resourcesOwner: this
|
5125
5055
|
});
|
5126
|
-
request.gasPrice = (0,
|
5127
|
-
request.gasLimit = (0,
|
5056
|
+
request.gasPrice = (0, import_math17.bn)(txParams.gasPrice ?? minGasPrice);
|
5057
|
+
request.gasLimit = (0, import_math17.bn)(txParams.gasLimit ?? gasUsed);
|
5128
5058
|
this.validateGas({
|
5129
5059
|
gasUsed,
|
5130
5060
|
gasPrice: request.gasPrice,
|
@@ -5144,10 +5074,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5144
5074
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
5145
5075
|
* @returns A promise that resolves to the transaction response.
|
5146
5076
|
*/
|
5147
|
-
async transfer(destination, amount, assetId =
|
5148
|
-
if ((0,
|
5149
|
-
throw new
|
5150
|
-
|
5077
|
+
async transfer(destination, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
5078
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
5079
|
+
throw new import_errors15.FuelError(
|
5080
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5151
5081
|
"Transfer amount must be a positive number."
|
5152
5082
|
);
|
5153
5083
|
}
|
@@ -5163,10 +5093,10 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5163
5093
|
* @param txParams - The optional transaction parameters.
|
5164
5094
|
* @returns A promise that resolves to the transaction response.
|
5165
5095
|
*/
|
5166
|
-
async transferToContract(contractId, amount, assetId =
|
5167
|
-
if ((0,
|
5168
|
-
throw new
|
5169
|
-
|
5096
|
+
async transferToContract(contractId, amount, assetId = import_configs11.BaseAssetId, txParams = {}) {
|
5097
|
+
if ((0, import_math17.bn)(amount).lte(0)) {
|
5098
|
+
throw new import_errors15.FuelError(
|
5099
|
+
import_errors15.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
5170
5100
|
"Transfer amount must be a positive number."
|
5171
5101
|
);
|
5172
5102
|
}
|
@@ -5175,7 +5105,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5175
5105
|
const params = { gasPrice: minGasPrice, ...txParams };
|
5176
5106
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5177
5107
|
hexlifiedContractId: contractAddress.toB256(),
|
5178
|
-
amountToTransfer: (0,
|
5108
|
+
amountToTransfer: (0, import_math17.bn)(amount),
|
5179
5109
|
assetId
|
5180
5110
|
});
|
5181
5111
|
const request = new ScriptTransactionRequest({
|
@@ -5186,9 +5116,9 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5186
5116
|
request.addContractInputAndOutput(contractAddress);
|
5187
5117
|
const { maxFee, requiredQuantities, gasUsed } = await this.provider.getTransactionCost(
|
5188
5118
|
request,
|
5189
|
-
[{ amount: (0,
|
5119
|
+
[{ amount: (0, import_math17.bn)(amount), assetId: String(assetId) }]
|
5190
5120
|
);
|
5191
|
-
request.gasLimit = (0,
|
5121
|
+
request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
|
5192
5122
|
this.validateGas({
|
5193
5123
|
gasUsed,
|
5194
5124
|
gasPrice: request.gasPrice,
|
@@ -5209,25 +5139,25 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5209
5139
|
async withdrawToBaseLayer(recipient, amount, txParams = {}) {
|
5210
5140
|
const { minGasPrice } = this.provider.getGasConfig();
|
5211
5141
|
const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
|
5212
|
-
const recipientDataArray = (0,
|
5142
|
+
const recipientDataArray = (0, import_utils27.arrayify)(
|
5213
5143
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5214
5144
|
);
|
5215
|
-
const amountDataArray = (0,
|
5216
|
-
"0x".concat((0,
|
5145
|
+
const amountDataArray = (0, import_utils27.arrayify)(
|
5146
|
+
"0x".concat((0, import_math17.bn)(amount).toHex().substring(2).padStart(16, "0"))
|
5217
5147
|
);
|
5218
5148
|
const script = new Uint8Array([
|
5219
|
-
...(0,
|
5149
|
+
...(0, import_utils27.arrayify)(withdrawScript.bytes),
|
5220
5150
|
...recipientDataArray,
|
5221
5151
|
...amountDataArray
|
5222
5152
|
]);
|
5223
5153
|
const params = { script, gasPrice: minGasPrice, ...txParams };
|
5224
5154
|
const request = new ScriptTransactionRequest(params);
|
5225
|
-
const forwardingQuantities = [{ amount: (0,
|
5155
|
+
const forwardingQuantities = [{ amount: (0, import_math17.bn)(amount), assetId: import_configs11.BaseAssetId }];
|
5226
5156
|
const { requiredQuantities, maxFee, gasUsed } = await this.provider.getTransactionCost(
|
5227
5157
|
request,
|
5228
5158
|
forwardingQuantities
|
5229
5159
|
);
|
5230
|
-
request.gasLimit = (0,
|
5160
|
+
request.gasLimit = (0, import_math17.bn)(params.gasLimit ?? gasUsed);
|
5231
5161
|
this.validateGas({
|
5232
5162
|
gasUsed,
|
5233
5163
|
gasPrice: request.gasPrice,
|
@@ -5239,7 +5169,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5239
5169
|
}
|
5240
5170
|
async signMessage(message) {
|
5241
5171
|
if (!this._connector) {
|
5242
|
-
throw new
|
5172
|
+
throw new import_errors15.FuelError(import_errors15.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
5243
5173
|
}
|
5244
5174
|
return this._connector.signMessage(this.address.toString(), message);
|
5245
5175
|
}
|
@@ -5251,8 +5181,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5251
5181
|
*/
|
5252
5182
|
async signTransaction(transactionRequestLike) {
|
5253
5183
|
if (!this._connector) {
|
5254
|
-
throw new
|
5255
|
-
|
5184
|
+
throw new import_errors15.FuelError(
|
5185
|
+
import_errors15.ErrorCode.MISSING_CONNECTOR,
|
5256
5186
|
"A connector is required to sign transactions."
|
5257
5187
|
);
|
5258
5188
|
}
|
@@ -5299,14 +5229,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5299
5229
|
minGasPrice
|
5300
5230
|
}) {
|
5301
5231
|
if (minGasPrice.gt(gasPrice)) {
|
5302
|
-
throw new
|
5303
|
-
|
5232
|
+
throw new import_errors15.FuelError(
|
5233
|
+
import_errors15.ErrorCode.GAS_PRICE_TOO_LOW,
|
5304
5234
|
`Gas price '${gasPrice}' is lower than the required: '${minGasPrice}'.`
|
5305
5235
|
);
|
5306
5236
|
}
|
5307
5237
|
if (gasUsed.gt(gasLimit)) {
|
5308
|
-
throw new
|
5309
|
-
|
5238
|
+
throw new import_errors15.FuelError(
|
5239
|
+
import_errors15.ErrorCode.GAS_LIMIT_TOO_LOW,
|
5310
5240
|
`Gas limit '${gasLimit}' is lower than the required: '${gasUsed}'.`
|
5311
5241
|
);
|
5312
5242
|
}
|
@@ -5315,14 +5245,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
5315
5245
|
|
5316
5246
|
// src/wallet/base-wallet-unlocked.ts
|
5317
5247
|
var import_hasher3 = require("@fuel-ts/hasher");
|
5318
|
-
var
|
5248
|
+
var import_utils30 = require("@fuel-ts/utils");
|
5319
5249
|
|
5320
5250
|
// src/signer/signer.ts
|
5321
5251
|
var import_address5 = require("@fuel-ts/address");
|
5322
5252
|
var import_crypto = require("@fuel-ts/crypto");
|
5323
5253
|
var import_hasher2 = require("@fuel-ts/hasher");
|
5324
|
-
var
|
5325
|
-
var
|
5254
|
+
var import_math18 = require("@fuel-ts/math");
|
5255
|
+
var import_utils28 = require("@fuel-ts/utils");
|
5326
5256
|
var import_secp256k1 = require("@noble/curves/secp256k1");
|
5327
5257
|
var Signer = class {
|
5328
5258
|
address;
|
@@ -5341,10 +5271,10 @@ var Signer = class {
|
|
5341
5271
|
privateKey = `0x${privateKey}`;
|
5342
5272
|
}
|
5343
5273
|
}
|
5344
|
-
const privateKeyBytes = (0,
|
5345
|
-
this.privateKey = (0,
|
5346
|
-
this.publicKey = (0,
|
5347
|
-
this.compressedPublicKey = (0,
|
5274
|
+
const privateKeyBytes = (0, import_math18.toBytes)(privateKey, 32);
|
5275
|
+
this.privateKey = (0, import_utils28.hexlify)(privateKeyBytes);
|
5276
|
+
this.publicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5277
|
+
this.compressedPublicKey = (0, import_utils28.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
|
5348
5278
|
this.address = import_address5.Address.fromPublicKey(this.publicKey);
|
5349
5279
|
}
|
5350
5280
|
/**
|
@@ -5358,11 +5288,11 @@ var Signer = class {
|
|
5358
5288
|
* @returns hashed signature
|
5359
5289
|
*/
|
5360
5290
|
sign(data) {
|
5361
|
-
const signature = import_secp256k1.secp256k1.sign((0,
|
5362
|
-
const r = (0,
|
5363
|
-
const s = (0,
|
5291
|
+
const signature = import_secp256k1.secp256k1.sign((0, import_utils28.arrayify)(data), (0, import_utils28.arrayify)(this.privateKey));
|
5292
|
+
const r = (0, import_math18.toBytes)(`0x${signature.r.toString(16)}`, 32);
|
5293
|
+
const s = (0, import_math18.toBytes)(`0x${signature.s.toString(16)}`, 32);
|
5364
5294
|
s[0] |= (signature.recovery || 0) << 7;
|
5365
|
-
return (0,
|
5295
|
+
return (0, import_utils28.hexlify)((0, import_utils28.concat)([r, s]));
|
5366
5296
|
}
|
5367
5297
|
/**
|
5368
5298
|
* Add point on the current elliptic curve
|
@@ -5371,8 +5301,8 @@ var Signer = class {
|
|
5371
5301
|
* @returns compressed point on the curve
|
5372
5302
|
*/
|
5373
5303
|
addPoint(point) {
|
5374
|
-
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5375
|
-
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5304
|
+
const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(this.compressedPublicKey));
|
5305
|
+
const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(point));
|
5376
5306
|
const result = p0.add(p1);
|
5377
5307
|
return `0x${result.toHex(true)}`;
|
5378
5308
|
}
|
@@ -5384,16 +5314,16 @@ var Signer = class {
|
|
5384
5314
|
* @returns public key from signature from the
|
5385
5315
|
*/
|
5386
5316
|
static recoverPublicKey(data, signature) {
|
5387
|
-
const signedMessageBytes = (0,
|
5317
|
+
const signedMessageBytes = (0, import_utils28.arrayify)(signature);
|
5388
5318
|
const r = signedMessageBytes.slice(0, 32);
|
5389
5319
|
const s = signedMessageBytes.slice(32, 64);
|
5390
5320
|
const recoveryParam = (s[0] & 128) >> 7;
|
5391
5321
|
s[0] &= 127;
|
5392
|
-
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0,
|
5322
|
+
const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils28.hexlify)(r)), BigInt((0, import_utils28.hexlify)(s))).addRecoveryBit(
|
5393
5323
|
recoveryParam
|
5394
5324
|
);
|
5395
|
-
const publicKey = sig.recoverPublicKey((0,
|
5396
|
-
return (0,
|
5325
|
+
const publicKey = sig.recoverPublicKey((0, import_utils28.arrayify)(data)).toRawBytes(false).slice(1);
|
5326
|
+
return (0, import_utils28.hexlify)(publicKey);
|
5397
5327
|
}
|
5398
5328
|
/**
|
5399
5329
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5412,7 +5342,7 @@ var Signer = class {
|
|
5412
5342
|
* @returns random 32-byte hashed
|
5413
5343
|
*/
|
5414
5344
|
static generatePrivateKey(entropy) {
|
5415
|
-
return entropy ? (0, import_hasher2.hash)((0,
|
5345
|
+
return entropy ? (0, import_hasher2.hash)((0, import_utils28.concat)([(0, import_crypto.randomBytes)(32), (0, import_utils28.arrayify)(entropy)])) : (0, import_crypto.randomBytes)(32);
|
5416
5346
|
}
|
5417
5347
|
/**
|
5418
5348
|
* Extended publicKey from a compact publicKey
|
@@ -5421,16 +5351,16 @@ var Signer = class {
|
|
5421
5351
|
* @returns extended publicKey
|
5422
5352
|
*/
|
5423
5353
|
static extendPublicKey(publicKey) {
|
5424
|
-
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0,
|
5425
|
-
return (0,
|
5354
|
+
const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils28.arrayify)(publicKey));
|
5355
|
+
return (0, import_utils28.hexlify)(point.toRawBytes(false).slice(1));
|
5426
5356
|
}
|
5427
5357
|
};
|
5428
5358
|
|
5429
5359
|
// src/wallet/keystore-wallet.ts
|
5430
5360
|
var import_address6 = require("@fuel-ts/address");
|
5431
5361
|
var import_crypto2 = require("@fuel-ts/crypto");
|
5432
|
-
var
|
5433
|
-
var
|
5362
|
+
var import_errors16 = require("@fuel-ts/errors");
|
5363
|
+
var import_utils29 = require("@fuel-ts/utils");
|
5434
5364
|
var import_uuid = require("uuid");
|
5435
5365
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5436
5366
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5507,13 +5437,13 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5507
5437
|
const macHashUint8Array = (0, import_crypto2.keccak256)(data);
|
5508
5438
|
const macHash = (0, import_crypto2.stringFromBuffer)(macHashUint8Array, "hex");
|
5509
5439
|
if (mac !== macHash) {
|
5510
|
-
throw new
|
5511
|
-
|
5440
|
+
throw new import_errors16.FuelError(
|
5441
|
+
import_errors16.ErrorCode.INVALID_PASSWORD,
|
5512
5442
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
5513
5443
|
);
|
5514
5444
|
}
|
5515
5445
|
const buffer = await (0, import_crypto2.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
|
5516
|
-
const privateKey = (0,
|
5446
|
+
const privateKey = (0, import_utils29.hexlify)(buffer);
|
5517
5447
|
return privateKey;
|
5518
5448
|
}
|
5519
5449
|
|
@@ -5558,7 +5488,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5558
5488
|
*/
|
5559
5489
|
async signMessage(message) {
|
5560
5490
|
const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
|
5561
|
-
return (0,
|
5491
|
+
return (0, import_utils30.hexlify)(signedMessage);
|
5562
5492
|
}
|
5563
5493
|
/**
|
5564
5494
|
* Signs a transaction with the wallet's private key.
|
@@ -5571,7 +5501,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5571
5501
|
const chainId = this.provider.getChainId();
|
5572
5502
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5573
5503
|
const signature = await this.signer().sign(hashedTransaction);
|
5574
|
-
return (0,
|
5504
|
+
return (0, import_utils30.hexlify)(signature);
|
5575
5505
|
}
|
5576
5506
|
/**
|
5577
5507
|
* Populates a transaction with the witnesses signature.
|
@@ -5630,17 +5560,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5630
5560
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5631
5561
|
|
5632
5562
|
// src/hdwallet/hdwallet.ts
|
5633
|
-
var
|
5563
|
+
var import_errors19 = require("@fuel-ts/errors");
|
5634
5564
|
var import_hasher6 = require("@fuel-ts/hasher");
|
5635
|
-
var
|
5636
|
-
var
|
5565
|
+
var import_math19 = require("@fuel-ts/math");
|
5566
|
+
var import_utils34 = require("@fuel-ts/utils");
|
5637
5567
|
var import_ethers3 = require("ethers");
|
5638
5568
|
|
5639
5569
|
// src/mnemonic/mnemonic.ts
|
5640
5570
|
var import_crypto3 = require("@fuel-ts/crypto");
|
5641
|
-
var
|
5571
|
+
var import_errors18 = require("@fuel-ts/errors");
|
5642
5572
|
var import_hasher5 = require("@fuel-ts/hasher");
|
5643
|
-
var
|
5573
|
+
var import_utils32 = require("@fuel-ts/utils");
|
5644
5574
|
var import_ethers2 = require("ethers");
|
5645
5575
|
|
5646
5576
|
// src/wordlists/words/english.ts
|
@@ -7702,9 +7632,9 @@ var Language = /* @__PURE__ */ ((Language2) => {
|
|
7702
7632
|
})(Language || {});
|
7703
7633
|
|
7704
7634
|
// src/mnemonic/utils.ts
|
7705
|
-
var
|
7635
|
+
var import_errors17 = require("@fuel-ts/errors");
|
7706
7636
|
var import_hasher4 = require("@fuel-ts/hasher");
|
7707
|
-
var
|
7637
|
+
var import_utils31 = require("@fuel-ts/utils");
|
7708
7638
|
function toUtf8Bytes(stri) {
|
7709
7639
|
const str = stri.normalize("NFKD");
|
7710
7640
|
const result = [];
|
@@ -7719,8 +7649,8 @@ function toUtf8Bytes(stri) {
|
|
7719
7649
|
i += 1;
|
7720
7650
|
const c2 = str.charCodeAt(i);
|
7721
7651
|
if (i >= str.length || (c2 & 64512) !== 56320) {
|
7722
|
-
throw new
|
7723
|
-
|
7652
|
+
throw new import_errors17.FuelError(
|
7653
|
+
import_errors17.ErrorCode.INVALID_INPUT_PARAMETERS,
|
7724
7654
|
"Invalid UTF-8 in the input string."
|
7725
7655
|
);
|
7726
7656
|
}
|
@@ -7771,20 +7701,20 @@ function entropyToMnemonicIndices(entropy) {
|
|
7771
7701
|
}
|
7772
7702
|
}
|
7773
7703
|
const checksumBits = entropy.length / 4;
|
7774
|
-
const checksum = (0,
|
7704
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
|
7775
7705
|
indices[indices.length - 1] <<= checksumBits;
|
7776
7706
|
indices[indices.length - 1] |= checksum >> 8 - checksumBits;
|
7777
7707
|
return indices;
|
7778
7708
|
}
|
7779
7709
|
function mnemonicWordsToEntropy(words, wordlist) {
|
7780
7710
|
const size = Math.ceil(11 * words.length / 8);
|
7781
|
-
const entropy = (0,
|
7711
|
+
const entropy = (0, import_utils31.arrayify)(new Uint8Array(size));
|
7782
7712
|
let offset = 0;
|
7783
7713
|
for (let i = 0; i < words.length; i += 1) {
|
7784
7714
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
7785
7715
|
if (index === -1) {
|
7786
|
-
throw new
|
7787
|
-
|
7716
|
+
throw new import_errors17.FuelError(
|
7717
|
+
import_errors17.ErrorCode.INVALID_MNEMONIC,
|
7788
7718
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
7789
7719
|
);
|
7790
7720
|
}
|
@@ -7798,10 +7728,10 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
7798
7728
|
const entropyBits = 32 * words.length / 3;
|
7799
7729
|
const checksumBits = words.length / 3;
|
7800
7730
|
const checksumMask = getUpperMask(checksumBits);
|
7801
|
-
const checksum = (0,
|
7731
|
+
const checksum = (0, import_utils31.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
7802
7732
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
7803
|
-
throw new
|
7804
|
-
|
7733
|
+
throw new import_errors17.FuelError(
|
7734
|
+
import_errors17.ErrorCode.INVALID_CHECKSUM,
|
7805
7735
|
"Checksum validation failed for the provided mnemonic."
|
7806
7736
|
);
|
7807
7737
|
}
|
@@ -7815,16 +7745,16 @@ var TestnetPRV = "0x04358394";
|
|
7815
7745
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
7816
7746
|
function assertWordList(wordlist) {
|
7817
7747
|
if (wordlist.length !== 2048) {
|
7818
|
-
throw new
|
7819
|
-
|
7748
|
+
throw new import_errors18.FuelError(
|
7749
|
+
import_errors18.ErrorCode.INVALID_WORD_LIST,
|
7820
7750
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
7821
7751
|
);
|
7822
7752
|
}
|
7823
7753
|
}
|
7824
7754
|
function assertEntropy(entropy) {
|
7825
7755
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
7826
|
-
throw new
|
7827
|
-
|
7756
|
+
throw new import_errors18.FuelError(
|
7757
|
+
import_errors18.ErrorCode.INVALID_ENTROPY,
|
7828
7758
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
7829
7759
|
);
|
7830
7760
|
}
|
@@ -7834,7 +7764,7 @@ function assertMnemonic(words) {
|
|
7834
7764
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
7835
7765
|
", "
|
7836
7766
|
)}] words, but got ${words.length}.`;
|
7837
|
-
throw new
|
7767
|
+
throw new import_errors18.FuelError(import_errors18.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
7838
7768
|
}
|
7839
7769
|
}
|
7840
7770
|
var Mnemonic = class {
|
@@ -7873,7 +7803,7 @@ var Mnemonic = class {
|
|
7873
7803
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
7874
7804
|
const words = getWords(phrase);
|
7875
7805
|
assertMnemonic(words);
|
7876
|
-
return (0,
|
7806
|
+
return (0, import_utils32.hexlify)(mnemonicWordsToEntropy(words, wordlist));
|
7877
7807
|
}
|
7878
7808
|
/**
|
7879
7809
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -7881,7 +7811,7 @@ var Mnemonic = class {
|
|
7881
7811
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7882
7812
|
*/
|
7883
7813
|
static entropyToMnemonic(entropy, wordlist = english) {
|
7884
|
-
const entropyBytes = (0,
|
7814
|
+
const entropyBytes = (0, import_utils32.arrayify)(entropy);
|
7885
7815
|
assertWordList(wordlist);
|
7886
7816
|
assertEntropy(entropyBytes);
|
7887
7817
|
return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
|
@@ -7950,14 +7880,14 @@ var Mnemonic = class {
|
|
7950
7880
|
* @returns 64-byte array contains privateKey and chainCode as described on BIP39
|
7951
7881
|
*/
|
7952
7882
|
static masterKeysFromSeed(seed) {
|
7953
|
-
const seedArray = (0,
|
7883
|
+
const seedArray = (0, import_utils32.arrayify)(seed);
|
7954
7884
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
7955
|
-
throw new
|
7956
|
-
|
7885
|
+
throw new import_errors18.FuelError(
|
7886
|
+
import_errors18.ErrorCode.INVALID_SEED,
|
7957
7887
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
7958
7888
|
);
|
7959
7889
|
}
|
7960
|
-
return (0,
|
7890
|
+
return (0, import_utils32.arrayify)((0, import_ethers2.computeHmac)("sha512", MasterSecret, seedArray));
|
7961
7891
|
}
|
7962
7892
|
/**
|
7963
7893
|
* Get the extendKey as defined on BIP-32 from the provided seed
|
@@ -7968,22 +7898,22 @@ var Mnemonic = class {
|
|
7968
7898
|
*/
|
7969
7899
|
static seedToExtendedKey(seed, testnet = false) {
|
7970
7900
|
const masterKey = Mnemonic.masterKeysFromSeed(seed);
|
7971
|
-
const prefix = (0,
|
7901
|
+
const prefix = (0, import_utils32.arrayify)(testnet ? TestnetPRV : MainnetPRV);
|
7972
7902
|
const depth = "0x00";
|
7973
7903
|
const fingerprint = "0x00000000";
|
7974
7904
|
const index = "0x00000000";
|
7975
7905
|
const chainCode = masterKey.slice(32);
|
7976
7906
|
const privateKey = masterKey.slice(0, 32);
|
7977
|
-
const extendedKey = (0,
|
7907
|
+
const extendedKey = (0, import_utils32.concat)([
|
7978
7908
|
prefix,
|
7979
7909
|
depth,
|
7980
7910
|
fingerprint,
|
7981
7911
|
index,
|
7982
7912
|
chainCode,
|
7983
|
-
(0,
|
7913
|
+
(0, import_utils32.concat)(["0x00", privateKey])
|
7984
7914
|
]);
|
7985
7915
|
const checksum = (0, import_ethers2.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
|
7986
|
-
return (0, import_ethers2.encodeBase58)((0,
|
7916
|
+
return (0, import_ethers2.encodeBase58)((0, import_utils32.concat)([extendedKey, checksum]));
|
7987
7917
|
}
|
7988
7918
|
/**
|
7989
7919
|
* Create a new mnemonic using a randomly generated number as entropy.
|
@@ -7998,7 +7928,7 @@ var Mnemonic = class {
|
|
7998
7928
|
* @returns A randomly generated mnemonic
|
7999
7929
|
*/
|
8000
7930
|
static generate(size = 32, extraEntropy = "") {
|
8001
|
-
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0,
|
7931
|
+
const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils32.concat)([(0, import_crypto3.randomBytes)(size), (0, import_utils32.arrayify)(extraEntropy)])) : (0, import_crypto3.randomBytes)(size);
|
8002
7932
|
return Mnemonic.entropyToMnemonic(entropy);
|
8003
7933
|
}
|
8004
7934
|
};
|
@@ -8006,12 +7936,12 @@ var mnemonic_default = Mnemonic;
|
|
8006
7936
|
|
8007
7937
|
// src/hdwallet/hdwallet.ts
|
8008
7938
|
var HARDENED_INDEX = 2147483648;
|
8009
|
-
var MainnetPRV2 = (0,
|
8010
|
-
var MainnetPUB = (0,
|
8011
|
-
var TestnetPRV2 = (0,
|
8012
|
-
var TestnetPUB = (0,
|
7939
|
+
var MainnetPRV2 = (0, import_utils34.hexlify)("0x0488ade4");
|
7940
|
+
var MainnetPUB = (0, import_utils34.hexlify)("0x0488b21e");
|
7941
|
+
var TestnetPRV2 = (0, import_utils34.hexlify)("0x04358394");
|
7942
|
+
var TestnetPUB = (0, import_utils34.hexlify)("0x043587cf");
|
8013
7943
|
function base58check(data) {
|
8014
|
-
return (0, import_ethers3.encodeBase58)((0,
|
7944
|
+
return (0, import_ethers3.encodeBase58)((0, import_utils34.concat)([data, (0, import_ethers3.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
|
8015
7945
|
}
|
8016
7946
|
function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
8017
7947
|
if (isPublic) {
|
@@ -8020,17 +7950,17 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8020
7950
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8021
7951
|
}
|
8022
7952
|
function isPublicExtendedKey(extendedKey) {
|
8023
|
-
return [MainnetPUB, TestnetPUB].includes((0,
|
7953
|
+
return [MainnetPUB, TestnetPUB].includes((0, import_utils34.hexlify)(extendedKey.slice(0, 4)));
|
8024
7954
|
}
|
8025
7955
|
function isValidExtendedKey(extendedKey) {
|
8026
7956
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8027
|
-
(0,
|
7957
|
+
(0, import_utils34.hexlify)(extendedKey.slice(0, 4))
|
8028
7958
|
);
|
8029
7959
|
}
|
8030
7960
|
function parsePath(path, depth = 0) {
|
8031
7961
|
const components = path.split("/");
|
8032
7962
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
8033
|
-
throw new
|
7963
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path}`);
|
8034
7964
|
}
|
8035
7965
|
if (components[0] === "m") {
|
8036
7966
|
components.shift();
|
@@ -8042,8 +7972,8 @@ function parsePath(path, depth = 0) {
|
|
8042
7972
|
var HDWallet = class {
|
8043
7973
|
depth = 0;
|
8044
7974
|
index = 0;
|
8045
|
-
fingerprint = (0,
|
8046
|
-
parentFingerprint = (0,
|
7975
|
+
fingerprint = (0, import_utils34.hexlify)("0x00000000");
|
7976
|
+
parentFingerprint = (0, import_utils34.hexlify)("0x00000000");
|
8047
7977
|
privateKey;
|
8048
7978
|
publicKey;
|
8049
7979
|
chainCode;
|
@@ -8055,16 +7985,16 @@ var HDWallet = class {
|
|
8055
7985
|
constructor(config) {
|
8056
7986
|
if (config.privateKey) {
|
8057
7987
|
const signer = new Signer(config.privateKey);
|
8058
|
-
this.publicKey = (0,
|
8059
|
-
this.privateKey = (0,
|
7988
|
+
this.publicKey = (0, import_utils34.hexlify)(signer.compressedPublicKey);
|
7989
|
+
this.privateKey = (0, import_utils34.hexlify)(config.privateKey);
|
8060
7990
|
} else {
|
8061
7991
|
if (!config.publicKey) {
|
8062
|
-
throw new
|
8063
|
-
|
7992
|
+
throw new import_errors19.FuelError(
|
7993
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8064
7994
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8065
7995
|
);
|
8066
7996
|
}
|
8067
|
-
this.publicKey = (0,
|
7997
|
+
this.publicKey = (0, import_utils34.hexlify)(config.publicKey);
|
8068
7998
|
}
|
8069
7999
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8070
8000
|
this.fingerprint = (0, import_ethers3.dataSlice)((0, import_ethers3.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
|
@@ -8083,28 +8013,28 @@ var HDWallet = class {
|
|
8083
8013
|
* @returns A new instance of HDWallet on the derived index
|
8084
8014
|
*/
|
8085
8015
|
deriveIndex(index) {
|
8086
|
-
const privateKey = this.privateKey && (0,
|
8087
|
-
const publicKey = (0,
|
8088
|
-
const chainCode = (0,
|
8016
|
+
const privateKey = this.privateKey && (0, import_utils34.arrayify)(this.privateKey);
|
8017
|
+
const publicKey = (0, import_utils34.arrayify)(this.publicKey);
|
8018
|
+
const chainCode = (0, import_utils34.arrayify)(this.chainCode);
|
8089
8019
|
const data = new Uint8Array(37);
|
8090
8020
|
if (index & HARDENED_INDEX) {
|
8091
8021
|
if (!privateKey) {
|
8092
|
-
throw new
|
8093
|
-
|
8022
|
+
throw new import_errors19.FuelError(
|
8023
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8094
8024
|
"Cannot derive a hardened index without a private Key."
|
8095
8025
|
);
|
8096
8026
|
}
|
8097
8027
|
data.set(privateKey, 1);
|
8098
8028
|
} else {
|
8099
|
-
data.set((0,
|
8029
|
+
data.set((0, import_utils34.arrayify)(this.publicKey));
|
8100
8030
|
}
|
8101
|
-
data.set((0,
|
8102
|
-
const bytes = (0,
|
8031
|
+
data.set((0, import_math19.toBytes)(index, 4), 33);
|
8032
|
+
const bytes = (0, import_utils34.arrayify)((0, import_ethers3.computeHmac)("sha512", chainCode, data));
|
8103
8033
|
const IL = bytes.slice(0, 32);
|
8104
8034
|
const IR = bytes.slice(32);
|
8105
8035
|
if (privateKey) {
|
8106
8036
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8107
|
-
const ki = (0,
|
8037
|
+
const ki = (0, import_math19.bn)(IL).add(privateKey).mod(N).toBytes(32);
|
8108
8038
|
return new HDWallet({
|
8109
8039
|
privateKey: ki,
|
8110
8040
|
chainCode: IR,
|
@@ -8113,7 +8043,7 @@ var HDWallet = class {
|
|
8113
8043
|
parentFingerprint: this.fingerprint
|
8114
8044
|
});
|
8115
8045
|
}
|
8116
|
-
const signer = new Signer((0,
|
8046
|
+
const signer = new Signer((0, import_utils34.hexlify)(IL));
|
8117
8047
|
const Ki = signer.addPoint(publicKey);
|
8118
8048
|
return new HDWallet({
|
8119
8049
|
publicKey: Ki,
|
@@ -8142,18 +8072,18 @@ var HDWallet = class {
|
|
8142
8072
|
*/
|
8143
8073
|
toExtendedKey(isPublic = false, testnet = false) {
|
8144
8074
|
if (this.depth >= 256) {
|
8145
|
-
throw new
|
8146
|
-
|
8075
|
+
throw new import_errors19.FuelError(
|
8076
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8147
8077
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
8148
8078
|
);
|
8149
8079
|
}
|
8150
8080
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8151
|
-
const depth = (0,
|
8081
|
+
const depth = (0, import_utils34.hexlify)(Uint8Array.from([this.depth]));
|
8152
8082
|
const parentFingerprint = this.parentFingerprint;
|
8153
|
-
const index = (0,
|
8083
|
+
const index = (0, import_math19.toHex)(this.index, 4);
|
8154
8084
|
const chainCode = this.chainCode;
|
8155
|
-
const key = this.privateKey != null && !isPublic ? (0,
|
8156
|
-
const extendedKey = (0,
|
8085
|
+
const key = this.privateKey != null && !isPublic ? (0, import_utils34.concat)(["0x00", this.privateKey]) : this.publicKey;
|
8086
|
+
const extendedKey = (0, import_utils34.arrayify)((0, import_utils34.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
|
8157
8087
|
return base58check(extendedKey);
|
8158
8088
|
}
|
8159
8089
|
/**
|
@@ -8165,34 +8095,34 @@ var HDWallet = class {
|
|
8165
8095
|
static fromSeed(seed) {
|
8166
8096
|
const masterKey = mnemonic_default.masterKeysFromSeed(seed);
|
8167
8097
|
return new HDWallet({
|
8168
|
-
chainCode: (0,
|
8169
|
-
privateKey: (0,
|
8098
|
+
chainCode: (0, import_utils34.arrayify)(masterKey.slice(32)),
|
8099
|
+
privateKey: (0, import_utils34.arrayify)(masterKey.slice(0, 32))
|
8170
8100
|
});
|
8171
8101
|
}
|
8172
8102
|
static fromExtendedKey(extendedKey) {
|
8173
8103
|
const decoded = (0, import_ethers3.toBeHex)((0, import_ethers3.decodeBase58)(extendedKey));
|
8174
|
-
const bytes = (0,
|
8104
|
+
const bytes = (0, import_utils34.arrayify)(decoded);
|
8175
8105
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8176
8106
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
8177
|
-
throw new
|
8107
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
8178
8108
|
}
|
8179
8109
|
if (!validChecksum) {
|
8180
|
-
throw new
|
8110
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8181
8111
|
}
|
8182
8112
|
const depth = bytes[4];
|
8183
|
-
const parentFingerprint = (0,
|
8184
|
-
const index = parseInt((0,
|
8185
|
-
const chainCode = (0,
|
8113
|
+
const parentFingerprint = (0, import_utils34.hexlify)(bytes.slice(5, 9));
|
8114
|
+
const index = parseInt((0, import_utils34.hexlify)(bytes.slice(9, 13)).substring(2), 16);
|
8115
|
+
const chainCode = (0, import_utils34.hexlify)(bytes.slice(13, 45));
|
8186
8116
|
const key = bytes.slice(45, 78);
|
8187
8117
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8188
|
-
throw new
|
8189
|
-
|
8118
|
+
throw new import_errors19.FuelError(
|
8119
|
+
import_errors19.ErrorCode.HD_WALLET_ERROR,
|
8190
8120
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
8191
8121
|
);
|
8192
8122
|
}
|
8193
8123
|
if (isPublicExtendedKey(bytes)) {
|
8194
8124
|
if (key[0] !== 3) {
|
8195
|
-
throw new
|
8125
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
8196
8126
|
}
|
8197
8127
|
return new HDWallet({
|
8198
8128
|
publicKey: key,
|
@@ -8203,7 +8133,7 @@ var HDWallet = class {
|
|
8203
8133
|
});
|
8204
8134
|
}
|
8205
8135
|
if (key[0] !== 0) {
|
8206
|
-
throw new
|
8136
|
+
throw new import_errors19.FuelError(import_errors19.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
8207
8137
|
}
|
8208
8138
|
return new HDWallet({
|
8209
8139
|
privateKey: key.slice(1),
|
@@ -8371,7 +8301,7 @@ __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
|
8371
8301
|
// src/wallet-manager/wallet-manager.ts
|
8372
8302
|
var import_address9 = require("@fuel-ts/address");
|
8373
8303
|
var import_crypto4 = require("@fuel-ts/crypto");
|
8374
|
-
var
|
8304
|
+
var import_errors22 = require("@fuel-ts/errors");
|
8375
8305
|
var import_events = require("events");
|
8376
8306
|
|
8377
8307
|
// src/wallet-manager/storages/memory-storage.ts
|
@@ -8394,7 +8324,7 @@ var MemoryStorage = class {
|
|
8394
8324
|
|
8395
8325
|
// src/wallet-manager/vaults/mnemonic-vault.ts
|
8396
8326
|
var import_address7 = require("@fuel-ts/address");
|
8397
|
-
var
|
8327
|
+
var import_errors20 = require("@fuel-ts/errors");
|
8398
8328
|
var _secret;
|
8399
8329
|
var MnemonicVault = class {
|
8400
8330
|
constructor(options) {
|
@@ -8450,8 +8380,8 @@ var MnemonicVault = class {
|
|
8450
8380
|
}
|
8451
8381
|
numberOfAccounts += 1;
|
8452
8382
|
} while (numberOfAccounts < this.numberOfAccounts);
|
8453
|
-
throw new
|
8454
|
-
|
8383
|
+
throw new import_errors20.FuelError(
|
8384
|
+
import_errors20.ErrorCode.WALLET_MANAGER_ERROR,
|
8455
8385
|
`Account with address '${address}' not found in derived wallets.`
|
8456
8386
|
);
|
8457
8387
|
}
|
@@ -8465,7 +8395,7 @@ __publicField(MnemonicVault, "type", "mnemonic");
|
|
8465
8395
|
|
8466
8396
|
// src/wallet-manager/vaults/privatekey-vault.ts
|
8467
8397
|
var import_address8 = require("@fuel-ts/address");
|
8468
|
-
var
|
8398
|
+
var import_errors21 = require("@fuel-ts/errors");
|
8469
8399
|
var _privateKeys;
|
8470
8400
|
var PrivateKeyVault = class {
|
8471
8401
|
/**
|
@@ -8506,8 +8436,8 @@ var PrivateKeyVault = class {
|
|
8506
8436
|
(pk) => Wallet.fromPrivateKey(pk).address.equals(ownerAddress)
|
8507
8437
|
);
|
8508
8438
|
if (!privateKey) {
|
8509
|
-
throw new
|
8510
|
-
|
8439
|
+
throw new import_errors21.FuelError(
|
8440
|
+
import_errors21.ErrorCode.WALLET_MANAGER_ERROR,
|
8511
8441
|
`No private key found for address '${address}'.`
|
8512
8442
|
);
|
8513
8443
|
}
|
@@ -8531,7 +8461,7 @@ var ERROR_MESSAGES = {
|
|
8531
8461
|
};
|
8532
8462
|
function assert(condition, message) {
|
8533
8463
|
if (!condition) {
|
8534
|
-
throw new
|
8464
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.WALLET_MANAGER_ERROR, message);
|
8535
8465
|
}
|
8536
8466
|
}
|
8537
8467
|
var _vaults, _passphrase, _isLocked, _serializeVaults, serializeVaults_fn, _deserializeVaults, deserializeVaults_fn;
|
@@ -8757,25 +8687,25 @@ deserializeVaults_fn = function(vaults) {
|
|
8757
8687
|
__publicField(WalletManager, "Vaults", [MnemonicVault, PrivateKeyVault]);
|
8758
8688
|
|
8759
8689
|
// src/wallet-manager/types.ts
|
8760
|
-
var
|
8690
|
+
var import_errors23 = require("@fuel-ts/errors");
|
8761
8691
|
var Vault = class {
|
8762
8692
|
constructor(_options) {
|
8763
|
-
throw new
|
8693
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8764
8694
|
}
|
8765
8695
|
serialize() {
|
8766
|
-
throw new
|
8696
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8767
8697
|
}
|
8768
8698
|
getAccounts() {
|
8769
|
-
throw new
|
8699
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8770
8700
|
}
|
8771
8701
|
addAccount() {
|
8772
|
-
throw new
|
8702
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8773
8703
|
}
|
8774
8704
|
exportAccount(_address) {
|
8775
|
-
throw new
|
8705
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8776
8706
|
}
|
8777
8707
|
getWallet(_address) {
|
8778
|
-
throw new
|
8708
|
+
throw new import_errors23.FuelError(import_errors23.ErrorCode.NOT_IMPLEMENTED, "Not implemented.");
|
8779
8709
|
}
|
8780
8710
|
};
|
8781
8711
|
__publicField(Vault, "type");
|
@@ -8785,21 +8715,21 @@ var StorageAbstract = class {
|
|
8785
8715
|
// src/predicate/predicate.ts
|
8786
8716
|
var import_abi_coder5 = require("@fuel-ts/abi-coder");
|
8787
8717
|
var import_address10 = require("@fuel-ts/address");
|
8788
|
-
var
|
8789
|
-
var
|
8790
|
-
var
|
8791
|
-
var
|
8718
|
+
var import_configs12 = require("@fuel-ts/address/configs");
|
8719
|
+
var import_errors24 = require("@fuel-ts/errors");
|
8720
|
+
var import_transactions19 = require("@fuel-ts/transactions");
|
8721
|
+
var import_utils36 = require("@fuel-ts/utils");
|
8792
8722
|
|
8793
8723
|
// src/predicate/utils/getPredicateRoot.ts
|
8794
8724
|
var import_hasher7 = require("@fuel-ts/hasher");
|
8795
8725
|
var import_merkle = require("@fuel-ts/merkle");
|
8796
|
-
var
|
8726
|
+
var import_utils35 = require("@fuel-ts/utils");
|
8797
8727
|
var getPredicateRoot = (bytecode) => {
|
8798
8728
|
const chunkSize = 16 * 1024;
|
8799
|
-
const bytes = (0,
|
8800
|
-
const chunks = (0,
|
8801
|
-
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0,
|
8802
|
-
const predicateRoot = (0, import_hasher7.hash)((0,
|
8729
|
+
const bytes = (0, import_utils35.arrayify)(bytecode);
|
8730
|
+
const chunks = (0, import_utils35.chunkAndPadBytes)(bytes, chunkSize);
|
8731
|
+
const codeRoot = (0, import_merkle.calcRoot)(chunks.map((c) => (0, import_utils35.hexlify)(c)));
|
8732
|
+
const predicateRoot = (0, import_hasher7.hash)((0, import_utils35.concat)(["0x4655454C", codeRoot]));
|
8803
8733
|
return predicateRoot;
|
8804
8734
|
};
|
8805
8735
|
|
@@ -8848,7 +8778,7 @@ var Predicate = class extends Account {
|
|
8848
8778
|
const request = transactionRequestify(transactionRequestLike);
|
8849
8779
|
const { policies } = BaseTransactionRequest.getPolicyMeta(request);
|
8850
8780
|
request.inputs?.forEach((input) => {
|
8851
|
-
if (input.type ===
|
8781
|
+
if (input.type === import_transactions19.InputType.Coin && (0, import_utils36.hexlify)(input.owner) === this.address.toB256()) {
|
8852
8782
|
input.predicate = this.bytes;
|
8853
8783
|
input.predicateData = this.getPredicateData(policies.length);
|
8854
8784
|
}
|
@@ -8864,7 +8794,7 @@ var Predicate = class extends Account {
|
|
8864
8794
|
* @param txParams - The transaction parameters (gasLimit, gasPrice, maturity).
|
8865
8795
|
* @returns A promise that resolves to the prepared transaction request.
|
8866
8796
|
*/
|
8867
|
-
async createTransfer(destination, amount, assetId =
|
8797
|
+
async createTransfer(destination, amount, assetId = import_configs12.BaseAssetId, txParams = {}) {
|
8868
8798
|
const request = await super.createTransfer(destination, amount, assetId, txParams);
|
8869
8799
|
return this.populateTransactionPredicateData(request);
|
8870
8800
|
}
|
@@ -8893,7 +8823,7 @@ var Predicate = class extends Account {
|
|
8893
8823
|
return new Uint8Array();
|
8894
8824
|
}
|
8895
8825
|
const mainFn = this.interface?.functions.main;
|
8896
|
-
const paddedCode = new
|
8826
|
+
const paddedCode = new import_transactions19.ByteArrayCoder(this.bytes.length).encode(this.bytes);
|
8897
8827
|
const VM_TX_MEMORY = (0, import_abi_coder5.calculateVmTxMemory)({
|
8898
8828
|
maxInputs: this.provider.getChain().consensusParameters.maxInputs.toNumber()
|
8899
8829
|
});
|
@@ -8909,13 +8839,13 @@ var Predicate = class extends Account {
|
|
8909
8839
|
* @returns An object containing the new predicate bytes and interface.
|
8910
8840
|
*/
|
8911
8841
|
static processPredicateData(bytes, jsonAbi, configurableConstants) {
|
8912
|
-
let predicateBytes = (0,
|
8842
|
+
let predicateBytes = (0, import_utils36.arrayify)(bytes);
|
8913
8843
|
let abiInterface;
|
8914
8844
|
if (jsonAbi) {
|
8915
8845
|
abiInterface = new import_abi_coder5.Interface(jsonAbi);
|
8916
8846
|
if (abiInterface.functions.main === void 0) {
|
8917
|
-
throw new
|
8918
|
-
|
8847
|
+
throw new import_errors24.FuelError(
|
8848
|
+
import_errors24.ErrorCode.ABI_MAIN_METHOD_MISSING,
|
8919
8849
|
'Cannot use ABI without "main" function.'
|
8920
8850
|
);
|
8921
8851
|
}
|
@@ -8960,8 +8890,8 @@ var Predicate = class extends Account {
|
|
8960
8890
|
mutatedBytes.set(encoded, offset);
|
8961
8891
|
});
|
8962
8892
|
} catch (err) {
|
8963
|
-
throw new
|
8964
|
-
|
8893
|
+
throw new import_errors24.FuelError(
|
8894
|
+
import_errors24.ErrorCode.INVALID_CONFIGURABLE_CONSTANTS,
|
8965
8895
|
`Error setting configurable constants: ${err.message}.`
|
8966
8896
|
);
|
8967
8897
|
}
|
@@ -8970,7 +8900,7 @@ var Predicate = class extends Account {
|
|
8970
8900
|
};
|
8971
8901
|
|
8972
8902
|
// src/connectors/fuel.ts
|
8973
|
-
var
|
8903
|
+
var import_errors25 = require("@fuel-ts/errors");
|
8974
8904
|
|
8975
8905
|
// src/connectors/fuel-connector.ts
|
8976
8906
|
var import_events2 = require("events");
|
@@ -9603,7 +9533,7 @@ var _Fuel = class extends FuelConnector {
|
|
9603
9533
|
const currentNetwork = await this.currentNetwork();
|
9604
9534
|
provider = await Provider.create(currentNetwork.url);
|
9605
9535
|
} else {
|
9606
|
-
throw new
|
9536
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_PROVIDER, "Provider is not valid.");
|
9607
9537
|
}
|
9608
9538
|
return provider;
|
9609
9539
|
}
|
@@ -9683,9 +9613,7 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9683
9613
|
WalletUnlocked,
|
9684
9614
|
addAmountToAsset,
|
9685
9615
|
addOperation,
|
9686
|
-
assemblePanicError,
|
9687
9616
|
assembleReceiptByType,
|
9688
|
-
assembleRevertError,
|
9689
9617
|
assembleTransactionSummary,
|
9690
9618
|
assets,
|
9691
9619
|
buildBlockExplorerUrl,
|
@@ -9700,7 +9628,6 @@ __publicField(Fuel, "defaultConfig", {});
|
|
9700
9628
|
english,
|
9701
9629
|
extractBurnedAssetsFromReceipts,
|
9702
9630
|
extractMintedAssetsFromReceipts,
|
9703
|
-
extractTxError,
|
9704
9631
|
gasUsedByInputs,
|
9705
9632
|
getAssetEth,
|
9706
9633
|
getAssetFuel,
|