@fuel-ts/account 0.97.2 → 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 +2922 -1249
- 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 +2 -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-message.d.ts +6 -6
- package/dist/test-utils/test-message.d.ts.map +1 -1
- package/dist/test-utils.global.js +2908 -1240
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +258 -219
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +287 -248
- 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 +28 -29
package/dist/test-utils.js
CHANGED
@@ -258,7 +258,8 @@ var launchNode = async ({
|
|
258
258
|
loggingEnabled = true,
|
259
259
|
basePath,
|
260
260
|
snapshotConfig = import_utils2.defaultSnapshotConfigs,
|
261
|
-
includeInitialState = false
|
261
|
+
includeInitialState = false,
|
262
|
+
killProcessOnExit = false
|
262
263
|
} = {}) => (
|
263
264
|
// eslint-disable-next-line no-async-promise-executor
|
264
265
|
new Promise(async (resolve, reject) => {
|
@@ -335,14 +336,14 @@ var launchNode = async ({
|
|
335
336
|
console.log(chunk.toString());
|
336
337
|
});
|
337
338
|
}
|
338
|
-
const
|
339
|
+
const removeChildListeners = () => {
|
339
340
|
child.stderr.removeAllListeners();
|
341
|
+
};
|
342
|
+
const removeTempDir = () => {
|
340
343
|
if ((0, import_fs.existsSync)(tempDir)) {
|
341
344
|
(0, import_fs.rmSync)(tempDir, { recursive: true });
|
342
345
|
}
|
343
346
|
};
|
344
|
-
child.on("error", removeSideffects);
|
345
|
-
child.on("exit", removeSideffects);
|
346
347
|
const childState = {
|
347
348
|
isDead: false
|
348
349
|
};
|
@@ -351,7 +352,7 @@ var launchNode = async ({
|
|
351
352
|
return;
|
352
353
|
}
|
353
354
|
childState.isDead = true;
|
354
|
-
|
355
|
+
removeChildListeners();
|
355
356
|
if (child.pid !== void 0) {
|
356
357
|
try {
|
357
358
|
process.kill(-child.pid);
|
@@ -370,6 +371,7 @@ var launchNode = async ({
|
|
370
371
|
} else {
|
371
372
|
console.error("No PID available for the child process, unable to kill launched node");
|
372
373
|
}
|
374
|
+
removeTempDir();
|
373
375
|
};
|
374
376
|
child.stderr.on("data", (chunk) => {
|
375
377
|
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
@@ -398,7 +400,18 @@ var launchNode = async ({
|
|
398
400
|
process.on("SIGUSR2", cleanup);
|
399
401
|
process.on("beforeExit", cleanup);
|
400
402
|
process.on("uncaughtException", cleanup);
|
401
|
-
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
|
+
});
|
402
415
|
})
|
403
416
|
);
|
404
417
|
|
@@ -443,7 +456,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
443
456
|
|
444
457
|
// src/providers/provider.ts
|
445
458
|
var import_address4 = require("@fuel-ts/address");
|
446
|
-
var
|
459
|
+
var import_errors20 = require("@fuel-ts/errors");
|
447
460
|
var import_math19 = require("@fuel-ts/math");
|
448
461
|
var import_transactions22 = require("@fuel-ts/transactions");
|
449
462
|
var import_utils30 = require("@fuel-ts/utils");
|
@@ -1314,13 +1327,6 @@ var GetConsensusParametersVersionDocument = import_graphql_tag.default`
|
|
1314
1327
|
}
|
1315
1328
|
}
|
1316
1329
|
`;
|
1317
|
-
var SubmitAndAwaitDocument = import_graphql_tag.default`
|
1318
|
-
subscription submitAndAwait($encodedTransaction: HexString!) {
|
1319
|
-
submitAndAwait(tx: $encodedTransaction) {
|
1320
|
-
...transactionStatusSubscriptionFragment
|
1321
|
-
}
|
1322
|
-
}
|
1323
|
-
${TransactionStatusSubscriptionFragmentDoc}`;
|
1324
1330
|
var SubmitAndAwaitStatusDocument = import_graphql_tag.default`
|
1325
1331
|
subscription submitAndAwaitStatus($encodedTransaction: HexString!) {
|
1326
1332
|
submitAndAwaitStatus(tx: $encodedTransaction) {
|
@@ -1436,9 +1442,6 @@ function getSdk(requester) {
|
|
1436
1442
|
getConsensusParametersVersion(variables, options) {
|
1437
1443
|
return requester(GetConsensusParametersVersionDocument, variables, options);
|
1438
1444
|
},
|
1439
|
-
submitAndAwait(variables, options) {
|
1440
|
-
return requester(SubmitAndAwaitDocument, variables, options);
|
1441
|
-
},
|
1442
1445
|
submitAndAwaitStatus(variables, options) {
|
1443
1446
|
return requester(SubmitAndAwaitStatusDocument, variables, options);
|
1444
1447
|
},
|
@@ -1722,7 +1725,7 @@ var import_abi_coder3 = require("@fuel-ts/abi-coder");
|
|
1722
1725
|
var import_address2 = require("@fuel-ts/address");
|
1723
1726
|
var import_configs6 = require("@fuel-ts/address/configs");
|
1724
1727
|
var import_crypto3 = require("@fuel-ts/crypto");
|
1725
|
-
var
|
1728
|
+
var import_errors10 = require("@fuel-ts/errors");
|
1726
1729
|
var import_math9 = require("@fuel-ts/math");
|
1727
1730
|
var import_transactions7 = require("@fuel-ts/transactions");
|
1728
1731
|
var import_utils11 = require("@fuel-ts/utils");
|
@@ -1766,7 +1769,6 @@ function assembleReceiptByType(receipt) {
|
|
1766
1769
|
const callReceipt = {
|
1767
1770
|
type: import_transactions3.ReceiptType.Call,
|
1768
1771
|
id,
|
1769
|
-
from: id,
|
1770
1772
|
to: hexOrZero(receipt?.to),
|
1771
1773
|
amount: (0, import_math5.bn)(receipt.amount),
|
1772
1774
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1834,10 +1836,6 @@ function assembleReceiptByType(receipt) {
|
|
1834
1836
|
rb,
|
1835
1837
|
rc,
|
1836
1838
|
rd,
|
1837
|
-
val0: ra,
|
1838
|
-
val1: rb,
|
1839
|
-
val2: rc,
|
1840
|
-
val3: rd,
|
1841
1839
|
pc: (0, import_math5.bn)(receipt.pc),
|
1842
1840
|
is: (0, import_math5.bn)(receipt.is)
|
1843
1841
|
};
|
@@ -1851,8 +1849,6 @@ function assembleReceiptByType(receipt) {
|
|
1851
1849
|
id: hexOrZero(receipt.id || receipt.contractId),
|
1852
1850
|
ra,
|
1853
1851
|
rb,
|
1854
|
-
val0: ra,
|
1855
|
-
val1: rb,
|
1856
1852
|
ptr: (0, import_math5.bn)(receipt.ptr),
|
1857
1853
|
len: (0, import_math5.bn)(receipt.len),
|
1858
1854
|
digest: hexOrZero(receipt.digest),
|
@@ -1867,7 +1863,6 @@ function assembleReceiptByType(receipt) {
|
|
1867
1863
|
const transferReceipt = {
|
1868
1864
|
type: import_transactions3.ReceiptType.Transfer,
|
1869
1865
|
id,
|
1870
|
-
from: id,
|
1871
1866
|
to: hexOrZero(receipt.toAddress || receipt?.to),
|
1872
1867
|
amount: (0, import_math5.bn)(receipt.amount),
|
1873
1868
|
assetId: hexOrZero(receipt.assetId),
|
@@ -1881,7 +1876,6 @@ function assembleReceiptByType(receipt) {
|
|
1881
1876
|
const transferOutReceipt = {
|
1882
1877
|
type: import_transactions3.ReceiptType.TransferOut,
|
1883
1878
|
id,
|
1884
|
-
from: id,
|
1885
1879
|
to: hexOrZero(receipt.toAddress || receipt.to),
|
1886
1880
|
amount: (0, import_math5.bn)(receipt.amount),
|
1887
1881
|
assetId: hexOrZero(receipt.assetId),
|
@@ -2231,6 +2225,7 @@ var NoWitnessAtIndexError = class extends Error {
|
|
2231
2225
|
};
|
2232
2226
|
|
2233
2227
|
// src/providers/transaction-request/helpers.ts
|
2228
|
+
var import_errors9 = require("@fuel-ts/errors");
|
2234
2229
|
var import_math8 = require("@fuel-ts/math");
|
2235
2230
|
var import_transactions6 = require("@fuel-ts/transactions");
|
2236
2231
|
var isRequestInputCoin = (input) => input.type === import_transactions6.InputType.Coin;
|
@@ -2263,6 +2258,32 @@ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
|
|
2263
2258
|
messages: []
|
2264
2259
|
}
|
2265
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
|
+
};
|
2266
2287
|
|
2267
2288
|
// src/providers/transaction-request/witness.ts
|
2268
2289
|
var import_utils10 = require("@fuel-ts/utils");
|
@@ -2646,7 +2667,7 @@ var BaseTransactionRequest = class {
|
|
2646
2667
|
* @hidden
|
2647
2668
|
*/
|
2648
2669
|
metadataGas(_gasCosts) {
|
2649
|
-
throw new
|
2670
|
+
throw new import_errors10.FuelError(import_errors10.FuelError.CODES.NOT_IMPLEMENTED, "Not implemented");
|
2650
2671
|
}
|
2651
2672
|
/**
|
2652
2673
|
* @hidden
|
@@ -3086,6 +3107,20 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3086
3107
|
this.scriptData = (0, import_utils18.arrayify)(scriptData ?? returnZeroScript.encodeScriptData());
|
3087
3108
|
this.abis = rest.abis;
|
3088
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
|
+
}
|
3089
3124
|
/**
|
3090
3125
|
* Converts the transaction request to a `TransactionScript`.
|
3091
3126
|
*
|
@@ -3240,7 +3275,7 @@ var ScriptTransactionRequest = class extends BaseTransactionRequest {
|
|
3240
3275
|
};
|
3241
3276
|
|
3242
3277
|
// src/providers/transaction-request/upgrade-transaction-request.ts
|
3243
|
-
var
|
3278
|
+
var import_errors12 = require("@fuel-ts/errors");
|
3244
3279
|
var import_hasher3 = require("@fuel-ts/hasher");
|
3245
3280
|
var import_transactions11 = require("@fuel-ts/transactions");
|
3246
3281
|
var import_utils19 = require("@fuel-ts/utils");
|
@@ -3344,7 +3379,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3344
3379
|
}
|
3345
3380
|
};
|
3346
3381
|
} else {
|
3347
|
-
throw new
|
3382
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3348
3383
|
}
|
3349
3384
|
return {
|
3350
3385
|
type: import_transactions11.TransactionType.Upgrade,
|
@@ -3386,7 +3421,7 @@ var UpgradeTransactionRequest = class extends BaseTransactionRequest {
|
|
3386
3421
|
txBytesSize
|
3387
3422
|
});
|
3388
3423
|
}
|
3389
|
-
throw new
|
3424
|
+
throw new import_errors12.FuelError(import_errors12.FuelError.CODES.NOT_IMPLEMENTED, "Invalid upgrade purpose");
|
3390
3425
|
}
|
3391
3426
|
};
|
3392
3427
|
|
@@ -3497,7 +3532,7 @@ var UploadTransactionRequest = class extends BaseTransactionRequest {
|
|
3497
3532
|
};
|
3498
3533
|
|
3499
3534
|
// src/providers/transaction-request/utils.ts
|
3500
|
-
var
|
3535
|
+
var import_errors13 = require("@fuel-ts/errors");
|
3501
3536
|
var import_transactions13 = require("@fuel-ts/transactions");
|
3502
3537
|
var transactionRequestify = (obj) => {
|
3503
3538
|
if (obj instanceof ScriptTransactionRequest || obj instanceof CreateTransactionRequest || obj instanceof BlobTransactionRequest || obj instanceof UpgradeTransactionRequest || obj instanceof UploadTransactionRequest) {
|
@@ -3521,8 +3556,8 @@ var transactionRequestify = (obj) => {
|
|
3521
3556
|
return UploadTransactionRequest.from(obj);
|
3522
3557
|
}
|
3523
3558
|
default: {
|
3524
|
-
throw new
|
3525
|
-
|
3559
|
+
throw new import_errors13.FuelError(
|
3560
|
+
import_errors13.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3526
3561
|
`Unsupported transaction type: ${type}.`
|
3527
3562
|
);
|
3528
3563
|
}
|
@@ -3532,7 +3567,7 @@ var isTransactionTypeScript = (request) => request.type === import_transactions1
|
|
3532
3567
|
var isTransactionTypeCreate = (request) => request.type === import_transactions13.TransactionType.Create;
|
3533
3568
|
|
3534
3569
|
// src/providers/transaction-response/transaction-response.ts
|
3535
|
-
var
|
3570
|
+
var import_errors17 = require("@fuel-ts/errors");
|
3536
3571
|
var import_math18 = require("@fuel-ts/math");
|
3537
3572
|
var import_transactions21 = require("@fuel-ts/transactions");
|
3538
3573
|
var import_utils27 = require("@fuel-ts/utils");
|
@@ -3551,12 +3586,8 @@ var calculateTXFeeForSummary = (params) => {
|
|
3551
3586
|
gasPrice,
|
3552
3587
|
rawPayload,
|
3553
3588
|
tip,
|
3554
|
-
totalFee,
|
3555
3589
|
consensusParameters: { gasCosts, feeParams, maxGasPerTx }
|
3556
3590
|
} = params;
|
3557
|
-
if (totalFee) {
|
3558
|
-
return totalFee;
|
3559
|
-
}
|
3560
3591
|
const gasPerByte = (0, import_math13.bn)(feeParams.gasPerByte);
|
3561
3592
|
const gasPriceFactor = (0, import_math13.bn)(feeParams.gasPriceFactor);
|
3562
3593
|
const transactionBytes = (0, import_utils23.arrayify)(rawPayload);
|
@@ -3614,7 +3645,7 @@ var calculateTXFeeForSummary = (params) => {
|
|
3614
3645
|
|
3615
3646
|
// src/providers/transaction-summary/operations.ts
|
3616
3647
|
var import_configs11 = require("@fuel-ts/address/configs");
|
3617
|
-
var
|
3648
|
+
var import_errors15 = require("@fuel-ts/errors");
|
3618
3649
|
var import_math15 = require("@fuel-ts/math");
|
3619
3650
|
var import_transactions17 = require("@fuel-ts/transactions");
|
3620
3651
|
|
@@ -3652,7 +3683,7 @@ var getFunctionCall = ({ abi, receipt }) => {
|
|
3652
3683
|
};
|
3653
3684
|
|
3654
3685
|
// src/providers/transaction-summary/input.ts
|
3655
|
-
var
|
3686
|
+
var import_errors14 = require("@fuel-ts/errors");
|
3656
3687
|
var import_math14 = require("@fuel-ts/math");
|
3657
3688
|
var import_transactions15 = require("@fuel-ts/transactions");
|
3658
3689
|
function getInputsByTypes(inputs, types) {
|
@@ -3680,10 +3711,10 @@ function findCoinInput(inputs, assetId) {
|
|
3680
3711
|
const coinInputs = getInputsCoin(inputs);
|
3681
3712
|
return coinInputs.find((i) => i.assetId === assetId);
|
3682
3713
|
}
|
3683
|
-
function aggregateInputsAmountsByAssetAndOwner(inputs,
|
3714
|
+
function aggregateInputsAmountsByAssetAndOwner(inputs, baseAssetId) {
|
3684
3715
|
const aggregated = /* @__PURE__ */ new Map();
|
3685
3716
|
getInputsCoinAndMessage(inputs).forEach((input) => {
|
3686
|
-
const assetId = isInputCoin(input) ? input.assetId :
|
3717
|
+
const assetId = isInputCoin(input) ? input.assetId : baseAssetId;
|
3687
3718
|
const owner = isInputCoin(input) ? input.owner : input.recipient;
|
3688
3719
|
let ownersMap = aggregated.get(assetId);
|
3689
3720
|
if (!ownersMap) {
|
@@ -3721,8 +3752,8 @@ function getInputContractFromIndex(inputs, inputIndex) {
|
|
3721
3752
|
return void 0;
|
3722
3753
|
}
|
3723
3754
|
if (contractInput.type !== import_transactions15.InputType.Contract) {
|
3724
|
-
throw new
|
3725
|
-
|
3755
|
+
throw new import_errors14.FuelError(
|
3756
|
+
import_errors14.ErrorCode.INVALID_TRANSACTION_INPUT,
|
3726
3757
|
`Contract input should be of type 'contract'.`
|
3727
3758
|
);
|
3728
3759
|
}
|
@@ -3775,8 +3806,8 @@ function getTransactionTypeName(transactionType) {
|
|
3775
3806
|
case import_transactions17.TransactionType.Upload:
|
3776
3807
|
return "Upload" /* Upload */;
|
3777
3808
|
default:
|
3778
|
-
throw new
|
3779
|
-
|
3809
|
+
throw new import_errors15.FuelError(
|
3810
|
+
import_errors15.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE,
|
3780
3811
|
`Unsupported transaction type: ${transactionType}.`
|
3781
3812
|
);
|
3782
3813
|
}
|
@@ -3969,7 +4000,7 @@ function getContractCallOperations({
|
|
3969
4000
|
}
|
3970
4001
|
function extractTransferOperationFromReceipt(receipt, contractInputs, changeOutputs) {
|
3971
4002
|
const { to: toAddress, assetId, amount } = receipt;
|
3972
|
-
let {
|
4003
|
+
let { id: fromAddress } = receipt;
|
3973
4004
|
const toType = contractInputs.some((input) => input.contractID === toAddress) ? 0 /* contract */ : 1 /* account */;
|
3974
4005
|
if (import_configs11.ZeroBytes32 === fromAddress) {
|
3975
4006
|
const change = changeOutputs.find((output) => output.assetId === assetId);
|
@@ -4156,7 +4187,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
4156
4187
|
};
|
4157
4188
|
|
4158
4189
|
// src/providers/transaction-summary/status.ts
|
4159
|
-
var
|
4190
|
+
var import_errors16 = require("@fuel-ts/errors");
|
4160
4191
|
var import_math16 = require("@fuel-ts/math");
|
4161
4192
|
var getTransactionStatusName = (gqlStatus) => {
|
4162
4193
|
switch (gqlStatus) {
|
@@ -4169,8 +4200,8 @@ var getTransactionStatusName = (gqlStatus) => {
|
|
4169
4200
|
case "SqueezedOutStatus":
|
4170
4201
|
return "squeezedout" /* squeezedout */;
|
4171
4202
|
default:
|
4172
|
-
throw new
|
4173
|
-
|
4203
|
+
throw new import_errors16.FuelError(
|
4204
|
+
import_errors16.ErrorCode.INVALID_TRANSACTION_STATUS,
|
4174
4205
|
`Invalid transaction status: ${gqlStatus}.`
|
4175
4206
|
);
|
4176
4207
|
}
|
@@ -4220,6 +4251,7 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
4220
4251
|
};
|
4221
4252
|
return processedGraphqlStatus;
|
4222
4253
|
};
|
4254
|
+
var getTotalFeeFromStatus = (status) => status && "totalFee" in status ? (0, import_math16.bn)(status.totalFee) : void 0;
|
4223
4255
|
|
4224
4256
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
4225
4257
|
function assembleTransactionSummary(params) {
|
@@ -4253,8 +4285,7 @@ function assembleTransactionSummary(params) {
|
|
4253
4285
|
const typeName = getTransactionTypeName(transaction.type);
|
4254
4286
|
const tip = (0, import_math17.bn)(transaction.policies?.find((policy) => policy.type === import_transactions19.PolicyType.Tip)?.data);
|
4255
4287
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
4256
|
-
const fee = calculateTXFeeForSummary({
|
4257
|
-
totalFee,
|
4288
|
+
const fee = totalFee ?? calculateTXFeeForSummary({
|
4258
4289
|
gasPrice,
|
4259
4290
|
rawPayload,
|
4260
4291
|
tip,
|
@@ -4308,8 +4339,8 @@ function getDecodedLogs(receipts, mainAbi, externalAbis = {}) {
|
|
4308
4339
|
return receipts.reduce((logs, receipt) => {
|
4309
4340
|
if (receipt.type === import_transactions20.ReceiptType.LogData || receipt.type === import_transactions20.ReceiptType.Log) {
|
4310
4341
|
const interfaceToUse = new import_abi_coder6.Interface(externalAbis[receipt.id] || mainAbi);
|
4311
|
-
const data = receipt.type === import_transactions20.ReceiptType.Log ? new import_abi_coder6.BigNumberCoder("u64").encode(receipt.
|
4312
|
-
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());
|
4313
4344
|
logs.push(decodedLog);
|
4314
4345
|
}
|
4315
4346
|
return logs;
|
@@ -4354,9 +4385,9 @@ var TransactionResponse = class {
|
|
4354
4385
|
* @param tx - The transaction ID or TransactionRequest.
|
4355
4386
|
* @param provider - The provider.
|
4356
4387
|
*/
|
4357
|
-
constructor(tx, provider, abis, submitTxSubscription) {
|
4388
|
+
constructor(tx, provider, chainId, abis, submitTxSubscription) {
|
4358
4389
|
this.submitTxSubscription = submitTxSubscription;
|
4359
|
-
this.id = typeof tx === "string" ? tx : tx.getTransactionId(
|
4390
|
+
this.id = typeof tx === "string" ? tx : tx.getTransactionId(chainId);
|
4360
4391
|
this.provider = provider;
|
4361
4392
|
this.abis = abis;
|
4362
4393
|
this.request = typeof tx === "string" ? void 0 : tx;
|
@@ -4381,7 +4412,8 @@ var TransactionResponse = class {
|
|
4381
4412
|
* @param provider - The provider.
|
4382
4413
|
*/
|
4383
4414
|
static async create(id, provider, abis) {
|
4384
|
-
const
|
4415
|
+
const chainId = await provider.getChainId();
|
4416
|
+
const response = new TransactionResponse(id, provider, chainId, abis);
|
4385
4417
|
await response.fetch();
|
4386
4418
|
return response;
|
4387
4419
|
}
|
@@ -4478,10 +4510,11 @@ var TransactionResponse = class {
|
|
4478
4510
|
*/
|
4479
4511
|
async getTransactionSummary(contractsAbiMap) {
|
4480
4512
|
const { tx: transaction, bytes: transactionBytes } = await this.getTransaction();
|
4481
|
-
const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
|
4482
|
-
const
|
4483
|
-
const
|
4484
|
-
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();
|
4485
4518
|
const transactionSummary = assembleTransactionSummary({
|
4486
4519
|
id: this.id,
|
4487
4520
|
receipts: this.getReceipts(),
|
@@ -4512,8 +4545,8 @@ var TransactionResponse = class {
|
|
4512
4545
|
this.status = statusChange;
|
4513
4546
|
if (statusChange.type === "SqueezedOutStatus") {
|
4514
4547
|
this.unsetResourceCache();
|
4515
|
-
throw new
|
4516
|
-
|
4548
|
+
throw new import_errors17.FuelError(
|
4549
|
+
import_errors17.ErrorCode.TRANSACTION_SQUEEZED_OUT,
|
4517
4550
|
`Transaction Squeezed Out with reason: ${statusChange.reason}`
|
4518
4551
|
);
|
4519
4552
|
}
|
@@ -4621,54 +4654,54 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
|
|
4621
4654
|
}
|
4622
4655
|
|
4623
4656
|
// src/providers/utils/handle-gql-error-message.ts
|
4624
|
-
var
|
4657
|
+
var import_errors18 = require("@fuel-ts/errors");
|
4625
4658
|
var handleGqlErrorMessage = (errorMessage, rawError) => {
|
4626
4659
|
switch (errorMessage) {
|
4627
4660
|
case "not enough coins to fit the target" /* NOT_ENOUGH_COINS */:
|
4628
|
-
throw new
|
4629
|
-
|
4661
|
+
throw new import_errors18.FuelError(
|
4662
|
+
import_errors18.ErrorCode.NOT_ENOUGH_FUNDS,
|
4630
4663
|
`The account(s) sending the transaction don't have enough funds to cover the transaction.`,
|
4631
4664
|
{},
|
4632
4665
|
rawError
|
4633
4666
|
);
|
4634
4667
|
case "max number of coins is reached while trying to fit the target" /* MAX_COINS_REACHED */:
|
4635
|
-
throw new
|
4636
|
-
|
4668
|
+
throw new import_errors18.FuelError(
|
4669
|
+
import_errors18.ErrorCode.MAX_COINS_REACHED,
|
4637
4670
|
"The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.",
|
4638
4671
|
{},
|
4639
4672
|
rawError
|
4640
4673
|
);
|
4641
4674
|
default:
|
4642
|
-
throw new
|
4675
|
+
throw new import_errors18.FuelError(import_errors18.ErrorCode.INVALID_REQUEST, errorMessage);
|
4643
4676
|
}
|
4644
4677
|
};
|
4645
4678
|
|
4646
4679
|
// src/providers/utils/validate-pagination-args.ts
|
4647
|
-
var
|
4680
|
+
var import_errors19 = require("@fuel-ts/errors");
|
4648
4681
|
var validatePaginationArgs = (params) => {
|
4649
4682
|
const { paginationLimit, inputArgs = {} } = params;
|
4650
4683
|
const { first, last, after, before } = inputArgs;
|
4651
4684
|
if (after && before) {
|
4652
|
-
throw new
|
4653
|
-
|
4685
|
+
throw new import_errors19.FuelError(
|
4686
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4654
4687
|
'Pagination arguments "after" and "before" cannot be used together'
|
4655
4688
|
);
|
4656
4689
|
}
|
4657
4690
|
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) {
|
4658
|
-
throw new
|
4659
|
-
|
4691
|
+
throw new import_errors19.FuelError(
|
4692
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4660
4693
|
`Pagination limit for this query cannot exceed ${paginationLimit} items`
|
4661
4694
|
);
|
4662
4695
|
}
|
4663
4696
|
if (first && before) {
|
4664
|
-
throw new
|
4665
|
-
|
4697
|
+
throw new import_errors19.FuelError(
|
4698
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4666
4699
|
'The use of pagination argument "first" with "before" is not supported'
|
4667
4700
|
);
|
4668
4701
|
}
|
4669
4702
|
if (last && after) {
|
4670
|
-
throw new
|
4671
|
-
|
4703
|
+
throw new import_errors19.FuelError(
|
4704
|
+
import_errors19.ErrorCode.INVALID_INPUT_PARAMETERS,
|
4672
4705
|
'The use of pagination argument "last" with "after" is not supported'
|
4673
4706
|
);
|
4674
4707
|
}
|
@@ -4822,7 +4855,7 @@ var _Provider = class {
|
|
4822
4855
|
try {
|
4823
4856
|
parsedUrl = new URL(url);
|
4824
4857
|
} catch (error) {
|
4825
|
-
throw new
|
4858
|
+
throw new import_errors20.FuelError(import_errors20.FuelError.CODES.INVALID_URL, "Invalid URL provided.", { url }, error);
|
4826
4859
|
}
|
4827
4860
|
const username = parsedUrl.username;
|
4828
4861
|
const password = parsedUrl.password;
|
@@ -4837,58 +4870,40 @@ var _Provider = class {
|
|
4837
4870
|
};
|
4838
4871
|
}
|
4839
4872
|
/**
|
4840
|
-
*
|
4841
|
-
*
|
4842
|
-
* @param url - GraphQL endpoint of the Fuel node
|
4843
|
-
* @param options - Additional options for the provider
|
4844
|
-
*
|
4845
|
-
* @returns A promise that resolves to a Provider instance.
|
4873
|
+
* Initialize Provider async stuff
|
4846
4874
|
*/
|
4847
|
-
|
4848
|
-
|
4849
|
-
|
4850
|
-
return provider;
|
4875
|
+
async init() {
|
4876
|
+
await this.fetchChainAndNodeInfo();
|
4877
|
+
return this;
|
4851
4878
|
}
|
4852
4879
|
/**
|
4853
|
-
* Returns the
|
4880
|
+
* Returns the `chainInfo` for the current network.
|
4854
4881
|
*
|
4855
4882
|
* @returns the chain information configuration.
|
4856
4883
|
*/
|
4857
|
-
getChain() {
|
4858
|
-
|
4859
|
-
|
4860
|
-
throw new import_errors19.FuelError(
|
4861
|
-
import_errors19.ErrorCode.CHAIN_INFO_CACHE_EMPTY,
|
4862
|
-
"Chain info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4863
|
-
);
|
4864
|
-
}
|
4865
|
-
return chain;
|
4884
|
+
async getChain() {
|
4885
|
+
await this.init();
|
4886
|
+
return _Provider.chainInfoCache[this.urlWithoutAuth];
|
4866
4887
|
}
|
4867
4888
|
/**
|
4868
|
-
* Returns the
|
4889
|
+
* Returns the `nodeInfo` for the current network.
|
4869
4890
|
*
|
4870
4891
|
* @returns the node information configuration.
|
4871
4892
|
*/
|
4872
|
-
getNode() {
|
4873
|
-
|
4874
|
-
|
4875
|
-
throw new import_errors19.FuelError(
|
4876
|
-
import_errors19.ErrorCode.NODE_INFO_CACHE_EMPTY,
|
4877
|
-
"Node info cache is empty. Make sure you have called `Provider.create` to initialize the provider."
|
4878
|
-
);
|
4879
|
-
}
|
4880
|
-
return node;
|
4893
|
+
async getNode() {
|
4894
|
+
await this.init();
|
4895
|
+
return _Provider.nodeInfoCache[this.urlWithoutAuth];
|
4881
4896
|
}
|
4882
4897
|
/**
|
4883
4898
|
* Returns some helpful parameters related to gas fees.
|
4884
4899
|
*/
|
4885
|
-
getGasConfig() {
|
4900
|
+
async getGasConfig() {
|
4886
4901
|
const {
|
4887
4902
|
txParameters: { maxGasPerTx },
|
4888
4903
|
predicateParameters: { maxGasPerPredicate },
|
4889
4904
|
feeParameters: { gasPriceFactor, gasPerByte },
|
4890
4905
|
gasCosts
|
4891
|
-
} = this.getChain().consensusParameters;
|
4906
|
+
} = (await this.getChain()).consensusParameters;
|
4892
4907
|
return {
|
4893
4908
|
maxGasPerTx,
|
4894
4909
|
maxGasPerPredicate,
|
@@ -4910,7 +4925,7 @@ var _Provider = class {
|
|
4910
4925
|
this.options = options ?? this.options;
|
4911
4926
|
this.options = { ...this.options, headers: { ...this.options.headers, ...headers } };
|
4912
4927
|
this.operations = this.createOperations();
|
4913
|
-
await this.
|
4928
|
+
await this.init();
|
4914
4929
|
}
|
4915
4930
|
/**
|
4916
4931
|
* Return the chain and node information.
|
@@ -4921,11 +4936,12 @@ var _Provider = class {
|
|
4921
4936
|
let nodeInfo;
|
4922
4937
|
let chain;
|
4923
4938
|
try {
|
4924
|
-
|
4925
|
-
|
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`);
|
4926
4944
|
}
|
4927
|
-
nodeInfo = this.getNode();
|
4928
|
-
chain = this.getChain();
|
4929
4945
|
} catch (_err) {
|
4930
4946
|
const data = await this.operations.getChainAndNodeInfo();
|
4931
4947
|
nodeInfo = {
|
@@ -5072,10 +5088,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5072
5088
|
*
|
5073
5089
|
* @returns A promise that resolves to the chain ID number.
|
5074
5090
|
*/
|
5075
|
-
getChainId() {
|
5091
|
+
async getChainId() {
|
5076
5092
|
const {
|
5077
5093
|
consensusParameters: { chainId }
|
5078
|
-
} = this.getChain();
|
5094
|
+
} = await this.getChain();
|
5079
5095
|
return chainId.toNumber();
|
5080
5096
|
}
|
5081
5097
|
/**
|
@@ -5083,30 +5099,31 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5083
5099
|
*
|
5084
5100
|
* @returns the base asset ID.
|
5085
5101
|
*/
|
5086
|
-
getBaseAssetId() {
|
5102
|
+
async getBaseAssetId() {
|
5103
|
+
const all = await this.getChain();
|
5087
5104
|
const {
|
5088
5105
|
consensusParameters: { baseAssetId }
|
5089
|
-
} =
|
5106
|
+
} = all;
|
5090
5107
|
return baseAssetId;
|
5091
5108
|
}
|
5092
5109
|
/**
|
5093
5110
|
* @hidden
|
5094
5111
|
*/
|
5095
|
-
validateTransaction(tx) {
|
5112
|
+
async validateTransaction(tx) {
|
5096
5113
|
const {
|
5097
5114
|
consensusParameters: {
|
5098
5115
|
txParameters: { maxInputs, maxOutputs }
|
5099
5116
|
}
|
5100
|
-
} = this.getChain();
|
5117
|
+
} = await this.getChain();
|
5101
5118
|
if ((0, import_math19.bn)(tx.inputs.length).gt(maxInputs)) {
|
5102
|
-
throw new
|
5103
|
-
|
5119
|
+
throw new import_errors20.FuelError(
|
5120
|
+
import_errors20.ErrorCode.MAX_INPUTS_EXCEEDED,
|
5104
5121
|
`The transaction exceeds the maximum allowed number of inputs. Tx inputs: ${tx.inputs.length}, max inputs: ${maxInputs}`
|
5105
5122
|
);
|
5106
5123
|
}
|
5107
5124
|
if ((0, import_math19.bn)(tx.outputs.length).gt(maxOutputs)) {
|
5108
|
-
throw new
|
5109
|
-
|
5125
|
+
throw new import_errors20.FuelError(
|
5126
|
+
import_errors20.ErrorCode.MAX_OUTPUTS_EXCEEDED,
|
5110
5127
|
`The transaction exceeds the maximum allowed number of outputs. Tx outputs: ${tx.outputs.length}, max outputs: ${maxOutputs}`
|
5111
5128
|
);
|
5112
5129
|
}
|
@@ -5121,20 +5138,26 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5121
5138
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
5122
5139
|
* @returns A promise that resolves to the transaction response object.
|
5123
5140
|
*/
|
5124
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
5141
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, enableAssetBurn } = {}) {
|
5125
5142
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
5143
|
+
validateTransactionForAssetBurn(
|
5144
|
+
await this.getBaseAssetId(),
|
5145
|
+
transactionRequest,
|
5146
|
+
enableAssetBurn
|
5147
|
+
);
|
5126
5148
|
if (estimateTxDependencies) {
|
5127
5149
|
await this.estimateTxDependencies(transactionRequest);
|
5128
5150
|
}
|
5129
|
-
this.validateTransaction(transactionRequest);
|
5151
|
+
await this.validateTransaction(transactionRequest);
|
5130
5152
|
const encodedTransaction = (0, import_utils30.hexlify)(transactionRequest.toTransactionBytes());
|
5131
5153
|
let abis;
|
5132
5154
|
if (isTransactionTypeScript(transactionRequest)) {
|
5133
5155
|
abis = transactionRequest.abis;
|
5134
5156
|
}
|
5135
5157
|
const subscription = await this.operations.submitAndAwaitStatus({ encodedTransaction });
|
5136
|
-
__privateMethod(this, _cacheInputs, cacheInputs_fn).call(this, transactionRequest.inputs, transactionRequest.getTransactionId(this.getChainId()));
|
5137
|
-
|
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);
|
5138
5161
|
}
|
5139
5162
|
/**
|
5140
5163
|
* Executes a transaction without actually submitting it to the chain.
|
@@ -5214,7 +5237,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5214
5237
|
const missingContractIds = [];
|
5215
5238
|
let outputVariables = 0;
|
5216
5239
|
let dryRunStatus;
|
5217
|
-
this.validateTransaction(transactionRequest);
|
5240
|
+
await this.validateTransaction(transactionRequest);
|
5218
5241
|
for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
|
5219
5242
|
const {
|
5220
5243
|
dryRun: [{ receipts: rawReceipts, status }]
|
@@ -5345,7 +5368,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5345
5368
|
if (diff < 6e4) {
|
5346
5369
|
return;
|
5347
5370
|
}
|
5348
|
-
|
5371
|
+
if (!_Provider.chainInfoCache?.[this.urlWithoutAuth]) {
|
5372
|
+
await this.fetchChainAndNodeInfo(true);
|
5373
|
+
return;
|
5374
|
+
}
|
5375
|
+
const chainInfo = _Provider.chainInfoCache[this.urlWithoutAuth];
|
5349
5376
|
const {
|
5350
5377
|
consensusParameters: { version: previous }
|
5351
5378
|
} = chainInfo;
|
@@ -5369,8 +5396,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5369
5396
|
const { transactionRequest } = params;
|
5370
5397
|
let { gasPrice } = params;
|
5371
5398
|
await this.autoRefetchConfigs();
|
5372
|
-
const chainInfo = this.getChain();
|
5373
|
-
const { gasPriceFactor, maxGasPerTx } = this.getGasConfig();
|
5399
|
+
const chainInfo = await this.getChain();
|
5400
|
+
const { gasPriceFactor, maxGasPerTx } = await this.getGasConfig();
|
5374
5401
|
const minGas = transactionRequest.calculateMinGas(chainInfo);
|
5375
5402
|
if (!(0, import_utils30.isDefined)(gasPrice)) {
|
5376
5403
|
gasPrice = await this.estimateGasPrice(10);
|
@@ -5482,7 +5509,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5482
5509
|
if (dryRunStatus && "reason" in dryRunStatus) {
|
5483
5510
|
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
|
5484
5511
|
}
|
5485
|
-
const { maxGasPerTx } = this.getGasConfig();
|
5512
|
+
const { maxGasPerTx } = await this.getGasConfig();
|
5486
5513
|
const pristineGasUsed = getGasUsedFromReceipts(receipts);
|
5487
5514
|
gasUsed = (0, import_math19.bn)(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
|
5488
5515
|
txRequestClone.gasLimit = gasUsed;
|
@@ -5739,7 +5766,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5739
5766
|
0
|
5740
5767
|
)?.[0];
|
5741
5768
|
} catch (error) {
|
5742
|
-
if (error instanceof
|
5769
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5743
5770
|
console.warn("Unsupported transaction type encountered");
|
5744
5771
|
return null;
|
5745
5772
|
}
|
@@ -5765,7 +5792,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5765
5792
|
try {
|
5766
5793
|
return coder.decode((0, import_utils30.arrayify)(rawPayload), 0)[0];
|
5767
5794
|
} catch (error) {
|
5768
|
-
if (error instanceof
|
5795
|
+
if (error instanceof import_errors20.FuelError && error.code === import_errors20.ErrorCode.UNSUPPORTED_TRANSACTION_TYPE) {
|
5769
5796
|
console.warn("Unsupported transaction type encountered");
|
5770
5797
|
return null;
|
5771
5798
|
}
|
@@ -5891,8 +5918,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
5891
5918
|
nonce
|
5892
5919
|
};
|
5893
5920
|
if (commitBlockId && commitBlockHeight) {
|
5894
|
-
throw new
|
5895
|
-
|
5921
|
+
throw new import_errors20.FuelError(
|
5922
|
+
import_errors20.ErrorCode.INVALID_INPUT_PARAMETERS,
|
5896
5923
|
"commitBlockId and commitBlockHeight cannot be used together"
|
5897
5924
|
);
|
5898
5925
|
}
|
@@ -6055,9 +6082,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
6055
6082
|
* @param transactionId - The transaction ID to get the response for.
|
6056
6083
|
* @returns A promise that resolves to the transaction response.
|
6057
6084
|
*/
|
6058
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
6059
6085
|
async getTransactionResponse(transactionId) {
|
6060
|
-
|
6086
|
+
const chainId = await this.getChainId();
|
6087
|
+
return new TransactionResponse(transactionId, this, chainId);
|
6061
6088
|
}
|
6062
6089
|
/**
|
6063
6090
|
* Returns Message for given nonce.
|
@@ -6147,7 +6174,7 @@ __publicField(Provider, "chainInfoCache", {});
|
|
6147
6174
|
__publicField(Provider, "nodeInfoCache", {});
|
6148
6175
|
|
6149
6176
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
6150
|
-
var
|
6177
|
+
var import_errors21 = require("@fuel-ts/errors");
|
6151
6178
|
var import_math20 = require("@fuel-ts/math");
|
6152
6179
|
var import_transactions23 = require("@fuel-ts/transactions");
|
6153
6180
|
var import_utils33 = require("@fuel-ts/utils");
|
@@ -6781,7 +6808,7 @@ __publicField(TestAssetId, "B", new _TestAssetId(
|
|
6781
6808
|
|
6782
6809
|
// src/test-utils/wallet-config.ts
|
6783
6810
|
var import_crypto9 = require("@fuel-ts/crypto");
|
6784
|
-
var
|
6811
|
+
var import_errors27 = require("@fuel-ts/errors");
|
6785
6812
|
var import_utils44 = require("@fuel-ts/utils");
|
6786
6813
|
|
6787
6814
|
// src/wallet/base-wallet-unlocked.ts
|
@@ -6792,8 +6819,7 @@ var import_utils39 = require("@fuel-ts/utils");
|
|
6792
6819
|
var import_abi_coder8 = require("@fuel-ts/abi-coder");
|
6793
6820
|
var import_address6 = require("@fuel-ts/address");
|
6794
6821
|
var import_crypto5 = require("@fuel-ts/crypto");
|
6795
|
-
var
|
6796
|
-
var import_interfaces = require("@fuel-ts/interfaces");
|
6822
|
+
var import_errors22 = require("@fuel-ts/errors");
|
6797
6823
|
var import_math21 = require("@fuel-ts/math");
|
6798
6824
|
var import_transactions24 = require("@fuel-ts/transactions");
|
6799
6825
|
var import_utils37 = require("@fuel-ts/utils");
|
@@ -6813,6 +6839,10 @@ var mergeQuantities = (...coinQuantities) => {
|
|
6813
6839
|
return Object.entries(resultMap).map(([assetId, amount]) => ({ assetId, amount }));
|
6814
6840
|
};
|
6815
6841
|
|
6842
|
+
// src/types.ts
|
6843
|
+
var AbstractAccount = class {
|
6844
|
+
};
|
6845
|
+
|
6816
6846
|
// src/utils/formatTransferToContractScriptData.ts
|
6817
6847
|
var import_abi_coder7 = require("@fuel-ts/abi-coder");
|
6818
6848
|
var import_address5 = require("@fuel-ts/address");
|
@@ -6859,7 +6889,7 @@ var assembleTransferToContractScript = async (transferParams) => {
|
|
6859
6889
|
|
6860
6890
|
// src/account.ts
|
6861
6891
|
var MAX_FUNDING_ATTEMPTS = 5;
|
6862
|
-
var Account = class extends
|
6892
|
+
var Account = class extends AbstractAccount {
|
6863
6893
|
/**
|
6864
6894
|
* The address associated with the account.
|
6865
6895
|
*/
|
@@ -6894,7 +6924,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6894
6924
|
*/
|
6895
6925
|
get provider() {
|
6896
6926
|
if (!this._provider) {
|
6897
|
-
throw new
|
6927
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_PROVIDER, "Provider not set");
|
6898
6928
|
}
|
6899
6929
|
return this._provider;
|
6900
6930
|
}
|
@@ -6950,7 +6980,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6950
6980
|
* @returns A promise that resolves to the balance amount.
|
6951
6981
|
*/
|
6952
6982
|
async getBalance(assetId) {
|
6953
|
-
const assetIdToFetch = assetId ?? this.provider.getBaseAssetId();
|
6983
|
+
const assetIdToFetch = assetId ?? await this.provider.getBaseAssetId();
|
6954
6984
|
const amount = await this.provider.getBalance(this.address, assetIdToFetch);
|
6955
6985
|
return amount;
|
6956
6986
|
}
|
@@ -6973,7 +7003,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
6973
7003
|
async fund(request, params) {
|
6974
7004
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee, gasPrice } = params;
|
6975
7005
|
const fee = request.maxFee;
|
6976
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7006
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
6977
7007
|
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || (0, import_math21.bn)(0);
|
6978
7008
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
6979
7009
|
amount: (0, import_math21.bn)(fee),
|
@@ -7045,12 +7075,12 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7045
7075
|
fundingAttempts += 1;
|
7046
7076
|
}
|
7047
7077
|
if (needsToBeFunded) {
|
7048
|
-
throw new
|
7049
|
-
|
7078
|
+
throw new import_errors22.FuelError(
|
7079
|
+
import_errors22.ErrorCode.NOT_ENOUGH_FUNDS,
|
7050
7080
|
`The account ${this.address} does not have enough base asset funds to cover the transaction execution.`
|
7051
7081
|
);
|
7052
7082
|
}
|
7053
|
-
this.provider.validateTransaction(request);
|
7083
|
+
await this.provider.validateTransaction(request);
|
7054
7084
|
request.updatePredicateGasUsed(estimatedPredicates);
|
7055
7085
|
const requestToReestimate = (0, import_ramda9.clone)(request);
|
7056
7086
|
if (addedSignatures) {
|
@@ -7077,7 +7107,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7077
7107
|
*/
|
7078
7108
|
async createTransfer(destination, amount, assetId, txParams = {}) {
|
7079
7109
|
let request = new ScriptTransactionRequest(txParams);
|
7080
|
-
request = this.addTransfer(request, {
|
7110
|
+
request = this.addTransfer(request, {
|
7111
|
+
destination,
|
7112
|
+
amount,
|
7113
|
+
assetId: assetId || await this.provider.getBaseAssetId()
|
7114
|
+
});
|
7081
7115
|
request = await this.estimateAndFundTransaction(request, txParams);
|
7082
7116
|
return request;
|
7083
7117
|
}
|
@@ -7117,11 +7151,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7117
7151
|
addTransfer(request, transferParams) {
|
7118
7152
|
const { destination, amount, assetId } = transferParams;
|
7119
7153
|
this.validateTransferAmount(amount);
|
7120
|
-
request.addCoinOutput(
|
7121
|
-
import_address6.Address.fromAddressOrString(destination),
|
7122
|
-
amount,
|
7123
|
-
assetId ?? this.provider.getBaseAssetId()
|
7124
|
-
);
|
7154
|
+
request.addCoinOutput(import_address6.Address.fromAddressOrString(destination), amount, assetId);
|
7125
7155
|
return request;
|
7126
7156
|
}
|
7127
7157
|
/**
|
@@ -7132,12 +7162,11 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7132
7162
|
* @returns The updated script transaction request.
|
7133
7163
|
*/
|
7134
7164
|
addBatchTransfer(request, transferParams) {
|
7135
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7136
7165
|
transferParams.forEach(({ destination, amount, assetId }) => {
|
7137
7166
|
this.addTransfer(request, {
|
7138
7167
|
destination,
|
7139
7168
|
amount,
|
7140
|
-
assetId
|
7169
|
+
assetId
|
7141
7170
|
});
|
7142
7171
|
});
|
7143
7172
|
return request;
|
@@ -7159,13 +7188,14 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7159
7188
|
...txParams
|
7160
7189
|
});
|
7161
7190
|
const quantities = [];
|
7191
|
+
const defaultAssetId = await this.provider.getBaseAssetId();
|
7162
7192
|
const transferParams = contractTransferParams.map((transferParam) => {
|
7163
7193
|
const amount = (0, import_math21.bn)(transferParam.amount);
|
7164
7194
|
const contractAddress = import_address6.Address.fromAddressOrString(transferParam.contractId);
|
7165
|
-
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) :
|
7195
|
+
const assetId = transferParam.assetId ? (0, import_utils37.hexlify)(transferParam.assetId) : defaultAssetId;
|
7166
7196
|
if (amount.lte(0)) {
|
7167
|
-
throw new
|
7168
|
-
|
7197
|
+
throw new import_errors22.FuelError(
|
7198
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7169
7199
|
"Transfer amount must be a positive number."
|
7170
7200
|
);
|
7171
7201
|
}
|
@@ -7205,7 +7235,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7205
7235
|
...amountDataArray
|
7206
7236
|
]);
|
7207
7237
|
const params = { script, ...txParams };
|
7208
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7238
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7209
7239
|
let request = new ScriptTransactionRequest(params);
|
7210
7240
|
const quantities = [{ amount: (0, import_math21.bn)(amount), assetId: baseAssetId }];
|
7211
7241
|
const txCost = await this.getTransactionCost(request, { quantities });
|
@@ -7230,7 +7260,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7230
7260
|
*/
|
7231
7261
|
async getTransactionCost(transactionRequestLike, { signatureCallback, quantities = [] } = {}) {
|
7232
7262
|
const txRequestClone = (0, import_ramda9.clone)(transactionRequestify(transactionRequestLike));
|
7233
|
-
const baseAssetId = this.provider.getBaseAssetId();
|
7263
|
+
const baseAssetId = await this.provider.getBaseAssetId();
|
7234
7264
|
const coinOutputsQuantities = txRequestClone.getCoinOutputsQuantities();
|
7235
7265
|
const requiredQuantities = mergeQuantities(coinOutputsQuantities, quantities);
|
7236
7266
|
const transactionFeeForDryRun = [{ assetId: baseAssetId, amount: (0, import_math21.bn)("100000000000000000") }];
|
@@ -7280,7 +7310,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7280
7310
|
*/
|
7281
7311
|
async signMessage(message) {
|
7282
7312
|
if (!this._connector) {
|
7283
|
-
throw new
|
7313
|
+
throw new import_errors22.FuelError(import_errors22.ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
|
7284
7314
|
}
|
7285
7315
|
return this._connector.signMessage(this.address.toString(), message);
|
7286
7316
|
}
|
@@ -7292,8 +7322,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7292
7322
|
*/
|
7293
7323
|
async signTransaction(transactionRequestLike) {
|
7294
7324
|
if (!this._connector) {
|
7295
|
-
throw new
|
7296
|
-
|
7325
|
+
throw new import_errors22.FuelError(
|
7326
|
+
import_errors22.ErrorCode.MISSING_CONNECTOR,
|
7297
7327
|
"A connector is required to sign transactions."
|
7298
7328
|
);
|
7299
7329
|
}
|
@@ -7306,10 +7336,13 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7306
7336
|
* @param sendTransactionParams - The provider send transaction parameters (optional).
|
7307
7337
|
* @returns A promise that resolves to the transaction response.
|
7308
7338
|
*/
|
7309
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true } = {}) {
|
7339
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = true, onBeforeSend, skipCustomFee = false } = {}) {
|
7310
7340
|
if (this._connector) {
|
7311
7341
|
return this.provider.getTransactionResponse(
|
7312
|
-
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike
|
7342
|
+
await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, {
|
7343
|
+
onBeforeSend,
|
7344
|
+
skipCustomFee
|
7345
|
+
})
|
7313
7346
|
);
|
7314
7347
|
}
|
7315
7348
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
@@ -7352,8 +7385,8 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7352
7385
|
/** @hidden * */
|
7353
7386
|
validateTransferAmount(amount) {
|
7354
7387
|
if ((0, import_math21.bn)(amount).lte(0)) {
|
7355
|
-
throw new
|
7356
|
-
|
7388
|
+
throw new import_errors22.FuelError(
|
7389
|
+
import_errors22.ErrorCode.INVALID_TRANSFER_AMOUNT,
|
7357
7390
|
"Transfer amount must be a positive number."
|
7358
7391
|
);
|
7359
7392
|
}
|
@@ -7382,16 +7415,16 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7382
7415
|
if (!(0, import_utils37.isDefined)(setGasLimit)) {
|
7383
7416
|
request.gasLimit = gasUsed;
|
7384
7417
|
} else if (gasUsed.gt(setGasLimit)) {
|
7385
|
-
throw new
|
7386
|
-
|
7418
|
+
throw new import_errors22.FuelError(
|
7419
|
+
import_errors22.ErrorCode.GAS_LIMIT_TOO_LOW,
|
7387
7420
|
`Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
|
7388
7421
|
);
|
7389
7422
|
}
|
7390
7423
|
if (!(0, import_utils37.isDefined)(setMaxFee)) {
|
7391
7424
|
request.maxFee = maxFee;
|
7392
7425
|
} else if (maxFee.gt(setMaxFee)) {
|
7393
|
-
throw new
|
7394
|
-
|
7426
|
+
throw new import_errors22.FuelError(
|
7427
|
+
import_errors22.ErrorCode.MAX_FEE_TOO_LOW,
|
7395
7428
|
`Max fee '${setMaxFee}' is lower than the required: '${maxFee}'.`
|
7396
7429
|
);
|
7397
7430
|
}
|
@@ -7402,7 +7435,7 @@ var Account = class extends import_interfaces.AbstractAccount {
|
|
7402
7435
|
// src/wallet/keystore-wallet.ts
|
7403
7436
|
var import_address7 = require("@fuel-ts/address");
|
7404
7437
|
var import_crypto6 = require("@fuel-ts/crypto");
|
7405
|
-
var
|
7438
|
+
var import_errors23 = require("@fuel-ts/errors");
|
7406
7439
|
var import_utils38 = require("@fuel-ts/utils");
|
7407
7440
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
7408
7441
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -7479,8 +7512,8 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
7479
7512
|
const macHashUint8Array = (0, import_crypto6.keccak256)(data);
|
7480
7513
|
const macHash = (0, import_crypto6.stringFromBuffer)(macHashUint8Array, "hex");
|
7481
7514
|
if (mac !== macHash) {
|
7482
|
-
throw new
|
7483
|
-
|
7515
|
+
throw new import_errors23.FuelError(
|
7516
|
+
import_errors23.ErrorCode.INVALID_PASSWORD,
|
7484
7517
|
"Failed to decrypt the keystore wallet, the provided password is incorrect."
|
7485
7518
|
);
|
7486
7519
|
}
|
@@ -7540,7 +7573,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
7540
7573
|
*/
|
7541
7574
|
async signTransaction(transactionRequestLike) {
|
7542
7575
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7543
|
-
const chainId = this.provider.getChainId();
|
7576
|
+
const chainId = await this.provider.getChainId();
|
7544
7577
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
7545
7578
|
const signature = await this.signer().sign(hashedTransaction);
|
7546
7579
|
return (0, import_utils39.hexlify)(signature);
|
@@ -7564,14 +7597,19 @@ var BaseWalletUnlocked = class extends Account {
|
|
7564
7597
|
* @param estimateTxDependencies - Whether to estimate the transaction dependencies.
|
7565
7598
|
* @returns A promise that resolves to the TransactionResponse object.
|
7566
7599
|
*/
|
7567
|
-
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false } = {}) {
|
7600
|
+
async sendTransaction(transactionRequestLike, { estimateTxDependencies = false, enableAssetBurn } = {}) {
|
7568
7601
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
7602
|
+
validateTransactionForAssetBurn(
|
7603
|
+
await this.provider.getBaseAssetId(),
|
7604
|
+
transactionRequest,
|
7605
|
+
enableAssetBurn
|
7606
|
+
);
|
7569
7607
|
if (estimateTxDependencies) {
|
7570
7608
|
await this.provider.estimateTxDependencies(transactionRequest);
|
7571
7609
|
}
|
7572
7610
|
return this.provider.sendTransaction(
|
7573
7611
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
7574
|
-
{ estimateTxDependencies: false }
|
7612
|
+
{ estimateTxDependencies: false, enableAssetBurn }
|
7575
7613
|
);
|
7576
7614
|
}
|
7577
7615
|
/**
|
@@ -7610,14 +7648,14 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
7610
7648
|
|
7611
7649
|
// src/hdwallet/hdwallet.ts
|
7612
7650
|
var import_crypto8 = require("@fuel-ts/crypto");
|
7613
|
-
var
|
7651
|
+
var import_errors26 = require("@fuel-ts/errors");
|
7614
7652
|
var import_hasher7 = require("@fuel-ts/hasher");
|
7615
7653
|
var import_math22 = require("@fuel-ts/math");
|
7616
7654
|
var import_utils43 = require("@fuel-ts/utils");
|
7617
7655
|
|
7618
7656
|
// src/mnemonic/mnemonic.ts
|
7619
7657
|
var import_crypto7 = require("@fuel-ts/crypto");
|
7620
|
-
var
|
7658
|
+
var import_errors25 = require("@fuel-ts/errors");
|
7621
7659
|
var import_hasher6 = require("@fuel-ts/hasher");
|
7622
7660
|
var import_utils41 = require("@fuel-ts/utils");
|
7623
7661
|
|
@@ -9674,7 +9712,7 @@ var english = [
|
|
9674
9712
|
];
|
9675
9713
|
|
9676
9714
|
// src/mnemonic/utils.ts
|
9677
|
-
var
|
9715
|
+
var import_errors24 = require("@fuel-ts/errors");
|
9678
9716
|
var import_hasher5 = require("@fuel-ts/hasher");
|
9679
9717
|
var import_utils40 = require("@fuel-ts/utils");
|
9680
9718
|
function getLowerMask(bits) {
|
@@ -9723,8 +9761,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9723
9761
|
for (let i = 0; i < words.length; i += 1) {
|
9724
9762
|
const index = wordlist.indexOf(words[i].normalize("NFKD"));
|
9725
9763
|
if (index === -1) {
|
9726
|
-
throw new
|
9727
|
-
|
9764
|
+
throw new import_errors24.FuelError(
|
9765
|
+
import_errors24.ErrorCode.INVALID_MNEMONIC,
|
9728
9766
|
`Invalid mnemonic: the word '${words[i]}' is not found in the provided wordlist.`
|
9729
9767
|
);
|
9730
9768
|
}
|
@@ -9740,8 +9778,8 @@ function mnemonicWordsToEntropy(words, wordlist) {
|
|
9740
9778
|
const checksumMask = getUpperMask(checksumBits);
|
9741
9779
|
const checksum = (0, import_utils40.arrayify)((0, import_hasher5.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
|
9742
9780
|
if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
|
9743
|
-
throw new
|
9744
|
-
|
9781
|
+
throw new import_errors24.FuelError(
|
9782
|
+
import_errors24.ErrorCode.INVALID_CHECKSUM,
|
9745
9783
|
"Checksum validation failed for the provided mnemonic."
|
9746
9784
|
);
|
9747
9785
|
}
|
@@ -9755,16 +9793,16 @@ var TestnetPRV = "0x04358394";
|
|
9755
9793
|
var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
|
9756
9794
|
function assertWordList(wordlist) {
|
9757
9795
|
if (wordlist.length !== 2048) {
|
9758
|
-
throw new
|
9759
|
-
|
9796
|
+
throw new import_errors25.FuelError(
|
9797
|
+
import_errors25.ErrorCode.INVALID_WORD_LIST,
|
9760
9798
|
`Expected word list length of 2048, but got ${wordlist.length}.`
|
9761
9799
|
);
|
9762
9800
|
}
|
9763
9801
|
}
|
9764
9802
|
function assertEntropy(entropy) {
|
9765
9803
|
if (entropy.length % 4 !== 0 || entropy.length < 16 || entropy.length > 32) {
|
9766
|
-
throw new
|
9767
|
-
|
9804
|
+
throw new import_errors25.FuelError(
|
9805
|
+
import_errors25.ErrorCode.INVALID_ENTROPY,
|
9768
9806
|
`Entropy should be between 16 and 32 bytes and a multiple of 4, but got ${entropy.length} bytes.`
|
9769
9807
|
);
|
9770
9808
|
}
|
@@ -9774,7 +9812,7 @@ function assertMnemonic(words) {
|
|
9774
9812
|
const errorMsg = `Invalid mnemonic size. Expected one of [${MNEMONIC_SIZES.join(
|
9775
9813
|
", "
|
9776
9814
|
)}] words, but got ${words.length}.`;
|
9777
|
-
throw new
|
9815
|
+
throw new import_errors25.FuelError(import_errors25.ErrorCode.INVALID_MNEMONIC, errorMsg);
|
9778
9816
|
}
|
9779
9817
|
}
|
9780
9818
|
var Mnemonic = class {
|
@@ -9892,8 +9930,8 @@ var Mnemonic = class {
|
|
9892
9930
|
static masterKeysFromSeed(seed) {
|
9893
9931
|
const seedArray = (0, import_utils41.arrayify)(seed);
|
9894
9932
|
if (seedArray.length < 16 || seedArray.length > 64) {
|
9895
|
-
throw new
|
9896
|
-
|
9933
|
+
throw new import_errors25.FuelError(
|
9934
|
+
import_errors25.ErrorCode.INVALID_SEED,
|
9897
9935
|
`Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
|
9898
9936
|
);
|
9899
9937
|
}
|
@@ -9970,7 +10008,7 @@ function isValidExtendedKey(extendedKey) {
|
|
9970
10008
|
function parsePath(path2, depth = 0) {
|
9971
10009
|
const components = path2.split("/");
|
9972
10010
|
if (components.length === 0 || components[0] === "m" && depth !== 0) {
|
9973
|
-
throw new
|
10011
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, `invalid path - ${path2}`);
|
9974
10012
|
}
|
9975
10013
|
if (components[0] === "m") {
|
9976
10014
|
components.shift();
|
@@ -9999,8 +10037,8 @@ var HDWallet = class {
|
|
9999
10037
|
this.privateKey = (0, import_utils43.hexlify)(config.privateKey);
|
10000
10038
|
} else {
|
10001
10039
|
if (!config.publicKey) {
|
10002
|
-
throw new
|
10003
|
-
|
10040
|
+
throw new import_errors26.FuelError(
|
10041
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10004
10042
|
"Both public and private Key cannot be missing. At least one should be provided."
|
10005
10043
|
);
|
10006
10044
|
}
|
@@ -10029,8 +10067,8 @@ var HDWallet = class {
|
|
10029
10067
|
const data = new Uint8Array(37);
|
10030
10068
|
if (index & HARDENED_INDEX) {
|
10031
10069
|
if (!privateKey) {
|
10032
|
-
throw new
|
10033
|
-
|
10070
|
+
throw new import_errors26.FuelError(
|
10071
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10034
10072
|
"Cannot derive a hardened index without a private Key."
|
10035
10073
|
);
|
10036
10074
|
}
|
@@ -10082,8 +10120,8 @@ var HDWallet = class {
|
|
10082
10120
|
*/
|
10083
10121
|
toExtendedKey(isPublic = false, testnet = false) {
|
10084
10122
|
if (this.depth >= 256) {
|
10085
|
-
throw new
|
10086
|
-
|
10123
|
+
throw new import_errors26.FuelError(
|
10124
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10087
10125
|
`Exceeded max depth of 255. Current depth: ${this.depth}.`
|
10088
10126
|
);
|
10089
10127
|
}
|
@@ -10114,10 +10152,10 @@ var HDWallet = class {
|
|
10114
10152
|
const bytes = (0, import_utils43.arrayify)(decoded);
|
10115
10153
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
10116
10154
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
10117
|
-
throw new
|
10155
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
|
10118
10156
|
}
|
10119
10157
|
if (!validChecksum) {
|
10120
|
-
throw new
|
10158
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
10121
10159
|
}
|
10122
10160
|
const depth = bytes[4];
|
10123
10161
|
const parentFingerprint = (0, import_utils43.hexlify)(bytes.slice(5, 9));
|
@@ -10125,14 +10163,14 @@ var HDWallet = class {
|
|
10125
10163
|
const chainCode = (0, import_utils43.hexlify)(bytes.slice(13, 45));
|
10126
10164
|
const key = bytes.slice(45, 78);
|
10127
10165
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
10128
|
-
throw new
|
10129
|
-
|
10166
|
+
throw new import_errors26.FuelError(
|
10167
|
+
import_errors26.ErrorCode.HD_WALLET_ERROR,
|
10130
10168
|
"Inconsistency detected: Depth is zero but fingerprint/index is non-zero."
|
10131
10169
|
);
|
10132
10170
|
}
|
10133
10171
|
if (isPublicExtendedKey(bytes)) {
|
10134
10172
|
if (key[0] !== 3) {
|
10135
|
-
throw new
|
10173
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid public extended key.");
|
10136
10174
|
}
|
10137
10175
|
return new HDWallet({
|
10138
10176
|
publicKey: key,
|
@@ -10143,7 +10181,7 @@ var HDWallet = class {
|
|
10143
10181
|
});
|
10144
10182
|
}
|
10145
10183
|
if (key[0] !== 0) {
|
10146
|
-
throw new
|
10184
|
+
throw new import_errors26.FuelError(import_errors26.ErrorCode.HD_WALLET_ERROR, "Invalid private extended key.");
|
10147
10185
|
}
|
10148
10186
|
return new HDWallet({
|
10149
10187
|
privateKey: key.slice(1),
|
@@ -10387,26 +10425,26 @@ var WalletsConfig = class {
|
|
10387
10425
|
amountPerCoin
|
10388
10426
|
}) {
|
10389
10427
|
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
10390
|
-
throw new
|
10391
|
-
|
10428
|
+
throw new import_errors27.FuelError(
|
10429
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10392
10430
|
"Number of wallets must be greater than zero."
|
10393
10431
|
);
|
10394
10432
|
}
|
10395
10433
|
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
10396
|
-
throw new
|
10397
|
-
|
10434
|
+
throw new import_errors27.FuelError(
|
10435
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10398
10436
|
"Number of assets per wallet must be greater than zero."
|
10399
10437
|
);
|
10400
10438
|
}
|
10401
10439
|
if (coinsPerAsset <= 0) {
|
10402
|
-
throw new
|
10403
|
-
|
10440
|
+
throw new import_errors27.FuelError(
|
10441
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10404
10442
|
"Number of coins per asset must be greater than zero."
|
10405
10443
|
);
|
10406
10444
|
}
|
10407
10445
|
if (amountPerCoin < 0) {
|
10408
|
-
throw new
|
10409
|
-
|
10446
|
+
throw new import_errors27.FuelError(
|
10447
|
+
import_errors27.FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
10410
10448
|
"Amount per coin must be greater than or equal to zero."
|
10411
10449
|
);
|
10412
10450
|
}
|
@@ -10459,7 +10497,8 @@ async function setupTestProviderAndWallets({
|
|
10459
10497
|
}
|
10460
10498
|
let provider;
|
10461
10499
|
try {
|
10462
|
-
provider =
|
10500
|
+
provider = new Provider(url, providerOptions);
|
10501
|
+
await provider.init();
|
10463
10502
|
} catch (err) {
|
10464
10503
|
cleanup();
|
10465
10504
|
throw err;
|