@fuel-ts/account 0.97.1 → 0.98.0
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.
- package/dist/account.d.ts +19 -16
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +4 -4
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/connectors/fuel.d.ts +3 -3
- package/dist/connectors/fuel.d.ts.map +1 -1
- package/dist/connectors/types/data-type.d.ts +8 -0
- package/dist/connectors/types/data-type.d.ts.map +1 -1
- package/dist/hdwallet/hdwallet.d.ts +1 -1
- package/dist/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.global.js +2923 -1250
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +333 -279
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +358 -309
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts +1 -1
- package/dist/mnemonic/mnemonic.d.ts.map +1 -1
- package/dist/mnemonic/utils.d.ts +1 -1
- package/dist/mnemonic/utils.d.ts.map +1 -1
- package/dist/predicate/predicate.d.ts +9 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts +1 -1
- package/dist/predicate/utils/getPredicateRoot.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +0 -169
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/coin-quantity.d.ts +1 -1
- package/dist/providers/coin-quantity.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +3 -2
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +8 -7
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/provider.d.ts +27 -34
- package/dist/providers/provider.d.ts.map +1 -1
- package/dist/providers/resource.d.ts +1 -1
- package/dist/providers/resource.d.ts.map +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/create-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/errors.d.ts +3 -3
- package/dist/providers/transaction-request/errors.d.ts.map +1 -1
- package/dist/providers/transaction-request/helpers.d.ts +26 -4
- package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +1 -1
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/output.d.ts +1 -1
- package/dist/providers/transaction-request/output.d.ts.map +1 -1
- package/dist/providers/transaction-request/script-transaction-request.d.ts +13 -3
- package/dist/providers/transaction-request/script-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/scripts.d.ts +1 -1
- package/dist/providers/transaction-request/scripts.d.ts.map +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts +1 -1
- package/dist/providers/transaction-request/storage-slot.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +5 -3
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/types.d.ts +7 -0
- package/dist/providers/transaction-request/types.d.ts.map +1 -1
- package/dist/providers/transaction-request/upgrade-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/upgrade-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/upload-transaction-request.d.ts +1 -1
- package/dist/providers/transaction-request/upload-transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-request/witness.d.ts +1 -1
- package/dist/providers/transaction-request/witness.d.ts.map +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts +1 -1
- package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
- package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts +0 -1
- package/dist/providers/transaction-summary/calculate-tx-fee-for-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
- package/dist/providers/transaction-summary/input.d.ts +1 -1
- package/dist/providers/transaction-summary/status.d.ts +9 -2
- package/dist/providers/transaction-summary/status.d.ts.map +1 -1
- package/dist/providers/transaction-summary/types.d.ts +1 -21
- package/dist/providers/transaction-summary/types.d.ts.map +1 -1
- package/dist/providers/utils/receipts.d.ts.map +1 -1
- package/dist/signer/signer.d.ts +1 -1
- package/dist/signer/signer.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +4 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -1
- package/dist/test-utils/test-coin.d.ts +1 -0
- package/dist/test-utils/test-coin.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +6 -6
- package/dist/test-utils/test-message.d.ts.map +1 -1
- package/dist/test-utils.global.js +3033 -1799
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +294 -223
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +323 -252
- package/dist/test-utils.mjs.map +1 -1
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/formatTransferToContractScriptData.d.ts +1 -1
- package/dist/utils/formatTransferToContractScriptData.d.ts.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/dist/wallet/keystore-wallet.d.ts +2 -2
- package/dist/wallet/keystore-wallet.d.ts.map +1 -1
- package/dist/wallet/wallet.d.ts +3 -2
- package/dist/wallet/wallet.d.ts.map +1 -1
- package/dist/wallet/wallets.d.ts +1 -1
- package/dist/wallet/wallets.d.ts.map +1 -1
- package/dist/wallet-manager/types.d.ts +4 -4
- package/dist/wallet-manager/types.d.ts.map +1 -1
- package/dist/wallet-manager/vaults/mnemonic-vault.d.ts +5 -5
- package/dist/wallet-manager/vaults/mnemonic-vault.d.ts.map +1 -1
- package/dist/wallet-manager/vaults/privatekey-vault.d.ts +5 -5
- package/dist/wallet-manager/vaults/privatekey-vault.d.ts.map +1 -1
- package/dist/wallet-manager/wallet-manager.d.ts +3 -3
- package/dist/wallet-manager/wallet-manager.d.ts.map +1 -1
- package/package.json +27 -28
package/dist/test-utils.js
CHANGED
@@ -192,7 +192,11 @@ var extractRemainingArgs = (args, flagsToRemove) => {
|
|
192
192
|
});
|
193
193
|
return newArgs;
|
194
194
|
};
|
195
|
-
function getFinalStateConfigJSON({
|
195
|
+
function getFinalStateConfigJSON({
|
196
|
+
stateConfig,
|
197
|
+
chainConfig,
|
198
|
+
includeInitialState = false
|
199
|
+
}) {
|
196
200
|
const defaultCoins = import_utils2.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
197
201
|
...coin,
|
198
202
|
amount: "18446744073709551615"
|
@@ -203,6 +207,26 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
|
203
207
|
}));
|
204
208
|
const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
|
205
209
|
const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
|
210
|
+
if (includeInitialState) {
|
211
|
+
coins.push({
|
212
|
+
tx_id: "0x0000000000000000000000000000000000000000000000000000000000000001",
|
213
|
+
output_index: 0,
|
214
|
+
tx_pointer_block_height: 0,
|
215
|
+
tx_pointer_tx_idx: 0,
|
216
|
+
owner: "0x94ffcc53b892684acefaebc8a3d4a595e528a8cf664eeb3ef36f1020b0809d0d",
|
217
|
+
amount: "18446744073709551615",
|
218
|
+
asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
219
|
+
});
|
220
|
+
coins.push({
|
221
|
+
tx_id: "0x0000000000000000000000000000000000000000000000000000000000000002",
|
222
|
+
output_index: 0,
|
223
|
+
tx_pointer_block_height: 0,
|
224
|
+
tx_pointer_tx_idx: 0,
|
225
|
+
owner: "0x09c0b2d1a486c439a87bcba6b46a7a1a23f3897cc83a94521a96da5c23bc58db",
|
226
|
+
amount: "18446744073709551615",
|
227
|
+
asset_id: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
228
|
+
});
|
229
|
+
}
|
206
230
|
if (!process.env.GENESIS_SECRET) {
|
207
231
|
const pk = Signer.generatePrivateKey();
|
208
232
|
const signer = new Signer(pk);
|
@@ -212,7 +236,7 @@ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
|
212
236
|
owner: signer.address.toHexString(),
|
213
237
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
214
238
|
amount: "18446744073709551615",
|
215
|
-
asset_id: chainConfig.consensus_parameters.
|
239
|
+
asset_id: chainConfig.consensus_parameters.V2.base_asset_id,
|
216
240
|
output_index: 0,
|
217
241
|
tx_pointer_block_height: 0,
|
218
242
|
tx_pointer_tx_idx: 0
|
@@ -233,7 +257,9 @@ var launchNode = async ({
|
|
233
257
|
fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
|
234
258
|
loggingEnabled = true,
|
235
259
|
basePath,
|
236
|
-
snapshotConfig = import_utils2.defaultSnapshotConfigs
|
260
|
+
snapshotConfig = import_utils2.defaultSnapshotConfigs,
|
261
|
+
includeInitialState = false,
|
262
|
+
killProcessOnExit = false
|
237
263
|
} = {}) => (
|
238
264
|
// eslint-disable-next-line no-async-promise-executor
|
239
265
|
new Promise(async (resolve, reject) => {
|
@@ -273,7 +299,14 @@ var launchNode = async ({
|
|
273
299
|
const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
|
274
300
|
const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
|
275
301
|
(0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
276
|
-
(0, import_fs.writeFileSync)(
|
302
|
+
(0, import_fs.writeFileSync)(
|
303
|
+
stateConfigPath,
|
304
|
+
getFinalStateConfigJSON({
|
305
|
+
...snapshotConfig,
|
306
|
+
includeInitialState
|
307
|
+
}),
|
308
|
+
"utf8"
|
309
|
+
);
|
277
310
|
(0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
|
278
311
|
(0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
|
279
312
|
snapshotDirToUse = tempDir;
|
@@ -303,14 +336,14 @@ var launchNode = async ({
|
|
303
336
|
console.log(chunk.toString());
|
304
337
|
});
|
305
338
|
}
|
306
|
-
const
|
339
|
+
const removeChildListeners = () => {
|
307
340
|
child.stderr.removeAllListeners();
|
341
|
+
};
|
342
|
+
const removeTempDir = () => {
|
308
343
|
if ((0, import_fs.existsSync)(tempDir)) {
|
309
344
|
(0, import_fs.rmSync)(tempDir, { recursive: true });
|
310
345
|
}
|
311
346
|
};
|
312
|
-
child.on("error", removeSideffects);
|
313
|
-
child.on("exit", removeSideffects);
|
314
347
|
const childState = {
|
315
348
|
isDead: false
|
316
349
|
};
|
@@ -319,7 +352,7 @@ var launchNode = async ({
|
|
319
352
|
return;
|
320
353
|
}
|
321
354
|
childState.isDead = true;
|
322
|
-
|
355
|
+
removeChildListeners();
|
323
356
|
if (child.pid !== void 0) {
|
324
357
|
try {
|
325
358
|
process.kill(-child.pid);
|
@@ -338,6 +371,7 @@ var launchNode = async ({
|
|
338
371
|
} else {
|
339
372
|
console.error("No PID available for the child process, unable to kill launched node");
|
340
373
|
}
|
374
|
+
removeTempDir();
|
341
375
|
};
|
342
376
|
child.stderr.on("data", (chunk) => {
|
343
377
|
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
@@ -366,7 +400,18 @@ var launchNode = async ({
|
|
366
400
|
process.on("SIGUSR2", cleanup);
|
367
401
|
process.on("beforeExit", cleanup);
|
368
402
|
process.on("uncaughtException", cleanup);
|
369
|
-
child.on("
|
403
|
+
child.on("exit", (code, _signal) => {
|
404
|
+
removeChildListeners();
|
405
|
+
removeTempDir();
|
406
|
+
if (killProcessOnExit) {
|
407
|
+
process.exit(code);
|
408
|
+
}
|
409
|
+
});
|
410
|
+
child.on("error", (err) => {
|
411
|
+
removeChildListeners();
|
412
|
+
removeTempDir();
|
413
|
+
reject(err);
|
414
|
+
});
|
370
415
|
})
|
371
416
|
);
|
372
417
|
|
@@ -411,7 +456,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
411
456
|
|
412
457
|
// src/providers/provider.ts
|
413
458
|
var import_address4 = require("@fuel-ts/address");
|
414
|
-
var
|
459
|
+
var import_errors20 = require("@fuel-ts/errors");
|
415
460
|
var import_math19 = require("@fuel-ts/math");
|
416
461
|
var import_transactions22 = require("@fuel-ts/transactions");
|
417
462
|
var import_utils30 = require("@fuel-ts/utils");
|
@@ -1282,13 +1327,6 @@ var GetConsensusParametersVersionDocument = import_graphql_tag.default`
|
|
1282
1327
|
}
|
1283
1328
|
}
|
1284
1329
|
`;
|
1285
|
-
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
1286
|
-
subscription submitAndAwait($encodedTransaction: HexString!) {
|
1287
|
-
submitAndAwait(tx: $encodedTransaction) {
|
1288
|
-
...transactionStatusSubscriptionFragment
|
1289
|
-
}
|
1290
|
-
}
|
1291
|
-
${TransactionStatusSubscriptionFragmentDoc}`;
|
1292
1330
|
var SubmitAndAwaitStatusDocument = import_graphql_tag.default`
|
1293
1331
|
subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
|
1294
1332
|
submitAndAwaitStatus(tx: $encodedTransaction) {
|
@@ -1404,9 +1442,6 @@ function getSdk(requester) {
|
|
1404
1442
|
getConsensusParametersVersion(variables, options) {
|
1405
1443
|
return requester(GetConsensusParametersVersionDocument, variables, options);
|
1406
1444
|
},
|
1407
|
-
submitAndAwait(variables, options) {
|
1408
|
-
return requester(SubmitAndAwaitDocument, variables, options);
|
1409
|
-
},
|
1410
1445
|
submitAndAwaitStatus(variables, options) {
|
1411
1446
|
return requester(SubmitAndAwaitStatusDocument, variables, options);
|
1412
1447
|
},
|
@@ -1690,7 +1725,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
1690
1725
|
var import_address2 = require("@fuel-ts/address");
|
1691
1726
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1692
1727
|
var import_crypto3 = require("@fuel-ts/crypto");
|
1693
|
-
var
|
1728
|
+
var import_errors10 = require("@fuel-ts/errors");
|
1694
1729
|
var import_math9 = require("@fuel-ts/math");
|
1695
1730
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1696
1731
|
var import_utils11 = require("@fuel-ts/utils");
|
@@ -1734,7 +1769,6 @@ function assembleReceiptByType(receipt) {
|
|
1734
1769
|
const callReceipt = {
|
1735
1770
|
type: import_transactions3.ReceiptType.Call,
|
1736
1771
|
id,
|
1737
|
-
from: id,
|
1738
1772
|
to: hexOrZero(receipt?.to),
|
1739
1773
|
amount: (0, import_math5.bn)(receipt.amount),
|
1740
1774
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1802,10 +1836,6 @@ function assembleReceiptByType(receipt) {
|
|
1802
1836
|
rb,
|
1803
1837
|
rc,
|
1804
1838
|
rd,
|
1805
|
-
val0: ra,
|
1806
|
-
val1: rb,
|
1807
|
-
val2: rc,
|
1808
|
-
val3: rd,
|
1809
1839
|
pc: (0, import_math5.bn)(receipt.pc),
|
1810
1840
|
is: (0, import_math5.bn)(receipt.is)
|
1811
1841
|
};
|
@@ -1819,8 +1849,6 @@ function assembleReceiptByType(receipt) {
|
|
1819
1849
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1820
1850
|
ra,
|
1821
1851
|
rb,
|
1822
|
-
val0: ra,
|
1823
|
-
val1: rb,
|
1824
1852
|
ptr: (0, import_math5.bn)(receipt.ptr),
|
1825
1853
|
len: (0, import_math5.bn)(receipt.len),
|
1826
1854
|
digest: hexOrZero(receipt.digest),
|
@@ -1835,7 +1863,6 @@ function assembleReceiptByType(receipt) {
|
|
1835
1863
|
const transferReceipt = {
|
1836
1864
|
type: import_transactions3.ReceiptType.Transfer,
|
1837
1865
|
id,
|
1838
|
-
from: id,
|
1839
1866
|
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1840
1867
|
amount: (0, import_math5.bn)(receipt.amount),
|
1841
1868
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1849,7 +1876,6 @@ function assembleReceiptByType(receipt) {
|
|
1849
1876
|
const transferOutReceipt = {
|
1850
1877
|
type: import_transactions3.ReceiptType.TransferOut,
|
1851
1878
|
id,
|
1852
|
-
from: id,
|
1853
1879
|
to: hexOrZero(receipt.toAddress || receipt.to),
|
1854
1880
|
amount: (0, import_math5.bn)(receipt.amount),
|
1855
1881
|
assetId: hexOrZero(receipt.assetId),
|
@@ -2199,6 +2225,7 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2199
2225
|
};
|
2200
2226
|
|
2201
2227
|
// src/providers/transaction-request/helpers.ts
|
2228
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2202
2229
|
var import_math8 = require("@fuel-ts/math");
|
2203
2230
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2204
2231
|
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
@@ -2231,6 +2258,32 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2231
2258
|
messages: []
|
2232
2259
|
}
|
2233
2260
|
);
|
2261
|
+
var getBurnableAssetCount = (baseAssetId, transactionRequest) => {
|
2262
|
+
const { inputs, outputs } = transactionRequest;
|
2263
|
+
const coinInputs = new Set(inputs.filter(isRequestInputCoin).map((input) => input.assetId));
|
2264
|
+
if (inputs.some((i) => isRequestInputMessage(i) && (0, import_math8.bn)(i.amount).gt(0))) {
|
2265
|
+
coinInputs.add(baseAssetId);
|
2266
|
+
}
|
2267
|
+
const changeOutputs = new Set(
|
2268
|
+
outputs.filter((output) => output.type === import_transactions6.OutputType.Change).map((output) => output.assetId)
|
2269
|
+
);
|
2270
|
+
const difference = new Set([...coinInputs].filter((x) => !changeOutputs.has(x)));
|
2271
|
+
return difference.size;
|
2272
|
+
};
|
2273
|
+
var validateTransactionForAssetBurn = (baseAssetId, transactionRequest, enableAssetBurn = false) => {
|
2274
|
+
if (enableAssetBurn === true) {
|
2275
|
+
return;
|
2276
|
+
}
|
2277
|
+
if (getBurnableAssetCount(baseAssetId, transactionRequest) <= 0) {
|
2278
|
+
return;
|
2279
|
+
}
|
2280
|
+
const message = [
|
2281
|
+
"Asset burn detected.",
|
2282
|
+
"Add the relevant change outputs to the transaction to avoid burning assets.",
|
2283
|
+
"Or enable asset burn, upon sending the transaction."
|
2284
|
+
].join("\n");
|
2285
|
+
throw new import_errors9.FuelError(import_errors9.ErrorCode.ASSET_BURN_DETECTED, message);
|
2286
|
+
};
|
2234
2287
|
|
2235
2288
|
// src/providers/transaction-request/witness.ts
|
2236
2289
|
var import_utils10 = require("@fuel-ts/utils");
|
@@ -2614,7 +2667,7 @@ var BaseTransactionRequest = class {
|
|
2614
2667
|
* @hidden
|
2615
2668
|
*/
|
2616
2669
|
metadataGas(_gasCosts) {
|
2617
|
-
throw new
|
2670
|
+
throw new import_errors10.FuelError(import_errors10.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2618
2671
|
}
|
2619
2672
|
/**
|
2620
2673
|
* @hidden
|
@@ -3054,6 +3107,20 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3054
3107
|
this.scriptData = (0, import_utils18.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
3055
3108
|
this.abis = rest.abis;
|
3056
3109
|
}
|
3110
|
+
/**
|
3111
|
+
* Helper function to estimate and fund the transaction request with a specified account.
|
3112
|
+
*
|
3113
|
+
* @param account - The account to fund the transaction.
|
3114
|
+
* @param params - The parameters for the transaction cost.
|
3115
|
+
* @returns The current instance of the `ScriptTransactionRequest` funded.
|
3116
|
+
*/
|
3117
|
+
async estimateAndFund(account, { signatureCallback, quantities = [] } = {}) {
|
3118
|
+
const txCost = await account.getTransactionCost(this, { signatureCallback, quantities });
|
3119
|
+
this.maxFee = txCost.maxFee;
|
3120
|
+
this.gasLimit = txCost.gasUsed;
|
3121
|
+
await account.fund(this, txCost);
|
3122
|
+
return this;
|
3123
|
+
}
|
3057
3124
|
/**
|
3058
3125
|
* Converts the transaction request to a `TransactionScript`.
|
3059
3126
|
*
|
@@ -3208,7 +3275,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3208
3275
|
};
|
3209
3276
|
|
3210
3277
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3211
|
-
var
|
3278
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3212
3279
|
var import_hasher3 = require("@fuel-ts/hasher");
|
3213
3280
|
var import_transactions11 = require("@fuel-ts/transactions");
|
3214
3281
|
var import_utils19 = require("@fuel-ts/utils");
|
@@ -3312,7 +3379,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3312
3379
|
}
|
3313
3380
|
};
|
3314
3381
|
} else {
|
3315
|
-
throw new
|
3382
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3316
3383
|
}
|
3317
3384
|
return {
|
3318
3385
|
type: import_transactions11.TransactionType.Upgrade,
|
@@ -3354,7 +3421,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3354
3421
|
txBytesSize
|
3355
3422
|
});
|
3356
3423
|
}
|
3357
|
-
throw new
|
3424
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3358
3425
|
}
|
3359
3426
|
};
|
3360
3427
|
|
@@ -3465,7 +3532,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3465
3532
|
};
|
3466
3533
|
|
3467
3534
|
// src/providers/transaction-request/utils.ts
|
3468
|
-
var
|
3535
|
+
var import_errors13 = require("@fuel-ts/errors");
|
3469
3536
|
var import_transactions13 = require("@fuel-ts/transactions");
|
3470
3537
|
var transactionRequestify = (obj) => {
|
3471
3538
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
@@ -3489,8 +3556,8 @@ var transactionRequestify = (obj) => {
|
|
3489
3556
|
return UploadTransactionRequest.from(obj);
|
3490
3557
|
}
|
3491
3558
|
default: {
|
3492
|
-
throw new
|
3493
|
-
|
3559
|
+
throw new import_errors13.FuelError(
|
3560
|
+
import_errors13.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3494
3561
|
`Unsupported transaction type: ${type}.`
|
3495
3562
|
);
|
3496
3563
|
}
|
@@ -3500,7 +3567,7 @@ var isTransactionTypeScript = (request) => request.type === import_transactions1
|
|
3500
3567
|
var isTransactionTypeCreate = (request) => request.type === import_transactions13.TransactionType.Create;
|
3501
3568
|
|
3502
3569
|
// src/providers/transaction-response/transaction-response.ts
|
3503
|
-
var
|
3570
|
+
var import_errors17 = require("@fuel-ts/errors");
|
3504
3571
|
var import_math18 = require("@fuel-ts/math");
|
3505
3572
|
var import_transactions21 = require("@fuel-ts/transactions");
|
3506
3573
|
var import_utils27 = require("@fuel-ts/utils");
|
@@ -3519,12 +3586,8 @@ var calculateTXFeeForSummary = (params) => {
|
|
3519
3586
|
gasPrice,
|
3520
3587
|
rawPayload,
|
3521
3588
|
tip,
|
3522
|
-
totalFee,
|
3523
3589
|
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
3524
3590
|
} = params;
|
3525
|
-
if (totalFee) {
|
3526
|
-
return totalFee;
|
3527
|
-
}
|
3528
3591
|
const gasPerByte = (0, import_math13.bn)(feeParams.gasPerByte);
|
3529
3592
|
const gasPriceFactor = (0, import_math13.bn)(feeParams.gasPriceFactor);
|
3530
3593
|
const transactionBytes = (0, import_utils23.arrayify)(rawPayload);
|
@@ -3582,7 +3645,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3582
3645
|
|
3583
3646
|
// src/providers/transaction-summary/operations.ts
|
3584
3647
|
var import_configs11 = require("@fuel-ts/address/configs");
|
3585
|
-
var
|
3648
|
+
var import_errors15 = require("@fuel-ts/errors");
|
3586
3649
|
var import_math15 = require("@fuel-ts/math");
|
3587
3650
|
var import_transactions17 = require("@fuel-ts/transactions");
|
3588
3651
|
|
@@ -3620,7 +3683,7 @@ var getFunctionCall = ({ abi, receipt }) => {
|
|
3620
3683
|
};
|
3621
3684
|
|
3622
3685
|
// src/providers/transaction-summary/input.ts
|
3623
|
-
var
|
3686
|
+
var import_errors14 = require("@fuel-ts/errors");
|
3624
3687
|
var import_math14 = require("@fuel-ts/math");
|
3625
3688
|
var import_transactions15 = require("@fuel-ts/transactions");
|
3626
3689
|
function getInputsByTypes(inputs, types) {
|
@@ -3648,10 +3711,10 @@ function findCoinInput(inputs, assetId) {
|
|
3648
3711
|
const coinInputs = getInputsCoin(inputs);
|
3649
3712
|
return coinInputs.find((i) => i.assetId === assetId);
|
3650
3713
|
}
|
3651
|
-
function aggregateInputsAmountsByAssetAndOwner(inputs,
|
3714
|
+
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
3652
3715
|
const aggregated = /* @__PURE__ */ new Map();
|
3653
3716
|
getInputsCoinAndMessage(inputs).forEach((input) => {
|
3654
|
-
const assetId = isInputCoin(input) ? input.assetId :
|
3717
|
+
const assetId = isInputCoin(input) ? input.assetId : baseAssetId;
|
3655
3718
|
const owner = isInputCoin(input) ? input.owner : input.recipient;
|
3656
3719
|
let ownersMap = aggregated.get(assetId);
|
3657
3720
|
if (!ownersMap) {
|
@@ -3689,8 +3752,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3689
3752
|
return void 0;
|
3690
3753
|
}
|
3691
3754
|
if (contractInput.type !== import_transactions15.InputType.Contract) {
|
3692
|
-
throw new
|
3693
|
-
|
3755
|
+
throw new import_errors14.FuelError(
|
3756
|
+
import_errors14.ErrorCode.INVALID_TRANSACTION_INPUT,
|
3694
3757
|
`Contract input should be of type 'contract'.`
|
3695
3758
|
);
|
3696
3759
|
}
|
@@ -3743,8 +3806,8 @@ function getTransactionTypeName(transactionType) {
|
|
3743
3806
|
case import_transactions17.TransactionType.Upload:
|
3744
3807
|
return "Upload" /* Upload */;
|
3745
3808
|
default:
|
3746
|
-
throw new
|
3747
|
-
|
3809
|
+
throw new import_errors15.FuelError(
|
3810
|
+
import_errors15.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3748
3811
|
`Unsupported transaction type: ${transactionType}.`
|
3749
3812
|
);
|
3750
3813
|
}
|
@@ -3937,7 +4000,7 @@ function getContractCallOperations({
|
|
3937
4000
|
}
|
3938
4001
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
3939
4002
|
const { to: toAddress, assetId, amount } = receipt;
|
3940
|
-
let {
|
4003
|
+
let { id: fromAddress } = receipt;
|
3941
4004
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3942
4005
|
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3943
4006
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
@@ -4124,7 +4187,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4124
4187
|
};
|
4125
4188
|
|
4126
4189
|
// src/providers/transaction-summary/status.ts
|
4127
|
-
var
|
4190
|
+
var import_errors16 = require("@fuel-ts/errors");
|
4128
4191
|
var import_math16 = require("@fuel-ts/math");
|
4129
4192
|
var getTransactionStatusName = (gqlStatus) => {
|
4130
4193
|
switch (gqlStatus) {
|
@@ -4137,8 +4200,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4137
4200
|
case "SqueezedOutStatus":
|
4138
4201
|
return "squeezedout" /* squeezedout */;
|
4139
4202
|
default:
|
4140
|
-
throw new
|
4141
|
-
|
4203
|
+
throw new import_errors16.FuelError(
|
4204
|
+
import_errors16.ErrorCode.INVALID_TRANSACTION_STATUS,
|
4142
4205
|
`Invalid transaction status: ${gqlStatus}.`
|
4143
4206
|
);
|
4144
4207
|
}
|
@@ -4188,6 +4251,7 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4188
4251
|
};
|
4189
4252
|
return processedGraphqlStatus;
|
4190
4253
|
};
|
4254
|
+
var getTotalFeeFromStatus = (status) => status && "totalFee" in status ? (0, import_math16.bn)(status.totalFee) : void 0;
|
4191
4255
|
|
4192
4256
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4193
4257
|
function assembleTransactionSummary(params) {
|
@@ -4221,8 +4285,7 @@ function assembleTransactionSummary(params) {
|
|
4221
4285
|
const typeName = getTransactionTypeName(transaction.type);
|
4222
4286
|
const tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions19.PolicyType.Tip)?.data);
|
4223
4287
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
4224
|
-
const fee = calculateTXFeeForSummary({
|
4225
|
-
totalFee,
|
4288
|
+
const fee = totalFee ?? calculateTXFeeForSummary({
|
4226
4289
|
gasPrice,
|
4227
4290
|
rawPayload,
|
4228
4291
|
tip,
|
@@ -4276,8 +4339,8 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
4276
4339
|
return receipts.reduce((logs, receipt) => {
|
4277
4340
|
if (receipt.type === import_transactions20.ReceiptType.LogData || receipt.type === import_transactions20.ReceiptType.Log) {
|
4278
4341
|
const interfaceToUse = new import_abi_coder6.Interface(externalAbis[receipt.id] || mainAbi);
|
4279
|
-
const data = receipt.type === import_transactions20.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.
|
4280
|
-
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.
|
4342
|
+
const data = receipt.type === import_transactions20.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.ra) : receipt.data;
|
4343
|
+
const [decodedLog] = interfaceToUse.decodeLog(data, receipt.rb.toString());
|
4281
4344
|
logs.push(decodedLog);
|
4282
4345
|
}
|
4283
4346
|
return logs;
|
@@ -4322,9 +4385,9 @@ var TransactionResponse = class {
|
|
4322
4385
|
* @param tx - The transaction ID or TransactionRequest.
|
4323
4386
|
* @param provider - The provider.
|
4324
4387
|
*/
|
4325
|
-
constructor(tx, provider, abis, submitTxSubscription) {
|
4388
|
+
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
4326
4389
|
this.submitTxSubscription = submitTxSubscription;
|
4327
|
-
this.id = typeof tx === "string" ? tx : tx.getTransactionId(
|
4390
|
+
this.id = typeof tx === "string" ? tx : tx.getTransactionId(chainId);
|
4328
4391
|
this.provider = provider;
|
4329
4392
|
this.abis = abis;
|
4330
4393
|
this.request = typeof tx === "string" ? void 0 : tx;
|
@@ -4349,7 +4412,8 @@ var TransactionResponse = class {
|
|
4349
4412
|
* @param provider - The provider.
|
4350
4413
|
*/
|
4351
4414
|
static async create(id, provider, abis) {
|
4352
|
-
const
|
4415
|
+
const chainId = await provider.getChainId();
|
4416
|
+
const response = new TransactionResponse(id, provider, chainId, abis);
|
4353
4417
|
await response.fetch();
|
4354
4418
|
return response;
|
4355
4419
|
}
|
@@ -4446,10 +4510,11 @@ var TransactionResponse = class {
|
|
4446
4510
|
*/
|
4447
4511
|
async getTransactionSummary(contractsAbiMap) {
|
4448
4512
|
const { tx: transaction, bytes: transactionBytes } = await this.getTransaction();
|
4449
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
4450
|
-
const
|
4451
|
-
const
|
4452
|
-
const
|
4513
|
+
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = await this.provider.getGasConfig();
|
4514
|
+
const totalFee = getTotalFeeFromStatus(this.status ?? this.gqlTransaction?.status);
|
4515
|
+
const gasPrice = totalFee ? (0, import_math18.bn)(0) : await this.provider.getLatestGasPrice();
|
4516
|
+
const maxInputs = (await this.provider.getChain()).consensusParameters.txParameters.maxInputs;
|
4517
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
4453
4518
|
const transactionSummary = assembleTransactionSummary({
|
4454
4519
|
id: this.id,
|
4455
4520
|
receipts: this.getReceipts(),
|
@@ -4480,8 +4545,8 @@ var TransactionResponse = class {
|
|
4480
4545
|
this.status = statusChange;
|
4481
4546
|
if (statusChange.type === "SqueezedOutStatus") {
|
4482
4547
|
this.unsetResourceCache();
|
4483
|
-
throw new
|
4484
|
-
|
4548
|
+
throw new import_errors17.FuelError(
|
4549
|
+
import_errors17.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
4485
4550
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
4486
4551
|
);
|
4487
4552
|
}
|
@@ -4589,54 +4654,54 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4589
4654
|
}
|
4590
4655
|
|
4591
4656
|
// src/providers/utils/handle-gql-error-message.ts
|
4592
|
-
var
|
4657
|
+
var import_errors18 = require("@fuel-ts/errors");
|
4593
4658
|
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4594
4659
|
switch (errorMessage) {
|
4595
4660
|
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4596
|
-
throw new
|
4597
|
-
|
4661
|
+
throw new import_errors18.FuelError(
|
4662
|
+
import_errors18.ErrorCode.NOT_ENOUGH_FUNDS,
|
4598
4663
|
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4599
4664
|
{},
|
4600
4665
|
rawError
|
4601
4666
|
);
|
4602
4667
|
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
4603
|
-
throw new
|
4604
|
-
|
4668
|
+
throw new import_errors18.FuelError(
|
4669
|
+
import_errors18.ErrorCode.MAX_COINS_REACHED,
|
4605
4670
|
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
4606
4671
|
{},
|
4607
4672
|
rawError
|
4608
4673
|
);
|
4609
4674
|
default:
|
4610
|
-
throw new
|
4675
|
+
throw new import_errors18.FuelError(import_errors18.ErrorCode.INVALID_REQUEST, errorMessage);
|
4611
4676
|
}
|
4612
4677
|
};
|
4613
4678
|
|
4614
4679
|
// src/providers/utils/validate-pagination-args.ts
|
4615
|
-
var
|
4680
|
+
var import_errors19 = require("@fuel-ts/errors");
|
4616
4681
|
var validatePaginationArgs = (params) => {
|
4617
4682
|
const { paginationLimit, inputArgs = {} } = params;
|
4618
4683
|
const { first, last, after, before } = inputArgs;
|
4619
4684
|
if (after && before) {
|
4620
|
-
throw new
|
4621
|
-
|
4685
|
+
throw new import_errors19.FuelError(
|
4686
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4622
4687
|
'Pagination arguments "after" and "before" cannot be used together'
|
4623
4688
|
);
|
4624
4689
|
}
|
4625
4690
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4626
|
-
throw new
|
4627
|
-
|
4691
|
+
throw new import_errors19.FuelError(
|
4692
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4628
4693
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4629
4694
|
);
|
4630
4695
|
}
|
4631
4696
|
if (first && before) {
|
4632
|
-
throw new
|
4633
|
-
|
4697
|
+
throw new import_errors19.FuelError(
|
4698
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4634
4699
|
'The use of pagination argument "first" with "before" is not supported'
|
4635
4700
|
);
|
4636
4701
|
}
|
4637
4702
|
if (last && after) {
|
4638
|
-
throw new
|
4639
|
-
|
4703
|
+
throw new import_errors19.FuelError(
|
4704
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4640
4705
|
'The use of pagination argument "last" with "after" is not supported'
|
4641
4706
|
);
|
4642
4707
|
}
|
@@ -4790,7 +4855,7 @@ var _Provider = class {
|
|
4790
4855
|
try {
|
4791
4856
|
parsedUrl = new URL(url);
|
4792
4857
|
} catch (error) {
|
4793
|
-
throw new
|
4858
|
+
throw new import_errors20.FuelError(import_errors20.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
4794
4859
|
}
|
4795
4860
|
const username = parsedUrl.username;
|
4796
4861
|
const password = parsedUrl.password;
|
@@ -4805,58 +4870,40 @@ var _Provider = class {
|
|
4805
4870
|
};
|
4806
4871
|
}
|
4807
4872
|
/**
|
4808
|
-
*
|
4809
|
-
*
|
4810
|
-
* @param url - GraphQL endpoint of the Fuel node
|
4811
|
-
* @param options - Additional options for the provider
|
4812
|
-
*
|
4813
|
-
* @returns A promise that resolves to a Provider instance.
|
4873
|
+
* Initialize Provider async stuff
|
4814
4874
|
*/
|
4815
|
-
|
4816
|
-
|
4817
|
-
|
4818
|
-
return provider;
|
4875
|
+
async init() {
|
4876
|
+
await this.fetchChainAndNodeInfo();
|
4877
|
+
return this;
|
4819
4878
|
}
|
4820
4879
|
/**
|
4821
|
-
* Returns the
|
4880
|
+
* Returns the `chainInfo` for the current network.
|
4822
4881
|
*
|
4823
4882
|
* @returns the chain information configuration.
|
4824
4883
|
*/
|
4825
|
-
getChain() {
|
4826
|
-
|
4827
|
-
|
4828
|
-
throw new import_errors19.FuelError(
|
4829
|
-
import_errors19.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4830
|
-
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4831
|
-
);
|
4832
|
-
}
|
4833
|
-
return chain;
|
4884
|
+
async getChain() {
|
4885
|
+
await this.init();
|
4886
|
+
return _Provider.chainInfoCache[this.urlWithoutAuth];
|
4834
4887
|
}
|
4835
4888
|
/**
|
4836
|
-
* Returns the
|
4889
|
+
* Returns the `nodeInfo` for the current network.
|
4837
4890
|
*
|
4838
4891
|
* @returns the node information configuration.
|
4839
4892
|
*/
|
4840
|
-
getNode() {
|
4841
|
-
|
4842
|
-
|
4843
|
-
throw new import_errors19.FuelError(
|
4844
|
-
import_errors19.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4845
|
-
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4846
|
-
);
|
4847
|
-
}
|
4848
|
-
return node;
|
4893
|
+
async getNode() {
|
4894
|
+
await this.init();
|
4895
|
+
return _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4849
4896
|
}
|
4850
4897
|
/**
|
4851
4898
|
* Returns some helpful parameters related to gas fees.
|
4852
4899
|
*/
|
4853
|
-
getGasConfig() {
|
4900
|
+
async getGasConfig() {
|
4854
4901
|
const {
|
4855
4902
|
txParameters: { maxGasPerTx },
|
4856
4903
|
predicateParameters: { maxGasPerPredicate },
|
4857
4904
|
feeParameters: { gasPriceFactor, gasPerByte },
|
4858
4905
|
gasCosts
|
4859
|
-
} = this.getChain().consensusParameters;
|
4906
|
+
} = (await this.getChain()).consensusParameters;
|
4860
4907
|
return {
|
4861
4908
|
maxGasPerTx,
|
4862
4909
|
maxGasPerPredicate,
|
@@ -4878,7 +4925,7 @@ var _Provider = class {
|
|
4878
4925
|
this.options = options ?? this.options;
|
4879
4926
|
this.options = { ...this.options, headers: { ...this.options.headers, ...headers } };
|
4880
4927
|
this.operations = this.createOperations();
|
4881
|
-
await this.
|
4928
|
+
await this.init();
|
4882
4929
|
}
|
4883
4930
|
/**
|
4884
4931
|
* Return the chain and node information.
|
@@ -4889,11 +4936,12 @@ var _Provider = class {
|
|
4889
4936
|
let nodeInfo;
|
4890
4937
|
let chain;
|
4891
4938
|
try {
|
4892
|
-
|
4893
|
-
|
4939
|
+
nodeInfo = _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4940
|
+
chain = _Provider.chainInfoCache[this.urlWithoutAuth];
|
4941
|
+
const noCache = !nodeInfo || !chain;
|
4942
|
+
if (ignoreCache || noCache) {
|
4943
|
+
throw new Error(`Jumps to the catch block and re-fetch`);
|
4894
4944
|
}
|
4895
|
-
nodeInfo = this.getNode();
|
4896
|
-
chain = this.getChain();
|
4897
4945
|
} catch (_err) {
|
4898
4946
|
const data = await this.operations.getChainAndNodeInfo();
|
4899
4947
|
nodeInfo = {
|
@@ -5040,10 +5088,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5040
5088
|
*
|
5041
5089
|
* @returns A promise that resolves to the chain ID number.
|
5042
5090
|
*/
|
5043
|
-
getChainId() {
|
5091
|
+
async getChainId() {
|
5044
5092
|
const {
|
5045
5093
|
consensusParameters: { chainId }
|
5046
|
-
} = this.getChain();
|
5094
|
+
} = await this.getChain();
|
5047
5095
|
return chainId.toNumber();
|
5048
5096
|
}
|
5049
5097
|
/**
|
@@ -5051,30 +5099,31 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5051
5099
|
*
|
5052
5100
|
* @returns the base asset ID.
|
5053
5101
|
*/
|
5054
|
-
getBaseAssetId() {
|
5102
|
+
async getBaseAssetId() {
|
5103
|
+
const all = await this.getChain();
|
5055
5104
|
const {
|
5056
5105
|
consensusParameters: { baseAssetId }
|
5057
|
-
} =
|
5106
|
+
} = all;
|
5058
5107
|
return baseAssetId;
|
5059
5108
|
}
|
5060
5109
|
/**
|
5061
5110
|
* @hidden
|
5062
5111
|
*/
|
5063
|
-
validateTransaction(tx) {
|
5112
|
+
async validateTransaction(tx) {
|
5064
5113
|
const {
|
5065
5114
|
consensusParameters: {
|
5066
5115
|
txParameters: { maxInputs, maxOutputs }
|
5067
5116
|
}
|
5068
|
-
} = this.getChain();
|
5117
|
+
} = await this.getChain();
|
5069
5118
|
if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
|
5070
|
-
throw new
|
5071
|
-
|
5119
|
+
throw new import_errors20.FuelError(
|
5120
|
+
import_errors20.ErrorCode.MAX_INPUTS_EXCEEDED,
|
5072
5121
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5073
5122
|
);
|
5074
5123
|
}
|
5075
5124
|
if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
|
5076
|
-
throw new
|
5077
|
-
|
5125
|
+
throw new import_errors20.FuelError(
|
5126
|
+
import_errors20.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
5078
5127
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5079
5128
|
);
|
5080
5129
|
}
|
@@ -5089,20 +5138,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5089
5138
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
5090
5139
|
* @returns A promise that resolves to the transaction response object.
|
5091
5140
|
*/
|
5092
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
5141
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, enableAssetBurn } = {}) {
|
5093
5142
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5143
|
+
validateTransactionForAssetBurn(
|
5144
|
+
await this.getBaseAssetId(),
|
5145
|
+
transactionRequest,
|
5146
|
+
enableAssetBurn
|
5147
|
+
);
|
5094
5148
|
if (estimateTxDependencies) {
|
5095
5149
|
await this.estimateTxDependencies(transactionRequest);
|
5096
5150
|
}
|
5097
|
-
this.validateTransaction(transactionRequest);
|
5151
|
+
await this.validateTransaction(transactionRequest);
|
5098
5152
|
const encodedTransaction = (0, import_utils30.hexlify)(transactionRequest.toTransactionBytes());
|
5099
5153
|
let abis;
|
5100
5154
|
if (isTransactionTypeScript(transactionRequest)) {
|
5101
5155
|
abis = transactionRequest.abis;
|
5102
5156
|
}
|
5103
5157
|
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
5104
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(this.getChainId()));
|
5105
|
-
|
5158
|
+
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(await this.getChainId()));
|
5159
|
+
const chainId = await this.getChainId();
|
5160
|
+
return new TransactionResponse(transactionRequest, this, chainId, abis, subscription);
|
5106
5161
|
}
|
5107
5162
|
/**
|
5108
5163
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -5182,7 +5237,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5182
5237
|
const missingContractIds = [];
|
5183
5238
|
let outputVariables = 0;
|
5184
5239
|
let dryRunStatus;
|
5185
|
-
this.validateTransaction(transactionRequest);
|
5240
|
+
await this.validateTransaction(transactionRequest);
|
5186
5241
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5187
5242
|
const {
|
5188
5243
|
dryRun: [{ receipts: rawReceipts, status }]
|
@@ -5313,7 +5368,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5313
5368
|
if (diff < 6e4) {
|
5314
5369
|
return;
|
5315
5370
|
}
|
5316
|
-
|
5371
|
+
if (!_Provider.chainInfoCache?.[this.urlWithoutAuth]) {
|
5372
|
+
await this.fetchChainAndNodeInfo(true);
|
5373
|
+
return;
|
5374
|
+
}
|
5375
|
+
const chainInfo = _Provider.chainInfoCache[this.urlWithoutAuth];
|
5317
5376
|
const {
|
5318
5377
|
consensusParameters: { version: previous }
|
5319
5378
|
} = chainInfo;
|
@@ -5337,8 +5396,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5337
5396
|
const { transactionRequest } = params;
|
5338
5397
|
let { gasPrice } = params;
|
5339
5398
|
await this.autoRefetchConfigs();
|
5340
|
-
const chainInfo = this.getChain();
|
5341
|
-
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
5399
|
+
const chainInfo = await this.getChain();
|
5400
|
+
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
5342
5401
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
5343
5402
|
if (!(0, import_utils30.isDefined)(gasPrice)) {
|
5344
5403
|
gasPrice = await this.estimateGasPrice(10);
|
@@ -5450,7 +5509,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5450
5509
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
5451
5510
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
5452
5511
|
}
|
5453
|
-
const { maxGasPerTx } = this.getGasConfig();
|
5512
|
+
const { maxGasPerTx } = await this.getGasConfig();
|
5454
5513
|
const pristineGasUsed = getGasUsedFromReceipts(receipts);
|
5455
5514
|
gasUsed = (0, import_math19.bn)(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
|
5456
5515
|
txRequestClone.gasLimit = gasUsed;
|
@@ -5707,7 +5766,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5707
5766
|
0
|
5708
5767
|
)?.[0];
|
5709
5768
|
} catch (error) {
|
5710
|
-
if (error instanceof
|
5769
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5711
5770
|
console.warn("Unsupported transaction type encountered");
|
5712
5771
|
return null;
|
5713
5772
|
}
|
@@ -5733,7 +5792,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5733
5792
|
try {
|
5734
5793
|
return coder.decode((0, import_utils30.arrayify)(rawPayload), 0)[0];
|
5735
5794
|
} catch (error) {
|
5736
|
-
if (error instanceof
|
5795
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5737
5796
|
console.warn("Unsupported transaction type encountered");
|
5738
5797
|
return null;
|
5739
5798
|
}
|
@@ -5859,8 +5918,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5859
5918
|
nonce
|
5860
5919
|
};
|
5861
5920
|
if (commitBlockId && commitBlockHeight) {
|
5862
|
-
throw new
|
5863
|
-
|
5921
|
+
throw new import_errors20.FuelError(
|
5922
|
+
import_errors20.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5864
5923
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5865
5924
|
);
|
5866
5925
|
}
|
@@ -6023,9 +6082,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
6023
6082
|
* @param transactionId - The transaction ID to get the response for.
|
6024
6083
|
* @returns A promise that resolves to the transaction response.
|
6025
6084
|
*/
|
6026
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
6027
6085
|
async getTransactionResponse(transactionId) {
|
6028
|
-
|
6086
|
+
const chainId = await this.getChainId();
|
6087
|
+
return new TransactionResponse(transactionId, this, chainId);
|
6029
6088
|
}
|
6030
6089
|
/**
|
6031
6090
|
* Returns Message for given nonce.
|
@@ -6115,7 +6174,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
6115
6174
|
__publicField(Provider, "nodeInfoCache", {});
|
6116
6175
|
|
6117
6176
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6118
|
-
var
|
6177
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6119
6178
|
var import_math20 = require("@fuel-ts/math");
|
6120
6179
|
var import_transactions23 = require("@fuel-ts/transactions");
|
6121
6180
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -6749,7 +6808,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
6749
6808
|
|
6750
6809
|
// src/test-utils/wallet-config.ts
|
6751
6810
|
var import_crypto9 = require("@fuel-ts/crypto");
|
6752
|
-
var
|
6811
|
+
var import_errors27 = require("@fuel-ts/errors");
|
6753
6812
|
var import_utils44 = require("@fuel-ts/utils");
|
6754
6813
|
|
6755
6814
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -6760,8 +6819,7 @@ var import_utils39 = require("@fuel-ts/utils");
|
|
6760
6819
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
6761
6820
|
var import_address6 = require("@fuel-ts/address");
|
6762
6821
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6763
|
-
var
|
6764
|
-
var import_interfaces = require("@fuel-ts/interfaces");
|
6822
|
+
var import_errors22 = require("@fuel-ts/errors");
|
6765
6823
|
var import_math21 = require("@fuel-ts/math");
|
6766
6824
|
var import_transactions24 = require("@fuel-ts/transactions");
|
6767
6825
|
var import_utils37 = require("@fuel-ts/utils");
|
@@ -6781,6 +6839,10 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6781
6839
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
6782
6840
|
};
|
6783
6841
|
|
6842
|
+
// src/types.ts
|
6843
|
+
var AbstractAccount = class {
|
6844
|
+
};
|
6845
|
+
|
6784
6846
|
// src/utils/formatTransferToContractScriptData.ts
|
6785
6847
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6786
6848
|
var import_address5 = require("@fuel-ts/address");
|
@@ -6827,7 +6889,7 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
6827
6889
|
|
6828
6890
|
// src/account.ts
|
6829
6891
|
var MAX_FUNDING_ATTEMPTS = 5;
|
6830
|
-
var Account = class extends
|
6892
|
+
var Account = class extends AbstractAccount {
|
6831
6893
|
/**
|
6832
6894
|
* The address associated with the account.
|
6833
6895
|
*/
|
@@ -6862,7 +6924,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6862
6924
|
*/
|
6863
6925
|
get provider() {
|
6864
6926
|
if (!this._provider) {
|
6865
|
-
throw new
|
6927
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
6866
6928
|
}
|
6867
6929
|
return this._provider;
|
6868
6930
|
}
|
@@ -6918,7 +6980,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6918
6980
|
* @returns A promise that resolves to the balance amount.
|
6919
6981
|
*/
|
6920
6982
|
async getBalance(assetId) {
|
6921
|
-
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
6983
|
+
const assetIdToFetch = assetId ?? await this.provider.getBaseAssetId();
|
6922
6984
|
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
6923
6985
|
return amount;
|
6924
6986
|
}
|
@@ -6941,7 +7003,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6941
7003
|
async fund(request, params) {
|
6942
7004
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
|
6943
7005
|
const fee = request.maxFee;
|
6944
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7006
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
6945
7007
|
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
|
6946
7008
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
6947
7009
|
amount: (0, import_math21.bn)(fee),
|
@@ -7013,12 +7075,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7013
7075
|
fundingAttempts += 1;
|
7014
7076
|
}
|
7015
7077
|
if (needsToBeFunded) {
|
7016
|
-
throw new
|
7017
|
-
|
7078
|
+
throw new import_errors22.FuelError(
|
7079
|
+
import_errors22.ErrorCode.NOT_ENOUGH_FUNDS,
|
7018
7080
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7019
7081
|
);
|
7020
7082
|
}
|
7021
|
-
this.provider.validateTransaction(request);
|
7083
|
+
await this.provider.validateTransaction(request);
|
7022
7084
|
request.updatePredicateGasUsed(estimatedPredicates);
|
7023
7085
|
const requestToReestimate = (0, import_ramda9.clone)(request);
|
7024
7086
|
if (addedSignatures) {
|
@@ -7045,7 +7107,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7045
7107
|
*/
|
7046
7108
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
7047
7109
|
let request = new ScriptTransactionRequest(txParams);
|
7048
|
-
request = this.addTransfer(request, {
|
7110
|
+
request = this.addTransfer(request, {
|
7111
|
+
destination,
|
7112
|
+
amount,
|
7113
|
+
assetId: assetId || await this.provider.getBaseAssetId()
|
7114
|
+
});
|
7049
7115
|
request = await this.estimateAndFundTransaction(request, txParams);
|
7050
7116
|
return request;
|
7051
7117
|
}
|
@@ -7085,11 +7151,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7085
7151
|
addTransfer(request, transferParams) {
|
7086
7152
|
const { destination, amount, assetId } = transferParams;
|
7087
7153
|
this.validateTransferAmount(amount);
|
7088
|
-
request.addCoinOutput(
|
7089
|
-
import_address6.Address.fromAddressOrString(destination),
|
7090
|
-
amount,
|
7091
|
-
assetId ?? this.provider.getBaseAssetId()
|
7092
|
-
);
|
7154
|
+
request.addCoinOutput(import_address6.Address.fromAddressOrString(destination), amount, assetId);
|
7093
7155
|
return request;
|
7094
7156
|
}
|
7095
7157
|
/**
|
@@ -7100,12 +7162,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7100
7162
|
* @returns The updated script transaction request.
|
7101
7163
|
*/
|
7102
7164
|
addBatchTransfer(request, transferParams) {
|
7103
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7104
7165
|
transferParams.forEach(({ destination, amount, assetId }) => {
|
7105
7166
|
this.addTransfer(request, {
|
7106
7167
|
destination,
|
7107
7168
|
amount,
|
7108
|
-
assetId
|
7169
|
+
assetId
|
7109
7170
|
});
|
7110
7171
|
});
|
7111
7172
|
return request;
|
@@ -7127,13 +7188,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7127
7188
|
...txParams
|
7128
7189
|
});
|
7129
7190
|
const quantities = [];
|
7191
|
+
const defaultAssetId = await this.provider.getBaseAssetId();
|
7130
7192
|
const transferParams = contractTransferParams.map((transferParam) => {
|
7131
7193
|
const amount = (0, import_math21.bn)(transferParam.amount);
|
7132
7194
|
const contractAddress = import_address6.Address.fromAddressOrString(transferParam.contractId);
|
7133
|
-
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) :
|
7195
|
+
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : defaultAssetId;
|
7134
7196
|
if (amount.lte(0)) {
|
7135
|
-
throw new
|
7136
|
-
|
7197
|
+
throw new import_errors22.FuelError(
|
7198
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7137
7199
|
"Transfer amount must be a positive number."
|
7138
7200
|
);
|
7139
7201
|
}
|
@@ -7173,7 +7235,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7173
7235
|
...amountDataArray
|
7174
7236
|
]);
|
7175
7237
|
const params = { script, ...txParams };
|
7176
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7238
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7177
7239
|
let request = new ScriptTransactionRequest(params);
|
7178
7240
|
const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
|
7179
7241
|
const txCost = await this.getTransactionCost(request, { quantities });
|
@@ -7198,7 +7260,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7198
7260
|
*/
|
7199
7261
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
7200
7262
|
const txRequestClone = (0, import_ramda9.clone)(transactionRequestify(transactionRequestLike));
|
7201
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7263
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7202
7264
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7203
7265
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7204
7266
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
|
@@ -7248,7 +7310,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7248
7310
|
*/
|
7249
7311
|
async signMessage(message) {
|
7250
7312
|
if (!this._connector) {
|
7251
|
-
throw new
|
7313
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7252
7314
|
}
|
7253
7315
|
return this._connector.signMessage(this.address.toString(), message);
|
7254
7316
|
}
|
@@ -7260,8 +7322,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7260
7322
|
*/
|
7261
7323
|
async signTransaction(transactionRequestLike) {
|
7262
7324
|
if (!this._connector) {
|
7263
|
-
throw new
|
7264
|
-
|
7325
|
+
throw new import_errors22.FuelError(
|
7326
|
+
import_errors22.ErrorCode.MISSING_CONNECTOR,
|
7265
7327
|
"A connector is required to sign transactions."
|
7266
7328
|
);
|
7267
7329
|
}
|
@@ -7274,10 +7336,13 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7274
7336
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
7275
7337
|
* @returns A promise that resolves to the transaction response.
|
7276
7338
|
*/
|
7277
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
7339
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, onBeforeSend, skipCustomFee = false } = {}) {
|
7278
7340
|
if (this._connector) {
|
7279
7341
|
return this.provider.getTransactionResponse(
|
7280
|
-
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike
|
7342
|
+
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, {
|
7343
|
+
onBeforeSend,
|
7344
|
+
skipCustomFee
|
7345
|
+
})
|
7281
7346
|
);
|
7282
7347
|
}
|
7283
7348
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
@@ -7320,8 +7385,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7320
7385
|
/** @hidden * */
|
7321
7386
|
validateTransferAmount(amount) {
|
7322
7387
|
if ((0, import_math21.bn)(amount).lte(0)) {
|
7323
|
-
throw new
|
7324
|
-
|
7388
|
+
throw new import_errors22.FuelError(
|
7389
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7325
7390
|
"Transfer amount must be a positive number."
|
7326
7391
|
);
|
7327
7392
|
}
|
@@ -7350,16 +7415,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7350
7415
|
if (!(0, import_utils37.isDefined)(setGasLimit)) {
|
7351
7416
|
request.gasLimit = gasUsed;
|
7352
7417
|
} else if (gasUsed.gt(setGasLimit)) {
|
7353
|
-
throw new
|
7354
|
-
|
7418
|
+
throw new import_errors22.FuelError(
|
7419
|
+
import_errors22.ErrorCode.GAS_LIMIT_TOO_LOW,
|
7355
7420
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7356
7421
|
);
|
7357
7422
|
}
|
7358
7423
|
if (!(0, import_utils37.isDefined)(setMaxFee)) {
|
7359
7424
|
request.maxFee = maxFee;
|
7360
7425
|
} else if (maxFee.gt(setMaxFee)) {
|
7361
|
-
throw new
|
7362
|
-
|
7426
|
+
throw new import_errors22.FuelError(
|
7427
|
+
import_errors22.ErrorCode.MAX_FEE_TOO_LOW,
|
7363
7428
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7364
7429
|
);
|
7365
7430
|
}
|
@@ -7370,7 +7435,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7370
7435
|
// src/wallet/keystore-wallet.ts
|
7371
7436
|
var import_address7 = require("@fuel-ts/address");
|
7372
7437
|
var import_crypto6 = require("@fuel-ts/crypto");
|
7373
|
-
var
|
7438
|
+
var import_errors23 = require("@fuel-ts/errors");
|
7374
7439
|
var import_utils38 = require("@fuel-ts/utils");
|
7375
7440
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7376
7441
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7447,8 +7512,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7447
7512
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
7448
7513
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
7449
7514
|
if (mac !== macHash) {
|
7450
|
-
throw new
|
7451
|
-
|
7515
|
+
throw new import_errors23.FuelError(
|
7516
|
+
import_errors23.ErrorCode.INVALID_PASSWORD,
|
7452
7517
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7453
7518
|
);
|
7454
7519
|
}
|
@@ -7508,7 +7573,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
7508
7573
|
*/
|
7509
7574
|
async signTransaction(transactionRequestLike) {
|
7510
7575
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7511
|
-
const chainId = this.provider.getChainId();
|
7576
|
+
const chainId = await this.provider.getChainId();
|
7512
7577
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
7513
7578
|
const signature = await this.signer().sign(hashedTransaction);
|
7514
7579
|
return (0, import_utils39.hexlify)(signature);
|
@@ -7532,14 +7597,19 @@ var BaseWalletUnlocked = class extends Account {
|
|
7532
7597
|
* @param estimateTxDependencies - Whether to estimate the transaction dependencies.
|
7533
7598
|
* @returns A promise that resolves to the TransactionResponse object.
|
7534
7599
|
*/
|
7535
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
|
7600
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, enableAssetBurn } = {}) {
|
7536
7601
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7602
|
+
validateTransactionForAssetBurn(
|
7603
|
+
await this.provider.getBaseAssetId(),
|
7604
|
+
transactionRequest,
|
7605
|
+
enableAssetBurn
|
7606
|
+
);
|
7537
7607
|
if (estimateTxDependencies) {
|
7538
7608
|
await this.provider.estimateTxDependencies(transactionRequest);
|
7539
7609
|
}
|
7540
7610
|
return this.provider.sendTransaction(
|
7541
7611
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
7542
|
-
{ estimateTxDependencies: false }
|
7612
|
+
{ estimateTxDependencies: false, enableAssetBurn }
|
7543
7613
|
);
|
7544
7614
|
}
|
7545
7615
|
/**
|
@@ -7578,14 +7648,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7578
7648
|
|
7579
7649
|
// src/hdwallet/hdwallet.ts
|
7580
7650
|
var import_crypto8 = require("@fuel-ts/crypto");
|
7581
|
-
var
|
7651
|
+
var import_errors26 = require("@fuel-ts/errors");
|
7582
7652
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7583
7653
|
var import_math22 = require("@fuel-ts/math");
|
7584
7654
|
var import_utils43 = require("@fuel-ts/utils");
|
7585
7655
|
|
7586
7656
|
// src/mnemonic/mnemonic.ts
|
7587
7657
|
var import_crypto7 = require("@fuel-ts/crypto");
|
7588
|
-
var
|
7658
|
+
var import_errors25 = require("@fuel-ts/errors");
|
7589
7659
|
var import_hasher6 = require("@fuel-ts/hasher");
|
7590
7660
|
var import_utils41 = require("@fuel-ts/utils");
|
7591
7661
|
|
@@ -9642,7 +9712,7 @@ var english = [
|
|
9642
9712
|
];
|
9643
9713
|
|
9644
9714
|
// src/mnemonic/utils.ts
|
9645
|
-
var
|
9715
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9646
9716
|
var import_hasher5 = require("@fuel-ts/hasher");
|
9647
9717
|
var import_utils40 = require("@fuel-ts/utils");
|
9648
9718
|
function getLowerMask(bits) {
|
@@ -9691,8 +9761,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9691
9761
|
for (let i = 0; i < words.length; i += 1) {
|
9692
9762
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9693
9763
|
if (index === -1) {
|
9694
|
-
throw new
|
9695
|
-
|
9764
|
+
throw new import_errors24.FuelError(
|
9765
|
+
import_errors24.ErrorCode.INVALID_MNEMONIC,
|
9696
9766
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9697
9767
|
);
|
9698
9768
|
}
|
@@ -9708,8 +9778,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9708
9778
|
const checksumMask = getUpperMask(checksumBits);
|
9709
9779
|
const checksum = (0, import_utils40.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9710
9780
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9711
|
-
throw new
|
9712
|
-
|
9781
|
+
throw new import_errors24.FuelError(
|
9782
|
+
import_errors24.ErrorCode.INVALID_CHECKSUM,
|
9713
9783
|
"Checksum validation failed for the provided mnemonic."
|
9714
9784
|
);
|
9715
9785
|
}
|
@@ -9723,16 +9793,16 @@ var TestnetPRV = "0x04358394";
|
|
9723
9793
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9724
9794
|
function assertWordList(wordlist) {
|
9725
9795
|
if (wordlist.length !== 2048) {
|
9726
|
-
throw new
|
9727
|
-
|
9796
|
+
throw new import_errors25.FuelError(
|
9797
|
+
import_errors25.ErrorCode.INVALID_WORD_LIST,
|
9728
9798
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9729
9799
|
);
|
9730
9800
|
}
|
9731
9801
|
}
|
9732
9802
|
function assertEntropy(entropy) {
|
9733
9803
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9734
|
-
throw new
|
9735
|
-
|
9804
|
+
throw new import_errors25.FuelError(
|
9805
|
+
import_errors25.ErrorCode.INVALID_ENTROPY,
|
9736
9806
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9737
9807
|
);
|
9738
9808
|
}
|
@@ -9742,7 +9812,7 @@ function assertMnemonic(words) {
|
|
9742
9812
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9743
9813
|
", "
|
9744
9814
|
)}] words, but got ${words.length}.`;
|
9745
|
-
throw new
|
9815
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
9746
9816
|
}
|
9747
9817
|
}
|
9748
9818
|
var Mnemonic = class {
|
@@ -9860,8 +9930,8 @@ var Mnemonic = class {
|
|
9860
9930
|
static masterKeysFromSeed(seed) {
|
9861
9931
|
const seedArray = (0, import_utils41.arrayify)(seed);
|
9862
9932
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
9863
|
-
throw new
|
9864
|
-
|
9933
|
+
throw new import_errors25.FuelError(
|
9934
|
+
import_errors25.ErrorCode.INVALID_SEED,
|
9865
9935
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
9866
9936
|
);
|
9867
9937
|
}
|
@@ -9938,7 +10008,7 @@ function isValidExtendedKey(extendedKey) {
|
|
9938
10008
|
function parsePath(path2, depth = 0) {
|
9939
10009
|
const components = path2.split("/");
|
9940
10010
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
9941
|
-
throw new
|
10011
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
9942
10012
|
}
|
9943
10013
|
if (components[0] === "m") {
|
9944
10014
|
components.shift();
|
@@ -9967,8 +10037,8 @@ var HDWallet = class {
|
|
9967
10037
|
this.privateKey = (0, import_utils43.hexlify)(config.privateKey);
|
9968
10038
|
} else {
|
9969
10039
|
if (!config.publicKey) {
|
9970
|
-
throw new
|
9971
|
-
|
10040
|
+
throw new import_errors26.FuelError(
|
10041
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
9972
10042
|
"Both public and private Key cannot be missing. At least one should be provided."
|
9973
10043
|
);
|
9974
10044
|
}
|
@@ -9997,8 +10067,8 @@ var HDWallet = class {
|
|
9997
10067
|
const data = new Uint8Array(37);
|
9998
10068
|
if (index & HARDENED_INDEX) {
|
9999
10069
|
if (!privateKey) {
|
10000
|
-
throw new
|
10001
|
-
|
10070
|
+
throw new import_errors26.FuelError(
|
10071
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10002
10072
|
"Cannot derive a hardened index without a private Key."
|
10003
10073
|
);
|
10004
10074
|
}
|
@@ -10050,8 +10120,8 @@ var HDWallet = class {
|
|
10050
10120
|
*/
|
10051
10121
|
toExtendedKey(isPublic = false, testnet = false) {
|
10052
10122
|
if (this.depth >= 256) {
|
10053
|
-
throw new
|
10054
|
-
|
10123
|
+
throw new import_errors26.FuelError(
|
10124
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10055
10125
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10056
10126
|
);
|
10057
10127
|
}
|
@@ -10082,10 +10152,10 @@ var HDWallet = class {
|
|
10082
10152
|
const bytes = (0, import_utils43.arrayify)(decoded);
|
10083
10153
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10084
10154
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10085
|
-
throw new
|
10155
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10086
10156
|
}
|
10087
10157
|
if (!validChecksum) {
|
10088
|
-
throw new
|
10158
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10089
10159
|
}
|
10090
10160
|
const depth = bytes[4];
|
10091
10161
|
const parentFingerprint = (0, import_utils43.hexlify)(bytes.slice(5, 9));
|
@@ -10093,14 +10163,14 @@ var HDWallet = class {
|
|
10093
10163
|
const chainCode = (0, import_utils43.hexlify)(bytes.slice(13, 45));
|
10094
10164
|
const key = bytes.slice(45, 78);
|
10095
10165
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10096
|
-
throw new
|
10097
|
-
|
10166
|
+
throw new import_errors26.FuelError(
|
10167
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10098
10168
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10099
10169
|
);
|
10100
10170
|
}
|
10101
10171
|
if (isPublicExtendedKey(bytes)) {
|
10102
10172
|
if (key[0] !== 3) {
|
10103
|
-
throw new
|
10173
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
10104
10174
|
}
|
10105
10175
|
return new HDWallet({
|
10106
10176
|
publicKey: key,
|
@@ -10111,7 +10181,7 @@ var HDWallet = class {
|
|
10111
10181
|
});
|
10112
10182
|
}
|
10113
10183
|
if (key[0] !== 0) {
|
10114
|
-
throw new
|
10184
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
10115
10185
|
}
|
10116
10186
|
return new HDWallet({
|
10117
10187
|
privateKey: key.slice(1),
|
@@ -10355,26 +10425,26 @@ var WalletsConfig = class {
|
|
10355
10425
|
amountPerCoin
|
10356
10426
|
}) {
|
10357
10427
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
10358
|
-
throw new
|
10359
|
-
|
10428
|
+
throw new import_errors27.FuelError(
|
10429
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10360
10430
|
"Number of wallets must be greater than zero."
|
10361
10431
|
);
|
10362
10432
|
}
|
10363
10433
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
10364
|
-
throw new
|
10365
|
-
|
10434
|
+
throw new import_errors27.FuelError(
|
10435
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10366
10436
|
"Number of assets per wallet must be greater than zero."
|
10367
10437
|
);
|
10368
10438
|
}
|
10369
10439
|
if (coinsPerAsset <= 0) {
|
10370
|
-
throw new
|
10371
|
-
|
10440
|
+
throw new import_errors27.FuelError(
|
10441
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10372
10442
|
"Number of coins per asset must be greater than zero."
|
10373
10443
|
);
|
10374
10444
|
}
|
10375
10445
|
if (amountPerCoin < 0) {
|
10376
|
-
throw new
|
10377
|
-
|
10446
|
+
throw new import_errors27.FuelError(
|
10447
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10378
10448
|
"Amount per coin must be greater than or equal to zero."
|
10379
10449
|
);
|
10380
10450
|
}
|
@@ -10397,7 +10467,7 @@ async function setupTestProviderAndWallets({
|
|
10397
10467
|
} = {}) {
|
10398
10468
|
Symbol.dispose ??= Symbol("Symbol.dispose");
|
10399
10469
|
const walletsConfig = new WalletsConfig(
|
10400
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.
|
10470
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V2?.base_asset_id ?? import_utils45.defaultSnapshotConfigs.chainConfig.consensus_parameters.V2.base_asset_id,
|
10401
10471
|
{
|
10402
10472
|
...defaultWalletConfigOptions,
|
10403
10473
|
...walletsConfigOptions
|
@@ -10427,7 +10497,8 @@ async function setupTestProviderAndWallets({
|
|
10427
10497
|
}
|
10428
10498
|
let provider;
|
10429
10499
|
try {
|
10430
|
-
provider =
|
10500
|
+
provider = new Provider(url, providerOptions);
|
10501
|
+
await provider.init();
|
10431
10502
|
} catch (err) {
|
10432
10503
|
cleanup();
|
10433
10504
|
throw err;
|