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